Graphics, Figures & TablesRedefine label in enumerate list

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Redefine label in enumerate list

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass[UKenglish]{article}
\usepackage{babel}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{hyperref}

\mathtoolsset{showonlyrefs}
\newcommand*{\hv}[1]{\label{eqn:#1}\stackrel{\mathclap{(#1)}}{=}}
\newcommand*{\fk}[1]{\item[\eqref{eqn:#1}]}

\begin{document}

We have
\begin{align}
  \Delta y
  &\hv{1} m(x_{0}+h) - m(x_{0})\\
  &\hv{2} \frac{f(x_{0}+h)}{g(x_{0}+h)} - \frac{f(x_{0})}{g(x_{0})}\\
  &\hv{3} \frac{f(x_{0}+h) \cdot g(x_{0})}{g(x_{0}+h) \cdot g(x_{0})} - \frac{f(x_{0}) \cdot g(x_{0}+h)}{g(x_{0}) \cdot g(x_{0}+h)}\\
  &= \dots
\end{align}
Explanations:
\begin{enumerate}[itemsep=0ex]
  \fk{1} A
  \fk{2} B
  \fk{3} C
\end{enumerate}

\end{document}
Issues:
1. This way of refering to the lines in the align expression seems wierd. Is there a better way of doing this?
2. I will like the labels "(1)", "(2)", ... to be printed above "=" only and not flushed right too. I there a way of doing this?

Ad 2. I have tried putting \notag at the end of each line but then I get the following error:

Code: Select all

Package amsmath Error: Multiple \label's: label 'eqn:1' will be lost.
Thank you in advance!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

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

svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Redefine label in enumerate list

Post by svend_tveskaeg »

I have cross-posted this question on {TeX} SX.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: Redefine label in enumerate list

Post by Stefan Kottwitz »

Hi Svend,

thanks for mentioning the crosspost and especially for linking back to here.

I have to admit that this way of placing tags looks very strange for me. References are for look-up, and as a reader I need a consistent position where I look for the tags. If I would see a reference to equation (12), I would like to look at the tags at the right (or always at the left), it would be much harder for me to find the small (12) set over an equal sign somewhere in the first third of a line. It requires me scanning the whole text and not just the margin for the tag I'm looking for. That's especially hard in a large document with many equations and varying positions because of different widths of the left terms.

Do you know books which do it this way? I'm just interested to see one, just because I never saw it this way.

In my opinion, tagging should be functional, even though your idea to tag the equal sign is a nice one.

Stefan
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Redefine label in enumerate list

Post by svend_tveskaeg »

@Stafan:
I have never seen tags like the ones I try to accomplish. :D (I have a short document with something like 10 equations.)

The reason why I choose this labelling was to try something new but I can see what you meen. ;)

P.S. Here is the solution from {TeX} SX:

Code: Select all

\documentclass[danish]{article}
\usepackage{babel}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{hyperref}

%\usepackage[color]{showkeys}
\mathtoolsset{showonlyrefs}

\setcounter{equation}{10}

\makeatletter
\newcommand*{\hv}[1]{%
    \refstepcounter{equation}%
    \ltx@label{EQ:#1}% Label%
    \stackrel{\mathclap{(\theequation)}}{=}%
}
\makeatother
\newcommand*{\fk}[1]{\item[\eqref{EQ:#1}]}

\begin{document}
We have
\begin{align*}
  \Delta y  &\hv{A} m(x_{0}+h) - m(x_{0})\\
            &\hv{B} \frac{f(x_{0}+h)}{g(x_{0}+h)} - \frac{f(x_{0})}{g(x_{0})}\\
            &\hv{C} \frac{f(x_{0}+h) \cdot g(x_{0})}{g(x_{0}+h) \cdot g(x_{0})} - \frac{f(x_{0}) \cdot g(x_{0}+h)}{g(x_{0}) \cdot g(x_{0}+h)}\\
            &= \dots
\end{align*}
Explanations:
\begin{enumerate}
  \fk{A} DESCA
  \fk{B} DESCB 
  \fk{C} DESCC
\end{enumerate}
\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Redefine label in enumerate list

Post by Stefan Kottwitz »

Thanks for adding the solution by ADP here.

Just another remark: I would not use an enumerate environment here. enumerate is for (sequentially) numbered lists, where the items can be referred to. Here is no need for references, and there's no numbering, since the "bullets" of this list can be arbitrary equation tags. It's just coincidence the they are ordered numbers and step up one by one. ;-)

An itemize or description list would do the same, or even a small table. My main point is just, that it isn't a numbered list.

Stefan
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Redefine label in enumerate list

Post by svend_tveskaeg »

Thank you for the explanation! I will choose another list environment.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply