2

I need to customize equation numbering as follows:

Some text ...

    a+b  (5)
    3+2  (5')

... some more text....

    c+d  (6)

The idea is that (5') is an example of (5). I thought of using subequations, but I am not sure how to customize the inner numbering, as it would generate 5a and 5b, or 5.i, 5.ii, etc.... If I use \tag{} instead, I am not sure how to get the previous equation number (5, in the example).

4

You can define an \eqorn command. If you use \eqorn[''] you get two primes; any math symbol can be specified in the optional argument.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\eqorn}[1][']{\tag{\theequation\ensuremath{#1}}}

\begin{document}

Some text ...
\begin{gather}% or align or whatnot
a+b \label{main} \\
3+2 \eqorn \label{secondary}
\end{gather}
... some more text....
\begin{equation}
c+d
\end{equation}
with references to \eqref{main} and \eqref{secondary}.

\end{document}

enter image description here

  • This is a very simple solution with which - as you say - any formula can be specified in the optional argument. Can it be modified so that the first equation in the series could also be customized (for instance, if I want three consecutive equations to be numbered as $(5_{x-y}), (5_{x+y}), (5_{z^2})$)? – R W Feb 11 at 0:25
  • @RW I'd say that \eqorn[_{x-y}] should work. – egreg Feb 11 at 0:45
  • My question is not about typesetting a subscript - this part works perfectly OK, and this is a great advantage of your solution (compared to using the subequations environment). However, what I don't manage to do right is the "main" numbering. In my example, if add \eqorn just before the labels for the 2nd and 3rd equations, I get $(5),(5_{x+y}),(5_{z^2})$, but if I add \eqorn before all 3 labels I get $(4_{x-y}), (4_{x+y}), (4_{z^2})$ (the counter doesn't move), whereas what I want is $(5_{x-y}), (5_{x+y}), (5_{z^2})$. Many thanks in advance! – R W Feb 11 at 1:08
  • @RW Not sure what you mean: if I open subequations and then make a gather environment with two equations having \eqorn[_a] and \eqorn[_b] respectively, I get 1_a and 1_b. If I then close subequations, the next equation is numbered 2. – egreg Feb 11 at 9:27
  • Here is an example \documentclass{article} \usepackage{amsmath} \newcommand{\eqorn}[1][']{\tag{\theequation\ensuremath{#1}}} \begin{document} \begin{equation} \label{before} c+d \end{equation} Some text ... \begin{gather} a+b \eqorn[a] \label{main} \\ 3+2 \eqorn[b] \label{secondary} \end{gather} ... some more text.... \begin{equation} \label{after} c+d \end{equation} with references to \eqref{before}, \eqref{main} and \eqref{secondary}, \eqref{after} \end{document} However, you are right, this does not happen inside the subequation environment. – R W Feb 11 at 12:15
3

Here's an approach using expl3's \prg_replicate:nn to produce n copies of ' to number the equations in subequations and etoolbox's \patchcmd to insert that in the subequations environment.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{expl3}

% Creating a command to print a number of apostrophes
\ExplSyntaxOn
\cs_new:Npn \apost #1
  { \__andy_apost:cn { c@ #1 } }
\cs_new:Npn \__andy_apost:Nn #1
  {
    \ensuremath {
      \prg_replicate:nn { #1 - 1 } { {'} }
    }
  }
\cs_generate_variant:Nn \__andy_apost:Nn { c }
\ExplSyntaxOff

% Patching-in that command in \subequations
\usepackage{etoolbox}
\patchcmd\subequations
  {\def\theequation{\theparentequation\alph{equation}}}
  {\def\theequation{\theparentequation\apost{equation}}}
  {}{\FAIL}

\begin{document}

\begin{subequations}
\begin{equation}
  a+b
\end{equation}
\begin{equation}
  3+2
\end{equation}
\begin{equation}
  5
\end{equation}
\end{subequations}

\end{document}
  • 1
    Possibly \ensuremath{\prg_replicate:nn { #1 - 1 }{'}} gives a better output. – egreg Nov 12 '18 at 22:29
1

An alternative is the modified answer from here:

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand*\ifcounter[1]{%
  \ifcsname c@#1\endcsname%
    \expandafter\@firstoftwo%
  \else%
    \expandafter\@secondoftwo%
  \fi%
}%
\makeatother



\newcommand\EqFamTag[2][roman]{%
\ifcounter{#2}{%
\expandafter\addtocounter{#2}{1}%
\expandafter\addtocounter{#2Prev}{1}
\xdef\temp{\csname #2 Eq\endcsname \ifnum\value{#2Prev}>0 \space(\csname #1\endcsname{#2Prev})\fi}%
\global\expandafter\let\csname #2\arabic{#2}\endcsname\temp%
\tag{\temp}%
}{%
\global\expandafter\newcounter{#2}%
\global\expandafter\newcounter{#2Prev}
\expandafter\addtocounter{#2}{1}%
\xdef\temp{\theequation \ifnum\value{#2Prev}>0 \space(\csname #1\endcsname{#2Prev})\fi}%
\xdef\eqonfamily{\theequation}%
\global\expandafter\let\csname #2 Eq\endcsname\eqonfamily%
\global\expandafter\let\csname #2\arabic{#2}\endcsname\temp%
\tag{\temp}%
\expandafter\addtocounter{equation}{1}
}%
}%

\newcommand\myFamRef[2][1]{\csname #2#1\endcsname}

\begin{document}
\section{test}
\begin{equation}
f(x)=3\cdot x
\end{equation}

\begin{equation}
    x=4\cdot y \EqFamTag{MyFamily}
\end{equation}

As an example:

\begin{equation}
    x=4\cdot 2=8\EqFamTag{MyFamily}
\end{equation}

The equation: \myFamRef[2]{MyFamily} is the first example/member of the equation \myFamRef{MyFamily}

\begin{equation}
    x=4\cdot y 
\end{equation}

Another example of :

\begin{equation}
    x=4\cdot 2=8\EqFamTag{MyFamily}
\end{equation}

The equation: \myFamRef[3]{MyFamily} is the second example/member of the equation \myFamRef{MyFamily}

Another family of equations is:

\begin{equation}
    f(x)=3+y \EqFamTag{NewFam}
\end{equation}

and a member of it is:

\begin{equation}
    f(6)=9 \EqFamTag{NewFam}
\end{equation}

\end{document}

Output:

enter image description here

0

It is very easy to have a first (main) subequation numbered as an ordinary equation, the subequations standard numbering starting only at the second subequation:

\documentclass{article}
\usepackage{amsmath}
\setcounter{equation}{4}

\begin{document}
Some text . . . . . .
\begin{subequations}
\addtocounter{equation}{-1}
\begin{gather}
  a+b \label{main} \\
  3+2 \label{ex-1} \\
  5\label{ex-2}
\end{gather}
\end{subequations}.
. . . . . .Some more text . . . . . .
\begin{equation}
  c + d
\end{equation}

\eqref{ex-1} and \eqref{ex-2} illustrate \eqref{main}.

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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