I want to use the exact same file for my beamer presentation and handout. I do not like the need to comment out lines in order to create the handout or presentation (my current solution), nor do I want to have multiple files with an \input command. I realized that I can have a link (I work in linux or bsd) pointing to my main file, say

talk_handout.tex -> talk.tex

then the macro \jobname will let me know if I'm compiling the main file or the link. Using \endswith from the xifthen package I could then figure out if I should do handout or presentation mode.

This is all nice in theory, but in practice I have no idea how to do this. I usually have either [handout] or [beamer] in my \documentclass line and I don't know how to combine that with my desired use of \jobname.

Of course, I could have two files with an \input command right after the \documentclass line ... but I was wondering if there's another way.

Any ideas?

  • 1
    I just noticed that you specifically vetoed a solution that involves \include. But, perhaps you could explain why this is not a good solution...
    – Seamus
    Nov 24, 2010 at 16:22
  • 2
    You should use \input, not \include... Nov 24, 2010 at 20:11
  • 2
    see also “Passing parameters to a document” for a variety of ways to do this (another possible duplicate?).
    – Caramdir
    Nov 24, 2010 at 20:29
  • 1
    @Seamus: I don't like having many files "cluttering" up my directories. I don't like having to worry about setting master documents. I don't like having files that don't compile. I like the challenge. Nov 24, 2010 at 21:29
  • 1
    @Henrik, @Caramdir: although the answers are closely related, the questions are different and this actually seems like the kind of question that might get asked quite often. So I disagree with the duplicate, but agree that the three questions should be clearly connected. Nov 25, 2010 at 8:18

5 Answers 5


My answer to this question came from exactly this situation. The code is there, I shan't repeat that, but I'll try to explain what it does so that you can see if it's worth clicking through to that question.

My solution is exactly what you outline in your first paragraph. I have a main file that contains all the code, say seminar.tex, and then a set of symlinks which all point to this file and are of the form seminar.beamer.tex, seminar.handout.tex and the same for trans or article if appropriate. The class that I load is actually a wrapper class which looks at various parameters - both the \jobname and any passed to it from the document - to decide which real class to load (and with what options). Thus the start of my real document is something like:


beamer tells it to load the beamer class, defaults sets up some stuff that I almost always use. Then it looks at the \jobname to see what type of document it is: beamer, handout, etc, and passes the appropriate option to the beamer class.

For lectures, I have a further option in that the format for my symlinks is actually:


When I'm editing the document, I make sure that I load it via the symlink that I'm most interested in (usually the beamer version) and then my editor correctly compiles that version.

I used to use a method like the one Seamus outlines. I switched to this method because:

  1. When doing a lecture series, it's much easier to create a batch load of symlinks than a batch load of files with specific content.

  2. If I do compile the master document, it falls back to something sensible.

  3. It doesn't actually need all the symlinks to still work. Since you can reset the jobname via the commandline, you could just do pdflatex -jobname=seminar.beamer.tex seminar.tex to get the right version compiled.


Here's my workflow for this sort of thing. It differs quite a lot from your idea, but it achieves more or less the same goal. [edit: it differs so much that your question excludes this sort of answer. But other people looking for similar solutions might find this acceptable]

I have one file for the presentation and one for the handout. Each of them includes \input{content}. Then I have a third content.tex file that contains the actual content of the talk.

%%% presentation

Above: the presentation; below: the handout

%%% handout

But what if I accidentally compile the content.tex? this will break because it doesn't have a document class declaration. I use my editor of choice's multiple documents capabilities: I specify that the master document for content.tex is presentation.tex. Then compiling content actually compiles the presentation.

In emacs, this would be the content file:


%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "presentation.tex"
%%% End: 

I guess I could make a makefile that runs pdflatex on both, but I don't need my handout compiled as often as my presentation: I'm often playing with overlays and compulsively recompiling to check a particular slide transition looks how I want...


Using the idea of Martin Scharrer's answer from a related question the following solution is quite elegant.

Assuming there is a presentation talk.tex:

$ ls talk.tex
$ head -1 talk.tex

