# Conditional compilation of documents using command line options for pdflatex

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

• The linked question (and its answer) partially answers this question. I vote to reopen this question and provide a complete answer... – Paul Gaborit Dec 31 '14 at 0:16
• @PaulGaborit It's reopened now. – Mike Renfro Dec 31 '14 at 0:58

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}

• Could you explain the use of jobname? – Praxeolitic Jul 4 '16 at 12:53
• @Praxeolitic Done... – Paul Gaborit Jul 4 '16 at 13:00
• Looks like that was a silly question. I was confused and had thought it was part of getting the conditional to work. – Praxeolitic Jul 4 '16 at 13:04