Menu

HowTo_ListOfEquations

How to generate a list of equations similar to the list of figures or list of tables

At most at math education scripts almost every formula has a name and should be listed in a directory similar to the list of figures or list of tables. KOMA-Script classes already use KOMA-Script package tocbasic, that provides command \DeclareNewTOC to generate such tables or lists of several kinds of content (TOCs). To create a new list of equations you need only

\DeclareNewTOC[listname={List of Equations},type=equation]{loe}

Now, you can already use \addxcontentsline{loe}{equation}[<number>]{<entry text>}. loe is the extension of the auxiliary file used to store the entries for the next LaTeX run. It es the last argument of \DeclareNewTOC and the first of \addxcontentsline. equation is the type of the entries of the optional argument of \DeclareNewTOC. It is also the type of the entries at the second argument of \addcontentsline. List of Euqations in the optional argument of \DeclareNewTOC is the headline used for the list of equations. This list can be printed using \listofequations, a command defined by \DeclareNewTOC.

If you are using such a \addxcontentsline command inside an equation environment, you would usually use \theequation as <number>. As <entry text> you can use whatever text you would like to have shown in the list of equations. So a first, example would be:

\documentclass[english]{scrartcl}

\usepackage{babel}

% To have a new list of equations we just declare a new TOC:
\DeclareNewTOC[listname={List of Equations},type=equation]{loe}

\begin{document}
\listofequations
\section{Examples}
\begin{equation}
  \addxcontentsline{loe}{equation}[\theequation]{Quadratic Formula}
  (a+b)^{2} = a^{2} + 2ab + b^{2}
\end{equation}
\end{document}

However, it would be a little bit uncomfortable to always type the same three arguments of \addxcontentsline. So it would be useful to define a new command to add the entries:

\documentclass[english]{scrartcl}

\usepackage{babel}

% To have a new list of equations we just declare a new TOC:
\DeclareNewTOC[listname={List of Equations},type=equation]{loe}
% And a command to add entries to the file:
\newcommand*{\setequationentry}[1]{%
  \addxcontentsline{loe}{equation}[\theequation]{#1}%
  \ignorespaces
}

\begin{document}
\listofequations
\section{Examples}
\begin{equation}
  \setequationentry{Quadratic Formula}
  (a+b)^{2} = a^{2} + 2ab + b^{2}
\end{equation}
\end{document}

Note: If you are using amsmath environments like align, these usually do not increase the equation counter at the very beginning but with every \\ and after the end of the formula. So using adding \setequationentry before the first \\ would result in a by one to low number in the list of equations. So using \setquationentry after the corresponding \\ could be done. However if you'd add a \\ after the last equation, you would get an extra line with an extra number. So you need a variant of \setequationentry that increases the equation counter only locally for generating the entry, e.g., to be used as:

\documentclass[english]{scrartcl}

\usepackage{babel}
\usepackage{amsmath}

% To have a new list of equations we just declare a new TOC:
\DeclareNewTOC[listname={List of Equations},type=equation]{loe}
% And a command to add entries to the file:
\newcommand*{\setequationentry}[2][0]{%
  \begingroup
    \advance \value{equation} by #1\relax
    \addxcontentsline{loe}{equation}[\theequation]{#2}%
  \endgroup
  \ignorespaces
}

\begin{document}
\listofequations
\section{Examples}
\begin{align}
  (a+b)^{2} &= a^{2} + 2ab + b^{2} \\
  \setequationentry{Binomial Formula $(a+b)^{2}$}
  (a-b)^{2} &= a^{2} - 2ab + b^{2}
  \setequationentry[1]{Binomial Formula $(a-b)^{2}$}
\end{align}

\end{document}

or better:

\documentclass[english]{scrartcl}

\usepackage{babel}
\usepackage{amsmath}

% To have a new list of equations we just declare a new TOC:
\DeclareNewTOC[listname={List of Equations},type=equation]{loe}
% And a command to add entries to the file:
\newcommand*{\setequationentry}[2][0]{%
  \begingroup
    \advance \value{equation} by #1\relax
    \addxcontentsline{loe}{equation}[\theequation]{#2}%
  \endgroup
  \ignorespaces
}

\begin{document}
\listofequations
\section{Examples}
\begin{align}
  \setequationentry[1]{Binomial Formula $(a+b)^{2}$}
  (a+b)^{2} &= a^{2} + 2ab + b^{2} \\
  \setequationentry[1]{Binomial Formula $(a-b)^{2}$}
  (a-b)^{2} &= a^{2} - 2ab + b^{2}
\end{align}

\end{document}

And because of almost always either adding nothing or adding 1, I would suggest using a command with star variant:

 \documentclass[english]{scrartcl}

\usepackage{babel}
\usepackage{amsmath}

% To have a new list of equations we just declare a new TOC:
\DeclareNewTOC[listname={List of Equations},type=equation]{loe}
% And a command to add entries to the file:
\NewDocumentCommand{\setequationentry} {sm} {%
  \begingroup
    \IfBooleanT {#1}{\advance \value{equation} by 1\relax}%
    \addxcontentsline{loe}{equation}[\theequation]{#2}%
  \endgroup
  \ignorespaces
}

\begin{document}
\listofequations
\section{Examples}
\begin{align}
  \setequationentry*{Binomial Formula $(a+b)^{2}$}
  (a+b)^{2} &= a^{2} + 2ab + b^{2} \\
  \setequationentry*{Binomial Formula $(a-b)^{2}$}
  (a-b)^{2} &= a^{2} - 2ab + b^{2}
\end{align}

There is also a third form:
\begin{equation}
  \setequationentry{Binomial Formula $(a+b)\times(a-b)$}
  (a+b)\times(a-b) = a^{2} - b^{2}
\end{equation}

\end{document}

You could also use the name of the current environment to decide, whether or not to increase equation:

\documentclass[english]{scrartcl}

\usepackage{babel}
\usepackage{amsmath}

% To have a new list of equations we just declare a new TOC:
\DeclareNewTOC[listname={List of Equations},type=equation]{loe}
% And a command to add entries to the file:
\makeatletter% because of the `@' in `\@currenvir` and `\@ne`
\newcommand{\setequationentry}[1]{%
  \begingroup
    \Ifstr{\@currenvir}{equation}{}{%
      \advance \value{equation} by \@ne\relax%
    }%
    \addxcontentsline{loe}{equation}[\theequation]{#1}%
  \endgroup
  \ignorespaces
}
\makeatother% because of the `\makeatletter' above

\begin{document}
\listofequations
\section{Examples}
\begin{align}
  \setequationentry{Binomial Formula $(a+b)^{2}$}
  (a+b)^{2} &= a^{2} + 2ab + b^{2} \\
  \setequationentry{Binomial Formula $(a-b)^{2}$}
  (a-b)^{2} &= a^{2} - 2ab + b^{2}
\end{align}

There is also a third form:
\begin{equation}
  \setequationentry{Binomial Formula $(a+b)\times(a-b)$}
  (a+b)\times(a-b) = a^{2} - b^{2}
\end{equation}

\end{document}

It would also be able to connect the tag generation and the entry generation to avoid the manipulation of the equation counter. But this would also depend on whether or not amsmath is used.

If you do not only want to add the name of the equation to a new list, but also show it in the document, please have a look into the KOMA-Script manual. There is a example of a remarkbox environment at the description of \DeclareNewTOC. You can easily adapt it for the definition of a namedequation floating environment or namedequation- non floating environment. Definition of at least one of these is needed to also be able to use \captionof.


Related

Wiki (English): HowTo_Floats

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.