# Meaning of an asterisk (*) in a macro name



Are there any guidelines about how to chose which version of a macro should be the starred condition?

• Possible duplicate of "Do all starred commands have anything in common?" (tex.stackexchange.com/questions/30456/…) and the associated answers? – Mico Feb 22 '12 at 12:51
• @mico thanks, I wasn't aware of that question. I am not sure it is a duplicate, but it is definitely close. I read that question as asking about why/when to use a * and my question is about given you have decided to use a * ... – StrongBad Feb 22 '12 at 13:05

As far as I know there are no such guidelines. As the author (and user) of a macro, you can decide how to use the starred version. But for a little consistency I’d use the star as mark for not numbered if the macro does something with numbering (as in your example).

Otherwise I’d prefer to use the non starred version as default (often used) and the starred version as special.


To define a starred macro one can use the LaTeX way with \@ifstar or the xparse package, which I prefer since you need no helper macros:

\documentclass{article}

\usepackage{xparse}

\NewDocumentCommand\foo{ s m }{% s = star, m = mandatory arg
\IfBooleanTF{#1}{%
Argument: #2 (starred)%
}{%
Argument: #2 (non-starred)%
}%
}

\begin{document}
\foo{Test}

\foo*{Test}
\end{document}
• I agree with this. I was in the process of drafting a similar kind of reply. The only reason why it took me so long is that I am not sure if \newcommand should be the default. I think it depends on the implementor. – user10274 Feb 22 '12 at 12:10

The general rule is that \command stands for default action and \command* stands for alternative action. Determine which behaviour is what and define your command accordingly. If you cannot categorize either behaviour as alternative, then it might be better to have two different commands altogether.


I defined a simple command, and it won't work for an argument such as

{a

b}

, and I don't understand why!

Or it could have been for historical reasons as well (a particular decision made in the beginning, can't be changed afterwards).

• \newcommand was in LaTeX since the beginning, the * form was added in LaTeX2e and we couldn't change the default behaviour. – David Carlisle Feb 22 '12 at 13:00
• @DavidCarlisle if \newcommand hadn't been in LaTeX since the beginning, or the need for the short version had been realized, do you think the * behavior would have been reversed? – StrongBad Feb 22 '12 at 15:06
• @DanielE.Shub "if" questions are not really answerable:-) For document level definitions the long form is probably the correct default, as it makes the macro work the same way as its replacement text. However for internal coding where often you are passing around small fragments and working at a level where such coding judgement is needed anyway, defaulting to non-long is probably right. So this works well in 2e where document authors use \newcommand in documents but package writers (mostly) use \def in lower level code, but it was never really discussed as there was no choice at the time – David Carlisle Feb 22 '12 at 15:33