Monday, 17 September 2012

LaTeX command with more than 9 argments

Upon my return from my field trip over the weekend, I have a number of samples to deal to, including a bunch of soil samples. With these samples, the opportunity exists to give a substantial amount more information than is possible on insect labels. Some of this information includes details of the landform and management practises of the area that the sample was collected.

To create the labels, I have enlisted the power of LaTeX (as one would probably expect). As I want the same headings on all samples, I wanted to create a command that includes all these details. However, I want more than 9 arguments, which is not allowed in general LaTeX commands. Searching for options to get around this problem, I found that it was a FAQ on the UK TeX list: How to break the 9-argument limit. Their helpful suggestion of using keyval wasn't backed up by an explicit example of how to implement it. The following code shows how to implement their example:

\usepackage{keyval}

\newcommand{\flowerinstance}[1]{\setkeys{flwr}{#1}}

\makeatletter
\define@key{flwr}{species}{\textbf{Species:} \emph{#1}\\}
\define@key{flwr}{family}{\textbf{Family:} #1\\}
\define@key{flwr}{location}{\textbf{Location:} #1\\}
\define@key{flwr}{locationtype}{\textbf{Location type:} #1\\}
\define@key{flwr}{date}{\textbf{Date:} #1\\}
\define@key{flwr}{numplants}{\textbf{Number of plants:} #1\\}
\define@key{flwr}{soiltype}{\textbf{Soil type:} #1\\}
\makeatother

\begin{document}

\flowerinstance{species=Primula veris,
family=Primulaceae,
location=Coldham's Common,
locationtype=Common grazing land,
date=1995/04/24,
numplants=50,
soiltype=alkaline
}

\end{document}
For more details regarding soil sampling which can be easily extended to other sorts of samples, see the Soil Description Handbook published by Manaaki Whenua Press.

No comments: