Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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
    
Yes, that's it exactly. –  gnirts Mar 27 '11 at 0:52
    
below I added a solution which removes "eq:" from the new list. –  Gonzalo Medina Mar 27 '11 at 1:36

3 Answers 3

up vote 6 down vote accepted

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}
share|improve this answer
    
Awesome! Is there any way to give you both credit? Thanks Gonzalo, and thanks Lev! –  gnirts Mar 27 '11 at 2:04
    
@gnirts: I don't know if that's possible. –  Gonzalo Medina Mar 27 '11 at 2:10

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} 
share|improve this answer
    
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

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).

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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