cases
我在同时使用、breqn
和时遇到问题hyperref
。这是我的 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}
当使用 loaded 编译我的论文时,breqn
我得到下面的图像,其中标签显然未设置并且 x 已消失。
当我不加载时,我得到了我想要的行为,但是却以牺牲我论文后面
breqn
需要的方程为代价:breqn
当我不加载时,hyperref
我也会得到可用的输出,但最终 PDF 中会有链接。有没有办法保留breqn
它hyperref
而不破坏我的subnumcases
环境?
答案1
不要问我怎么发现这一点的,只是我最近喝了太多咖啡。
\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}
输出: