[Tex/LaTex] List of Equations / Table of Equations

equationstable of contentstocloft

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.

Best Answer

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}