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


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

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.


2 Answers 2


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, 2011 at 18:18
  • 1
    @Seamus: This is exactly what I do for my lectures. I explain my method in my answer: tex.stackexchange.com/questions/5899/… (the code is actually in another answer, but it's linked from that answer). Mar 23, 2011 at 18:45

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

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.

  • 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, 2011 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. Mar 23, 2011 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, 2011 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. Mar 23, 2011 at 18:41
  • 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, 2011 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.