# Can I reference a number relative to a counter without changing the counter?

I have a counter called LCount, which I want to use in some text, and i would like to be able to reference numbers that are relative to that counter. for example, I would like this LaTeX code:

For the regular languages:
\begin{align*}
&L_\theLCount = L((a|b^*)cc^*a^*(c|b^*)^*)\\\stepcounter{LCount}
&L_\theLCount = L(ac^*c(a^*|b)^*)\stepcounter{LCount}
\end{align*}
If $L_\theLCount = L_{\theLCount-2} \cap L_{\theLCount-1}$, then:


to render like this:

if LCount has an initial value of 2. Is there a way of doing this? Should I be using something different other than counters? I know i can use \addtocounter a bunch of times and make the final line:

If $L_\theLCount = \addtocounter{LCount}{-2} L_\theLCount \cap \addtocounter{LCount}{1} L_\theLCount$\stepcounter{LCount}, then:


but that seems really clumsy and inefficient. Is there a better way?

• The standard way would be to use refstepcounter and labels, but it seems that there is some clash with equation labelling... see also tex.stackexchange.com/questions/21300/… Apr 27, 2016 at 7:33

You can do something like this:

\makeatletter
\newcount\tmpc@unter
\newcount\LCount
\LCount=2
\def\theL{{\the\LCount}}
\def\nextL{{\stepL\theL}}
\makeatother
\begin{document}
$$L_\theL = L_\nextL + L_\nextL$$
and now:
$$L_\refL{-2} = L_\refL{-1} + L_\theL$$
\end{document}


I.e. use temporal counter.

An option is to use the standard way of \refstepcounter:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\newcounter{LCount}
\begin{document}
\stepcounter{LCount}\stepcounter{LCount}
For the regular languages:
$$\refstepcounter{LCount}\label{first} L_\theLCount = L((a|b^*)cc^*a^*(c|b^*)^*)$$
$\refstepcounter{LCount}\label{second} L_\theLCount = L(ac^*c(a^*|b)^*)$
\refstepcounter{LCount}
If $L_\theLCount = L_{\ref{first}} \cap L_{\ref{second}}$, then:
\end{document}


But beware that there will be problems (worth another question, I think) with amsmath and the counters used for equation numbering.

(BTW, post a complete MWE next time...)