TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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'm trying to get nostarch working and it won't even get out of the gate. I'm just a lowly user so these kinds of errors leave me quite clueless.

The sample doc in the distribution nssample.tex gives me the same error as this simple example does:


And I get the error:

! LaTeX Error: \thelstlisting undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

l.580 \renewcommand \thelstlisting

Clearly nostarch is pulling in listings (or is it listing?), or maybe more correctly, it needs it but it isn't pulling it in? I'm using a fully updated TeXLive 2011 on OS X Lion.

share|improve this question
up vote 8 down vote accepted

Version 1.4 of listings.sty includes the following code snippet:

           {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@lstlisting}

Version 1.3 of nostarch.cls contains the following code snippet:

\renewcommand \thelstlisting
     {\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@lstlisting}

In other words, nostarch tries to redefine a counter (lstlisting) in the preamble which will only be defined by listings at the begin of the document body. This results in the error message you observed.

Solution: Copy nostarch.cls to your working directory and rename the copy to, say, mynostarch.cls. In the renamed copy, replace the above code lines with

  \renewcommand \thelstlisting
       {\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@lstlisting}%

Then, replacing nostarch with mynostarch in your example (and actually typesetting something in the document body) should compile without errors.

EDIT: As Peter Grill pointed out in a (now deleted) comment, adding \def\thelstlisting{} before \documentclass will remove the error message in your original example. However, nostarchs attempted redefinition of \thelstlisting (replacing the dot with a dash) won't be applied. Here's an alternative solution that doesn't involve modifying a custom copy of nostarch.sty:



  \renewcommand \thelstlisting
       {\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@lstlisting}%



\begin{lstlisting}[caption={A listing}]

share|improve this answer
Wow... I'm glad I asked :) Googling got me nowhere and this was way beyond my meager LaTeX-ness. Thanks very much! – Derek Wyatt Mar 26 '12 at 0:26

Your Answer


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.