2

Is there a way to use the equation counter for referencing single symbols inside the equation instead of the whole equation? For example like this

\documentclass[10pt]{scrartcl}

\usepackage{amsmath}
\usepackage[utf8]{inputenc}

\begin{document}

$$\Phi(x)\underset{(1)}{=}\lambda x~,$$
Reference (1) later in the text.

\end{document}

Whole equations and symbol references should use the same counter, so they cannot interfere with one another and the symbol reference should work in $$...$$ as well as align* environment.

My first attempt implementing this looks like this

\documentclass[10pt]{scrartcl}

\usepackage{amsmath}
\usepackage[utf8]{inputenc}

\newcommand{\oplabel}[1]{\refstepcounter{equation}(\theequation\label{#1})}

\begin{document}

$$\Phi(x)\underset{\oplabel{somename}}{=}\lambda x~,$$
Reference \eqref{somename} later in the text.

\end{document}

and it works for $$...$$, but neither for \begin{align}...\nonumber\end{align} nor for \begin{align*}...\end{align*}.

Is there a way to use the equation counter in the align* environment too? (I know the * stands for "no line counting", but I'd like to manually add references where I need them without numbering every line.)

1
  • 2
    Side note: $$...$$ is deprecated. Use \[...\]. And align* does not use the equation counter. Another issue is that the align etc. redefine \label
    – user31729
    Commented May 20, 2017 at 11:43

1 Answer 1

5

The reason why \label does not work the expected way is that that amsmath package redefines it.

In order to provide a working version, use the original version of \label which is stored by amsmath into \ltx@label. This will work for align, align* and \[...\] as well.

Side note: Don't use $$...$$, that's deprecated syntax, use \[...\] instead.

\documentclass[10pt]{scrartcl}

\usepackage{amsmath}
\usepackage[utf8]{inputenc}

\makeatletter
\newcommand{\oplabel}[1]{\refstepcounter{equation}(\theequation\ltx@label{#1})}
\makeatother
\begin{document}

\[\Phi(x)\underset{\oplabel{somename}}{=}\lambda x,\]

\begin{align}
  \Phi(x)&\underset{\oplabel{someothername}}{=}\lambda x~ \nonumber
\end{align}

\begin{align*}
  \Phi(x)&\underset{\oplabel{yetanothername}}{=}\lambda x~ 
\end{align*}

Reference \eqref{someothername} or \eqref{somename} or \eqref{yetanothername} later in the text.

\end{document}

enter image description here

5
  • On thinking about this: Perhaps, it's better to use a different counter and not equation for this.
    – user31729
    Commented May 20, 2017 at 11:56
  • 1
    Works great. Thank you :) Still wondering, why it might be better to not use equation for this?
    – Cubi73
    Commented May 20, 2017 at 12:29
  • @Cubinator73: You're referencing a symbol rather than an equation. But its a matter of taste, in the end.
    – user31729
    Commented May 20, 2017 at 12:31
  • Oh ok. I like writing an equation into a single line and referencing single steps with text more than writing multiple lines of equations and little text inbetween. That's the reason behind this question.
    – Cubi73
    Commented May 20, 2017 at 12:34
  • @ChristianHupfer +1 I vote positive always to my friends.
    – Sebastiano
    Commented May 20, 2017 at 20:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .