I would like to be able to generate a latex document while processing another one. In more concrete terms: I am preparing slides for a course. The slides include some developed examples (in particular, proofs) which I would like to make available as a separate handout. What I would like is to save these proofs, which I can enclose in a command, in a separate file to generate a separate paper. I could write these proofs in separate files and include them in the beamer presentation and in a handouts file, but I would prefer to avoid it, since it means maintaining several files and jumping from one to another one.

I guess it can be done based on \typeout commands, but, is there any other higher-level, partially cooked solution already available?

Thanks in advance!

  • 1
    Welcome to TeX.SX! Do you know the handout mode in beamer? ;-). \typeout isn't the right way to do is anyway (at least not without much ado and tedious filtering etc.) handout requires two compilations, however – user31729 Oct 6 '15 at 9:15
  • 1
    What's a separate handout? Do you want two independent handouts, i.e., the normal one and some extra frames into another one? Do you want a normal handout and and extended one with extra frames in their position? Should the extra handout look like beamer frames or as a regular article? – Ignasi Oct 6 '15 at 10:12
  • The extra handout should look like a regular article. No need for it to be beamer slides (although it that's the way to go I could live with it). The handout (or "notes" if you want) is not an extension of the presentation, with additional frames, but an excerpt where some selected parts of the presentation are put together in a different document. To give an example, if I had \begin{frame} ..text... \mystuff{here my stuff} \end{frame} "here my stuff" should go to the slide and (just this text) to a different file which will be the notes. – Manuel Carro Liñares Oct 6 '15 at 12:32
  • beamer provides several modes (beamer, handout, article, ...) to select which part of a presentation is included in corresponding kind of document. With beamerarticle package the whole presentation can be formated as an article, book or whatever you want. The problem is that is the whole presentation which is included and not only some selected parts as you want. In case you are still interested in this solution, take a look at sections 21.2 and 21.3 in beameruserguide. – Ignasi Oct 6 '15 at 14:43
  • Thanks, Ignasi. I have been looking at these section (I knew about modes but never used them). They seem to be step forward but they don't exactly do what I'd like -- excluding part of the slides, with the minimal amount of additional markup. I'm afraid that at the moment, and while I don't find a better option, I'd have to do some latex source code manipulation -- probably using m4 macros or something like that. – Manuel Carro Liñares Oct 7 '15 at 7:30

I find the filecontents package approach the easiest


filecontents actually bypasses the morewrites mechanism so if you need extra file streams you may need to hack the package - if you get a relevant error.

Then for each snippet

whatever code you want to reuse



whenever (and from whatever compilation) you want to use it.

If you want to keep things tidier you can write the files into a subfolder, and read them back from there

Hello audience

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.