1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<head>
<title>UK TeX FAQ -- question label moren9</title>
</head><body>
<h3>How to break the 9-argument limit</h3>
<p/>If you think about it, you will realise that Knuth’s command
definition syntax:
<blockquote>
<pre>
\def\blah#1#2 ... #9{<macro body>}
</pre>
</blockquote><p>
is intrinsically limited to just 9 arguments. There’s no direct way
round this: how would you express a 10th argument? — and ensure that
the syntax didn’t gobble some other valid usage?
<p/>If you really must have more than 9 arguments, the way to go is:
<blockquote>
<pre>
\def\blah#1#2 ... #9{%
\def\ArgI{{#1}}%
\def\ArgII{{#2}}%
...
\def\ArgIX{{#9}}%
\BlahRelay
}
\def\BlahRelay#1#2#3{%
% arguments 1-9 are now in
% \ArgI-\ArgIX
% arguments 10-12 are in
% #1-#3
<macro body>%
}
</pre>
</blockquote><p>
This technique is easily extendible by concert pianists of the TeX
keyboard, but is really hard to recommend.
<p/>LaTeX users have the small convenience of merely giving a number of
arguments in the <code>\</code><code>newcommand</code> that defines each part of the
relaying mechanism: Knuth’s restriction applies to <code>\</code><code>newcommand</code>
just as it does to <code>\</code><code>def</code>. However, LaTeX users also have the
way out of such barbarous command syntax: the <i>keyval</i>
package. With <i>keyval</i>, and a bit of programming, one can
write really quite sophisticated commands, whose invocation might look
like:
<blockquote>
<pre>
\flowerinstance{species=Primula veris,
family=Primulaceae,
location=Coldham's Common,
locationtype=Common grazing land,
date=1995/04/24,
numplants=50,
soiltype=alkaline
}
</pre>
</blockquote><p>
The merit of such verbosity is that it is self-explanatory: the typist
doesn’t have to remember that argument twelve is <code>soiltype</code>, and so
on: the commands may be copied from field notes quickly and
accurately.
<dl>
<dt><tt><i>keyval.sty</i></tt><dd>Distributed as part of <a href="ftp://cam.ctan.org/tex-archive/macros/latex/required/graphics.zip">macros/latex/required/graphics</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/required/graphics.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/required/graphics/">browse</a>)
</dl>
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=moren9">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=moren9</a>
</body>
|