Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

\NewEnviron and \refstepcounter

10 views
Skip to first unread message

Pluto

unread,
Dec 30, 2009, 1:29:11 PM12/30/09
to
The \NewEnviron command from the 'environ' package doesn't give the
correct reference number using the \refstepcounter. Perhaps a problem
with the \@currenvir or \@currentlabel. Does anyone, especially Will
Robertson, have any suggestions? Sincerely.

\documentclass{article}
\begin{document}

% Sample from the LaTeX Companion:

\newcounter{excnt}[section]
\renewcommand\theexcnt{\thesection.\Alph{excnt}}
\newenvironment{EX}{\begin{flushleft}%
\refstepcounter{excnt}%
\textbf{Exercise~\theexcnt:}}%
{\end{flushleft}}

\setcounter{section}{4} % just for testing

\section{A Success}

\begin{EX} \label{ex:A} A test text. \end{EX}
\begin{EX} \label{ex:B} Another test text. \end{EX}

\noindent Referencing exercises with {\tt\string\newenvironment}: \ref
{ex:A} and \ref{ex:B}.

% \NewEnviron failed to give the correct references:

\NewEnviron{EXC}{%
\begin{flushleft}%
\refstepcounter{excnt}%
\textbf{Exercise~\theexcnt:}%
\end{flushleft}%
}

\section{A Failure}

\begin{EXC} \label{exc:A} A test text. \end{EXC}
\begin{EXC} \label{exc:B} Another test text. \end{EXC}

\noindent Referencing exercises using {\tt\string\NewEnviron}: \ref
{exc:A} and \ref{exc:B}.

\end{document}

Will Robertson

unread,
Jan 4, 2010, 11:11:47 PM1/4/10
to
On 2009-12-31 04:59:11 +1030, Pluto <a.m...@rocketmail.com> said:

> \NewEnviron{EXC}{%
> \begin{flushleft}%
> \refstepcounter{excnt}%
> \textbf{Exercise~\theexcnt:}%
> \end{flushleft}%
> }

You're missing "\BODY".

W

0 new messages