0

Latex gives seemingly unrelated errors if I use a macro with an @ in it while defining a macro. Errors are consistent across tectonic, pdflatex, and Overleaf, although Overleaf seems to power through the errors and produce a doc anyway.

Drilling down into an error from using \@whilenum in a macro definition, I got to the following minimal latex that reproduces the error:

\documentclass{article}
\makeatletter
\def\@atcommand #1{}
\makeatother
\begin{document}
\newcommand{\mymacro}{
  \newcounter{x}
  \makeatletter
  \@atcommand{\value{x}}
  \makeatother
}
\mymacro
Notempty % Ensure we don't get emptydoc
\end{document}

This gives the error:

! You can't use `\spacefactor' in vertical mode.
\@ ->\spacefactor 
                  \@m {}
l.12 \mymacro

Or, if in a tikzpicture (as the original snippet was), Missing number, treated as zero.

Any of the following prevents there being an error: removing the @ from both the definition and use of the atcommand macro; lifting the definition of mymacro outside of a macro and running it directly; and calling atcommand with an integer value instead of the value of a counter.

Just curious what is going on. The question originated from a student asking why their document didn't compile: I've given them an alternative way to achieve what they wanted, but I want to get them a solid explanation of what was wrong with their first attempt.

0 Answers0