16

Is it possible to compile two different pdf outputs from the same .tex file?

For example, let's say I have a document main.tex which contains questions for students, and answers only for teachers, which I want to hide from the students. Is it possible to compile the student and teacher versions of the document from the command line with different options?

pdflatex '\documentversion{student}' main -o student.pdf # output is student.pdf
pdflatex '\documentversion{teacher}' main -o teacher.pdf # output is teacher.pdf

1 Answers1

18

Here is an example.

You must compile this document with this two commands to get the two versions (students.pdf and teachers.pdf):

pdflatex -jobname=students '\def\student{}\input{main}'
pdflatex -jobname=teachers '\def\teachers{}\input{main}'

(The -jobname option defines the name of the produced PDF document. Ex: with -jobname=students option, the command produces students.pdf.)

The main.tex document (using etoolbox to simplify the test):

\documentclass{beamer}
\usepackage{etoolbox}
\begin{document}
\begin{frame}
  \frametitle{Title}
  \ifdef{\teachers}
  {Content for teachers}
  {Content for students}
\end{frame}
\end{document}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283