[Tex/LaTex] How to use the exact same file for handout and presentation modes in beamer


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?

Best Answer

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.

Related Question