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!


5 Answers 5


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.

  • Thanks Charles. This combined with you Passing Parameters answer were very helpful.
    – Charlie
    Commented Sep 1, 2010 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

  • 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
    Commented Aug 31, 2010 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
    Commented Sep 1, 2010 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.

  • That's a nice trick, Joseph; I didn't know that you could "write" a TeX file right there on the pdflatex line.
    – Charlie
    Commented Sep 1, 2010 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









   \setjobnamebeamerversion{\[email protected]}

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.


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.

You must log in to answer this question.

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