TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...)?

share|improve this question
up vote 8 down vote accepted

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}
  }
  {}
share|improve this answer
    
Of course... yes, makes sense... in retrospect at least... :) Thanx! – Egon Willighagen Oct 9 '10 at 15:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.