3

how would I go about automatically making a table that includes all of the equations that are in my document and their label?

Let's assume I got this code:

\documentclass[11pt,german,a4paper]{article}
\usepackage{german}

\newcommand{\tu}[1]{\textsuperscript{#1}} \newcommand{\td}[1]{\textsubscript{#1}} \newcommand{\nl}{\newline}

\begin{document}

\tableofcontents % Inhaltsverzeichnis erzeugen für jede Section \newpage

\section{Die Maxwell'schen Gleichungen} \subsection{Maxwellgleichung 1} Elektrische Feldlinien beginnen an positiven und enden an negativen Ladungen. Deshalb wird ein B-Feld als Quellenfeld bezeichnet.
\begin{equation} \label{eqn:Maxwell-1} \epsilon\td{0} = \Sigma Q \end{equation}

\subsection{Maxwellgleichung 2} 
Es gibt keine magnetischen Ladungen/ Monopole; magnetische Felder sind deshalb immer Wirbelfelder mit in sich geschlossenen Feldlinien (auch quellenfrei genannt). 
Auch das magnetische Feld eines Permanentmagneten ist ein Wirbelfeld. Es ist im Inneren des Magneten längs der Feldlinien von S nach N und außerhalb von N nach S  gerichtet.
\begin{equation} 
\label{eqn:Maxwell-2}
\oint \! BdA = 0
\end{equation}

\subsection{Maxwellgleichung 3}
Ein sich zeitlich änderndes magnetisches Feld generiert ein elektrisches Wirbelfeld, dessen geschlossene Feldlinien ringförmig die Feldlinien des sich ändernden magnetischen Feldes umgeben. \nl
Die zeitliche Änderung eines B-Feldes durch eine Fläche A hindurch ist gleich der Stärke des E-Feldes entlang des Randes der Fläche A.
\begin{equation} 
\label{eqn:Maxwell-3}
\oint \! Eds = \frac{d}{dt} \oint \! BdA
\end{equation}

\subsection{Maxwellgleichung 4}     
Ein sich änderndes elektrisches Feld oder ein Strom erzeugt ein magnetisches Wirbelfeld.  
\begin{equation} 
\label{eqn:Maxwell-4}
\oint \! Bds = \mu\td{0}\Sigma I + \mu\td{0} \epsilon\td{0} \frac{d}{dt} \oint \! EdA
\end{equation}

\end{document}

I've stumbled upon examples that looked like \tableofcontents, but they didn't include the equations.

Thanks :)

Roland
  • 6,655
Drizzel
  • 31
  • 3
    Welcome to TeX.SX! Thanks for providing a MWE. Unrelated note: Never use the package german. It is outdated for decades and should be replaced by \usepackage[ngerman]{babel} (if you are okay with the new orthography rules). – TeXnician Feb 23 '20 at 10:39
  • The new orthography rule are the worst garbage. If you like a high quality german orthography use \usepackage[german]{babel}. – Weißer Kater Feb 23 '20 at 15:15

3 Answers3

4

This is based on my answer at call / repeat / duplicate equation based on label . EDITED to build the table rows automatically, and one can optionally specify a counter range (which does not necessarily equate with the label number).

Provides \literallabel{} to save the argument to the saved-equation list and assumes you are already in math mode. Provides \literaleq environment as a version of the equation environment, where the content is saved to the saved-equation list.

It allows for equations to be omitted from the summary.

\documentclass{article}
\usepackage{environ,pgffor}
\newcounter{literaleqctr}
\newcommand\literallabel[1]{%
  \stepcounter{literaleqctr}%
  \label{litlbl_\theliteraleqctr}
  \expandafter\gdef\csname literaleq_\theliteraleqctr\endcsname{#1}
  #1
}
\NewEnviron{literaleq}{%
  \stepcounter{literaleqctr}%
  \begin{equation}
  \label{litlbl_\theliteraleqctr}%
  \expandafter\gdef\csname 
    literaleq_\theliteraleqctr\expandafter\endcsname\expandafter{\BODY}
  \BODY
  \end{equation}%
}
\newcommand\theliteraleq[1]{$\csname literaleq_#1\endcsname$}
\newcommand\literalref[1]{\ref{litlbl_#1}}
\newtoks\eqsumtoks
\newcommand{\addtotoks}[2]{#1\expandafter{\the#1#2}}
\newcommand{\xaddtotoks}[2]{\expandafter\addtotoks\expandafter#1\expandafter{#2}}

\newcommand\eqsummarytoks[1][1,...,\theliteraleqctr]{%
  \eqsumtoks{}%
  \foreach\z in {#1}{%
    \global\addtotoks\eqsumtoks{\theliteraleq}%
    \global\xaddtotoks\eqsumtoks{\expandafter{\z} & \literalref}%
    \global\xaddtotoks\eqsumtoks{\expandafter{\z}\\}%
  }%
  \the\eqsumtoks
}
\begin{document}
\begin{equation}
    \literallabel{a + b = c}  \quad\textrm{, explanatory text}
\end{equation}
Omit this next equation from the save list
\begin{equation}
  y = Ax + by + C
\end{equation}
Now another
\begin{literaleq}
  E = mc^2
\end{literaleq}
A third
\begin{literaleq}
  F=ma
\end{literaleq}

\begin{table}[ht]
\caption{Equation Summary}\medskip
\centering
\begin{tabular}{cr}
\hline
Equation & Label \\
\hline
\eqsummarytoks[1,...,2]
\end{tabular}
\end{table}

\begin{table}[ht]
\caption{Equation Summary (cont.)}\medskip
\centering
\begin{tabular}{cr}
\hline
Equation & Label \\
\hline
\eqsummarytoks[3,...,3]
\end{tabular}
\end{table}
\end{document}

enter image description here

2

This, I hope, answers your question but not in an elegant way. Here is a revision of your MWE, for which thank you.

% listofeqprob.tex SE 529655 List of equations??

\documentclass[11pt,german,a4paper]{article}
\usepackage{german}

% setup a new listof Equations
\usepackage{tocloft}
\newcommand{\listequationname}{List of Equations}
\newlistof{eqnum}{leq}{\listequationname}

\newcommand{\tu}[1]{\textsuperscript{#1}}
\newcommand{\td}[1]{\textsubscript{#1}}
\newcommand{\nl}{\newline}

\begin{document}

\tableofcontents % Inhaltsverzeichnis erzeugen für jede Section
\newpage

\listofeqnum  

\newpage

\section{Die Maxwell'schen Gleichungen}
    \subsection{Maxwellgleichung 1}
    Elektrische Feldlinien beginnen an positiven und enden an negativen Ladungen. Deshalb wird ein B-Feld als Quellenfeld bezeichnet.       
%    create a macro of the equation
    \newcommand{\Maxwella}{\epsilon\td{0} = \Sigma Q}
%   and print it just to show how it can be used
    \par
    \(\Maxwella\)
    \par
    \begin{equation} 
    \label{eqn:Maxwell-1}
%   here is the equation text
    \Maxwella
    \end{equation}
%   add the equation to the List of Ewuations
    \addcontentsline{leq}{eqnum}%
      {\protect\numberline{\ref{eqn:Maxwell-1}}\(\Maxwella\)}

    \subsection{Maxwellgleichung 2} 
    Es gibt keine magnetischen Ladungen/ Monopole; magnetische Felder sind deshalb immer Wirbelfelder mit in sich geschlossenen Feldlinien (auch quellenfrei genannt). 
    Auch das magnetische Feld eines Permanentmagneten ist ein Wirbelfeld. Es ist im Inneren des Magneten längs der Feldlinien von S nach N und außerhalb von N nach S  gerichtet.
    \begin{equation} 
    \label{eqn:Maxwell-2}
    \oint \! BdA = 0
    \end{equation}

    \subsection{Maxwellgleichung 3}
    Ein sich zeitlich änderndes magnetisches Feld generiert ein elektrisches Wirbelfeld, dessen geschlossene Feldlinien ringförmig die Feldlinien des sich ändernden magnetischen Feldes umgeben. \nl
    Die zeitliche Änderung eines B-Feldes durch eine Fläche A hindurch ist gleich der Stärke des E-Feldes entlang des Randes der Fläche A.

% and similarly for the third equation

\newcommand{\Maxwellc}{\oint \! Eds = \frac{d}{dt} \oint \! BdA}
    \begin{equation} 
    \label{eqn:Maxwell-3}
    \oint \! Eds = \frac{d}{dt} \oint \! BdA
    \end{equation}
    \addcontentsline{leq}{eqnum}%
      {\protect\numberline{\ref{eqn:Maxwell-3}}\(\Maxwellc\)}%\par}


    \subsection{Maxwellgleichung 4}     
    Ein sich änderndes elektrisches Feld oder ein Strom erzeugt ein magnetisches Wirbelfeld.  
    \begin{equation} 
    \label{eqn:Maxwell-4}
    \oint \! Bds = \mu\td{0}\Sigma I + \mu\td{0} \epsilon\td{0} \frac{d}{dt} \oint \! EdA
    \end{equation}

\end{document}

I hope that this helps (please read the tocloft package documentation for more information about what I have done). Perhaps others will come up with a more efficient solution.

** MORE EFFICIENT/ELEGANT ANSWER **

Having given more thought to the problem I have come up with what I think is a better answer.

\documentclass[11pt,a4paper]{article}

% setup a new listof Equations
\usepackage{tocloft}
\newcommand{\listequationname}{List of Equations}
\newlistof{equations}{leq}{\listequationname}

% \lequation{<label>}{<the maths>}
% typesets a labelled equation and adds it to the list of equations
\newcommand{\lequation}[2]{%
  \begin{equation} \label{#1} #2 \end{equation}%
  \addcontentsline{leq}{equations}{\protect\numberline{\ref{#1}}\(#2\)}%
  % extra space between leq entries, if needed
  \addtocontents{leq}{\protect\addvspace{10pt}}%
}


\newcommand{\tu}[1]{\textsuperscript{#1}}
\newcommand{\td}[1]{\textsubscript{#1}}
\newcommand{\nl}{\newline}

\begin{document}

\listofequations  

\newpage

\lequation{eqn:Maxwell-1}{\epsilon\td{0} = \Sigma Q}

\lequation{eqn:Maxwell-3}{\oint \! Eds = \frac{d}{dt} \oint \! BdA}

\newpage

\lequation{eqn:Maxwell-5}%
  { \oint \! Bds = \mu\td{0}\Sigma I + \mu\td{0} \epsilon\td{0} \frac{d}{dt} \oint \! EdA}

The first equation is \ref{eqn:Maxwell-1}.

\end{document}

A List of Equations is set up (I now understand that you asked for a table but I mentally converted that to table (of contents). The macro lequation is defined which takes a label and an equation as arguments. It typesets the equation and adds the label reference, the equation, and the page number to the List of Equations. It seemed to me that the resulting entries were a little too close so there is also code to put a little more space between the List of Equations entries (use judiciously). The normal equation environment is unaltered.

Peter Wilson
  • 28,066
  • Great, thanks a lot. How can I use german letter like ä or ü? And how do I get the Title \listequationname smaller? – Drizzel Feb 25 '20 at 10:17
  • To make the title smaller \renewcommand{\cftleqtitlefont}{\small\bfseries} replacing \small with whatever size you want. I know nothing about German letters; just try them and see. – Peter Wilson Feb 25 '20 at 17:54
0

Works well:

\documentclass[11pt,a4paper]{article}

% setup a new listof Equations
\usepackage{tocloft}
\usepackage{xstring}
\usepackage{amsmath}

\newcommand{\listequationname}{List of Equations}
\newlistof{equations}{leq}{\listequationname}
\renewcommand{\cftleqtitlefont}{\Large\bfseries} %\Large controls font size

% \lequation{<label>}{<the maths>}
% typesets a labelled equation and adds it to the list of equations
\newcommand{\lequation}[2]{%
  \begin{equation} \label{#1} #2 \end{equation}%
  \addcontentsline{leq}{equations}{\protect\numberline{\ref{#1}}\($#1$:#2\)} %$#1$ so that label is not printed in italics and spaces are now kept
  % extra space between leq entries, if needed
  \addtocontents{leq}{\protect\addvspace{10pt}}%
}

\newcommand{\tu}[1]{\textsuperscript{#1}} %just for comfort
\newcommand{\td}[1]{\textsubscript{#1}}
\newcommand{\nl}{\newline}

\begin{document}

\listofequations  

\newpage

\lequation{Maxwell 1}{\epsilon\td{0} = \Sigma Q}

\lequation{Maxwell 3}{\oint \! Eds = \frac{d}{dt} \oint \! BdA}
\lequation{Maxwell-5}%
  { \oint \! Bds = \mu\td{0}\Sigma I + \mu\td{0} \epsilon\td{0} \frac{d}{dt} \oint \! EdA}


\end{document}
Drizzel
  • 31
  • That is remarkably like the answer I gave although including changing the title font as I said in my response to your comment. Glad to know that you have no problems with \hyperref and German characters. – Peter Wilson Feb 26 '20 at 18:54
  • It is your answer. I thought I could close my question by providing an answer, but apparently that was incorrect. It’s my first question here... And for some reason German letters worked flawlessly without me consciously changing anything, even though they caused errors at first. No idea why :) – Drizzel Feb 27 '20 at 19:14