Number of equation with condition

Harald Hanche-Olsen harald.hanche-olsen at
Sun Mar 28 11:58:29 CEST 2021

Hello! I am working in a article documentclass. It have five section using the command \section. My intention is that each equation number showed a determined format depending on if the section number is odd or even.

I intended using the conditionals, before the \section, for example:
\ifodd \value{section} \renewcommand{\theequation}{\textbf{{\thesection}-\alph{equation}}} \else \renewcommand{\theequation}{\textit{{\thesection}-\arabic{equation}}}\fi

This might work. However there are two problems: (1) in the code you showed, you run this conditional only once, thus choosing the “even” branch of the conditional, since the section number is zero initially. This will then be in force in the entire document. You would have to run this code together with each \section command. (2) The \section command increments the counter, so if you run your code before \section, the sense of even vs odd will be flipped. Better run it after \section.

A better approach still would be to incorporate the test into \theeequation. Here is a sample document that hopefully does what you want:


\begin{equation} \label{zero}
\begin{equation} \label{one}
\begin{equation} \label{two}
Reference to \ref{zero}, \ref{one}, \ref{two}.

– Harald

PS. When asking question like this, please do include a minimal, but complete file demonstrating your approach. By complete, I mean something that anybody can compile and which shows the problem you are trying to solve. You are much more likely to get help if you do.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the texhax mailing list.