LaTeX forum ⇒ Math & Science ⇒ How to define a new counter in gather environment Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
bcpn
Posts: 3
Joined: Fri Sep 05, 2014 4:19 pm

How to define a new counter in gather environment

Hi everyone!

I have been trying to create a new counter to clearly identify a specific subset of equations. I use the following code to overwrite the equation environment:
\newcounter{newcounter}\setcounter{newcounter}{0}\newenvironment{NEWequation}{\addtocounter{equation}{-1}\refstepcounter{newcounter}\renewcommand\theequation{NEW.\thenewcounter}\begin{equation}}{\end{equation}}

This is working as I want it to, but then I want to use and increment the same counter for gather environments, and I fail to increase the counter within the environment. So far I've tried the following:

\NewEnviron{NEWgather}{\addtocounter{equation}{-1}\refstepcounter{newcounter}\renewcommand\theequation{NEW.\thenewcounter}\begin{gather}\BODY\end{gather}}

It properly updates the counter from NEWgather/NEWequation environment to the next NEWgather/NEWequation environment, but fails to do so in the body.

Does anyone know how to overcome this issue? Thank you for your help!

Tags:

Johannes_B
Site Moderator
Posts: 3587
Joined: Thu Nov 01, 2012 4:08 pm
Can you extend your code to a compilable example showing not only the definition but an example of use as well?
I think a bullet-proof solution may already exist in a package.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

bcpn
Posts: 3
Joined: Fri Sep 05, 2014 4:19 pm
Yes of course! Here is a compilable code of what I would like to obtain..
Thanks!


Johannes_B
Site Moderator
Posts: 3587
Joined: Thu Nov 01, 2012 4:08 pm
Not really predefined by a package nor bullet-proof but it seems to work.

SwitchNumbering saves the appearance of the tag and its current numerical value and then resets the numbering. It expects one argument of you to put in front to describe the new numbering scheme.

switchBack later resumes both the appearance and the last number to go on as nothing has ever happened.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

bcpn
Posts: 3
Joined: Fri Sep 05, 2014 4:19 pm
Thank you very much, that should do the work!