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

I recently created a makefile to use with my TeX documents and am quite happy with the discovery. When I create Beamer slides to use in class, I create both a set of slides and a handout to go along with them. I'd like to have a makefile that creates the slides, then changes one or two lines of the header of my TeX file (by uncommenting and commenting perhaps) to create a set of handouts (possibly by generating a new, intermediate TeX file). I'm guessing that a make file can't edit my TeX file, but that would be cool. Is it possible? Thanks!

share|improve this question
This is a very similar problem to tex.stackexchange.com/questions/1492/… – Caramdir Aug 31 '10 at 9:52
up vote 6 down vote accepted

This is the same sort of problem as asked the Passing parameters to a document question; what follows is adapted from my answer there.

Have the target in your Makefile clobber a file that is \input by your Latex document, which should set the header. Don't be fussy about Latex convention: saving characters by using \def makes your makefile easier to read.

For example, let the Makefile have:


handout: echo "\def\hdrparam{$(HEADERNAME)}">params.tex;  latex manuscript

Then manuscript.tex should begin with \input{params.tex}, defining \hdrparam for use in your header macros.

share|improve this answer
Thanks Charles. This combined with you Passing Parameters answer were very helpful. – Charlie Sep 1 '10 at 18:50

The way I would accomplish this would be to place the core content in one LaTeX file (say content.tex) and write two wrapper files (say slides.tex and handouts.tex) that incorporate content.tex by invoking \input{content}. Then you could create the appropriate targets and rules in your makefile, one to compile slides.tex and the other to compile handouts.tex

share|improve this answer
This works quite well. I've also set up some other wrapper files to produce 2-up, 4-up, and 8-up versions of the slides to put on course web sites. (There was never a clear consensus for one format and it is easy enough to do several.) I've also used the optional package to make the screen and download versions slightly different. Works great. – vanden Aug 31 '10 at 4:57
Thanks las3rjock. That's a good solution, but I prefer one where I only have a single TeX file floating around. – Charlie Sep 1 '10 at 18:49

Another way to do this is to use a macro to contain the information you wish to pass, and do something like

pdflatex "\def\MyHeaders{Whatever} \input MyFile.tex"

in your makefile. You'd probably include a \providecommand*\MyHeaders{} line in the main document to avoid awkward errors.

share|improve this answer
That's a nice trick, Joseph; I didn't know that you could "write" a TeX file right there on the pdflatex line. – Charlie Sep 1 '10 at 18:52

My answer to the question passing parameters to a document wasn't great because I didn't give any code. So I'll take this opportunity to put the code in!

In short, my method for this is to have symlinks to the main file with the name of the symlink containing parameters. It is, perhaps, not as flexible as passing options to the file but it does mean that the resulting compiled file will have the right name and neither it nor any of the auxiliary files will get clobbered by making different versions.

The core bit of the code is as follows:


% Copied from the TeX FAQ entry 'comparing the ``jobname'''.



% Find out how many components jobname has.  Format is
% name[.type[.date]] where name has not dots, type is the type of
% output (default ``beamer'') and date is the date of the lecture to
% be produced, in ISO format of YYYYMMDD.




% Only one component



% Only two components


% Three components










It's probably not the cleanest code - I could probably condense half the \expandafters. This code comes from a class that I load for all my documents which can be found (with a brief description) here.

share|improve this answer

The answer by las3rjock is probably the best, but if you really want make to change or generate your headers, there are several options. You could use sed or another stream editor to actually edit your file. Or you could use a preprocessor like cpp or M4 to generate a proper file from a template.

share|improve this answer

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.