diff options
Diffstat (limited to 'Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-ltxhash.html')
-rw-r--r-- | Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-ltxhash.html | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-ltxhash.html b/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-ltxhash.html new file mode 100644 index 00000000000..0e3d777727f --- /dev/null +++ b/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-ltxhash.html @@ -0,0 +1,55 @@ +<head> +<title>UK TeX FAQ -- question label ltxhash</title> +</head><body> +<h3>Defining LaTeX commands within other commands</h3> +<p/>LaTeX command definition is significantly different from the TeX +primitive form discussed in an +<a href="FAQ-hash.html">earlier question</a> about definitions within +macros. +<p/>In most ways, the LaTeX situation is simpler (at least in part +because it imposes more restrictions on the user); however, defining a +command within a command still requires some care. +<p/>The earlier question said you have to double the <code>#</code> signs in command +definitions: in fact, the same rule holds, except that LaTeX +already takes care of some of the issues, by generating argument lists +for you. +<p/>The basic problem is that: +<blockquote> +<pre> +\newcommand{\abc}[1]{joy, oh #1!% + \newcommand{\ghi}[1]{gloom, oh #1!}% +} +</pre> +</blockquote><p> +followed by a call: +<blockquote> +<pre> +\cmdinvoke{abc}{joy} +</pre> +</blockquote><p> +typesets “joy, oh joy!”, but defines a command <code>\</code><code>ghi</code> that takes +one parameter, which it ignores; <code>\</code><code>ghi{gloom}</code> will expand to +“gloom, oh joy!”, which is presumably not what was expected. +<p/>And (as you will probably guess, if you’ve read the earlier question) +the definition: +<blockquote> +<pre> +\newcommand{\abc}[1]{joy, oh #1!% + \newcommand{\ghi}[1]{gloom, oh ##1!}% +} +</pre> +</blockquote><p> +does what is required, and <code>\</code><code>ghi{gloom}</code> will expand to +“gloom, oh gloom!”, whatever the argument to <code>\</code><code>abc</code>. +<p/>The doubling is needed whether or not the enclosing command has an +argument, so: +<blockquote> +<pre> +\newcommand{\abc}{joy, oh joy!% + \newcommand{\ghi}[1]{gloom, oh ##1!}% +} +</pre> +</blockquote><p> +is needed to produce a replica of the <code>\</code><code>ghi</code> we defined earlier. +<p/><p/><p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=ltxhash">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=ltxhash</a> +</body> |