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 approach answers only your question [A] (see below for a complete solution).
Replace the line
\setlength{\cftmyequationsnumwidth}{3em}
with
\setlength{\cftmyequationsindent}{1.5em}
\setlength{\cftmyequationsnumwidth}{2.3em}
so to match the corresponding definitions for \listoffigures
in tocloft.sty
:
\setlength{\cftfigindent}{1.5em}
\setlength{\cftfignumwidth}{2.3em}
MWE:
\documentclass[
pdftex,
listof=totoc,
]{scrreprt}
\usepackage{amsmath}
\usepackage{xstring}
\usepackage{tocloft}
\usepackage{blindtext}
\usepackage[demo]{graphicx}
\makeatletter
\numberwithin{equation}{chapter}
% 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{\cftmyequationsindent}{1.5em}
\setlength{\cftmyequationsnumwidth}{2.3em}
\makeatother
\begin{document}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 1}
\label{fig:1}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 2}
\label{fig:2}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 3}
\label{fig:3}
\end{figure}
\blinddocument
\begin{equation}
1 + 1 = 2
\label{eq:first}
\end{equation}
\begin{equation}
2 + 2 = 4
\label{eq:second}
\end{equation}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 4}
\label{fig:4}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 5}
\label{fig:5}
\end{figure}
\listoffigures
\listofmyequations
\end{document}
Output:
A different approach can be used to achieve both [A] and [B].
I don't like this one very much, but here it is.
We use the package float
and declare the Equation
environment to be a new floating environment.
So, replace all the stuff between \makeatletter ... \makeatother
with:
\newfloat{Equation}{htbp}{equ}[chapter]
\newcommand{\listequationsname}{List of Equations}
At this point you can use equations inside Equation
in this way:
\begin{Equation}[!htb]
\centering
\begin{equation}
1 + 1 = 2
\end{equation}
\caption{First equation}
\label{eq:first}
\end{Equation}
and to print the List of Equations you have to write the line:
\listof{Equation}{\listequationsname}
instead of
\listofmyequations
MWE:
\documentclass[
pdftex,
listof=totoc,
]{scrreprt}
\usepackage{amsmath}
\usepackage{xstring}
\usepackage{float}
\usepackage{blindtext}
\usepackage[demo]{graphicx}
\newfloat{Equation}{htbp}{equ}[chapter]
\newcommand{\listequationsname}{List of Equations}
\begin{document}
\begin{Equation}[!htb]
\centering
\begin{equation}
0 + 0 = 0
\end{equation}
\caption{Zeroth equation}
\label{eq:zeroth}
\end{Equation}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 1}
\label{fig:1}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 2}
\label{fig:2}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 3}
\label{fig:3}
\end{figure}
\blinddocument
\begin{Equation}[!htb]
\centering
\begin{equation}
1 + 1 = 2
\end{equation}
\caption{First equation}
\label{eq:first}
\end{Equation}
\begin{Equation}[!htb]
\centering
\begin{equation}
2 + 2 = 4
\end{equation}
\caption{Second equation}
\label{eq:second}
\end{Equation}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 4}
\label{fig:4}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[width=5cm,height=4.5cm]{image1}
\caption{figure 5}
\label{fig:5}
\end{figure}
\listoffigures
\listof{Equation}{\listequationsname}
\end{document}
Output:
Best Answer
The described issue isn't seen in this example. I've added
\usepackage{tocbibind}
for including ofToC
etc. intoToC
and added theLoE
to theToC
as well.However, the manual usage of
\myequation
is error-prone and isn't recommended!