Text Formattingtocloft package and problem with equation labels

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
gkl
Posts: 28
Joined: Sat Jan 17, 2009 12:21 am

tocloft package and problem with equation labels

Post by gkl »

Dear All,

I am using the tocloft package to generate a list of equations I have in my thesis for the table of contents. It builds successfully with the following code:

Code: Select all

\newcommand{\listequationsname}{List of Equations}
\newlistof{myequations}{equ}{\listequationsname}
\newcommand{\myequations}[1]{%
%\refstepcounter{myequations}
%\par\noindent\textbf{Equation \theequation. #1}
\addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}\par}
Now if I want to have a title for the equation I will do something like:

Code: Select all

\begin{equation}
\label{eq:pythagoras}
$$\myequations{Test}$$
x^2 + y^2 = z^2
\end{equation}
This will get the entry in the table of contents, but will remove the label - you can no longer say

Code: Select all

look at equation~\ref{eq:pythagoras}
, it will just give you the section's number.

Any ideas as to how to fix this?

Regards,
George

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

tocloft package and problem with equation labels

Post by frabjous »

Can you provide a minimal working example showing the misbehavior? If I simply do:

Code: Select all

\documentclass{article}
\usepackage{tocloft}
\usepackage{amsmath}
\newcommand{\listequationsname}{List of Equations}
\newlistof{myequations}{equ}{\listequationsname}
\newcommand{\myequations}[1]{%
%\refstepcounter{myequations}
%\par\noindent\textbf{Equation \theequation. #1}
\addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}\par}

\begin{document}
\listofmyequations
\section{Something}
\section{Another}
\begin{equation}
\label{eq:pythagoras}
\text{\myequations{Test}}
x^2 + y^2 = z^2
\end{equation}
Equation (\ref{eq:pythagoras}) is right there.
\end{document}
then the \ref command works just fine.

(By the way, I recommend using \text rather than $$..$$ to escape back to text mode inside the equation, but I don't think that's your problem. Also, I wonder why you don't use \newlistentry instead of \addcontentsline)
gkl
Posts: 28
Joined: Sat Jan 17, 2009 12:21 am

Re: tocloft package and problem with equation labels

Post by gkl »

I haven't considered using \text and \listentry to be honest. However, I found that the problem can be solved by simply moving the \myequations command outside the equation environment and have it immediately after the equation code.

I think this is because \addtocontentsline uses the equation counter (\theequation) so it might be resetting it or something but just moving it outside the equation block did the trick.

George
Post Reply