正如标题所述,我想中断并恢复位于某个subequations
区域内的方程块。当中断的内容本身包含方程时,就会出现问题:
\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\begin{document}
\begin{subequations}\label{eq:master}%
\begin{align}%
a & = b \label{eq:master:ab}\\
c & = d \label{eq:master:cd}
\end{align}%
\end{subequations}%
%
Some stuff in between
\begin{equation}%
A = B\label{eq:helper}
\end{equation}
%
Resume here the subequations, i.e., continue with 1c:
\begin{subequations}%
\begin{align}%
e & = f \label{eq:master:ef}\\
g & = h \label{eq:master:gh}
\end{align}%
\end{subequations}%
Master~\eqref{eq:master}, consisting of~\eqref{eq:master:ab}, \eqref{eq:master:cd}, \eqref{eq:master:ef}, \eqref{eq:master:gh},
and helper~\eqref{eq:helper}.
\end{document}
我知道如何手动摆弄计数器,但这并不LaTeX 方式。我见过类似的利用enumitem
包的枚举。一个优雅的解决方案是什么样的,让我可以写
\begin{subequations}[resume]%
\begin{align}%
e & = f \label{eq:master:ef}\\
g & = h \label{eq:master:gh}
\end{align}%
\end{subequations}%
答案1
这是另一种方法。
我解释一下:subequations
现在接受一个可选参数。预期值为 resume
、intermezzo
或为零。一旦遇到既不是resume
也不intermezzo
是,就会初始化一个新的潜在线程:继续执行resume
,中间放置的东西可以是任何东西,如果它再次是一个subequations
块,则必须将其标记为intermezzo
。
代码考虑到了hyperref
补丁 subequations
。
需要注意的是:subequations
在间奏中扮演角色的块不能被全局标记:只有实际的子方程才可以。
\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
% original amsmath definition
% \subequations:
% \long macro:->\refstepcounter {equation}\protected@edef \theparentequation {\theequation }\setcounter {parentequation}{\value {equation}}\setcounter {equation}{0}\def \theequation {\theparentequation \alph {equation}}\ignorespaces
% saved by hyperref in
% > \HyOrg@subequations=\long macro:
% hyperref-patched \subequations: (\endsubequations not modified)
% > \subequations=macro:
% ->\stepcounter {equation}\protected@edef \theHparentequation {\@ifundefined {th
% eHequation}\theequation \theHequation }\addtocounter {equation}{-1}\HyOrg@subeq
% uations \def \theHequation {\theHparentequation \alph {equation}}\ignorespaces
% .
% extending the environment
% 1. with optional parameter: expected values resume or intermezzo or none.
% 2. while keeping the hyperref customization.
\makeatletter
\def\user@resume{resume}
\def\user@intermezzo{intermezzo}
%
\newcounter{previousequation}
\newcounter{lastsubequation}
\newcounter{savedparentequation}
\setcounter{savedparentequation}{1}
%
\renewenvironment{subequations}[1][]{%
\def\user@decides{#1}%
\setcounter{previousequation}{\value{equation}}%
\ifx\user@decides\user@resume
\setcounter{equation}{\value{savedparentequation}}%
\else
\ifx\user@decides\user@intermezzo
\refstepcounter{equation}%
\else
\setcounter{lastsubequation}{0}%
\refstepcounter{equation}%
\fi\fi
\protected@edef\theHparentequation{%
\@ifundefined {theHequation}\theequation \theHequation}%
\protected@edef\theparentequation{\theequation}%
\setcounter{parentequation}{\value{equation}}%
\ifx\user@decides\user@resume
\setcounter{equation}{\value{lastsubequation}}%
\else
\setcounter{equation}{0}%
\fi
\def\theequation {\theparentequation \alph{equation}}%
\def\theHequation {\theHparentequation \alph{equation}}%
\ignorespaces
}{%
% \arabic{equation};\arabic{savedparentequation};\arabic{lastsubequation}
\ifx\user@decides\user@resume
\setcounter{lastsubequation}{\value{equation}}%
\setcounter{equation}{\value{previousequation}}%
\else
\ifx\user@decides\user@intermezzo
\setcounter{equation}{\value{parentequation}}%
\else
\setcounter{lastsubequation}{\value{equation}}%
\setcounter{savedparentequation}{\value{parentequation}}%
\setcounter{equation}{\value{parentequation}}%
\fi\fi
% \arabic{equation};\arabic{savedparentequation};\arabic{lastsubequation}
\ignorespacesafterend
}
\makeatother
\begin{document}\thispagestyle{empty}
\begin{subequations}\label{eq:master}
\begin{align}
a & = b \label{eq:master:ab}\\
c & = d \label{eq:master:cd}
\end{align}
\end{subequations}
%
Some intermezzo stuff in between
\begin{equation}
A = B\label{eq:helper}
\end{equation}
%
\begin{subequations}[intermezzo]
\begin{align}
C &= D\label{eq:inter1}\\
E &= F\label{eq:inter2}
\end{align}
\end{subequations}
Resume here the subequations, i.e., continue with 1c:
\begin{subequations}[resume]
% \label{eq:Master} % NO! impossible here
\begin{align}
e & = f \label{eq:master:ef}\\
g & = h \label{eq:master:gh}\\
g & = h \label{eq:master:gh2}
\end{align}
\end{subequations}
Master~\eqref{eq:master}, consisting of~\eqref{eq:master:ab},
\eqref{eq:master:cd} and \eqref{eq:master:ef}, \eqref{eq:master:gh},
\eqref{eq:master:gh2}
and helpers \eqref{eq:helper}, \eqref{eq:inter1} and \eqref{eq:inter2}. But one
can not label the intermezzo block, only its subequations.
Some more continued stuff:
\begin{subequations}[resume]
\begin{align}
i & = j \label{eq:master:ij}\\
k & = l \label{eq:master:kl}\\
i & = j \label{eq:master:ij2}
\end{align}
\end{subequations}
and we re-initialize again (resuming will continue from here):
\begin{subequations}
\begin{align}
A &= B\label{eq:final1}\\
B &= A\label{eq:final2}
\end{align}
\end{subequations}
Two intermezzi (my head starts spinning!):
\begin{subequations}[intermezzo]
\label{eq:Intermediate}
\begin{align}
A &= B\label{eq:final3}\\
B &= A\label{eq:final4}
\end{align}
\end{subequations}
\begin{align}
A &= B\label{eq:final5}\\
B &= A\label{eq:final6}
\end{align}
And we resume again (some aspirin please!)
\begin{subequations}[resume]
\begin{align}
A &= B\label{eq:final7}\\
B &= A\label{eq:final8}
\end{align}
\end{subequations}
So we had a new block of subequations \eqref{eq:final1}, \eqref{eq:final2},
\eqref{eq:final7}, and \eqref{eq:final8}; and in-between there were
\eqref{eq:final3}, \eqref{eq:final4}, \eqref{eq:final5}, and \eqref{eq:final6}.
\end{document}
答案2
我的解决方案提供了第二个环境,它从上一个或环境subequations*
中获取值。重新定义了 该部分以将计数器的值(在本例中为和= )保存在辅助计数器中。这些在环境中使用。subequations
subequations*
\end{subequations}
1
2
b
subequations*
笔记:可以标记subequations*
环境,这意味着将有多个“主”方程。当您使用时,这会变得有趣\pageref
。
etoolbox
' macor的原因\patchcmd
可以读取在我的另一个回答中. 简短版本:该\theparentequation
宏的定义独立于parentequation
计数器。
代码
\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\usepackage{etoolbox}
\makeatletter
\newcounter{qrr@oldeq}
\newcounter{qrr@oldsubeq}
\newcounter{qrr@realeq}
\renewenvironment{subequations}{%
\refstepcounter{equation}%
\protected@edef\theparentequation{\theequation}%
\setcounter{parentequation}{\value{equation}}%
\setcounter{equation}{0}%
\def\theequation{\theparentequation\alph{equation}}%
\ignorespaces
}{%
\setcounter{qrr@oldeq}{\value{parentequation}}%
\setcounter{qrr@oldsubeq}{\value{equation}}%
\setcounter{equation}{\value{parentequation}}%
\ignorespacesafterend
}
\newenvironment{subequations*}{%
\setcounter{qrr@realeq}{\value{equation}}%
\let\theparentequation\theequation%
\patchcmd{\theparentequation}{equation}{parentequation}{}{}%
\setcounter{parentequation}{\numexpr\value{qrr@oldeq}-1}%
\setcounter{equation}{\value{qrr@oldsubeq}}%
\def\theequation{\theparentequation\alph{equation}}%
\refstepcounter{parentequation}%
\ignorespaces
}{%
\setcounter{qrr@oldeq}{\value{parentequation}}%
\setcounter{qrr@oldsubeq}{\value{equation}}%
\setcounter{equation}{\value{qrr@realeq}}%
\ignorespacesafterend
}
\makeatother
\begin{document}
\begin{subequations}\label{eq:master}%
\begin{align}%
a & = b \label{eq:master:ab}\\
c & = d \label{eq:master:cd}
\end{align}%
\end{subequations}%
%
Some stuff in between
\begin{equation}%
A = B\label{eq:helper}
\end{equation}
%
Resume here the subequations, i.e., continue with 1c:
\begin{subequations*}\label{eq:Master}
\begin{align}%
e & = f \label{eq:master:ef}\\
g & = h \label{eq:master:gh}
\end{align}%
\end{subequations*}%
Master~\eqref{eq:master}, consisting of~\eqref{eq:master:ab}, \eqref{eq:master:cd} and \eqref{eq:master:ef}, \eqref{eq:master:gh} from Master \eqref{eq:Master},
and helper~\eqref{eq:helper} and final~\eqref{eq:final}.
Some stuff at the end:
\begin{equation}%
A = B\label{eq:final}
\end{equation}
\end{document}
输出
答案3
我找到了一个实用的解决方案,可以恢复某些内容之间的子方程。我使用了该\tag{}
选项,但我将选项包含在标签中,\ref{}
如下所示:
\begin{subequations}
\begin{align}
\rm\displaystyle \tan\upgamma&=\frac{\upeta_r}{1-(\upomega/\upomega_r)^2} \\
\rm\displaystyle \tan(90^{\circ}-\upgamma)&=\tan\left(\frac{\uptheta}{2}\right)=\frac{1-(\upomega/\rm \upomega_r)^2}{\upeta_r}
\end{align}
\label{eq:1}
一些文字或任何你想要的东西
begin{equation}
\rm\displaystyle \upomega^2=\upomega_r^2\left(1-\upeta_r\tan\left(\frac{\uptheta}{2}\right)\right)\tag{\ref{eq:1}c}
\label{eq:ewins_4_6_c}
\end{equation}
我知道这不是办法,\LaTeX{}
但很实用