The LaTeX homework Document Class

There are LaTeX document classes for typesetting books, articles, exams, presentations, and more. Now, there’s one for homework assignments, too.

Source

Check out and download the source on GitHub.

What

This is a LaTeX document class. That means you use it with \documentclass{homework} at the top of the document. It provides a document layout and some helper commands that make working with questions easy.

Installation

Certainly the easiest way to start using this template is to copy the .cls file to your computer in the same directory as your LaTeX project directory.

A better way to install this template is to fork the above repository and then clone that fork to a particular folder on your computer:

git clone https://github.com/<your-username>/latex-hw-template
Install

Then, whenever you need to use the template, you can copy the template wherever. Also, if there are ever any updates, you can simply run

git pull
Update

to update the template.

Preferred Installation

The best way to install this file is to follow the instructions here, keeping in mind that you’re trying to install a .cls file instead of three .sty files.

Usage

See the homework.tex file for an exhaustive list of usage examples. There are also comments explaining features for which there are no examples given.

The result is the following:

The class file also has a bunch of helper \usepackages that you might want to take a look at in homework.cls.

For your convenience, the file template.tex is a nearly-empty LaTeX file that contains the bare essentials to get started using the homework class.

\question

To start a question, just type \question. It will add the text “Question #” with a line underneath to the document. If you’d like to change “Question” to something else, use

\renewcommand{\questiontype}{Whatever You Want}
% Now questions will be titled "Whatever You Want #"
Change the Question Type

Similarly, if you ever need to skip numbers, you can do

\setcounter{\questionCounter}{<target number - 1>}
Non-contiguous Question Numbers

So, to skip to the 10th question, <target number - 1> = 9.

See homework.tex for more.

\question*

Some classes like to give their homework questions fancy names. If this is the case, you can use \question*{The Question's Name} to make a named question.

See homework.tex for more.

Question Parts

Another common thing on homework assignments is to have multi-part questions. To deal with these, use the form

\begin{alphaparts}
  \questionpart
    This will be part (a).
  \questionpart
    This will be part (b).
\end{alphaparts}
Lettered Question Parts

or

\begin{arabicparts}
  \questionpart
    This will be part x.1.
  \questionpart
    This will be part x.2.
\end{arabicparts}
Numbered Question Parts

See homework.tex for more.

Induction Proofs

In math classes, induction proofs come up a lot, and they almost always have the same form: base case, induction hypothesis, and induction step.

\begin{induction}
  \basecase
    This is my fancy base case.
  \indhyp
    Assume some claim.
  \indstep
    Finish off the proof
\end{induction}
Induction Environment

Markdown

One of my favorite features of this document class is that it redefines the \section macros. This means you can use tools like Markdown, which have a concise syntax, together with a tool like pandoc to convert Markdown into LaTeX. As an example, consider that we have the Markdown:

#

This is my first answer.

#

This is my next answer.

$$a^2 + b^2 = c^2$$
my-homework.md

Running pandoc -f markdown -t latex my-homework.md will output

% $ pandoc -f markdown -t latex my-homework.md
\section{}\label{section}

This is my first answer.

\section{}\label{section-1}

This is my next answer.

\[a^2 + b^2 = c^2\]
Convert markdown to LaTeX

And since \section is the same thing as , we’re golden, and this compiles as we’d want it to. Throw it into the blank template.tex file included in the repo, and you’ve got yourself a typeset homework.

More

I’ve make a lot of other LaTeX-related posts. Be sure to check them out as well! My hope is that you find something that makes developing LaTeX just that much easier.