1

I'm writing a problem set with a solution. Right now I have the following setup:

\newtheorem*{sol}{Solution}

\newif\ifshow
\showfalse

\ifshow
    \newenvironment{bluesol}
    {\begin{sol} \color{NavyBlue}}
    {\end{sol}}
\else
    \excludecomment{bluesol}
\fi

So my solutions would be in the bluesol environment.

Currently, if I want to compile a problem set questions, I'd do \showfalse, and when I want to compile the solutions, I'd do \showtrue instead. This works... but the output files are the same, so I have to manually change the file name to something like pset1questions.pdf before compiling the solutions.

I'm wondering if there's a way to automatically do this; i.e. run once for \showfalse, and rename the target file to pset1questions.pdf, and run again for \showtrue, and rename the target file to pset1sol.pdf

I'm also open to a completely new way to do this (but I still would like my solutions to be within the environment though).

Thanks a lot!

Art
  • 152
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Jul 08 '15 at 19:24
  • 1
    And there are perhaps better ways to achieve this: probsoln, answers, exsheets etc. –  Jul 08 '15 at 19:28
  • here is your answer http://tex.stackexchange.com/questions/74243/automatically-create-two-pdf-output-files-from-one-tex-file – touhami Jul 08 '15 at 20:59
  • @touhami: I think the problem is inside ... but as long as the O.P. does not provide a clear MWE, it's difficult to tell –  Jul 08 '15 at 21:18
  • @ChristianHupfer I add an answer – touhami Jul 08 '15 at 22:39

1 Answers1

1

Here is a solution. suppose your file is question.tex

\documentclass{article}
\usepackage{comment}
\usepackage{xcolor}

\newtheorem{sol}{Solution}

%\newif\ifshow    % uncomment this line for normal use

% uncomment next line for solutions
%\showtrue

\ifshow
    \newenvironment{bluesol}
    {\begin{sol} \color{blue}}
    {\end{sol}}
\else
    \excludecomment{bluesol}
\fi

\begin{document}
This is a question
\begin{bluesol}
Here is the solution
\end{bluesol}
\end{document}

Note: you need \showtrue as \showfalse is the defaut value.

in this approch we dont need \newif\ifshow and \showtrue

we compile in line command:

pdflatex \newif\ifshow\showtrue \input{question.tex} && copy question.pdf solution.pdf

and then

pdflatex \newif\ifshow \input{question.tex}
touhami
  • 19,520