11

After finding Table of Equations and http://www.latex-community.org/forum/viewtopic.php?f=5&t=428, I set about making a List of Equations for my document. The catch here is that we already have a working draft and its hundreds of pages and contains dozens of equations.

The above links describe how to use tocloft to add the List of Equations, but both require following each equation with a tag such as \myequations{Display name}. To avoid having to add this for all of our equations, I redefined equation to automatically include our \myequations{} command:

\let\oldequation = \equation
\let\endoldequation = \endequation
\renewenvironment{equation}{
    \begin{oldequation}
}{
    \end{oldequation}
    \myequations{\@currentlabelname}
}

I proceeded with the tocloft-specific code which is directly based on the above links, ending with:

\usepackage{tocloft}
\newcommand{\listequationsname}{List of Equations}
\newlistof{myequations}{equ}{\listequationsname}

% myequation takes in its display name
\newcommand{\myequations}[1]{

% display name is printed
\addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}\par}

Then all \equations will appear automatically in the List of Equations. That's great, but there is one problem:


Each \equations displayed name in the List of Equations is not its own \label (eg. "Torque") but instead is the name of the \subsection in which it appears (such that dozens of equations have the name of "DC Motor Operation," etc.)


Any ideas? What can I replace \@currentlabelname with to drop in the name of the \label for the equation? A simple one looks like this:

\begin{equation}
\tau=F\times r
\label{eq:Torque}
\end{equation}

FWIW, I am actually doing this in Lyx but that doesn't seem to be the source of my problems. In fact, if there is a more elegant solution for Lyx, I'm all ears.

Thanks!

Example in LaTeX:

\documentclass[english]{article}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\usepackage{amsmath}
\usepackage[unicode=true, pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 0},backref=false,colorlinks=false]
 {hyperref}

\makeatletter
\numberwithin{equation}{section}

