[texhax] setting counters to output of a \ref command

Philip G. Ratcliffe philip.ratcliffe at fastwebnet.it
Thu Feb 8 23:19:49 CET 2007


> Here is the problem I'm trying to solve.  I'd like to have a 
> particular 
> theorem appear twice in a paper, and I'd like its appearance to be 
> identical in both, the numbering in particular, without 
> having to set the 
> section and theorem counters by hand.
> 
> Is there a way of getting a hold of the numbers generated by the \ref 
> command so I can use them to set the relevant counters and 
> duplicate the 
> appearance of the theorem?  I've tried several sources of LaTeX 
> documentation and just can't seem to find a way to do this; the only 
> related piece of information I found was that one can "transport" the 
> current value of a counter with \value{counter}, but here I'm 
> interested 
> in transporting a value that is not current.

The following is adapted from a suggestion in the FAQ for lists, it should
be possible to do something similar for theorems.

\documentclass{article}
\begin{document}
\noindent Here's a list:
\begin{enumerate}
  \item A
  \item B
  \newcounter{it:last-scalar-rule}%
  \setcounter{it:last-scalar-rule}{\value{enumi}}%
  \item C
\end{enumerate}
And here's a repetition:
\begin{enumerate}
  \setcounter{enumi}{\value{it:last-scalar-rule}}
  \addtocounter{enumi}{-1}
  \item B
\end{enumerate}
\end{document}

Cheers,  Phil Ratcliffe



More information about the texhax mailing list