0

I am starting to collaborate with colleagues who have exercise sheets which are actually a long list of exercises. Here 2 exercises (notice the second one has a title).

Typesetting goal

I find it ugly, but I can live with it.

However, it turns out that their LaTeX code for that indeed consists in a very big enumerate, where each exercise is an \item :

\begin{enumerate}
\item Beginning of first exercise.

Very long text......

\item Oh, the second exercise.

\suspend{enumerate}

Some text which is not an exercise.

\resume{enumerate}
\item An exercise.

\end{enumerate}

This is just filthy. I cannot work with this. For the code to be legible, I need each exercise to be in an environment.

\begin{exercise}
 Beginning of first exercise.
    
    Very long text......
\end{exercise}

\begin{exercise}
Second exercise.
\end{exercise}

Currently, I am using the following :

\usepackage{amsthm, thmtools}
\def\aLaLigne{\newline\leavevmode\null}
\let\finLigne\relax
\declaretheoremstyle[
notebraces={}{\global\let\finLigne\aLaLigne}, % hack because we want a line break iff there is a title to the exercise
notefont=\normalfont\sffamily,
headfont=\normalfont\bfseries,
bodyfont=\normalfont,
headpunct={.\finLigne\global\let\finLigne\relax},
headformat=margin,
headindent=3em
]{styleQuestion}
\declaretheorem[style=styleQuestion, title={}]{question}

\usepackage{enumitem}
\newlist{ssquest}{enumerate}{1}
\setlist[ssquest]{label=(\alph*)}

Which is almost right.

Current situation

I still need to have the content of the exercise typeset with an increased left-margin, so it does not go to the left of the exercise number. Also, I have not yet managed to effectively break a line at the beginning when the content starts with a enumerate, despite using \leavevmode as per amsthm's doc.

3
  • You should take a look at the ntheorem package, which defines a \theoremindent length and defines the change style.
    – Bernard
    Aug 25, 2022 at 10:35
  • To be honest, I am not sure what exactly want to do with the lists of exercises and how you want them to look. As I can see from your picture the section and exercise numbers have the same numbers, which is not so nice, and also the (a) subquestion is in the same line with question 1 and not aligned with the (b) subquestion which also does not look so nice. You can give a look at exam document class, which has the ability to organize lists of exercises. If you gine us some more details we may help you suggesting more specific solutions.
    – miltos
    Aug 25, 2022 at 12:38
  • I agree the aimed display is awful. I am trying to sneakily change the code while keeping the current display for now, and once the code has been gradually converted, push for a better presentation, by changing the definition of the environments.
    – ysalmon
    Aug 25, 2022 at 15:47

1 Answer 1

0

Thanks for the various comments. The suggestion to use ntheorem could not be applied directly because I was not able to change the font of the title with it.

However, exploring its source to see how it does the margin led me to this answer, which I have been able to adapt as follows.

\usepackage{amsthm, thmtools, etoolbox}


\makeatletter
\patchcmd\@thm
  {\trivlist}
  {\list{}{\leftmargin3.25em\itemindent-15em}}
  {}{}
\newcommand{\xdeclaretheorem}[2][]{%
  \declaretheorem[#1]{#2}%
  \expandafter\patchcmd\csname thmt@original@end#2\endcsname
    {\endtrivlist}{\endlist}{}{}%
}


\def\aLaLigne{\leavevmode\par}
\let\finLigne\relax
\declaretheoremstyle[
notebraces={}{\global\let\finLigne\aLaLigne},
notefont=\normalfont\sffamily,
headfont=\normalfont\bfseries,
bodyfont=\normalfont,
headpunct={},
headformat={\hskip-.4em\makebox[0pt][r]{\NUMBER.}\NOTE},
postheadhook={\finLigne\global\let\finLigne\relax},
]{styleQuestion}
\xdeclaretheorem[style=styleQuestion, title={\hskip-.9ex.}]{question}

\usepackage{enumitem}
\newlist{ssquest}{enumerate}{1}
\setlist[ssquest]{label=(\alph*)}

The colleagues are happy ; this compiles on their computer and the PDF looks as ugly as they are used to.

I am gradually going to subvert all the code to use these new environments, and one day we will switch to a nicer presentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .