[XeTeX] Counter reset problem
Ross Moore
ross at ics.mq.edu.au
Fri Sep 18 23:44:24 CEST 2009
Hello Karljürgen,
On 19/09/2009, at 4:02 AM, Karljurgen Feuerherm wrote:
> Hello all,
>
> I have set up a counter and environment (using XeLaTeX) as follows:
>
> \newcounter{examples}[chapter]
>
> \newenvironment{examples}
> {\begin{list}%
> {\textsc{Example} \arabic{examples}.} %
> {\setlength{\labelsep}{10pt} %
> \setlength{\itemindent}{10pt} %
> \setlength{\leftmargin}{0pt} %
> \setlength{\labelwidth}{0pt} %
> \usecounter{examples}%
> } %
> } %
> {\end{list}}
>
> The idea is to let the examples counter run through each chapter
> and only reset at the next chapter. For some reason, it resets
> itself in environment changes (for example after enumerates, at
> each new section...).
No, it resets itself for every use of the {examples}
environment.
This is because of how \usecounter expands;
viz.
\usecounter #1->\@nmbrlisttrue \def \@listctr {#1}\setcounter {#1}\z@
#1<-examples
That \setcounter {#1}\z@ is resetting to zero.
You'll need a second counter or macro to retain the
value of your 'examples' counter at the end of each
environment.
e.g.
\newcounter{examples}[chapter]
\newcounter{runningexample}[chapter]
\newenvironment{examples}{%
\begin{list}%
{\textsc{Example}~\arabic{examples}.}%
{\usecounter{examples}%
\setcounter{examples}{\value{runningexample}}%
\setlength{\labelsep}{10pt}%
\setlength{\itemindent}{10pt}%
\setlength{\leftmargin}{0pt}%
\setlength{\labelwidth}{0pt}%
}%
} %
{\end{list}%
\setcounter{runningexample}{\value{examples}}%
}
Note also that I've suppressed the extra spaces after '}'
that your coding was inserting (to no great harm though).
>
> What am I doing wrong?
With the 'runningexample' counter as above,
the following example works fine, so far as I can tell.
\begin{document}
%\maketitle
\chapter{One}
\begin{examples}
\item First example
\item Second example
\item Third example
\end{examples}
\begin{enumerate}
\item something else
\end{enumerate}
\begin{examples}
\item Another First example
\item Another Second example
\item Another Third example
\end{examples}
\chapter{Two}
\begin{examples}
\item First example
\item Second example
\item Third example
\end{examples}
\begin{enumerate}
\item more other things
\end{enumerate}
\begin{examples}
\item Another First example
\item Another Second example
\item Another Third example
\end{examples}
\end{document}
>
> Thanks
>
> K
>
> Karljürgen G. Feuerherm, PhD
> Department of Archaeology and Classical Studies
> Wilfrid Laurier University
Hope this helps,
Ross
------------------------------------------------------------------------
Ross Moore ross at maths.mq.edu.au
Mathematics Department office: E7A-419
Macquarie University tel: +61 (0)2 9850 8955
Sydney, Australia 2109 fax: +61 (0)2 9850 8114
------------------------------------------------------------------------
More information about the XeTeX
mailing list