[OS X TeX] Exercises

Michael Sharpe msharpe at ucsd.edu
Fri Apr 10 14:33:52 EDT 2009


On Apr 10, 2009, at 9:56 AM, George Gratzer wrote:

> In my new book, I have exercises at the end of each section. I use  
> the xcb environment from amsbook.cls:
>
> \newenvironment{xcb}{%
>  \setcounter{enumi}{0}%
>  \settowidth{\leftmargini}{\labelenumi\hskip\labelsep}%
>  \setcounter{enumii}{4}% letter d
>  \settowidth{\leftmarginii}{\labelenumii\hskip\labelsep}%
>  \@startsection{section}% counter name; ignored because of the
>                                % * below
>  {1}% sectioning level
>  {\z@}% indent to the left of the section title
>  {18\p@\@plus2\p@}% vertical space above
>  {1sp}% Space below of 13pt base-to-base, so none needs to be added
>      % here; but \z@ would cause the following text to be run-in, so  
> we
>      % use 1sp instead.
>  {\bfseries}% The font of the subsection title
>  *% always unnumbered
> }{%
>  \par
> }
>
>
> modified as follows:
>
> \newenvironment{exercises}
>     {
>     \begin{xcb}{}\noindent\textbf{Exercises}
>     \begin{enumerate}
>     \renewcommand{\labelenumi}{\theenumi.}
>     \settowidth{\leftmargini}{NN.\hskip\labelsep}
>     }
>     {\end{enumerate}\end{xcb}}
>
> and then
>
> \begin{exercises}
>
> \item
>
> \begin{exercises}
>
> works well.
>
> Problem: I want the difficult exercises marked with a *:
>
> 25*.
>
> How could I do that? How do I modify one number, without effecting  
> the rest?
>

One way is to redefine the exercises environment as follows.

\newenvironment{exercises}
     {
     \begin{xcb}{}\noindent\textbf{Exercises}
     \begin{enumerate}
\let\olditem\item
\def\staritem{\let\exerstar\par\olditem }
\renewcommand{\item}{\let\exerstar\empty\olditem }
\renewcommand{\labelenumi}{\theenumi\ifx\exerstar\empty\else*\fi.}
     \settowidth{\leftmargini}{NN.\hskip\labelsep}
     }
     {\end{enumerate}\end{xcb}}

You might want to change the alignment of the numbers, or perhaps  
place the * before the exercise number---that's a simple change.

Michael




More information about the MacOSX-TeX mailing list