2

I have this counter which I have defined using \newcounter{myCounter}.

Printing the value of myCounter can be easily done via \arabic{myCounter}. How can I print the value of (myCounter - 2)?

3

Either use the \label-\ref system if you're stepping myCounter via \refstepcounter system, or manually calculate it via \numexpr:

enter image description here

\documentclass{article}
\newcounter{myCounter}

\begin{document}

\setcounter{myCounter}{5}
\verb|\themyCounter:     | \themyCounter

\verb|\arabic{myCounter}:| \arabic{myCounter}

\bigskip

\refstepcounter{myCounter}\label{myLabel}
\verb|\themyCounter:     | \themyCounter

\addtocounter{myCounter}{2}
\verb|\themyCounter:     | \themyCounter

\bigskip

\verb|\ref{myLabel}:     | \ref{myLabel}

\verb|Calculation:       | \number\numexpr\value{myCounter}-2\relax

\end{document}

\the<counter> is usually used to represent the value of <counter>, and is defined as \arabic{<counter>} by default. As reference, see The \the command.

More options exist (with LaTeX's fp and LaTeX3's l3fp) if you want to perform more intricate calculations.

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