Macros – Resolving Package Incompatibilities: etoolbox, hyperref, and bm, standalone

etoolboxhyperrefincompatibilitymacrosstandalone

I am trying to transition to using the etoolbox package, but seem to have run into some difficulties and they appear related to the hyperref and bm packages which to me seem totally unrelated. The MWE example compiles since \RemoveEToolbox is defined and shows that there is no apparent problem before etoolbox was used.

Commenting out the \def\RemoveEToolbox{} line produces two problems:

  1. With both the \renewcommand, and the usepackage{hyperref} commented, this results in "Runaway argument? Paragraph ended before \bm@test@token was complete".

  2. Including the usepackage{hyperref} (with \renewcommand commented) results in "Undefined control sequence. \Call@AtVeryEndDocument …cumentHook \@undefined"

But if uncomment the \renewcommand{\bm}{#1} line (effectively doing without any \bm), then this seems to compile.

I have been using this for a while now and things appeared to have been working fine, but now that I attempt to use etoolbox I seem to run into problems.

\documentclass{standalone}
\def\RemoveEToolbox{}% Shows that this works fine without {etoolbox}

\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{bm}

\ifdefined\RemoveEToolbox
    \newcommand*{\iftoggle}[3]{#2}% Default to true value of "if"
\else
    \usepackage{etoolbox}
    \newtoggle{paper}
    \toggletrue{paper}

    %\renewcommand{\bm}[1]{#1}% Why can't I have a normal \bm with {etoolbox}?
\fi

% \usepackage{hyperref}

\begin{document}

This document is intended for 
\iftoggle{paper}{paper}{electronic}
distribution.

\bm{\textcolor{blue}{Solve $x^2-1=0$}}

\begin{align*}
    a &= b\\
    \iftoggle{paper}{
        c &= d\\
    }{}
    e &= f\\
\end{align*}
\end{document}

Best Answer

The issues is that both the standalone class and the etoolbox package redefine the document environment. This causes a clash. You can avoid this by loading etoolbox before the class using \RequirePackage. I will try to support the normal of this package, but it will take a while until I have to time to release a new version of standalone.

Workaround:

\def\RemoveEToolbox{}% Shows that this works fine without {etoolbox}

\ifdefined\RemoveEToolbox
    \newcommand*{\iftoggle}[3]{#2}% Default to true value of "if"
\else
    \RequirePackage{etoolbox}
    \newtoggle{paper}
    \toggletrue{paper}

    %\renewcommand{\bm}[1]{#1}% Why can't I have a normal \bm with {etoolbox}?
\fi

\documentclass{standalone}

\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{bm}

% \usepackage{hyperref}

\begin{document}

This document is intended for 
\iftoggle{paper}{paper}{electronic}
distribution.

\bm{\textcolor{blue}{Solve $x^2-1=0$}}

\begin{align*}
    a &= b\\
    \iftoggle{paper}{
        c &= d\\
    }{}
    e &= f\\
\end{align*}
\end{document}

Update 2011/12/21

The new version 1.0 of standalone works fine with etoolbox, due to a changed way to patch the document environment. However, the new default settings ignore paragraph breaks, so you will a problem with align*. You can fix easily this by using the varwidth class option.