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

Create issue
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.

Comments (6)

  1. Falk Hanisch

    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%
      \newread\sa@read%
      \def\@tempa##1\sa@multi@numpages##2\@nnil{%
        \if\relax\detokenize{##2}\relax\else\@tempb\fi%
      }%
      \let\@tempb\@empty%
      \endlinechar=\m@ne%
      \immediate\openin\sa@read=\sa@convert@subjobname.aux%
      \loop\unless\ifeof\sa@read%
        \read\sa@read to\@tempb%
        \expandafter\@tempa\@tempb\sa@multi@numpages\@nnil%
      \repeat%
      \immediate\closein\sa@read%
    \fi%
    
  2. Martin Scharrer repo owner

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

  3. Log in to comment