8

I have an issue when using cases, breqn and hyperref together. This is my MWE

\documentclass[preview]{standalone}
\usepackage{cases}
\usepackage{breqn} % For line breaks in some really long equations in another part of the document
\usepackage{hyperref} 

\begin{document}
\begin{subnumcases}{\label{eq:case} x =}
a+b, & example 1\\
c+d, & example 2.
\end{subnumcases}
This text refers to \ref{eq:case}.
\end{document}

When compiling my thesis with breqn loaded I get the image below, where apparently the label isn't set and x has disappeared. What I get

When I don't load breqn I get the behaviour I want but at the expense of the equations that do require breqn later on in my thesis: What I want

And when I don't load hyperref I also get useable output but with the links in the final PDF. Is there a way to keep breqn and hyperref without breaking my subnumcases environments?

3
  • 2
    The package documentation talks about option clashes, but if your problem sticks to breaking long equations, you could use the more-trusted amsmath environments, as discussed in this question.
    – TheVal
    Sep 17, 2013 at 16:12
  • What platform are you using ? With Ubuntu 12.04, Texlive 2012, I have different results (still none of them is correct): when x is visible, the label does not work, and vice versa (depending if breqn is loaded or not). Like Andrea, I recommand you to take a look at the amsmath package, in particular the environment split, cases and subequations.
    – Adam B.
    Sep 17, 2013 at 18:17
  • I'm using TeXWorks with MikTeX on Windows 7. And I'm leaning more toward removing breqn and doing as you say as it appears to be interfering with some pgfplots I have.
    – TeaDee
    Sep 18, 2013 at 19:13

1 Answer 1

9

Don't ask me how I found this out, I just drink too much coffee these days.

\documentclass{article}
\usepackage{cases}
\usepackage{breqn} % For line breaks in some really long equations in another part of the document
\usepackage{hyperref} 

% Patching the numcases environment from 
% cases.sty for compatibility with breqn+hyperref
% Source of problem: use of \box\z@, but \box\z@ somehow
% is used by some other macro at some point when breqn+hyperef
% are used.
\usepackage{etoolbox}
\makeatletter
\newbox\boxzero
\patchcmd{\numcases}{\setbox\z@}{\setbox\boxzero}{}{}
\patchcmd{\numcases}{\kern\wd\z@}{\kern\wd\boxzero}{}{}
\patchcmd{\endnumcases}{\displaystyle \box\z@}{\displaystyle\box\boxzero}{}{}
\let\endsubnumcases\endnumcases
\makeatother


\begin{document}
\begin{subnumcases}{\label{eq:case}x =}
a+b, & example 1\\
c+d, & example 2.
\end{subnumcases}

This text refers to \ref{eq:case}.
\end{document}

Output:

cases

1
  • Nice find! I still think that numbering cases separately is wrong, though.
    – egreg
    Sep 17, 2013 at 20:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .