我想自动生成文档中存在的方程式列表,其中包括方程本身。下面是 MWE:
\documentclass{文章} \def\caption#1{} \开始{文档} 欧拉首先观察到 \开始{方程} 1 + e^{i \Pi} = 0. \caption{欧拉方程将数学的五个基本常数联系在一起} \end{方程} 然后,高斯发现了正态分布: \开始{方程} P(x) = \frac{1}{{\sigma \sqrt {2\pi } }}e^{{{ - \left( {x - \mu } \right)^2 } \mathord{\left/ {\vphantom {{ - \left( {x - \mu } \right)^2 } {2\sigma ^2 }}} \right. \kern-\nulldelimiterspace} {2\sigma ^2 }}} \caption{正态分布} \end{方程} 最后,爱因斯坦宣称: \开始{方程} E = m C^2 \caption{质量和能量的等价性} \end{方程} \结束{文档}
这是输出可能呈现的样子的一个例子,但其他格式也可以;当然,如果有超链接、页码等就更好了,但这些并不是必需的。
\section*{方程列表} \开始{枚举} \item 欧拉方程将数学的五个基本常数联系在一起 \[ 1 + e^{i \Pi} = 0. \] \item 正态分布: \[ P(x) = \frac{1}{{\sigma \sqrt {2\pi } }}e^{{{ - \left( {x - \mu } \right)^2 } \mathord{\left/ {\vphantom {{ - \left( {x - \mu } \right)^2 } {2\sigma ^2 }}} \right. \kern-\nulldelimiterspace} {2\sigma ^2 }}} \] \item 质量和能量的等价性 \[ E = m C^2 \] \end{枚举}
答案1
既然你想要一份备忘单,我推荐extract
包。MWE 略有不同:
\documentclass{article}
\usepackage[
active,
header=false,
copydocumentclass=true,
generate=\jobname-Cheatsheet,
extract-env={equation},
extract-cmdline={synopsis},
]{extract} % http://ctan.org/pkg/extract
\begin{extract*}
% Items executed in both the main and extracted document
% (extract manual, section 5.1)
\usepackage{amsmath}
\end{extract*}
\begin{extract}
% Items executed only in extracted document
\def\synopsis#1{#1}
\end{extract}
\def\synopsis#1{}
\begin{document}
First Euler observed that
\synopsis{Euler's equation tying together the five fundamental constants of mathematics}%
\begin{equation}
1 + e^{i \Pi} = 0.
\end{equation}
Then, Gauss discovered the normal distribution:
\synopsis{Normal distribution}%
\begin{equation}
P(x) = \frac{1}{{\sigma \sqrt {2\pi } }}e^{{{ - \left( {x - \mu } \right)^2 } \mathord{\left/ {\vphantom {{ - \left( {x - \mu } \right)^2 } {2\sigma ^2 }}} \right. \kern-\nulldelimiterspace} {2\sigma ^2 }}}
\end{equation}
Finally, Einstein proclaimed:
\synopsis{Equivalence of mass and energy}%
\begin{equation}
E = m C^2
\end{equation}
\end{document}
您将获得以下原始文件:
以及一份摘录的文档:
\documentclass{article}
% Items executed in both the main and extracted document
% (extract manual, section 5.1)
\usepackage{amsmath}
% Items executed only in extracted document
\def\synopsis#1{#1}
\begin{document}
\synopsis{Euler's equation tying together the five fundamental constants of mathematics}%
\begin{equation}
1 + e^{i \Pi} = 0.
\end{equation}
\synopsis{Normal distribution}%
\begin{equation}
P(x) = \frac{1}{{\sigma \sqrt {2\pi } }}e^{{{ - \left( {x - \mu } \right)^2 } \mathord{\left/ {\vphantom {{ - \left( {x - \mu } \right)^2 } {2\sigma ^2 }}} \right. \kern-\nulldelimiterspace} {2\sigma ^2 }}}
\end{equation}
\synopsis{Equivalence of mass and energy}%
\begin{equation}
E = m C^2
\end{equation}
\end{document}
和:
这也适用于您的原始\caption
命令。
答案2
我强烈建议你看一下float
包裹\listof
,随之而来的是可用于生成自定义浮动环境列表的命令。
然后,您可以定义自己的方程环境并使用该\listof
命令生成方程列表。
这是一个简单的例子:
\documentclass{article}
\usepackage{float}
\floatstyle{plain}
\newfloat{myequation}{H}{eq}[section]
\floatname{myequation}{Equation}
\begin{document}
\listof{myequation}{List of Equations}
\section{First Section}
First Euler observed that
\begin{myequation}
\begin{equation}
1 + e^{i \Pi} = 0.
\end{equation}
\caption{Euler's equation tying together the five fundamental constants of mathematics}
\end{myequation}
\end{document}
但是现在方程式标题和方程式都已编号,因此您可能希望使用equation
环境的标准版本来生成内部方程式,从而抑制内部方程式的编号。equation*
环境可以在包中找到amsmath
。
可以使用命令的可选参数来将实际方程式包含在方程式列表中,\caption
如下所示:
\caption[$$1 + e^{i \Pi} = 0$$]{caption part not to be included in the list of equations}
然而,如果等式跨越多条线,比如说一个分数,这种方法就不起作用......
答案3
基于extract
环境的答案听起来确实很有希望而且很优雅,但结果却有点脆弱,尤其是beamerarticle
。有时它似乎毫无理由地很挑剔,直到\begin{equation}
where 之前的空间发生变化。
这是使用该包的替代方法environ
。使用方法如下:
\documentclass[twocolumn,10pt]{article}
\title{Demo of \texttt{generate-list-equations}}
\author{Yogi the bear}
\usepackage[fleqn]{amsmath}
\usepackage{generate-list-of-equations}
\begin{document}
\maketitle
\section{Start with a list of all equations}
\listofequations
\section{Main matters}
People say that \begin{equation}1+1=2\end{equation} but how do we know that this is true?
First, Euler observed that
\begin{equation}
1 + e^{i \pi} = 0.
\synopsis{Euler's equation tying together the five fundamental constants of mathematics}%
\end{equation}
Then, Gauss discovered the normal distribution:
\begin{equation}
P(x) = \frac{1}{{\sigma \sqrt {2\pi }}} e^{-\frac{(x - \mu)^2} {2 \sigma^2}}
\synopsis{Normal distribution}%
\end{equation}
Finally, Einstein proclaimed:
\begin{equation}
E = m C^2
\synopsis{Equivalnce of mass and energy}
\end{equation}
Only then, it became clear that
\begin{equation}
2 + 2 = 4
\synopsis{Two and two before!}
\end{equation}
\section{The END}
That's all folks!
\section{PS. The list of equations can be placed anywhere}
\listofequations
\end{document}
这是实际的代码;它写在一个.sty
文件中,但还不够完善,还不能被视为一个包。如果您需要使用它,很可能需要对其进行调整。
\RequirePackage{amsmath}
\RequirePackage{environ}
% The main command generates a list of equations by
% simply \input ting `\jobname.leq`
\newcommand\listofequations{%
\IfFileExists{\jobname.leq}{\input{\jobname.leq}}{\relax}
}
% File "\jobname.eqn" collects all equations
\AtBeginDocument{%
\newwrite\equationsListFile
\immediate\openout\equationsListFile=\jobname.eqn%
\immediate\write\equationsListFile{\unexpanded{\begingroup\description}}
\immediate\write\equationsListFile{
\unexpanded{\def\synopsis}
\hashchar
\unexpanded{1{}}
}
\immediate\write\equationsListFile{\unexpanded{\setlength{\itemsep}{2pt}}}
\immediate\write\equationsListFile{\unexpanded{\abovedisplayskip=3pt plus 3pt minus 2pt}}
\immediate\write\equationsListFile{\unexpanded{\belowdisplayskip=2pt plus 3pt minus 2pt}}
}
% Copy "\jobname.eqn" to "\jobname.leq"
\AtEndDocument{%
\immediate\write\equationsListFile{\unexpanded{\enddescription\endgroup}}
\immediate\closeout\equationsListFile
\newread\in
\openin\in=\jobname.eqn
\newwrite\out
\immediate\openout\out\jobname.leq
\endlinechar-1
\loop \unless\ifeof\in
\readline\in to\l
\immediate\write\out{\l}
\repeat
\immediate\closeout\out
\closein\in
}
% Save previous \begin{equation} and \end{equation} commands:
\let\beginEquation=\equation
\let\endEquation=\endequation
% Undefine them, so that that the environment can be redefined:
\providecommand*\@nameundef[1]{%
\expandafter\let\csname #1\endcsname\@undefined
}
\@nameundef{equation}
\@nameundef{endequation}
\NewEnviron{equation}{{%
% Default equation name is empty:
\gdef\equationName{}
% Let the synposis command record the equation's name
\def\synopsis##1{\gdef\equationName{##1}}
% Generate equation in document as usual (but hook on \labe)
\beginEquation
\BODY
\label{eq:\theequation}
\endEquation
\@onelevel@sanitize\BODY
\@onelevel@sanitize\equationName
% Generate an entry in \jobname.leq (tweak as necessary)
\immediate\write\equationsListFile{\unexpanded{\pagebreak[3]}}
\immediate\write\equationsListFile{\unexpanded{\item}}
\immediate\write\equationsListFile{[(\unexpanded{\ref}{eq:\theequation})]}
\immediate\write\equationsListFile{\equationName\unexpanded{~~\dotfill~~}\thepage}
\immediate\write\equationsListFile{\unexpanded{\nopagebreak[3]}}
\immediate\write\equationsListFile{\unexpanded{\\\begin{equation*}}}
\immediate\write\equationsListFile{\BODY}
\immediate\write\equationsListFile{\unexpanded{\end{equation*}}}
}}
% globally defines a macro \hashchar which holds a verbatim `#`
\begingroup
\catcode`\#=12
\gdef\hashchar{#}%
\endgroup
答案4
我找到了这个。非常简单!我只需要弄清楚如何让标题样式与文档中的其他列表相匹配,但我仍抱有希望!
https://latex.org/forum/viewtopic.php?t=428
\documentclass{article}
\usepackage{amsmath}
\usepackage{tocloft}
\begin{document}
\newcommand{\listequationsname}{List of Equations}
\newlistof{myequations}{equ}{\listequationsname}
\newcommand{\myequations}[1]{%
\addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}\par}
\listofmyequations
\begin{equation}\label{eq:Eq1}
a=b
\end{equation}
\myequations{Equation number \ref{eq:Eq1}}
\newpage
\begin{equation}\label{eq:Eq2}
b=c
\end{equation}
\myequations{Equation number \ref{eq:Eq2}}
\end{document}