# Do starred commands eat up space after them?

Do starred commands eat up spaces after them, like unstarred ones do? That is, is \somecommand* nextword equivalent to \somecommand*nextword?

And: Does it depend on the particular way a starred command is defined?

Edit: Note that the original version of my question left out me considering only zero-argument commands. I was assuming this, and it was mostly clear (albeit implicit) from the question statement. User @tohecz has written a valuable answer (to the pre-edit version) addressing this detail.

Note that I'm asking about commands with a star at the end of their name (\somecommand*), not about whether the command was defined using a starred defining command (e.g. with \newcommand*).

-
This should be fairly easy to test or am I missing something? Behavior really should be the same as without the *, unless the macro was designed to do things differently based on the presence or absence of the *. –  Peter Grill Feb 11 '13 at 5:07
@PeterGrill Yeah :-) I was gonna test it but then found that there are a handful of different ways of doing things (e.g. what's in the UK TeX FAQ). I figured someone might already know this already, if the answer is method-independent (for the methods that are presently used). –  Lover of Structure Feb 11 '13 at 5:12

No they don't:

\documentclass{article}
\usepackage{suffix,xparse}% http://ctan.org/pkg/{suffix,xparse}
\makeatletter
\newcommand{\mycmdA}{\@ifstar
\mycmdA@star% \mycmd*
\mycmdA@nostar% \mycmd
}
\newcommand{\mycmdA@star}{A1}
\newcommand{\mycmdA@nostar}{A2}
\NewDocumentCommand{\mycmdB}{s}{%
B\IfBooleanTF{#1}{1}{2}}
\newcommand{\mycmdC}{C1}
\WithSuffix\newcommand\mycmdC*{C2}
\makeatother
\begin{document}
Here is \mycmdA and \mycmdA* in one line. \par
Here is \mycmdB and \mycmdB* in one line. \par
Here is \mycmdC and \mycmdC* in one line.
\end{document}

-
By the way, see my comment in the tohecz thread. –  Lover of Structure Feb 12 '13 at 0:58

As the other answers show, they do not. However, the spaces get "eaten" if the macro takes other arguments after *:

\documentclass{article}

\pagestyle{empty}

\begin{document}

\section {Hello}
\section* {World!}

\end{document}


In general, TeX ignores all spaces when looking for an argument (unless it is not, which is when an argument is delimited (like optional arguments are):

\newcommand{\foo}[1][A]{(#1)}
\foo [abc]    % prints: (abc)
\foo[abc]     % prints: (abc)
\foo [ abc]   % prints: ( abc)
\foo[ abc]    % prints: ( abc)

\def\baz|#1|{(#1)}
\baz |abc|    % prints: (abc)
\baz|abc|     % prints: (abc)
\baz | abc|   % prints: ( abc)
\baz| abc|    % prints: ( abc)

-
Good point; see my edit to the question statement. –  Lover of Structure Feb 11 '13 at 7:52
@LoverofStructure Despite not being what you ask for, it seems to be a consensus here that we treat even the closely-related stuff, in the sense of "wiki-like" approach ;) –  tohecz Feb 11 '13 at 7:59
I welcome your answer and I think it belongs here. (Just like other informative edits and questions, though some other SE sites have a more rigid approach towards the latter.) But it's also good that I clarified the scope of my question; it'll prevent confusion. More importantly I'd find it weird not to tell you about my edit :-) –  Lover of Structure Feb 11 '13 at 8:12
Agreed :) . –  tohecz Feb 11 '13 at 9:02
@LoverofStructure: This is intentional. All spaces after a control sequence is gobbled; grabbing the first * is as a result of \@ifstar, leaving a final * for printing... –  Werner Feb 14 '13 at 1:46

As other answers have indicated, technically the space dropping is part of the scanning for a command name, and at the primitive TeX level the * is not part of the name.

However in LaTeX syntax the star form is always considered a distinct command \section and \section* are documented as two related commands, not one command that looks ahead to see if there is a * or not.

So it is good practice to make the star form have similar behaviour to the non-star form.

In all cases in the base LaTeX format, as far as I can see, the *-command is always used with arguments (like \section*) and so any space is skipped at a different stage or occurs at places where a space character will make a space token but won't produce space in the output \\*, \ProcessOptions*.

Thus I don't think any standard LaTeX * form of a command would produce white space from a space character after the *.

-
Or \tableofcontents* in memoir. –  egreg Feb 11 '13 at 17:28
Thanks! One thing I can't quite follow is the part of the sentence that reads "skipped at a different stage". –  Lover of Structure Feb 11 '13 at 19:38
@egreg See my comment to the @tohecz thread. David Carlisle's point that in TeX the * is not part of the name shows in those examples. Parsing irregularities in (La)TeX are imho an area that needs improvement. (LaTeX 3?) –  Lover of Structure Feb 11 '13 at 19:56
@LoverofStructure in \section {hello} the space is never tokenized it is lost while scanning the command name. in \section* {hello} the space is seen and tokenized but space tokens before mandatory arguments are dropped while scanning for macro arguments "a different stage" –  David Carlisle Feb 11 '13 at 20:24

Only control words eat space after them! Control words are macros begin with the escape character \ and followed by one or more letters.

-