6

Here is a hypothetical scenario. I want to make a beamer presentation and a handout for that presentation. I start my file as follows:

\newif\ifhandout
\handouttrue
\ifhandout
\PassOptionsToClass{handout}{beamer}
\fi
\documentclass{beamer}

\ifhandout
\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[a4paper,landscape,border shrink=5mm]
\fi

Now, what I'd like to add to this conditional-fu is a command that tells LaTeX to compile to handout-\jobname.pdf if the relevant statement is true. Is this sort of thing possible, or can I only do this from the command line?

I've not added the beamer tag because this is not a question about beamer. I couldn't think of any other tags that this might fall under.

lockstep
  • 250,273
Seamus
  • 73,242

2 Answers2

7

Depending on your environment, you could try doing it the other way around: have presentation.tex and presentation-handout.tex, the latter being a symlink to the former, and inspect \jobname to decide. Or have a wrapper file for the handut that does a few \RequirePackages and \AtBeginDocuments, this depends a lot on how much you need.

  • Could you explain how the evaluating \jobname thing would work? – Seamus Mar 23 '11 at 18:18
  • 1
    @Seamus: This is exactly what I do for my lectures. I explain my method in my answer: http://tex.stackexchange.com/questions/5899/how-to-use-the-exact-same-file-for-handout-and-presentation-modes-in-beamer/5930#5930 (the code is actually in another answer, but it's linked from that answer). – Andrew Stacey Mar 23 '11 at 18:45
4

You can't change the jobname from inside the document. (Ok, you could do some \write18 trickery to compile the document with a different compiler instance...)

The simplest thing to do would to create a wrapper file for the handout:

% handout.tex
\PassOptionsToClass{handout}{beamer}
\input{presenation}

Where presentation.tex is your presentation file. Then you get presentation.pdf and handout.pdf. Note that if you use these commands on the command line the jobname will be the one of the \input file. You would need to use -jobname to change that.

Martin Scharrer
  • 262,582
  • On the command line, you can tell pdflatex where to compile to, right? Why can't you do that from inside the file? – Seamus Mar 23 '11 at 18:34
  • @Seamus: Because the file might already be open? The PDF file isn't opened in the preamble yet, but the log file is most likely. – Martin Scharrer Mar 23 '11 at 18:36
  • @Martin well I don't care where the log gets written. As long as I put it before documentclass, there's every chance the PDF file hasn't been opened yet. – Seamus Mar 23 '11 at 18:38
  • @Seamus: In my tests the PDF isn't open (i.e. the old one isn't overwritten) until the first page is flushed out. But TeX doesn't care about that and fixes the \jobname at the beginning. – Martin Scharrer Mar 23 '11 at 18:41
  • It's a shame there isn't an option to specify the jobname in the first line of the .tex file. That would be cool. (Although given that I'd want to put it inside a conditional, it would have to be looser than strictly the first line.) – Seamus Mar 23 '11 at 19:05
  • 2
    @Seamus I think it's more a security issue than a technical problem - allowing the document to choose where the output file is written could cause possible damage when compiling a malicious input file. – diabonas Mar 23 '11 at 21:30
  • MArtin your wrapper solution doesn't work as is, since like I say in my question, I want to do more with the conditional switch than just pass an option to a class. I also want differentiated colour schemes for the two files... – Seamus Mar 25 '11 at 17:31