diff options
author | Karl Berry <karl@freefriends.org> | 2007-12-28 19:57:02 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2007-12-28 19:57:02 +0000 |
commit | c7cfef6687f65c2538898ddd7c6bc9c9ba50e58d (patch) | |
tree | 8f4de70d1a11463779871162ba84c1dbc874155b /Master/texmf-doc/doc/english/FAQ-en/html/FAQ-twooptarg.html | |
parent | 8948a31a6e2ac27883f7adac1b339003961ba43f (diff) |
uk-tex-faq 3.17 (7nov07)
git-svn-id: svn://tug.org/texlive/trunk@5977 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-doc/doc/english/FAQ-en/html/FAQ-twooptarg.html')
-rw-r--r-- | Master/texmf-doc/doc/english/FAQ-en/html/FAQ-twooptarg.html | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-twooptarg.html b/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-twooptarg.html index 16c3aae2ed0..bb7b1a8208c 100644 --- a/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-twooptarg.html +++ b/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-twooptarg.html @@ -2,18 +2,19 @@ <title>UK TeX FAQ -- question label twooptarg</title> </head><body> <h3>More than one optional argument</h3> -<p>If you’ve already read +<p/>If you’ve already read “<a href="FAQ-moren9.html">breaking the 9-argument limit</a>”. -you can probably guess the solution to this problem: command relaying. -<p>LaTeX allows commands with a single optional argument thus: +you can probably guess the “simple” solution to this problem: +command relaying. +<p/>LaTeX allows commands with a single optional argument thus: <pre> \newcommand{\blah}[1][Default]{...} </pre> -<p>You may legally call such a command either with its optional argument +<p/>You may legally call such a command either with its optional argument present, as -<code>\</code><code>blah[nonDefault]</code> or as <code>\</code><code>blah</code>; in the latter case, the -code of <code>\</code><code>blah</code> will have an argument of <code>Default</code>. -<p>To define a command with two optional arguments, we use the relaying +<code>\</code><code>blah[nonDefault]</code> or without, as <code>\</code><code>blah</code>; in the latter +case, the code of <code>\</code><code>blah</code> will have an argument of <code>Default</code>. +<p/>To define a command with two optional arguments, we use the relaying technique, as follows: <pre> \newcommand{\blah}[1][Default1]{% @@ -30,32 +31,48 @@ technique, as follows: Of course, <code>\</code><code>BlahRelay</code> may have as many mandatory arguments as are allowed, after allowance for the one taken up with its own optional argument — that is, 8. -<p>Variants of <code>\</code><code>newcommand</code> (and friends), with names like +<p/>Variants of <code>\</code><code>newcommand</code> (and friends), with names like <code>\</code><code>newcommandtwoopt</code>, are available in the <i>twoopt</i> package. However, if you can, it’s probably better to learn to write the commands yourself, just to see why they’re not even a good idea from the programming point of view. -<p>A command with two optional arguments strains the limit of what’s +<p/>A command with two optional arguments strains the limit of what’s sensible: obviously you can extend the technique to provide as many optional arguments as your fevered imagination can summon. However, see the comments on the use of the <i>keyval</i> package, in “<a href="FAQ-moren9.html">breaking the 9-argument limit</a>”, which offers an alternative way forward. -<p>If you must, however, consider the <i>optparams</i> package; +<p/>If you must, however, consider the <i>optparams</i> or +<i>xargs</i> packages. <i>Optparams</i> provides a <code>\</code><code>optparams</code> command that you use as an intermediate in defining commands with up to nine optional arguments. The documentation shows examples of commands with four optional arguments (and this from an author who has his own key-value package!). -<p>An alternative approach is offered by Scott Pakin’s +<p/>The <i>xargs</i> package uses a key-value package +(<i>xkeyval</i>) to <em>define</em> the layout of the optional +arguments. Thus +<blockquote> +<pre> +\usepackage{xargs} +... +\newcommandx{\foo}[3][1=1, 3=n]{...} +</pre> +</blockquote><p> +defines a command <code>\</code><code>foo</code> that has an optional first argument +(default 1), a mandatory second argument, and an optional third +argument (default n). +<p/>An alternative approach is offered by Scott Pakin’s <i>newcommand</i> program, which takes a command name and a definition of a set of command arguments (in a fairly readily-understood language), and emits (La)TeX macros which enable the command to be defined. The command requires that a -<i>Python</i> system be installed on your computer. +<i>Python</i> interpreter (etc.) be installed on your computer. <dl> <dt><tt><i>newcommand.py</i></tt><dd><a href="ftp://cam.ctan.org/tex-archive/support/newcommand.zip">support/newcommand</a> (<a href="ftp://cam.ctan.org/tex-archive/support/newcommand.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/support/newcommand/">browse</a>) <dt><tt><i>optparams.sty</i></tt><dd>Distributed as part of <a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/sauerj.zip">macros/latex/contrib/sauerj</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/sauerj.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/sauerj/">browse</a>) <dt><tt><i>twoopt.sty</i></tt><dd>Distributed as part of <a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/oberdiek.zip">macros/latex/contrib/oberdiek</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/oberdiek.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/oberdiek/">browse</a>) +<dt><tt><i>xargs.sty</i></tt><dd><a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/xargs.zip">macros/latex/contrib/xargs</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/xargs.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/xargs/">browse</a>) +<dt><tt><i>xkeyval.sty</i></tt><dd><a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/xkeyval.zip">macros/latex/contrib/xkeyval</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/xkeyval.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/xkeyval/">browse</a>) </dl> -<p><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=twooptarg">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=twooptarg</a> +<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=twooptarg">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=twooptarg</a> </body> |