# A more structured way to typeset assignments in LaTeX

I'm typing up some assignments with the basic structure

Problem problem number

Solution

and I'm not really satisfied with the LaTeX source I'm making. For example

\section*{Problem 1}
In order to solve $a^2+b^2 = c^2$ ...


This solution is not very good since it doesn't use the automatic counters and though the assignments are short I might have longer ones later and need a table of contents.

Now, problems in my context are logical sections of my documents, and so \section makes sense. Would some type of new command say \problem make more sense?

-
You'll find more LaTeX questions and answers on Stack Overflow than super user: stackoverflow.com/questions/tagged/latex . See meta questions meta.stackexchange.com/questions/7135/… and meta.stackexchange.com/questions/12918/… for some discussion on where such questions are most appropriate. –  dmckee Oct 21 '09 at 14:47
It didn't feel appropriate on Stack Overflow as this was a more mathy homework assignment and LaTeX isn't very programmy. –  Flame Oct 21 '09 at 19:08
It is not perfectly clear, but there seem to be more LaTeXers on SO than SU, that's all... –  dmckee Oct 21 '09 at 20:12


\documentclass{article}
\begin{document}

\newcounter{set}
\setcounter{set}{2}
\newcounter{problem}[set]

\newcommand{\problem}{\refstepcounter{problem}{\vspace{2\baselineskip}\noindent\large \bfseries Problem~\arabic{set}.\arabic{problem}}\\}

\problem
\textit{Sum-product algorithm:}  Consider the sum-product\ldots.

\problem
\textit{Max-marginals:} Consider the max-marginals\ldots.

\stepcounter{problem}
\problem
Demonstraction of \verb"\stepcounter"

\problem
Counter increments can be negative!

\end{document}

-

I use the exam document class for this task. A basic document then looks like this:

\documentclass[answers]{exam}
\begin{document}
\firstpageheader{}{}{\bf\large Name \\ Class \\ Assignment \\ Due Date}

\begin{questions}
\question
This is the question.

\begin{solution}
This is the solution to the question.
\end{solution}

\end{questions}
\end{document}


Prior to discovering the exam class, I used the hmcpset document class from the mathematics department at Harvey Mudd College.

-
+1 I like your answer better than mine ;-) –  DaveParillo Oct 21 '09 at 19:58
+1 for mentioning Harvey Mudd College :^) –  Broseph Jun 24 at 16:21

I would suggest using enumerate to organize problems and use sections to group them. For example:

\begin{enumerate}
\item
The enumerate'' environment numbers the list elements, like this.

Items in a list can contain multiple paragraphs.
These paragraphs are appropriately spaced and indented according to their
position in the list.
\begin{itemize}
\item The itemize'' environment sets off list items with bullets'',
like this. Finally, the description'' environment lets you put your own
\begin{description}
\item[A] label on each item, like this A''.
\item[If the label is long,] the first line of the item text will
be spaced over to the right as needed.
\end{description}
\end{enumerate}


Taken from pangea.stanford.edu LaTeX by Example

Doing this gives you way more flexibility structuring the details of your individual assignments - for example you can enumerate as deeply as you need, but can only take sections to 3 levels.

-

For this kind of thing, I would probably use the theorem package. Using it, you can define a theorem-like environment like this:

\newtheorem{problem}{Problem}[chapter]


Here, the optional argument [chapter] says that numbering is to be performed per-chapter, so you get numbering like 1.1, 1.2 in the first chapter, 2.1 in the second chapter and so on. If you just want sequential numbering throughout the document, leave out that argument altogether.

And you would use it like this:

\begin{problem}\label{prob:1}
... text here
\end{problem}


Of course, you would want to give it a more descriptive label than just prob:1.

Also, the default typesetting puts the text in italics. You can change that by replacing the definition with something like

{\theorembodyfont{\rmfamily}\newtheorem{problem}{Problem}[chapter]}


I've encased the font change in {} so that it only affects this environment definition and not any others you might have.

-
I used to do this; then I discovered document classes designed for this task. –  las3rjock Oct 21 '09 at 18:27

One way to do it is to use the equation environment:

$$\label{myeq} a^2 + b^2 = c^2$$

In order to solve \eqref{myeq} ...


That gives you numbered equations and a way to refer to them.

-