A colleague of mine had a LaTeX-specific issue for which I did not exactly know the cause of the issue. I have distilled a Minimal Working Example to illustrate the issue.
Originally my colleague had several files and used \include
in the following way:
Main .tex file: testi.tex:
\documentclass{article}
\usepackage{graphics}
\makeatletter
\newcommand{\test@}{test}
\makeatother
\begin{document}
\scalebox{0.8}{
\input{testii}
}
\end{document}
Included .tex file: testii.tex:
\makeatletter
\test@
\makeatother
This worked without any problems (the included constructs of this form originated from automated generated code to annotate .pdf images). Then, my colleague tried to make a single *.tex file. Hence, he replaced the \input
command by including the content of testii.tex in testi.tex:
Single-file testi.tex: testd.tex:
\documentclass{article}
\usepackage{graphics}
\makeatletter
\newcommand{\test@}{test}
\makeatother
\begin{document}
\scalebox{0.8}{
\makeatletter
\test@
\makeatother
}
\end{document}
The file testd.tex did, however, not compile: the error message was:
! Undefined control sequence.
<argument> \makeatletter \test
Hence: LaTeX reads the command \test
instead of \test@
, which should have been read due to the \makeatletter
construct. We found a way to resolve the issue (by placing \scalebox
inside a \makeatletter
/\makeatother
pair), but still I am wondering what the cause (bug?) of the differences in behavior between inlined LaTeX code and \input
-ed LaTeX code is.
Best Answer
This is unrelated to
\input
(or to the specifics of\scalebox
)in
the argument has already been parsed and tokenised as
\test
@
before it is executed, so\makeatletter
has no effect. This is the same reason that you can not use\verb
in the argument to another command. You need