How to print a past value of a counter
1,212
Either use the \label
-\ref
system if you're stepping myCounter
via \refstepcounter
system, or manually calculate it via \numexpr
:
\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.
Related videos on Youtube
Author by
Werner
Updated on August 01, 2022Comments
-
Werner over 1 year
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)?-
Werner over 8 years
-