[OS X TeX] Re: "! LaTeX Error: No counter 'a' defined." (solution)

Martin Costabel costabel at wanadoo.fr
Wed Dec 22 14:39:42 CET 2010

On 22/12/10 02:22 , John B. Thoo wrote:
> Here is a minimal example:
> <http://ms.yccd.edu/~jb2/PickUp/minexample.zip>   (8.7 KB)
> Reminder: I am using TeX-Live 2009 in X11.
> If I typeset "latex narrowhom.tex" with all the \includeonly (lines 52--56) commented out, there are no errors.
> If I then uncomment \includeonly{ch_geom}, I get the errors
> ! LaTeX Error: No counter 'a' defined.
> See the LaTeX manual or LaTeX Companion for explanation.
> Type  H<return>   for immediate help.
>   ...
> l.183 \include{ch_numthry}

I think you exposed a fundamental bug in LaTeX. It is so basic that I 
suspect it will be called a "feature", and it is probably well known:

You cannot use \newcounter in files that are included using \include.

The workaround is to remove the \newcounter command from the included 
file and place it into the master file. In your case, remove (or 
comment) the lines


in the file ch_numthry.tex and place them in the master file just before 
the line


This will typeset identically to what you (wanted to) get, without the 

The reason for the breakage is that latex writes all \setcounter 
commands into the *.aux files. This is reasonable, in principle. But 
when you use \includeonly, only the *.aux files of the not included 
files are read, so the \setcounter commands are read, without the 
corresponding \newcounter commands, which are not in the *.aux file: Crash!

Here is a really minimal example:

%%%% file counterbug.tex, this is the master file
%%%% typeset, then uncomment the \includeonly line to see the bug
%%%% end counterbug.tex

%%%% file counter.tex
%%%% end counter.tex


More information about the macostex-archives mailing list