Then you can supply the handout class option via the command line like this:

$ pdflatex -jobname talk_print "\PassOptionsToClass{handout}{beamer}\input{talk}
$ pdflatex -jobname talk_print "\PassOptionsToClass{handout}{beamer}\input{talk}

That means that talk_print.pdf contains only full pages for handouts or reference.

$ pdflatex talk
$ pdflatex talk

This generates just the presentation version talk.pdf where the \pause etc. commands work as expected.

  • 2
    Hint: use a shell function to avoid writing the whole command, and just call something like: pdfhandout talk. Using bash: add to .bash_functions the following line: pdfhandout () { pdflatex -jobname "${1}_print" "\PassOptionsToClass{handout}{beamer}\input{$1}"; }
    – ggll
    Oct 4, 2016 at 16:55
  • Another alternative is to use \providecommand as here: tex.stackexchange.com/a/614/17145
    – ggll
    Oct 4, 2016 at 17:00

I found another solution using subfiles package:

%% CommonBeamerMainFile.tex
%% used for ALL presentations 
\input{praeambel.tex}  %% layout definitions
\begin{document}\end{document} %% it is basically empty

%% the concrete presentation
     something important here

%% Praesentation-handouts.tex
%% create the Handout for the concrete presentation
\pgfpagesuselayout{4 on 1}[a4paper,landscape,border shrink=5mm]

having this set up you can compile your presentation with
lualatex Praesentation.tex
and your handouts with
lualatex Praesentation-handouts.tex


This is a very old post, but I wanted to share my solution too (inspired from quite a few different places). You can add this at the top of your latex file:

\documentclass[... all your other options ...]{beamer}

Then, you can generate the handout with:

pdflatex -synctex=1 -interaction=nonstopmode "\def\ishandout{1} \input{yourtexfile.tex}"

or the regular version just as you'd do normally:

pdflatex -synctex=1 -interaction=nonstopmode yourtexfile.tex

I extended this a bit with a script (my proficiency in bash is quite low, probably not optimal) to either generate a handout or a regular version without overriding the generated pdfs (basically a handout version and a regular version with \pause enabled, amongst other tricks I do):

## Generate latex PDF files and clear generated files
## Options:
##      "-b" to also generate bibtex stuff
##      "-h" to generate the handout version

texfile=$(ls *.tex | head -1)
filename=$(basename "$texfile" .tex)


while getopts 'bh' flag; do
  case "${flag}" in
    b) gen_bibtex="true" ;;
    h) gen_params="\def\ishandout{1} \input{$texfile}"
    *) printf "Wrong flag passed.\n Usage:\n\t-b to generate the bibtex\n\t-h to generate a handout\n"
       exit 1 ;;

printf "\n*** generate $texfile with jobname $jobname ***\n\n"
pdflatex -synctex=1 -interaction=nonstopmode --jobname="$jobname" "$gen_params"

if [[ $gen_bibtex == "true" ]]; then 
  if [[ $gen_params == "\input{$texfile}" ]]; then

  printf "\n\n*** generate bibtex $auxfile ***\n\n"
  bibtex "$auxfile"
  pdflatex --shell-escape -synctex=1 -interaction=nonstopmode --jobname="$jobname" "$gen_params"

pdflatex --shell-escape -synctex=1 -interaction=nonstopmode --jobname="$jobname" "$gen_params"
printf "\n\n"

printf "\n*** done ***\n"

The clear-latex-gen script (assume only one .tex file in directory):

## Clear latex gen files from current directory

texfile=$(ls *.tex | head -1)
filename=$(basename "$texfile" .tex)

printf "***remove generated files $filename ***\n"

declare -a extensions=(".log" ".dvi" ".nav" ".out" ".snm" ".vrb" ".toc" ".run.xml" ".fls" ".bbl" ".blg" ".aux" ".fdb_latexmk" "-blx.bib")

for ext in "${extensions[@]}"; do
  rm ${filename}${ext} > /dev/null 2>&1
  rm ${filename}-handout${ext} > /dev/null 2>&1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .