# Class file for Homework/Assignments

I was wondering if there is a good general purpose homework class file/template out there. I want to use it for classes. Generally, math-centered courses. I would like if there was syntax highlighting for programming (Python, Ruby, C, Java, etc.).

-
You might also want to look into the answers package, it is very nice =) – N3buchadnezzar Mar 19 '12 at 23:09

For the class file itself: I actually made my own class file (adapted from the report class file) to format my homework the way I wanted. It is here, if you're interested in trying it or fiddling with it:

https://gist.github.com/1278588

You supply it with \author and \title in the preamble, and it automatically uses today's date.

This file is used by inserting \documentclass{jhwhw} at the beginning of a document.

The standard formatting for a problem looks like this:

\problem{NAME OF PROBLEM}
<<statements of problem>>
\solution
<<solution>>


It creates a new page for every problem. Also, if a problem has multiple "parts" the formatting might look like this

\problem{NAME OF PROBLEM}
\begin{enumerate}
\item <<Part (a) problem statement>>
\item <<Part (b) problem statement>>
\end{enumerate}
\solution
\part
<<Solution to part (a)>>
\part
<<Solution to part (b)>>


The enumerate will use letters (a), (b), etc. And \part will use (a), then (b), etc.

An example page (from a real homework assignment) looks like this

If you want to try it out, download it, put it in your texmf folder and run texconfig rehash (if you're on a UNIX based system).

There are definitely things in this class file that are automated that people would want more control over, so I suggest fiddling around to find what works best for you.

For syntax highlighting: Werner's answer mentioning the listings package for syntax highlighting and code is great. (That style file could be used with this class file.)

-
Hey man is there a way to prevent each problem from starting on a new page? – Antillar Maximus Sep 2 '13 at 22:03
Yeah, in the \newcommand*{\anyproblem}[1]{\newpage\subsection*{#1}} line of the style file (as of this writing: L60), remove the \newpage. That should prevent it from starting each problem on a new page. – qgp07 Sep 27 '13 at 20:38

In my opinion the (standard) article document class would work for that. The reason for not suggesting something like book or report is that they are meant for much larger texts (since they include chapters and parts). Additional syntax-highlight can be obtained by means of the listings package - you specify the language (and possibly other formatting) and put the code in a lstlisting environment and that's that. See the listings documentation for more information on this (p 12 presents a list of supported languages, although you can define your own).

For mathematical typesetting, I would suggest using the amsmath package as well. It provides the powerful align environment for typesetting equations (numbered; otherwise, for unnumbered equations using align*) with alignment properties. It also improves on other standard mathematical components used in LaTeX.

Here's an outline of what I'm talking about:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{listings}% http://ctan.org/pkg/listings
% ... other packages that you may want to use
\begin{document}
% Paragraph text...
% Enumerate/itemize environments...
% Listings (or programming code segments)...
% Tables...
% Figures...
% Mathematics (align, align*, , ...)
\end{document}


If, in general, your expertise in LaTeX needs a solid foundation, consider reading through the Not So Short Introduction to LaTeX2ε.

-
Also consider the exam class (related question) for a question/answer structure. – Mike Renfro Oct 11 '11 at 3:12

You can make a topic search at CTAN and under exams you will find a complete list of packages related with exercises or exams. I think most of them are compatible with listings and minted to typeset code.

-
The links have since rotted. Is there an alternative? – Kat Sep 20 '14 at 23:51
Broken link.... – JPCF Oct 8 '15 at 15:31
@JPCF I've revised links. – Ignasi Oct 8 '15 at 15:39