3

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:

enter image description here

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?

1

2 Answers 2

1

You can do something like this:

\makeatletter
\newcount\tmpc@unter
\newcount\LCount
\LCount=2
\def\stepL{\global\advance\LCount1\relax}
\def\theL{{\the\LCount}}
\def\nextL{{\stepL\theL}}
\def\refL#1{{\tmpc@unter=\LCount\advance\tmpc@unter#1\relax\the\tmpc@unter}}
\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.

0

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:
\begin{equation}
    \refstepcounter{LCount}\label{first}
    L_\theLCount = L((a|b^*)cc^*a^*(c|b^*)^*)
\end{equation}
\[
    \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.

Output in standard article class

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .