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
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:
HEADERNAME = My Header 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.– CharlieSep 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.– vandenAug 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.– CharlieSep 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.– CharlieSep 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:
\def\my@real@class{beamer}
% Copied from the TeX FAQ entry 'comparing the ``jobname'''.
\def\be@mertypeis#1{FF\fi
\edef\my@predicate{#1}%
\edef\my@predicate{\expandafter\strip@prefix\meaning\my@predicate}%
\edef\my@job{\be@mertype}%
\ifx\be@mertype\my@predicate
}
\def\be@mertwo#1.#2\relax{#2}
\def\be@merone#1.#2\relax{#1}
% 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.
\let\be@merdate\@empty
\edef\be@mertest{\expandafter\be@merone\jobname.j\relax}
\edef\my@jobname{\jobname}
\ifx\be@mertest\my@jobname
% Only one component
\def\be@mertype{beamer}
\def\be@merfile{\jobname}
\else
\edef\be@mertest{\expandafter\be@merone\jobname\relax.\expandafter\expandafter\expandafter\be@merone\expandafter\be@mertwo\jobname.j\relax\relax}
\ifx\be@mertest\my@jobname
% Only two components
\edef\be@mertype{\expandafter\be@mertwo\jobname\relax}
\edef\be@merfile{\expandafter\be@merone\jobname\relax}
\else
% Three components
\edef\be@merdate{\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\be@merone\expandafter\expandafter\expandafter\be@mertwo\expandafter\be@mertwo\jobname\relax\relax.j\relax}
\edef\be@mertype{\expandafter\expandafter\expandafter\be@merone\expandafter\be@mertwo\jobname\relax\relax}
\edef\be@merfile{\expandafter\be@merone\jobname\relax}
\g@addto@macro{\my@afterpackages}{%
\expandafter\includeonlylecture\expandafter{\be@merdate}
}
\fi
\fi
\edef\be@merdefopts{12pt,t,xcolor=dvipsnames,ignorenonframetext}
\if\be@mertypeis{article}
\def\my@real@class{article}
\PassOptionsToPackage{envcountsect}{beamerarticle}
\PassOptionsToClass{a4paper,10pt}
\fi
\if\be@mertypeis{handout}
\PassOptionsToClass{handout,12pt,xcolor=dvipsnames,xcolor=gray,ignorenonframetext}{beamer}
\fi
\if\be@mertypeis{trans}
\PassOptionsToClass{trans,12pt,xcolor=dvipsnames,ignorenonframetext}{beamer}
\fi
\LoadClass{\my@real@class}
\if\be@mertypeis{article}
\RequirePackage[envcountsect]{beamerarticle}
\setjobnamebeamerversion{\be@merfile.beamer}
\fi
It's probably not the cleanest code - I could probably condense half the \expandafter
s.
This code comes from a class that I load for all my documents which can be found (with a brief description) here.