First of all, this is not a LaTeX tutorial. I will not teach you LaTeX. There are far more qualified people who have done an excellent job on the matter. If you want to learn LaTeX, More Math Into LaTeX 4th Edition. It's fantastic. What I'm doing here is merely documenting some tricks to use LaTeX code to generate a math test. LaTeX, if you aren't aware, was designed primarily for university and research types to publish journal articles at a time long before word processor apps could properly display math symbols. It is a markup language akin to HTML but for documents. Very very pretty documents. If you know basic HTML and/or have taken a computer science course, it's just a matter of learning the syntax.

Previously I used Word 2008 and MathType to generate tests. But there are some hair-tearing frustrations that result from this, because Word has a very funky alignment grid for pictures and at random decides to align MathType formulas wherever it pleases. I also used Word objects to make any figures with so-so results.

I use TeXShop (part of the MacTeX package) to write the mark up and PDFPen to insert graphics. I make graphics in Fireworks CS5. LaTeX does support coding graphics but I've gotten better rendering results by leaving an appropriate blank in my .tex file and adding the graphic with PDFPen later. TeXShop outputs to PDF by default. PDFPen has a grid overlay you can enable and avoids all the headaches involved with trying to align something in Word. At the end of the article I have posted the Word version and LaTeX generated version of the same test so you can compare the results.

Templates and Preamble

The fastest way to get a new document started is to have a nice template. LaTeX files require a decent preamble, and you don't want to type it every time. This is my template. Biggest thing here, after you make your template and are satisfied, close it in TeXShop, set the file aside from your primary work folder and LOCK it. Clicking "Typeset" in TeXShop saves your markup file and if the file isn't locked you WILL overwrite your template by accident.

%template for test creation

\documentclass[11pt]{amsart}

\usepackage{fullpage}

\usepackage[tmargin = 0.5in, bmargin = 1in, hmargin = 1in]{geometry}     %1-inch margins

\geometry{letterpaper}                  

\usepackage{graphicx}

\usepackage{amssymb}

\usepackage{epstopdf}

\pagestyle{empty}                       %no page numbers

\thispagestyle{empty}                   %removes first page number

\setlength{\parindent}{0in}               %no paragraph indents

\raggedright                               %left justified text

\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\begin{document}

Mr. Claydon\hspace{2.8in} Name:\ \makebox[1.366in]{\hrulefill} Date:\ \makebox[0.5in]{\hrulefill}\\

Pre\,-\,Calculus \hfill Period:\ \makebox[0.5in]{\hrulefill}

\vspace{6pt}

\begin{center}

    \textbf{test title}

\end{center}

\vspace{12pt}

%uncomment for 2nd page

%\newpage

%Mr. Claydon\hfill \textbf{Test 5.3\,-\,5.4}\\

%Pre\,-\,Calculus

%\vspace{12pt}

%for bonuses

\vfill Bonus:

\end{document}

I commented the nice bits. The biggest things to keep you from making journal articles are suppressing page numbers and left justifying the text. Note my changes to the geometry package, by default LaTeX uses very odd margins. Odd margins for a test, anyway. There are no headers and footers really, so I make the top margin small and use the \vfill to shove my bonus question to the bottom regardless of how much of the page is used.

All of the makebox and hrulefill stuff generates lines they can write their name on. Took me a little bit of thinking to figure this out.

Link: test.textest.pdf

Floating Alignment

The most important command you need. LaTeX is intended as sort of a one formula per line system, typical of journal articles. This alignment code will let you create a bank of problems all neatly ordered under one another. Similar to setting tab points in Word. A typical use case:

flalign.png

The code that makes it:

\begin{flalign*}

    1.\ &\sum_{k=1}^{10}3(0.6)^{k-1} & 2.\ & \sum_{j=0}^{7}0.4\left(\frac{1}{5}\right)^{j} & 3.\ & \sum_{i=1}^{24}50(1.006)^{i-1}\\[24pt]

    4.\ &\sum_{k=1}^{\infty}6\left(\frac{2}{3}\right)^{k-1} & 5.\ &\sum_{n=0}^{\infty}8(0.54)^{n} & 6.\ &\sum_{g=0}^{\infty}0.57\left(\frac{7}{2}\right)^{g}

\end{flalign*}

The flalign command tells LaTeX to use the full width of the page to align whatever you give it using the &s as tab points. The * is the key, it suppresses equation numbers. The [24pt] defines the vertical space between one line of equations and the next.

Formula Boxes

In Pre-Cal there are many times where some formulas will help. Previously I would draw a text box and dump some MathType into it.

formulabox.png

The code that makes it:

