3

I'm trying to hack together a way to generate solutions files to my quizzes and exams. Here is my current workflow.

I have a file quiz.tex:

\documentclass[12pt]{article}

\newcommand{\solutionscolor}{white}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{color}
\usepackage{thmtools}

\theoremstyle{definition}
\newtheorem{problem}{Problem}

\declaretheoremstyle[
headfont=\color{\solutionscolor}\normalfont\bfseries,
bodyfont=\color{\solutionscolor}
]{colored}

\declaretheorem[
style=colored,
% style=phantom,
name=Solution,
numbered=no
]{solution}

\newcommand{\fillblank}[2]{\underline{\hspace{#1}{\color{\solutionscolor}#2}\hspace{#1}}}

\title{Quiz}
\author{Name \fillblank{1.25in}{Solutions}}
\date{}

\begin{document}

\maketitle

\begin{problem}
  Let $f(x)=\cos(2\,x)$. Determine the concavity of $f(x)$ at $x=\pi$.
\end{problem}
\begin{solution}
  The first derivative of $f(x)$ may be computed using the chain rule
  \[
  f^{\prime}(x)
  = -\sin(2\,x)(2)
  = -2\sin(2\,x)
  \]
  The second derivative of $f(x)$ may then be computed by using the chain rule
  again
  \[
  f^{\prime\prime}(x)
  = -2\cos(2\,x)(2)
  = -4\cos(2\,x)
  \] 
  It follows that
  \[
  f^{\prime\prime}(\pi)=-4\cos(2\pi)=-4<0
  \]
  Since $f^{\prime\prime}(\pi)<0$, $f(x)$ is \emph{concave down} at $x=\pi$.
\end{solution}


\begin{problem}
  Fill in the blanks.
  \begin{align*}
    \sin(\pi) &= \fillblank{.25in}{0} &
    \cos(\pi) &= \fillblank{.25in}{-1} &
    \sin\left(\frac{\pi}{2}\right) &= \fillblank{.25in}{1} &
    \cos(34\pi) &= \fillblank{.25in}{1} 
  \end{align*}
\end{problem}

\end{document}

Compiling this document produces quiz.pdf:

enter image description here

If I change the value of \solutionscolor to blue, the result looks like this:

enter image description here

My problem is that I want two files: quiz.pdf (with no solutions) and quiz-solutions.pdf (with solutions). Currently I have to do this manually.

Is there a way to automate my output to produce two files?

1 Answers1

4

The fundamental problem is that by default, filename.tex writes to filename.pdf. But there are a few ways around that. The first step is to remove the \solutionscolor newcommand from quiz.tex.

The easiest approach is to have two separate files:
student.tex:

\newcommand{\solutionscolor}{white}
\input quiz

solutions.tex:

\newcommand{\solutionscolor}{blue}
\input quiz

A slightly better idea may be to just have two commands that you use:

pdflatex -jobname solutions "\newcommand{\solutionscolor}{blue}\input quiz"
pdflatex -jobname student "\newcommand{\solutionscolor}{white}\input quiz"

Either approach doubles your aux and log files, and requires that you compile each document separately. But you could have a script run things for you, or combine your commands into one:

pdflatex student ; pdflatex solutions
pdflatex -jobname solutions "\newcommand{\solutionscolor}{blue}\input quiz" ; pdflatex -jobname student "\newcommand{\solutionscolor}{white}\input quiz"

(You should be aware that white text is still present. Distributing the document electronically means that people could access the data you've hidden.)

Teepeemm
  • 6,708