10

I'm writing tutorial of TeX and I accidently typed \* and realized the compiler does not read it as an error. I know that adding * triggers \ifstar condition, but I'm curious that how compiler treat \*.

On Overleaf, it will not produce any error nor warnings, but it also didn't do anything visible(even a tiny space). What will compiler do when realize the control sequence token is "\*" ?

haur576
  • 150
  • 8
    \* is a normal macro (normally, commands consist only of letters, but there is an exception for one-character-non-letter names like \$, \%, \@, \> and \*). It does not trigger \@ifstar. The macro is a 'discretionary multiplication sign'. In LaTeX it is defined as \DeclareRobustCommand\*{\discretionary{\thinspace\the\textfont2\char2}{}{}}. You can see it in action in \parbox{1.5cm}{$(x+y)\*(x-y)$} Compare that to \parbox{5cm}{$(x+y)\*(x-y)$}. The idea is that \* normally has no output, but becomes a multiplication sign if it happens to come after a line break. – moewe Aug 18 '21 at 19:04
  • Oh, I keeping thinking that it is a starred-version empty macro until this. This makes more sense to me. – haur576 Aug 19 '21 at 10:31

1 Answers1

12

By itself, * triggers nothing. Only some commands will accept * for a variant, but they are defined in a special way. For instance, in LaTeX we have

% latex.ltx, line 6002:
\DeclareRobustCommand\vspace{\@ifstar\@vspacer\@vspace}

so if \vspace is followed by *, LaTeX will do \@vspacer (and gobble the asterisk), otherwise it will do \@vspace.

In plain TeX there is no *-variant (unless one defines the infrastructure and does a specific definition).

According to the tokenization rules, \* is a control symbol and it is defined in plain TeX and LaTeX to produce a “discretionary multiplication symbol”: if it is used for hyphenation, it will produce a thin space followed by character 2 in \textfont2, usually ✕, at the end of the line. It's normally (but not frequently) used in math mode.

An example:

\documentclass{article}

\begin{document}

\parbox{0pt}{$x*y$}

\end{document}

enter image description here

The \parbox with zero width will force the \discretionary to be used.

egreg
  • 1,121,712