Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
2  
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
1  
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
add comment

5 Answers

up vote 2 down vote accepted

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}
share|improve this answer
add comment

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}
\runningheader{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.

share|improve this answer
    
+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
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
I used to do this; then I discovered document classes designed for this task. –  las3rjock Oct 21 '09 at 18:27
add comment

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

\begin{equation}
\label{myeq}
a^2 + b^2 = c^2
\end{equation}

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

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.