TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

(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.)

share|improve this question
I heard the rites have something do do with waving a dead chicken above your computer... have you tried that? :P – Sharpie Aug 14 '10 at 1:34
The title is so Donald Knuth-y – hayalci Oct 3 '10 at 11:02
up vote 9 down vote accepted

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}
share|improve this answer
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.) – Loop Space Aug 16 '10 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! – Loop Space Aug 27 '10 at 17:14

One solution is to use filecontents (CTAN).

share|improve this answer

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.

share|improve this answer
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. – Loop Space Aug 16 '10 at 12:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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