I teach university courses and my goal is to be able to output two pdf's from the same tex file:
- A problem set
- A problem set with solutions
I already do this manually by calling \newif and then setting \soltrue or \solfalse in the header depending on whether I want to output solutions or not. Then I surround the solutions in \ifsol and \fi and we're off to the races. It's great because edits to the problem set require changes to only one document, not two. The only annoyance is that I have to compile it once, change that pdf's name, then change the header from \soltrue to \solfalse, then recompile again to get both documents. I'd like to use arara to automate this.
I've been following this excellent how-to on creating a yaml rule to get arara to do what I want. In the how-to, the author (cmhughes) creates a rule to compile a tex document into two pdf's, one with one column and the other with two. Obviously my application is slightly different.
I have created the following solutions.yaml rule:
!config
# Make two versions of document depending on if statement "sol"
# author: Shane Auerbach (based on work by Chris Hughes)
# requires arara 3.0+
#
# Sample usage
#
# % arara: solutions
# % arara: solutions: {solutions: true}
# % arara: solutions: {solutions: false}
#
identifier: solutions
name: Solutions
commands:
- <arara> pdflatex "\newif\ifsol\sol@{trigger}\input{@{file}}"
- <arara> @{ isWindows( "cmd /c move", "mv" ) } @{getBasename(file)}.pdf @{getBasename(file)}@{trigger.toUpperCase()}.pdf
arguments:
- identifier: trigger
flag: <arara> @{parameters.trigger}
default: false
And this is the test mytex.tex file:
% arara: solutions: {trigger: true}
% arara: solutions: {trigger: false}
\documentclass{article}
\begin{document}
Question: What is $2+2$?
\ifsol \begin{quote} \textbf{Solution:} $2+2=3$ \end{quote} \fi
\end{document}
It works great. When I run arara on the tex file, it outputs two pdf's, one with the solution and one without, as desired. There are two improvements I would like to make but do not know how to implement:
As is, I can currently only compile the
texfile withararaas the file itself has neither\soltruenor\solfalsein it. I would like to be able to put in something that set it if and only if it was not already set byararaso that I could compile this outside ofararaalso. But I do not want it to overwritearara's setting, as this would defeat the purpose. Any ideas?Currently the
pdffiles generated are calledmytexTRUE.pdf(with solutions) andmytexFALSE.pdf(without solutions). I'd prefer to have something likemytexS.pdf(with solutions) andmytexQ.pdf(without solutions). The only way I could think to implement this would be a conditional statement insolutions.yaml, but from what I've readyamlis not really designed for conditional statements. Any ideas on this front?
If you've read this far, you're a true hero. Thanks! If you skipped the middle, tl;dr: help this stranger make his workflow ever-so-slightly more efficient.
araramight have some goodies for this case, but since it's not officially released (it's in the works), I will write a compatible solution for version 3.0 as well.:)– Paulo Cereda Jun 07 '16 at 21:20