(with apologies for the title)

I've just entered the murky waters of trying to get one LaTeX file to write out something useful as it goes along. In brief, I want my lecture LaTeX file to be able to write out a file that, upon LaTeX'ing, will give me the corresponding lesson plan. So at the start of the (main) document I want to write out the header, then as the document progresses, I want to write out bits to go in the plan, then at the end it needs to write out a footer.

What is confusing me is when writes happen. The lecture file consists of lots and lots of lectures (it's a beamer file) and only one is produced upon LaTeX'ing, but one of the pieces of information that I want to write out is the lecture title and I keep getting the last lecture title. I thought that maybe \immediate would be the answer, but that really does mean immediate. What I want is to put the \write in a macro in such a way that when the macro is called, the write is immediate (in particular, I want to hook it in to the lecture title page). So the question is: how do I do that?

I'm probably just missing something obvious, but whatever it is, I'm missing it!

(And for some reason, searching on google for 'latex write' doesn't help much.)

  • 3
    I heard the rites have something do do with waving a dead chicken above your computer... have you tried that? :P
    – Sharpie
    Aug 14, 2010 at 1:34
  • The title is so Donald Knuth-y
    – hayalci
    Oct 3, 2010 at 11:02

3 Answers 3


I guess I must not understand the question. What is wrong with:


Although I like to be a bit more complete and handle the fact that not all input files may be read on each compilation (due to \includeonly) but you still want the complete lesson plan even if some parts live in the non-included files, also the user maybe want to switch off all file output via \nofiles, or only wants to stop automatically updating the lesson plan so they can do some hand editing (here remove the \makemyrecords line). I would also want to avoid putting spurious spaces in the document, so I would do it this way, modelled loosely after how \makeindex works in latex:

          [2010/08/14 v0.01 my example record package (LSB)]



    \typeout{Writing my records to file \jobname\myrec@outputfileextension}%






If I test this with what I imagine you have in mind (obviously you would want to wrap the \renewcommand{\currenttitle}\mywritecurrenttitle up with a command that generates the document sectioning, or put them in hooks provided by your document class).

\newcommand*{\currenttitle}{This is the title of lesson 1}
Lesson 1....

\renewcommand{\currenttitle}{This is the title of lesson 2}
Lesson 2.....


Then, as expected, the lesson plan file looks like

\documentclass {lessonplan} \begin {document}
\lessonplanitem {This is the title of lesson 1}
\lessonplanitem {This is the title of lesson 2}
\end {document}
  • This is great! Thanks. With a little tweaking to take into account the details I didn't tell you about, it's now a working solution. (Basically, I can't use the aux file route because I want the lesson plan to be generated when \nofiles is in effect. But it was simple to edit that out.) Aug 16, 2010 at 12:39
  • A follow-up: I'm now using this "in the wild" and it's fantastic. I now scatter my beamer presentation with the lesson plan stuff, plus a few things are added automatically, and my lesson plan gets written out into a separate file which I can TeX to get a very nice-looking plan. Thanks again! Aug 27, 2010 at 17:14

One solution is to use filecontents (CTAN).


Can you not just use \let to save the current title, and use it later to write to a file? Another alternative would be to always use \immediate so that the chronology of typesetting is respected.

  • This is, as far as I can tell, pretty much what Lev's answer does. For some reason, when I tried simply putting in \immediates in front of the \writes then it wasn't doing what I expected. Aug 16, 2010 at 12:38

You must log in to answer this question.

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