3

I'm currently relying on the exam class to produce separate exercise sheets for questions and solutions. Is there a way to use that class to produce a third sheet with hints instead of full solutions, or a better alternative?

The structure of the unique tex file would be something like:

\documentclass{exam} % or any other suggestion
\begin{document}

\begin{questions}

\question Prove that $A\implies B$.

\begin{hint}
Use contradiction.
\end{hint}

\begin{solution}
The details...
\end{solution}

\end{questions}

\end{document}

And then an appropriate Makefile with latexmk would produce sheet-questions.pdf, sheet-hints.pdf and sheet-solutions.pdf by passing the right options to the selected class, as instructed elsewhere on this site.

  • What have you tried? We already have some questions about how to pass information from the command line to the LaTeX run, so you might start with one of these posts… – TeXnician Mar 13 '19 at 16:19
  • 1
    Nothing yet, I would first like to know if a class with a comparable environment to what I'm looking for exists (i.e. hints besides questions and solutions) before reinventing the wheel. My question is not about passing options to classes; I already know how to achieve what I described in the last paragraph (one tex -> several different pdfs). – Anthony Labarre Mar 14 '19 at 08:07
  • 1
    Something like this? https://tex.stackexchange.com/q/224408/ (an xsim solution can be found in its manual: eample 9 (hints)) – cgnieder Oct 03 '19 at 09:55
  • @clemens That looks promising, I'll give it a try as soon as possible. Thanks! – Anthony Labarre Oct 03 '19 at 12:54

1 Answers1

0

I already had lots of files that use the exam class, so I ended up using the optional package to define a simple environment which shows nothing if option showhints is not used. Here's a basic example:

\documentclass{exam}
\qformat{\textbf{Question \thequestion\hfill}}

% The "optional" package allows the definition of an environment % hints that will only be printed if the showhints option is passed \usepackage[dummy]{optional} % document fails to compile if optional has no options ...

\makeatletter @ifpackagewith{optional}{showhints}{ % environment definition for the case where hints must be shown \newenvironment{hints}[1][]{\textbf{Hints:} #1}{} }{ % environment definition for the case where hints must be hidden \newenvironment{hints}[1][]{\setbox\z@\vbox\bgroup}{\egroup} } \makeatother

\begin{document}

\begin{questions} \question How do you include a package in \LaTeX?

\begin{hints} Ask around at tex.stackexchange.com if you dare. \end{hints}

\begin{solution} Use the \texttt{\textbackslash usepackage} command. \end{solution}

\end{questions}

\end{document}

Assuming the above is saved to a file named mwe.tex, the following Makefile produces three different outputs:

  1. mwe-base.pdf, which is the intended exercise sheet;
  2. mwe-answers.pdf, which features solutions but no hints;
  3. mwe-hints.pdf, which features hints but no solutions.
SOURCES = $(wildcard *.tex)
TARGETS = $(patsubst %.tex, %, $(SOURCES))

all: $(TARGETS)

%: %.tex latexmk -jobname=$(basename $<)-base -pdf -pdflatex='pdflatex -shell-escape -interaction=nonstopmode' $< latexmk -jobname=$(basename $<)-answers -pdf -pdflatex='pdflatex -jobname=$(basename $<)-answers -shell-escape -interaction=nonstopmode "\PassOptionsToClass{answers}{exam}\input{$(basename $<)}"' $< latexmk -jobname=$(basename $<)-hints -pdf -pdflatex='pdflatex -jobname=$(basename $<)-hints -shell-escape -interaction=nonstopmode "\PassOptionsToPackage{showhints}{optional}\input{$(basename $<)}"' $<

clean: rm -f .out aux bbl blg log toc .ptb .tod .fls .fdb_latexmk *.lof

There's most probably room for improvement.