类似于\listoffigures
或\listoftables
,我想创建一个\listofequations
命令。这对于遵循编号连续性的方程式很有效,但不适用于标记方程式。
我不知道如何构建一个命令来\theequation
处理编号方程式或标记方程式的标签。
\documentclass{article}
\usepackage{amsmath, etoolbox, hyperref}
\makeatletter
\newcommand{\listeq}[1]{\global\def\eqtitle{#1}}
\def\eqtitle{}%
\apptocmd{\maketag@@@}{%
\addcontentsline{loe}{equation}{%
\protect\numberline{\theequation}%
\eqtitle%
}%
\global\def\eqtitle{}%
}
{}
{\FAIL}
\newcommand\listequationname{List of equations}
\newcommand\listofequations{%
\section*{\listequationname}%
\@starttoc{loe}%
}
\newcommand*\l@equation{\@dottedtocline{1}{1.5em}{2.3em}}
\makeatother
\begin{document}
\listofequations
\begin{equation}\listeq{First equation}
i^2=-1
\end{equation}
\begin{equation}\listeq{Not working}
i^2=-1 \tag{*}
\end{equation}
\begin{equation}\listeq{Not working too}
i^2=-1 \tag*{*}
\end{equation}
\begin{subequations}
\begin{equation}
i^2=-1
\end{equation}
\begin{equation}\listeq{A subequation}
i^2=-1
\end{equation}
\end{subequations}
\begin{align}
i^2=-1\listeq{Eq 1}\\
i^2=-1\listeq{Eq 2}\\
i^2=-1\tag{§}
\end{align}
\end{document}
写如下内容是行不通的:
\apptocmd{\maketag@@@}{%
\addcontentsline{loe}{equation}{%
\protect\numberline{#1}%
\eqtitle%
}%
\def\eqtitle{}%
}
{}
{\FAIL}
答案1
经过几次尝试,我想我找到了一个解决方案。这个方案不是很优雅,但它在我测试的少数情况下有效。
\documentclass{article}
\usepackage{amsmath, etoolbox, hyperref}
\makeatletter
\newcommand{\listeq}[1]{\gdef\eqtitle{#1}}
\def\eqtitle{}%
\def\thecurrenttag{\theequation}%
\apptocmd{\maketag@@@}{%
\addcontentsline{loe}{equation}{%
\protect\numberline{\thecurrenttag}%
\eqtitle%
}%
\gdef\eqtitle{}%
\gdef\thecurrenttag{\theequation}%
}
{}
{\FAIL}
\apptocmd{\make@df@tag@@}{%
\gdef\thecurrenttag{#1}%
}
{}
{\FAIL}
\apptocmd{\make@df@tag@@@}{%
\gdef\thecurrenttag{#1}%
}
{}
{\FAIL}
\newcommand\listequationname{List of equations}
\newcommand\listofequations{%
\section*{\listequationname}%
\@starttoc{loe}%
}
\newcommand*\l@equation{\@dottedtocline{1}{1.5em}{2.3em}}
\makeatother
\begin{document}
\listofequations
\begin{equation}\listeq{First equation}
i^2=-1
\end{equation}
\begin{equation}
i^2=-1 \tag{*}\listeq{Working}
\end{equation}
\begin{equation}\listeq{Working too}
i^2=-1 \tag*{\$}
\end{equation}
\begin{subequations}
\begin{equation}
i^2=-1
\end{equation}
\begin{equation}\listeq{A subequation}
i^2=-1
\end{equation}
\end{subequations}
\begin{align}
i^2=-1\listeq{An align}\\
i^2=-1\\
i^2=-1\tag{§}\\
i^2=-1
\end{align}
\begin{multline}\tag{£}\listeq{A multiline --- Working}\label{multline}
a+b+c+d+e+f\\
+g+h+i+j+k+l\\
+m+n+o+p+q+r
\end{multline}
\begin{gather}\tag{µ}\listeq{A gather}
a_1=b_1+c_1\\
a_2=b_2+c_2-d_2+e_2
\end{gather}
\begin{flalign}
a_{11} + b_{11}& = c_{11}&
a_{12}& =b_{12}\\\tag{\#}\listeq{A flalign}
b_{21}& = c_{21}&
a_{22}& =b_{22}+c_{22}
\end{flalign}
\begin{alignat}{2}
x& = y_1-y_2+y_3-y_5+y_8-\dots
&\quad& \text{bla bla bla}\\\tag{\&}\listeq{An alignat}
& = y’\circ y^* && \text{bla bla bla}\\
& = y(0) y’ && \text {bla bla bla}
\end{alignat}
\end{document}
然而,环境仍然存在一个问题multline
:
查看了 的定义后multline@
,我注意到问题出在mmeasure@
命令上。注释掉一行似乎可以解决问题,但我不知道这样做是否安全,以及在某些情况下是否不会产生问题。
\def\mmeasure@#1{%
\begingroup
\measuring@true
\def\label##1{%
\begingroup\measuring@false\label@in@display{##1}\endgroup%
}%
\def\math@cr@@@{\cr}%
\let\shoveleft\@iden \let\shoveright\@iden
\savecounters@
\global\row@\z@
\setbox\@ne\vbox{%
\global\let\df@tag\@empty
\halign{%
\setboxz@h{\@lign$\m@th\displaystyle{}##$}%
\iftagsleft@
\ifnum\row@=\@ne
\global\totwidth@\wdz@
\global\lineht@\ht\z@
\fi
\else
\global\totwidth@\wdz@
\global\lineht@\dp\z@
\fi
\crcr
#1%
\crcr
}%
}%
\ifx
\df@tag\@empty
\else
\global\tag@true
\fi
\if@eqnsw
\global\tag@true
\fi
\iftag@
\setboxz@h{%
\if@eqnsw
\stepcounter{equation}%
\tagform@\theequation
\else
% \df@tag % !!!!!!!!!!!!!!!!!!!!!!!!!!
\fi
}%
\global\tagwidth@\wdz@
\dimen@\totwidth@
\advance\dimen@\tagwidth@
\advance\dimen@\multlinetaggap
\iftagsleft@\else
\if@fleqn
\advance\dimen@\@mathmargin
\fi
\fi
\ifdim\dimen@>\displaywidth
\global\shifttag@true
\else
\global\shifttag@false
\fi
\fi
\restorecounters@
\endgroup
}