TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a midterm exam written with the solutions included using the versions package. I use this to create an assignment/exam PDF and a solution PDF from the same basic tex file (this is great---change a question a bit and you don't have to change the question in a separate solutions file).

Is there a way to create separate assignment and solution tex (as opposed to PDF) files that exclude and include the appropriate version environments? The reason that I want to do this is because this is a take-home exam and some students want to submit their answers using LaTeX on the original file.

share|improve this question
It's not necessary to begin your questions with a greeting. – lockstep Mar 15 '11 at 19:19
up vote 5 down vote accepted

You are probably looking for a pure TeX/LaTeX solution but I'd try to solve the problem on a different level: I'd use a Makefile and the Unix sed command to derive a LaTeX file that does not contain the solutions any more. If each solution is included in some environment, something along the following lines would do it:

sed '/\\begin{solution}/,/\\end{solution}/d' file.tex > file-without-solutions.tex

Both file.tex and file-without-solutions.tex could be compiled to PDF files with the additional benefit that you could hand out the source code for file-without-solutions.tex.

share|improve this answer
Makefile works for me---thanks! – Charlie Mar 16 '11 at 4:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.