%% This is file `plantslabels.sty' v1.0 by Merciadri Luca.
% Many thanks to Enrico Gregorio for his help.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{plantslabels}[2010/04/05 Writing plant labels]
\PackageInfo{plantslabels}{This is Plantslabels by Merciadri Luca.}

\PassOptionsToPackage{newdimens}{labels}
\RequirePackage{labels}[2003/05/22]
\RequirePackage{graphicx}[2005/12/01]

\LeftPageMargin=2mm% These four parameters give the
\RightPageMargin=2mm% page gutter sizes. The outer edges of
\TopPageMargin=2mm% the outer labels are the specified
\BottomPageMargin=2mm% distances from the edge of the paper.
\InterLabelColumn=1mm% Gap between columns of labels
\InterLabelRow=1mm% Gap between rows of labels
\LeftLabelBorder=5mm% These four parameters give the extra
\RightLabelBorder=5mm% space used around the text on each
\TopLabelBorder=5mm% actual label.
\BottomLabelBorder=5mm%

\newsavebox{\mybox}

\newcommand{\lm@measurebox}[5]{%
  \sbox\mybox{%
    \begin{tabular}{cc}
    \ifx\relax#1\relax\else \textbf{Name} & \textit{#1}\\ \fi
    \ifx\relax#2\relax\else \textbf{Price} & #2\,\ #3\\ \fi
    \ifx\relax#4\relax\else \textbf{Temperature} & #4\\ \fi
    \ifx\relax#5\relax\else \textbf{Substratum} & #5\\ \fi
    \end{tabular}%
  }%
}

\newcommand{\lm@ig}[1]{\multicolumn{2}{c}{%
    \includegraphics[width=0.33\wd\mybox,
      height=0.33\ht\mybox,
      keepaspectratio]{#1}}}

\newcommand{\plant}[9]{%
  \renewcommand{\LabelCols}{#1}%
  \renewcommand{\LabelRows}{#2}%
  \renewcommand{\numberoflabels}{#3}%
  \lm@measurebox{#4}{#5}{#6}{#7}{#8}%
  \addresslabel[\fboxsep=0pt]{%
    \fbox{%
      \begin{tabular}{cc}
      \ifx\relax#4\relax\else \textbf{Name} & \textit{#4}\\ \fi
      \ifx\relax#5\relax\else \textbf{Price} & #5\,\ #6\\ \fi
      \ifx\relax#7\relax\else \textbf{Temperature} & #7\\ \fi
      \ifx\relax#8\relax\else \textbf{Substratum} & #8\\ \fi
      \ifx\relax#9\relax\else \lm@ig{#9} \fi
      \end{tabular}%
    }%
  }%
}
\relax