\begin{center}

    \fbox{\parbox[l][1.3in]{1in}{Hinty Hints:\\%

            \begin{align*}

                & \frac{\sin A}{a}=\frac{\sin B}{b}=\frac{\sin C}{c}    &    a^{2}&=b^{2}+c^{2}%

                    -2bc\cos A &&\\[6pt]

                &&    \cos A&=\frac{b^{2}+c^{2}-a^{2}}{2bc} &&

            \end{align*}}}

\end{center}

I used a standard align command here because I didn't want to thrust what little I had to the far ends. The fbox makes the border, the parbox defines what goes inside. Not necessary if you just want to frame one equation or a bit of text, but necessary for a table or big set of formulas. The []'d portion defines width, the {} height.

Text and Formula Boxes

It is possible for boxes to share space with other items.

wordsandformulabox.png

The code that makes it:

\parbox{4in}{18.\ A baseball leaves the hand of the first baseman at an angle of $\theta$ with the horizontal and with an initial velocity of $v_{0}=80$ feet per second. The ball is caught by the second baseman 100 feet away. The range $r$ of a projectile is given by $r=\frac{1}{32}v_{0}^{2}\sin 2\theta$\dots speaking of baseball, how bummed are you that the faculty/senior softball game was cancelled?}\hfill\fbox{\parbox[c][1.5in]{2.1in}{\begin{center}$\tan\left(a+b\right)=\dfrac{\tan a + \tan b}{1 - \tan a\tan b}$\vspace{30pt}\\$\tan\left(a-b\right)=\dfrac{\tan a - \tan b}{1 + \tan a\tan b}$\\\end{center} }}

A little messy. The parbox sits on the left by default, I snuck in an \hfill to send the other box as far right as will allow and then defined a 1.5in x 2.1in box for some formulas. Since I didn't use an align environment to enter those formulas, all the math needs to be flanked by $s.

Multiple Problem Sets

Sometimes problem sets need to be broken up by new instructions.

multiplealigns.png

The code that makes it:

\begin{flalign*}

    1.\ &f(x)=\frac{1}{2}\tan x    \hspace{-0.3in}    &    2.\ &f(x)=4\tan\frac{x}{5}    \hspace{0.2in}    &    3.\ &f(x)=\cot2x \hspace{0.2in}

\end{flalign*}

\vspace{96pt}\\

Find the value of each expression using your wits and a unit circle.\\[6pt]

\begin{flalign*}

    4.\ &\arcsin1        &    5.\ &\sin^{-1}\left(\frac{\sqrt{2}}{2}\right)        &    6.\ &\cos^{-1}\left(\frac{1}{2}\right) \hspace{0.3in}\\[48pt]

    7.\ &\arctan0        &    8.\ &\cos^{-1}\left(-\frac{\sqrt{3}}{2}\right)    &    9.\ &\tan^{-1}\left(-1\right) \hspace{0.3in}

\end{flalign*}

However, each align environment spreads its contents and only its contents evenly across the page. It pays no attention to any previous or future align environments and where they put things. So if the content of one problem set is wider or shorter than another on the same page, your numbers won't line up. Clever use of \hspace in between problems and at the end of a line will allow you to get the numbers in the same spots.

Word Problems

wordproblem.png

This nicely justified text is accomplished by typing the number and then sticking the text into a \parbox.

The code that makes it:

