Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm looking to do the following automatically rather than manually

\documentclass{article}
\usepackage{amsmath}

\begin{document}
These equations are pretty important.

    \begin{align}
        \label{eqn:one}     a+b&=c\\
        \label{eqn:two}     d+e&=f\\
        \label{eqn:three}   g+h&=i
    \end{align}

But as it turns out, we can actually do better by recalling
    that $a=1$, so we have

    \begin{equation*}
        \tag{\ref{eqn:one}A}
            1+b=c\\
    \end{equation*}

Furthermore, $c=d=e=2$, so we have

    \begin{align*}
        \tag{\ref{eqn:one}B}    1+b&=2\\
        \tag{\ref{eqn:two}A}    2+2&=f
    \end{align*}

\end{document}

enter image description here

In other words, I'd like to provide a switch that tells an equation to display a number based on which iteration of a previous equation it is. Non-requirements:

  • I can manually instruct it which equation is its ancestor; I don't need it to "figure it out" automatically.
  • I also don't care what the format of these numbers is as I presume any solution will make that easy to change (so e.g. I'd be just as happy with 1.1, 1.2 instead of 1A, 1B).
  • Finally, there is no need to support automatic re-labeling, as I can manually re-label the important future iterations so long as the label "grabs" the tagged-displayed number in references.

Requirement:

  • The one thing that is essential is that I would like to automate the sub-numbering process so I don't risk messing it up by moving equations around / deleting them.

Unfortunately I'm not sure what this is called. Sub-referencing equations? Self-referencing equation numbering?

share|improve this question
    
I am pretty sure that there was an earlier question similar to this. I think @egreg had posted a solution, but since he has answered sooooo many questions it is not easy to find. –  Peter Grill Aug 10 '12 at 21:39
    
This is similar...but doesn't seem to answer my question; more coming in same category (similar but not sufficiently similar). –  Philip Aug 10 '12 at 21:40
    
This is kind-of similar. –  Philip Aug 10 '12 at 21:42
    
This is very similar, but still doesn't seem to get it...or I'm not understanding the answer. The key point is @LeoLiu 's comment "There should not be any manual serial numbers in LaTeX." –  Philip Aug 10 '12 at 21:42
    
tiny format niggle ... there's too much space above the displays (compared with the space below). don't leave a blank line between text and a following display, or, if you want it to be more visible in the input file, put a % at the beginning of that blank line. –  barbara beeton Aug 11 '12 at 16:12
add comment

1 Answer

up vote 6 down vote accepted
\documentclass{article}
\usepackage{amsmath}

\def\subeqncount#1{%
\newcounter{sub:#1}%
\expandafter\def\csname thesub:#1\endcsname{\ref{#1}\Alph{sub:#1}}}

\def\subeqntag#1{%
\refstepcounter{sub:#1}%
\tag{\csname thesub:#1\endcsname}}


\subeqncount{eqn:one}
\subeqncount{eqn:two}

\begin{document}
These equations are pretty important.

    \begin{align}
        \label{eqn:one}     a+b&=c\\
        \label{eqn:two}     d+e&=f\\
        \label{eqn:three}   g+h&=i
    \end{align}

But as it turns out, we can actually do better by recalling
    that $a=1$, so we have

    \begin{equation*}
           \subeqntag{eqn:one}
            1+b=c\\
    \end{equation*}

Furthermore, $c=d=e=2$, so we have

    \begin{align*}
        \subeqntag{eqn:one}    1+b&=2\\
        \subeqntag{eqn:two}    2+2&=f
    \end{align*}

\end{document}
share|improve this answer
    
This is pretty sweet. Is there a way to skip having to manually do \subeqncount{ } for each counter I use though? I'm guessing no. The problem is, I'm working in a multi-part document with no way to anticipate which future equations will need labels or "sub-labels," or how those label names might change as the document progresses, so this creates another manual serialization issue, albeit a MUCH smaller one. So it's still pretty cool. Thanks! –  Philip Aug 10 '12 at 21:49
1  
I wondered about that but you basically need to make a global assignment and doing that from within an ams alignment isn't exactly impossible but likely to make the code very fragile and error prone. If you wanted to do it probably best would be to trap the "undefined counter" error that you get if it is not defined, and make it write a \newcounter declaration to the aux file so it is defined next time, or something... (too late to think about it too hard:-) –  David Carlisle Aug 10 '12 at 21:53
    
Lol, thanks! Maybe a TeXpert--which I am not--on this side of the pond can fill in the blanks for me :) –  Philip Aug 10 '12 at 21:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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