# Reading the aux with \globaldefs=-1 breaks providecommand.

Issue #22 resolved
u_fischer created an issue

This problem has been reported on tex.sx: http://tex.stackexchange.com/questions/302959/multiple-errors-when-compiling-standalone-document

The newest version of the standalone.cls (2015/07/15 v1.2) reads the aux-file in \sa@convert with \globaldefs=-1, and this breaks the internal latex command \renew@command which relies on an \xdef inside a group.

The following example demonstrates the problem. The error message can vary depending on the definition of \@gtempa and the location of the \providecommand.

\documentclass{article}

\makeatletter
%\def\renew@command#1{%
%  \begingroup \escapechar\m@ne\xdef\@gtempa{{\string#1}}\endgroup %<-- xdef breaks
%  \expandafter\@ifundefined\@gtempa
%     {\@latex@error{\noexpand#1undefined}\@ehc}%
%     \relax
%  \let\@ifdefinable\@rc@ifdefinable
%  \new@command#1}
\def\@gtempa{foo} % breaks the \providecommand because of the missing inner braces.
\makeatother
\begingroup
\globaldefs=-1
\providecommand\blub{abc}
\endgroup

\begin{document}
\end{document}

Side remark: Imho the issue https://bitbucket.org/martin_scharrer/standalone/issues/16/convert-option-and-babel-package is also caused by the reading of the aux-file in \sa@convert. As far as I can see the aux-file is read only to get the current value of \sa@multi@numpages. In my opinion this value should be better saved to some other external file. The aux-file can contain so many things that it is difficult to control side effects.

1. reporter
• edited description
2. repo owner
• changed status to open

One approach would be to parse the file aux-line by line for \sa@multi@numpages and simply set the given value if it is found. So instead of using \@@input\sa@convert@subjobname.aux\relax within

\IfFileExists{\sa@convert@subjobname.aux}{%
\globaldefs=\m@ne
\@@input\sa@convert@subjobname.aux\relax
\globaldefs=\z@
\xdef\sa@multi@numpages{\sa@multi@numpages}%
}{}%

something like the following code snippet would fulfill the task

\IfFileExists{\sa@convert@subjobname.aux}{\@tempswatrue}{\@tempswafalse}%
\if@tempswa%
\def\@tempa##1\sa@multi@numpages##2\@nnil{%
\if\relax\detokenize{##2}\relax\else\@tempb\fi%
}%
\let\@tempb\@empty%
\endlinechar=\m@ne%
\expandafter\@tempa\@tempb\sa@multi@numpages\@nnil%
\repeat%
\fi%

3. repo owner

This is also the cause of issue #16, as the AUX file is read before the babel package is loaded.

4. repo owner

Issue #16 was marked as a duplicate of this issue.

5. repo owner
• edited description
• changed status to resolved

Fixed in revision 336:0bdf7fc019ef