% we use this for our refernces as well
\AtBeginDocument{\renewcommand{\ref}[1]{\mbox{\autoref{#1}}}}

% redefinition of \equation for convenience
\let\oldequation = \equation
\let\endoldequation = \endequation
\renewenvironment{equation}{
\begin{oldequation}
}{
\end{oldequation}
\myequations{\@currentlabelname}
}

% try to make a List of Equations, 
% error is most likely in the @currentlabelname above
\usepackage{tocloft}
\newcommand{\listequationsname}{List of Equations} 
\newlistof{myequations}{equ}{\listequationsname} 
\newcommand{\myequations}[1]{ 
\addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}\par}
\setlength{\cftmyequationsnumwidth}{3em}

\makeatother

\begin{document}
\tableofcontents{}
\listofmyequations

\section{Brushless Motor Fundamentals}
\subsubsection{DC Motor Operation}
Torque is generated in DC motors from the magnetic force, 
also known as the Lorentz force, which is produced when an
electric current is passed through a coil in a magnetic field. 
This force is given by \ref{eq:Force}.

\begin{equation}
F=q[E+(v\times B)]
\label{eq:Force}
\end{equation}
where F is the force perpendicular to the coil, 
E is the electric field in the coil, 
v is the velocity of the charged particles in the coil, 
and B is the magnetic field. From mechanics, torque is 

\begin{equation}
\tau=F\times r\label{eq:Torque}\end{equation}
If the electrical force in \ref{eq:Force} is ignored, 
and the remaining magnetic force is used in \ref{eq:Torque}, 
with the assumption that v is perpendicular to B, we find that
\begin{equation}
\tau=qvBrsin\theta
\label{eq:Magnetic}\end{equation}

\end{document}

[FIXED - Thank you Mike Renfro] Equations 2.1 - 2.9 display correctly in the List of Equations but after the equation number hits 2.10 the last digit ('ones' digit) overlaps with the beginning of the display name.

  • let me see if I understand your problem: you want to use the string that you write in the argument of \label as the entry for the new list of equations, but stripping out the eq: prefix used in \label? For example, if you have \label{eq:Torque} then just Torque should be placed in the list of equations? – Gonzalo Medina Mar 26 '11 at 22:30
  • below I added a solution which removes "eq:" from the new list. – Gonzalo Medina Mar 27 '11 at 1:36
  • Would it be possible (how?) to refer to an (optional) \caption for equations? Because purpose of \label is kind of different. – KcFnMi Mar 31 at 17:10
7

Here's a modified version of Lev Bishop's code; I used the xstring package to remove the string "eq:" from the labels:

\documentclass[english]{article}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\usepackage{amsmath}
\usepackage{tocloft}
\usepackage{xstring}
\usepackage[unicode=true, pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 0},backref=false,colorlinks=false]
 {hyperref}

\makeatletter
\numberwithin{equation}{section}

% we use this for our refernces as well
\AtBeginDocument{\renewcommand{\ref}[1]{\mbox{\autoref{#1}}}}

% redefinition of \equation for convenience
\let\oldequation = \equation
\let\endoldequation = \endequation
\AtBeginDocument{\let\oldlabel = \label}% \AtBeginDocument because hyperref redefines \label
\newcommand{\mynewlabel}[1]{%
  \StrBehind{#1}{eq:}[\Str]% remove "eq:" from labels
  \myequations{\Str}\oldlabel{#1}}
  \renewenvironment{equation}{%
  \oldequation
  \let\label\mynewlabel
}{\endoldequation}

\newcommand{\listequationsname}{List of Equations}
\newlistof{myequations}{equ}{\listequationsname}
\newcommand{\myequations}[1]{%
      \addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}}
\setlength{\cftmyequationsnumwidth}{3em}

\makeatother

\begin{document}
\tableofcontents
\listofmyequations

\section{Brushless Motor Fundamentals}
\subsubsection{DC Motor Operation}
Torque is generated in DC motors from the magnetic force,
also known as the Lorentz force, which is produced when an
electric current is passed through a coil in a magnetic field.
This force is given by \ref{eq:Force}.
\begin{equation}
  F=q[E+(v\times B)]
  \label{eq:Force}
\end{equation}
where $F$ is the force perpendicular to the coil,
$E$ is the electric field in the coil,
$v$ is the velocity of the charged particles in the coil,
and $B$ is the magnetic field. From mechanics, torque is
\begin{equation}
  \tau=F\times r
  \label{eq:Torque}
\end{equation}
If the electrical force in \ref{eq:Force} is ignored,
and the remaining magnetic force is used in \ref{eq:Torque},
with the assumption that $v$ is perpendicular to $B$, we find that
\begin{equation}
      \tau=qvBrsin\theta
  \label{eq:Magnetic}
\end{equation}

\end{document}
  • This doesn't work when you use underscores in your labels. It results in an error for the first equation using underscores in its label: ! Missing $ inserted. <inserted text> $ <to be read again> _ <argument> ...stname }{\numberline {2.1.1}example_ matrix_universe}\hyper@lin... \l@myequations ...\@nameuse {cftmyequationsfont}#1 }\nobreak \@nameuse {cftmy... ... The error message goes on for a bit more. It's too long for a comment. How to fix? – Zelphir Kaltstahl Mar 27 '16 at 15:38
  • Also it's not really a missing $ in the document. I checked, when I don't use your list of enumerations, the error does not occur. – Zelphir Kaltstahl Mar 27 '16 at 16:06
4

Here is a modified version of your example. The main change is that I redefine \label within equation environments:

\documentclass[english]{article}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\usepackage{amsmath}
\usepackage[unicode=true, pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 0},backref=false,colorlinks=false]
 {hyperref}

\makeatletter
\numberwithin{equation}{section}

% we use this for our refernces as well
\AtBeginDocument{\renewcommand{\ref}[1]{\mbox{\autoref{#1}}}}

% redefinition of \equation for convenience
\let\oldequation = \equation
\let\endoldequation = \endequation
\AtBeginDocument{\let\oldlabel = \label}% \AtBeginDocument because hyperref redefines \label
\newcommand{\mynewlabel}[1]{\myequations{#1}\oldlabel{#1}}
\renewenvironment{equation}{%
\oldequation
\let\label\mynewlabel
}{\endoldequation}

% try to make a List of Equations,
% error is most likely in the @currentlabelname above
\usepackage{tocloft}
\newcommand{\listequationsname}{List of Equations}
\newlistof{myequations}{equ}{\listequationsname}
\newcommand{\myequations}[1]{%
\addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}}
\setlength{\cftmyequationsnumwidth}{3em}

\makeatother

\begin{document}
\tableofcontents{}
\listofmyequations

\section{Brushless Motor Fundamentals}
\subsubsection{DC Motor Operation}
Torque is generated in DC motors from the magnetic force,
also known as the Lorentz force, which is produced when an
electric current is passed through a coil in a magnetic field.
This force is given by \ref{eq:Force}.

\begin{equation}
F=q[E+(v\times B)]
\label{eq:Force}
\end{equation}
where F is the force perpendicular to the coil,
E is the electric field in the coil,
v is the velocity of the charged particles in the coil,
and B is the magnetic field. From mechanics, torque is

\begin{equation}
\tau=F\times r\label{eq:Torque}\end{equation}
If the electrical force in \ref{eq:Force} is ignored,
and the remaining magnetic force is used in \ref{eq:Torque},
with the assumption that v is perpendicular to B, we find that
\begin{equation}
\tau=qvBrsin\theta
\label{eq:Magnetic}\end{equation}

\end{document} 
  • Using TexMaker this builds fine but the output shows "Contents" (so far so good) then "List of Equations" (warmer...) and then skips right to the first section, "Brushless Motor Fundamentals," without displaying any of the equations in the list :-( – gnirts Mar 27 '11 at 0:54
  • Compile it twice? Any error messages in log file? – Lev Bishop Mar 27 '11 at 1:02
  • Good catch---compiling it twice it definitely works. Now I just need to figure out how to remove the "eq:", if that's even possible. – gnirts Mar 27 '11 at 1:04
2

I couldn't come up with a minimal working example in regular LaTeX yet.

As for (2), try setting \cftmyequationsnumwidth to a larger value (see tocloft manual, section 2.3).

  • is there any way to attach a minimal working example? – gnirts Mar 26 '11 at 20:48
  • @gnirts: If you have to attach the example, it's not minimal. ;-) – lockstep Mar 26 '11 at 20:51
  • I added \setlength{\cftmyequationsnumwidth}{3em} and that works great, thank you! I also updated the original post with a working example – gnirts Mar 26 '11 at 21:51
1

I expanded upon the previous answers to define a command that you can use like so:

\noteworthy{a^2 + b^2 = c^2}{Pythagorean theorem} 

And it will automatically label, reference, box, and list the equations that I consider noteworthy. I'm really happy with the result.

Note that the red squares just highlight hyperlinks, they're not visible on the pdf.

enter image description here

And then the equation is numbered, boxed, labelled with text (that matches the list of equations), and gets a label to allow us to reference it.

enter image description here

Minimum viable example:

\documentclass{article}
\usepackage{tocloft}    % for list of equations
\usepackage{ragged2e}   % to undo \centering
\usepackage{hyperref}   % to make references hyperlinks
\usepackage{glossaries} 

% define list of equations
\newcommand{\listequationsname}{\Large{List of Equations}}
\newlistof{myequations}{equ}{\listequationsname}
\newcommand{\myequations}[1]{
   \addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}
}
\setlength{\cftmyequationsnumwidth}{2.3em}
\setlength{\cftmyequationsindent}{1.5em}

% command to box, label, reference, and 
% include noteworthy equation in list of equations
\newcommand{\noteworthy}[2]{
\begin{align} \label{#2} \ensuremath{\boxed{#1}} \end{align} 
\myequations{#2} \centering \small \textit{#2} \normalsize \justify }

\begin{document}

\listofmyequations \pagebreak

\noteworthy{P(\bigcup_{n=1}^n A_n) \leq \sum_{n=1}^n P(A_n)}{Boole's inequality}

Where the events $A_n$ are disjoint, then the inequality 
in equation \ref{Boole's inequality} becomes an equality.

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.