14.\ \parbox[t]{6.1in}{For Thanksgiving you decide to visit the San Jacinto Monument. A lovely tower that rises high about nearby Galveston Bay. Standing in its presence reminds you of what it must have been like to live in Texas in the 1830s. I mean, it was probably pretty hard, no texting, no cars, and just old copies of \emph{Popular Science} with fascinating articles like ``Why We Will Never Build Flying Machines." All this time you tune back in to hear the tour guide mention that this amazing memorial to fallen heros is $567ft$ tall. Your tour group stands just $63ft$ from the tower.\\[36pt]What is the angle of elevation necessary to look at the top? Use complete sentences to answer.}

The [t] argument forces the box to start even with the current line.

Tables

table.png

Tables are a little quirky. LaTeX by default will equate cell width to the width of whatever you type. So widths can be wildly different. For something like I've shown here, you have to instead stick your text within a box of known size. Yes, you can define cell width from the tabular argument, but it will always be left justified.

The code that makes it:

\begin{center}

\begin{tabular}{|c|c|c|c|c|c|c|c|}

    \hline

    $x$        & \makebox[0.5in][c]{-0.1} & \makebox[0.5in][c]{-0.01} & \makebox[0.5in][c]{-0.001} & \makebox[0.5in][c]{0} & \makebox[0.5in][c]{0.001} & \makebox[0.5in][c]{0.01} & \makebox[0.5in][c]{0.1} \\ \hline

    $f(x)$ & & & & \makebox[0.5in][c]{?} & & & \\ \hline

\end{tabular}

\end{center}

Organization

Cranking out LaTeX generates a LOT of files. The compiling process kicks out a .log, .gcz, and .aux file for everything you run. It's only necessary to keep the .tex and .pdf output. In fact, the compiler that comes with MacTeX has an option for deleting the aux files after you're satisfied. I work in my Dropbox and organize things by subject and have separate folders for .tex and .pdf files. This way if I accidentally recompile I won't overwrite a PDF that already has graphics in it or something. 

workfolder2.png

Comparison

My initial work was to see if I could recreate my Word versions of my tests. I kept all the problems the same. I will definitely be changing the content for the coming year, but this was to prove LaTeX's ability to reproduce existing work. Compare.

Quiz 8-1 8-2: WordLaTeX

Test 6-1 6-3: WordLaTeX

Custom Commands

I have a couple folks at my school interested in my testing methods this semester. I'll be sharing some Boot Camp items with them as well as tests I generate. Of course they'd like the tests to have their name on them and since TeXShop kicks out PDFs, that part is not readible editable to someone without the proper tools.

So, you can define a command at the beginning of a test for the teacher name and subject. So if you and a colleague are going to use the same test, you need only edit the name once and typeset rather than hunt and peck for the name/subject references in the document body. Here's how you'd do it:

After the preamble, type this:

\newcommand{\teachername}{---their name goes here---}

\newcommand{\subject}{---subject name goes here---}

In the second set of brackets, enter the name of the teacher and their subject, Pre-Cal, Algebra II, etc. In the body of your document, you need only type \teachername and \subject where you'd like to see those appear. So in my templates below, the spots where you see "Mr. Claydon" would be replaced with \teachername and LaTeX will insert whatever text has been defined for \teachername. 

Integration with Other Applications

An advantage of MathType is that it can installed within Office or iWork to let you insert equations in a document quickly. This is a bit of a disadvantage with LaTeX because TeXShop kicks out dedicated PDFs for whatever it is you've written. Sometimes if all I want is to generate a quick 5-problem set for a poster project, I'd wrather not go the TeXShop route. To get the nice, beautiful LaTeX equations there are several third party options that will interpret the LaTeX code (to be fair, I've been told MathType is able to interpret LaTeX) and give you a PNG or PDF you can drag and drop into the document. I use Brisk ($10, Mac App Store) for inserting equations into Pages. You can set point size and most important, dpi so that if something is intended for print it will pop. Simple interface, just type your LaTeX code and drag the result into the app of choice. If you aren't fluent in LaTeX, it has many palettes for picking and choosing symbols.

brisk.tiff

Test Template

Finally, here is ny test template for my standards based grading system.

\documentclass[11pt]{amsart}
\usepackage{fullpage}
\usepackage[tmargin = 0.5in, bmargin = 1in, hmargin = 1in]{geometry}     %1-inch margins
\geometry{letterpaper}                  
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\pagestyle{empty}   %no page numbers
\thispagestyle{empty}   %removes first page number
\setlength{\parindent}{0in}   %no paragraph indents
\raggedright   %left justified text
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}
\begin{document}
Mr. Claydon\hspace{2.8in} Name:\ \makebox[1.366in]{\hrulefill} Date:\ \makebox[0.5in]{\hrulefill}\\
Algebra II \hfill Period:\ \makebox[0.5in]{\hrulefill}
\vspace{6pt}
\begin{center}
\textbf{test title}
\end{center}
\vspace{12pt}
1.\ \emph{Topic Title} \hfill \makebox[0.3in]{\hrulefill} /4 pts.\\[6pt]
Directions.\\[6pt]
\begin{flalign*}
a.\quad&question&b.\quad &question&&\\[0.5in]
c.\quad&question&d.\quad &question&&
\end{flalign*}\\[1in]
\dotfill\\[6pt]
2.\ \emph{Topic Title} \hfill \makebox[0.3in]{\hrulefill} /4 pts.\\[6pt]
Directions.\\[6pt]
\begin{flalign*}
a.\quad&&b.\quad &&&\\[0.5in]
c.\quad&&d.\quad &&&
\end{flalign*}
%uncomment for 2nd page
\newpage
Mr. Claydon\hfill \textbf{Test No.}\\
Algebra II\\
\vspace{12pt}
\emph{Basics}\hfill \makebox[0.3in]{\hrulefill} /4 pts.\\[6pt]
Directions.\\[6pt]
\begin{flalign*}
a.\quad&&b.\quad &&&\\[0.5in]
c.\quad&&d.\quad &&&
\end{flalign*}
\end{document} 
Posted
AuthorJonathan Claydon