# Use of \GetIdInfoAuxI doesn't match its definition and other errors

I have several errors reported with this minimal example (latest TeX Live 2012). The errors were introduced with recent TeX Live updates.

\RequirePackage[l2tabu, orthodox]{nag}

\documentclass{scrbook}
\usepackage{morewrites}
\RequirePackage{listings}
\AtBeginDocument{%
\RequirePackage{mdframed}
}

\begin{document}
\end{document}


In xparse.sty:

! Use of \GetIdInfoAuxI doesn't match its definition. l.66 \GetIdInfo$Id: xparse.dtx 4467 2013-03-12 08:29:05Z joseph$

In etoolbox.sty:

(c:/texlive/2012/texmf-dist/tex/latex/etoolbox/etoolbox.sty ! Missing $ inserted. In mdframed.sty: ! TeX capacity exceeded, sorry [input stack size=5000]. \etoolbox.sty-h@@k ->\etoolbox.sty-h@@k \etb@catcodes \undef \etb@catcodes l.72 \RequirePackage{etoolbox}[2011/01/03] - I'd love to drop the entire \GetIdInfo business: a team decision, though, so not mine :-( – Joseph Wright Apr 7 '13 at 15:05 Why do you want to load mdframed at this point? I don't know any conflicts with other packages. – Marco Daniel Apr 7 '13 at 15:30 ## 2 Answers The answer by @DavidCarlisle details the cause of this problem, and while the solution works it may be preferrable to use a solution with less catcode magic. Using the \AtEndPreamble macro provided by etoolbox, one can rewrite the MWE so that no errors occur: \RequirePackage[l2tabu, orthodox]{nag} \documentclass{scrbook} \usepackage{morewrites} \RequirePackage{listings} \usepackage{etoolbox} \AtEndPreamble{% \RequirePackage{mdframed} } \begin{document} \end{document}  Although I see no reason to postpone loading mdframed to begin with. - +1 see: you've more points than my answer already;-) – David Carlisle Apr 7 '13 at 17:08 The nag package changes $ from its usual definition to be "active"

\AtBeginDocument{\catcode$\active}%$
\AtEndDocument{\catcode$=3\relax}  It tries to minimise the clashes that this can cause by delaying it to begin document. the mdframed (via xparse) use $ to parse the source control headers in the package files This fails as the RequirePackage has been delayed until BeginDocument.

The most obvious fix for this is just to use

\usepackage{mdframed}


rather than

\AtBeginDocument{%
\RequirePackage{mdframed}
}


But it depends why the package loading was delayed in the first place...

As noted in comments delaying package loading in \AtBeginDocument is always risky as it loads the package later than intended, after LaTeX has set up global font and page size structures, however this works:

\RequirePackage[l2tabu, orthodox]{nag}

\documentclass{scrbook}
\usepackage{morewrites}
\RequirePackage{listings}
\AtBeginDocument{%
\edef\saveddcatcode{\the\catcode\expandafter\string$}% \catcode\$3 %
\RequirePackage{mdframed}%
\catcode\\$ \saveddcatcode\relax
}

\begin{document}
\end{document}

-
In my packages I try to move package loading to the end to avoid option clashes. –  Matthias Pospiech Apr 7 '13 at 12:19
@MatthiasPospiech It's relatively fragile thing to do, apart from clashing with other packages (nag here) trying to do use the same hook to avoid clashes, any packages that load fonts or change any page layout size or ... should be loaded before this hook is run as latex sets up its output routine and global font tables before executing code from AtBeginDocument. mdframed is probably safe normally but.... –  David Carlisle Apr 7 '13 at 12:27
@MatthiasPospiech workaround code added to answer. –  David Carlisle Apr 7 '13 at 12:40
Perhaps using \AfterEndPreamble from the etoolbox package instead of \AtBeginDocument` is a cleaner solution? –  You Apr 7 '13 at 12:46
@You if you tested that and it works you should post as a separate answer, you might steal a few points from me:-) –  David Carlisle Apr 7 '13 at 12:48