6

I have defined a custom environment (using the tocloft package, thanx to Juan) that looks like:

\newcommand{\listscriptname}{List of Scripts}
\newlistof[chapter]{script}{spt}{\listscriptname}
\def\thescript{\thechapter-\arabic{script}}
\newenvironment{script}[2][]
  { \vspace{3mm}\hspace{3mm}
    \colorbox{orange}{\refstepcounter{script}
    \textbf{Script~\thescript #1:code/#2.groovy}}
    \addcontentsline{spt}{script}
       {\protect\numberline{\thescript}#1~~code/#2.groovy}
  }
  {}

which I use like:

\begin{script}{FooBar}
\label{script:FooBar}
BitStream.
\end{script}

And refer to it with:

Script~\ref{script:FooBar}.

But instead of the script environment number, I get the number of the section.

What am I doing wrong (I did try several variations...)?

1 Answers1

9

Move \refstepcounter out of the \colorbox:

\newenvironment{script}[2][]
  {\vspace{3mm}\hspace{3mm}%
    \refstepcounter{script}%
    \colorbox{orange}{%
    \textbf{Script~\thescript foo#1bar:code/#2.groovy}}
    \addcontentsline{spt}{script}
       {\protect\numberline{\thescript}#1~~code/#2.groovy}
  }
  {}
lockstep
  • 250,273
Martin Heller
  • 11,391