Take the 2-minute tour ×
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.

I'm using exercise.sty and have two Exercise counters I'm trying to use, one for Examples with in a chapter, and one for Problems for the chapter. Here's an example:

\documentclass[]{scrreprt}
\usepackage[]{exercise}
\usepackage[svgnames]{xcolor}
\usepackage[]{chngcntr}
\newcounter{Example}
\counterwithin{Example}{chapter}
\counterwithin{Exercise}{chapter}

\newcommand{\makeproblem}[3]{%
\begin{Exercise}[ title={#1}, label={#2} ]%
#3%
\end{Exercise}%
}

\newcommand{\makeexample}[3]{%
\begin{Exercise}[ title={#1}, label={#2}, name={Example}, counter={Example} ]%
#3%
\end{Exercise}%
}

\begin{document}

\chapter{Ch1.}

   \makeexample{blah}{ch1:ex1}{
   Given $b=e$, compute $foo(b)$...
   }

   \makeexample{another}{ch1:ex2}{
   Given $b=f$, compute $foo(b)$...
   }

   \makeproblem{compute foo}{ch1:problem:foo}{
   Given $b=a$, compute $foo(b)$.
   }

   \makeproblem{compute bar}{ch1:problem:bar}{
   Given $b=a$, compute $bar(b)$.
   }

\end{document}

However, in the output:

with basic formatting

notice how the counters for the Examples are not shown incrementing (even within one chapter).

EDIT: noticed only after the fact that my example without any change to the formatting also didn't show incrementing Example numbers. Deleted all parts of the question about my formatting modifications.

EDIT2: This issue appears to be due to a mis-interaction of the chngcntr package with the exercise package once a non-default counter is used. Is there any way to deal with this?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You could use \renewcounter, provided by the same package, and redefine \theExercise:

\renewcounter{Exercise}[chapter]
\makeatletter
\renewcommand{\theExercise}{\if@ExeStared\else\thechapter.\arabic{\@ExerciseCounter}\fi}
\makeatother
\newcounter{Example}
\renewcounter{Example}[chapter]

Internally, the package uses \@ExerciseCounter (initialized with Exercise) with \theExercise, that's why just redefining \theExample doesn't work.

share|improve this answer
    
Thanks. It wasn't clear to me from the documentation how to use that renewcounter command (written for a much more sofisticated latex user than myself). I'd tried, but must have had the syntax wrong. –  Peeter Joot May 22 '12 at 17:44
add comment

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.