A more structured way to typeset assignments in LaTeX

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?

Best Answer

I found this example. It's not exactly what you want, but if you look up using counters and the newcommand and renewcommand definitions, you should be able to do exactly what you want, which wasn't totally clear to me.

\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"

\addtocounter{problem}{-1}
\problem
Counter increments can be negative!

\end{document}
Related Question