LaTeX commands commonly have "versions" defined with an asterisk
tagged onto their name: for example \
newcommand
and
\
newcommand*
(the former defines a \
long
version of the
command).
The simple-minded way for a user to write such a command involves use of the ifthen package:
This does the trick, for sufficiently simple commands, but it has various tiresome failure modes, and it requires\newcommand{\mycommand}[1]{\ifthenelse{\equal{#1}{*}}% {\mycommandStar}% {\mycommandNoStar{#1}}% } \newcommand{\mycommandStar}{starred version} \newcommand{\mycommandNoStar}[1]{normal version}
\
mycommandnostar
to take an argument.
Of course, the LaTeX kernel has something slicker than this:
Which is all very well, is fast and efficient, but requires the definition to be\newcommand{\mycommand}[1]{\@ifstar \mycommandStar% \mycommandNoStar% } \newcommand{\mycommandStar}{starred version} \newcommand{\mycommandNoStar}{normal version}
\
makeatletter
protected.
The technique doesn't interfere at all with the definitions of
\
mycommandStar
or \
mycommandNoStar
; they can have any
combination of optional and mandatory arguments that you could define
them to have in the ordinary way.
A pleasing alternative is the suffix package. This elegant piece of code allows you to define variants of your commands:
The package needs e-LaTeX, 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 "\newcommand\mycommand{normal version} \WithSuffix\newcommand\mycommand*{starred version}
*
" in the \
WithSuffix
version). You can also use the TeX primitive commands, creating a
definition like:
\WithSuffix\gdef\mycommand*{starred version}
This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=cmdstar