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.).

  • 1
    You might also want to look into the answers package, it is very nice =) Mar 19, 2012 at 23:09

3 Answers 3


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:


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:

  <<statements of problem>>

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

    \item <<Part (a) problem statement>>
    \item <<Part (b) problem statement>>
    <<Solution to part (a)>>
    <<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 picture

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? Sep 2, 2013 at 22:03
  • 2
    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, 2013 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:

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

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


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.

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

You must log in to answer this question.

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