Text FormattingSet current reference string in list environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
kfeuerherm
Posts: 5
Joined: Thu May 21, 2009 11:13 pm

Set current reference string in list environment

Post by kfeuerherm »

Hi

I'm relatively new to LaTeX... and I'm trying to define a list environment which will generate cross-reference labels automatically as per the code below:

%% Environment for numbered display items
%% The argument is used to define a label allowing later reference to the number
\newcounter{ndictr}%
\newenvironment{ndi}[1]%
{% open environment ndi
\newcommand{\ndil}{(\thendictr)}
\begin{list}{}%
{% declarations
\settowidth{\labelwidth}{\makelabel{(999)}}%
\setlength{\leftmargin}{\labelwidth+\labelsep}%
\addtocounter{ndictr}{1}%
}%
\item [\ndil] \mbox{}\outl{\thendictr}\label{ndi#1key}%
\ignorespaces%
}%
{% close environment ndi
\unskip%
\end{list}%
}% end of environment ndi

The label is generated as expected, but later uses of \ref{key} fail because, as expected, the current reference string is not being set.

Can someone tell me what to do in order to get that set?

Thanks!

K

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
kfeuerherm
Posts: 5
Joined: Thu May 21, 2009 11:13 pm

Re: Set current reference string in list environment

Post by kfeuerherm »

OOPS. Sorry, ignore the piece of code which reads \outl{\thendictr}. I was trying something out (which didn't work) and forgot to remove it.

K
kfeuerherm
Posts: 5
Joined: Thu May 21, 2009 11:13 pm

Re: Set current reference string in list environment

Post by kfeuerherm »

Aha! I think I've hit on it.

I read through the code of the cjoutl package, which does something similar to enumerate, and by sheer process of elimination discovered the \refstepcounter command: this increments the counter and sets the \ref value as well.

See A Document Preparation System: LaTeX--User's Guide and Reference Manual, p. 195.

Seems to work :)

Thanks

K
Post Reply