[OS X TeX] need help modifying an "exercise" environment

Art Werschulz agw at comcast.net
Fri Jun 15 17:30:48 CEST 2012


Hi.

Awhile back, several people on this group helped me with an "exercise" environment for a book I'm co-writing.  The main thing is that the exercise number should be outdented, e.g., 

   1.1  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent 
        venenatis mattis dignissim. Vivamus euismod lacinia dictum. Nulla 
        facilisi. 
        (a) Vestibulum ante ipsum primis in faucibus orci luctus et ultrices 
            posuere cubilia Curae.
        (b) Praesent dignissim rutrum leo, quis ornare diam hendrerit non. 

It's used as follows:

\begin{exercises}
  \begin{ex}
    Blah blah blah.
      \begin{soln}
         Blah blah blah.
      \end{soln}
  \end{ex}

  \begin{ex}
    Blah blah blah.
    \begin{problist}
      \item Blah.
      \item Blah.
    \end{problist}

    \begin{soln}
      \begin{solnlist}
        \item Blah.
        \item Blah.
      \end{solnlist}
    \end{soln}
\end{exercises}

Here's the definition of said environment:

\newenvironment{exercises}{\section{Exercises}}{}
\makeatletter
\newcounter{ex}[chapter]
\newenvironment{ex at problist}{\begin{enumerate}}{\end{enumerate}} % private            
\renewcommand{\theex}{\thechapter.\arabic{ex}}
\newdimen\probindent  \probindent=20pt
\newcommand\itembox[1]{\noindent\llap{\hbox to 1.2\probindent{#1\hss}}}
\newenvironment{ex}[1][]{%                                                            
  \parskip=\smallskipamount%                                                          
  \renewcommand{\labelenumi}{(\alph{enumi})}%                                         
  \renewcommand{\labelenumii}{(\arabic{enumii})}%                                     
  \def\@currentlabel{\theex}%                                                         
  \let\problist\ex at problist                                                           
  \let\endproblist\endex at problist                                                     
  \refstepcounter{ex}\parindent0pt\leftskip1.2\probindent%                            
  \@ifnotempty#1{\label{#1}}                                                          
  \par\itembox{\textbf{\theex.}}\nobreak \hspace{1sp}\ignorespaces}%                  
  {\par\medbreak}
\makeatother

It works fine, as is.  However, we now want to change exercise numbering to include the section number, since 
	1.6 Exercises

	1.1 Prove that blah blah blah
looks a little weird.  No problem: simply change \theex to 
	\renewcommand{\theex}{\thesection.\arabic{ex}}

Our problem: Exercise numbers overlap the exercise text.  I was able to fix this by changing the definition of \itembox to be
	\newcommand\itembox[1]{\noindent\llap{\hbox to 1.6\probindent{#1\hss}}}
But the exercise number now juts out too far to the left, into the margin.

I've tried playing around with the various parameters, but to no avail.  One thing I discovered was that changing the parameter in \hskip{1sp} did nothing whatsoever.  Maybe I simply haven't found the right combination of parameters; maybe there's something else I should be doing.

Do any of you see how to handle this problem?  

Many thanks!!

Art Werschulz (8-{)}   "Metaphors be with you."  -- bumper sticker
GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y?
Internet: agw STRUDEL comcast.net






More information about the macostex-archives mailing list