[Tex/LaTex] breqn package incompatibility

breqnincompatibility

Edit: For clarity about what this post is asking, I have placed the specific questions at the beginning of the post.

I would like to understand the technical details of the incompatibilities of breqn.sty (v0.98a) with other packages in TexLive2009. These incompatibilities appear to vanish in subsequent editions of TexLive, and I would like to know what changes have been made to the remediate the incompatibilities? Lastly, what does the obscure and unhelpful error message cited below signify?


Background to contextualize the above questions:

On an amd64 linux system running TexLive 2009, I find that the package breqn (v0.98a) must be the last package loaded, otherwise it interferes with loading of certain other packages, in particular listings (v1.4), xcolor (v2.11), and graphicx (v1.0f).

Below, I include an example document that generates an error.

\documentclass{article}
\usepackage{breqn}
\usepackage{listings}
\begin{document}
Null.
\end{document}

The output (including the error message) produced upon compilation of this document with pdflatex is:

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
(./breqn.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, nohyphenation, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo))
(/usr/share/texmf-texlive/tex/latex/mh/breqn.sty
(/usr/share/texmf-texlive/tex/latex/mh/flexisym.sty
(/usr/share/texmf-texlive/tex/latex/mh/cmbase.sym)
(/usr/share/texmf-texlive/tex/latex/mh/mathstyle.sty))
(/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty)
(/usr/share/texmf-texlive/tex/latex/tools/calc.sty))
(/usr/share/texmf-texlive/tex/latex/listings/listings.sty
! Missing number, treated as zero.
<to be read again> 
                   ^
l.44 \lst@InputCatcodes

?

When I compile the same code on a mac osx 10.6 system running MacTeX-2011, the code compiles without error, regardless of when breqn.sty is loaded.

The following excerpt from the breqn manual (Section 6.1) does specify that such incompatibilities may occur:

As it pushes the envelope of what is possible within the context of LaTeX 2ε, the breqn package will tend to break other packages when used in combination with them, or to fail itself, when there are any areas of internal overlap; successful use may in some cases depend on package loading order.

Best Answer

The breqn package has undergone a thorough revision from the version in TeX Live 2009 to the one in TeX Live 2010 (which is identical to the version in TeX Live 2011).

The error is triggered by the fact that flexisym.sty changes the category code of ^ too early, so that a syntax such as \catcode`\^^@ which is needed by listings is not legal any more: for it to work the ^ must have category code 7 and not 12.

The newer versions of the packages breqn and flexisym delay the category code change at begin document, so packages can still use the ^^ notation. This was clearly a misfeature in breqn and flexisym, but explains why loading breqn last might solve the problem.

Related Question