4

I just created an answer that uses a temporary variable with \write\@auxout and thought it would be good idea to scope with \begingroup, \endgroup. For some Reason this results in:

! Undefined control sequence.
<write> \tempvariable

MWE

\documentclass{article}

\makeatletter
\newcommand{\abc}{%
    \begingroup%
    \newcommand\tempvariable{\relax}%
    \write\@auxout{\tempvariable}%
    \endgroup%
}
\makeatother

\begin{document}
    Why isn't this working???
    \abc 

\end{document}

Why is this happening and how can I fix this?

5

Adding \immediate should help:

\documentclass{article}

\makeatletter
\newcommand{\abc}{%
   \begingroup%
    \newcommand\tempvariable{\relax}%
%    \write\@auxout{\tempvariable}%
\immediate \write\@auxout{\tempvariable}%
    \endgroup%
}
\makeatother

\begin{document}
    Why isn't this working???
    \abc 

\end{document}

I can see from your anwer from the link, that you know command \immediate, so probably no additional comment is needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.