GeneralCustom and automatic equation numbering

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
cbustaam
Posts: 57
Joined: Mon Sep 01, 2008 10:17 pm

Custom and automatic equation numbering

Post by cbustaam »

I all,
I'm trying to enumerate a group of "special" equations inside an align environment. I need something like the following

Code: Select all

.. = ..... (E1)
 .. = ....  (E2)
.. = ..... (E3)
but I want that this special numbering don's affect the ordinal equation numbering, it means, if the previous equation to the align environment is labeled as equation (4), the equation below this environment has to be labeled as (5).

I've trying a solution with the \tag command, but this command not is automatic (I have to write explicitly "E1", "E2", and "E3"). I only want to declare that the following equations number begin with "E" and next a number "automatically generated.

Any ideas?
Bests
"Show me your .emacs and I'll tell you who you are." -- modified proverb

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Custom and automatic equation numbering

Post by gmedina »

Hi,

try the environment myalign that I defined in the following example code:

Code: Select all

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcounter{oldequation}
\newenvironment{myalign}{%
  \setcounter{oldequation}{\theequation}
  \renewcommand\theequation{E\arabic{equation}}
  \setcounter{equation}{0}
  \start@align\@ne\st@rredfalse\m@ne
}{%
  \math@cr \black@\totwidth@
  \egroup
  \ifingather@
    \restorealignstate@
    \egroup
    \nonumber
    \ifnum0=`{\fi\iffalse}\fi
  \else
    $$%
  \fi
  \ignorespacesafterend
  \setcounter{equation}{\theoldequation}
  \renewcommand\theequation{\arabic{equation}}
}
\makeatother

\begin{document}

\begin{equation}
  a=b.
\end{equation}

\begin{myalign}
  a &= b\\
  &= c\\
  &= d
\end{myalign}

\begin{equation}
  a=b.
\end{equation}

\begin{equation}
  a=b.
\end{equation}

\begin{myalign}
  a &= b\\
  &= c\\
  &= d\\
  &= e\\
  &=f.
\end{myalign}

\begin{equation}
  a=b.
\end{equation}

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
cbustaam
Posts: 57
Joined: Mon Sep 01, 2008 10:17 pm

Custom and automatic equation numbering

Post by cbustaam »

Thanks a lot gmedina.. it works great.
Best regards
"Show me your .emacs and I'll tell you who you are." -- modified proverb
edmundfo
Posts: 1
Joined: Mon Jan 17, 2011 9:05 am

Re: Custom and automatic equation numbering

Post by edmundfo »

gmedina, how would you change the align environment so that no equation numbers are displayed?

I ask about this because I am currently trying to modify the align environment so that everything in an align environment is displayed in a particular color. That is, I want a starred version of the following:

\newenvironment{balign}{%
\color{black}{%
}%
\align
\color{black}{%
}%
}{%
\color{black}{%
}%
\endalign
% extra material here
}

By the way, I believe that I should be able to achieve the same with \everydisplay{\color{black}}, but this only seems to affect the equation environment, and not the align environment.
macnolds
Posts: 3
Joined: Wed Dec 28, 2011 3:18 pm

Custom and automatic equation numbering

Post by macnolds »

A simpler solution, using enumerate:

Code: Select all

\begin{enumerate}[(E1)]
\item $first$ \label{un}
\item $second$ \label{deux}
\item $third$. \label{trois}
\end{enumerate}
The only issue here is that when you try to reference one of these equations, it'll show a number such as "1" (or "(1)" with \eqref), instead of "E1."
Last edited by Stefan Kottwitz on Wed Dec 28, 2011 4:40 pm, edited 2 times in total.
macnolds
Posts: 3
Joined: Wed Dec 28, 2011 3:18 pm

Custom and automatic equation numbering

Post by macnolds »

Here's a way to use the enumitem package in order to customize your iterated lists and get the "/ref" command to reference your equations properly.

Code: Select all

\usepackage{enumitem}
....
\begin{enumerate}[label=(E\arabic*), ref=(E\arabic*)]
\item blah \label{eq1}
\item blah \label{eq2}
\end{enumerate}

Check out equation \ref{eq1}.
Last edited by macnolds on Wed Dec 28, 2011 4:41 pm, edited 2 times in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Custom and automatic equation numbering

Post by Stefan Kottwitz »

Hi macnolds,

welcome to the board!

You don't need to make the code bold. The forum provides a Code button for marking code, when editing. I did it for you above, so you can see how the result looks like.

Stefan
LaTeX.org admin
macnolds
Posts: 3
Joined: Wed Dec 28, 2011 3:18 pm

Re: Custom and automatic equation numbering

Post by macnolds »

Thanks, Stefan.
Post Reply