While writing a package with a key-value interface,
I had a lot of repetitive key definitions.
Naturally, one would like to express these definitions with a loop.
When the definition contains something more complicated like \PassOptionsToPackage, things get messy. The degree of messiness depends on the package used for the loops. etoolbox complains a lot, forarray not so much. Minimal working example for forarray:
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{package}
[2012/09/18 Example]
\RequirePackage{keyreader}
\RequirePackage{forarray}
\DeclareOptionX*{%
\PackageWarningNoLine{}{Cant understand option(s): \CurrentOption}%
}
\CommandForEach{,}{%
\krdDeclareOption{#1}{\PassOptionsToPackage{##1}{#1}}%
}%
{todonotes}
\krdProcessOptions
This is the package, and the latex file is
\documentclass{article}
\usepackage[todonotes=shadow]{package}
\usepackage{todonotes}
\begin{document}
\todo{2 do}
\end{document}
This produces the warning
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.13 {todonotes}
?
No greater harm done, pressing return brings it to the end. Only the todonotes in the documents remains of the trouble, but the todo box has a nice shadow. What is wrong here?
\CommandForEach, you have to use a command as one token as second argument and the list element in the third argument need an additional pair of curly braces. There are better ways to parse comma separated lists. – Heiko Oberdiek Sep 18 '12 at 19:14