summaryrefslogtreecommitdiff
path: root/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-cmdstar.html
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-doc/doc/english/FAQ-en/html/FAQ-cmdstar.html')
-rw-r--r--Master/texmf-doc/doc/english/FAQ-en/html/FAQ-cmdstar.html68
1 files changed, 68 insertions, 0 deletions
diff --git a/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-cmdstar.html b/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-cmdstar.html
new file mode 100644
index 00000000000..0caaa1afd29
--- /dev/null
+++ b/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-cmdstar.html
@@ -0,0 +1,68 @@
+<head>
+<title>UK TeX FAQ -- question label cmdstar</title>
+</head><body>
+<h3>Commands defined with * options</h3>
+<p>LaTeX commands commonly have "versions" defined with an asterisk
+tagged onto their name: for example <code>\</code><code>newcommand</code> and
+<code>\</code><code>newcommand*</code> (the former defines a <code>\</code><code>long</code> version of the
+command).
+<p>The simple-minded way for a user to write such a command involves use
+of the <i>ifthen</i> package:
+<blockquote>
+<pre>
+\newcommand{\mycommand}[1]{\ifthenelse{\equal{#1}{*}}%
+ {\mycommandStar}%
+ {\mycommandNoStar{#1}}%
+}
+\newcommand{\mycommandStar}{starred version}
+\newcommand{\mycommandNoStar}[1]{normal version}
+</pre>
+</blockquote>
+
+This does the trick, for sufficiently simple commands, but it has
+various tiresome failure modes, and it requires <code>\</code><code>mycommandnostar</code>
+to take an argument.
+<p>Of course, the LaTeX kernel has something slicker than this:
+<blockquote>
+<pre>
+\newcommand{\mycommand}[1]{\@ifstar
+ \mycommandStar%
+ \mycommandNoStar%
+}
+\newcommand{\mycommandStar}{starred version}
+\newcommand{\mycommandNoStar}{normal version}
+</pre>
+</blockquote>
+Which is all very well, is fast and efficient, but requires the
+definition to be <a href="FAQ-atsigns.html"><code>\</code><code>makeatletter</code> protected</a>.
+The technique doesn't interfere at all with the definitions of
+<code>\</code><code>mycommandStar</code> or <code>\</code><code>mycommandNoStar</code>; they can have any
+combination of optional and mandatory arguments that you could define
+them to have in the ordinary way.
+<p>A pleasing alternative is the <i>suffix</i> package. This elegant
+piece of code allows you to define variants of your commands:
+
+<blockquote>
+<pre>
+\newcommand\mycommand{normal version}
+\WithSuffix\newcommand\mycommand*{starred version}
+</pre>
+</blockquote>
+The package needs <a href="FAQ-NTS.html">e-LaTeX</a>, but any new enough
+distribution defines LaTeX as e-LaTeX by default. Command
+arguments may be specified in the normal way, in both command
+definitions (after the "<code>*</code>" in the <code>\</code><code>WithSuffix</code>
+version). You can also use the TeX primitive commands, creating a
+definition like:
+<blockquote>
+<pre>
+\WithSuffix\gdef\mycommand*{starred version}
+</pre>
+</blockquote>
+<dl>
+<dt><tt><i>ifthen.sty</i></tt><dd>Part of the LaTeX distribution
+<dt><tt><i>suffix.sty</i></tt><dd>Distributed as part of <a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/bigfoot.zip">macros/latex/contrib/bigfoot</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/bigfoot.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/bigfoot/">browse</a>)
+</dl>
+<p>
+<p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=cmdstar">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=cmdstar</a>
+</body>