LaTeX makefile

Fri 14 February 2014

[caption id="" align="alignright" width="350"]Dostoyevsky's notes for Chapter 5 of The Broth... Document writing without makefile (Photo credit: Wikipedia)[/caption]

As many people writing using efficient tools, I use [latex]LaTeX[/latex]. I divide my work in chapters, each chapter being written in separate .tex file[1. as explained in wikibooks]. I need an efficient way to easily generate the final document[2. including bibliography, index, and table of content]. Here is my solution[3. works with texlive 2013 and GNU/make 3.82], based on a makefile and a main document.

the preambule

The main document looks like:

\documentclass[]{report}
%{wanted packages}
\usepackage{makeidx}
\makeindex
\author{Manu}

\title{Great title}
\begin{document}
\maketitle{}
\tableofcontents
\listoffigures
\listofalgorithms

\chapter*{intro}
\input{intro.tex}

\chapter{foo}
\input{foo.tex}

\chapter{bar}
\input{bar.tex}

\chapter{foobar}
\input{foobar.tex}

\chapter*{end}
\input{end.tex}

\bibliographystyle{apalike}
\bibliography{biblio,rfc}

\printindex
\end{document}

the makefile

the makefile looks like:

SRC=document.tex intro.tex foo.tex bar.tex foobar.tex end.tex   #.tex files
FIG=fig/logo.png fig/seagull.pdf    #fig needed
BIB=rfc.bib math.bib    # bibtex files
TEX=pdflatex    #compiler

all: domcument.pdf  #final target

%.pdf: %.tex %.log %.ind %.bbl %.toc $(SRC) $(FIG) $(BIB)
    while grep -e 'Rerun to get' -e 'run LaTeX again' *.log ; do $(TEX) $< ; done

%.aux %.idx %.toc %.log: %.tex
        $(TEX) $<

%.bbl %.blg: %.aux $(BIB)
        bibtex $< && $(TEX) $*.tex

%.ind: %.idx
        makeindex $< && $(TEX) $*.tex

It is not quite clean, but it works and it is understandable. Implicit variables ($<, $*, ...) are useful but I only found one place where it is documented.

(Non-)Related articles

Enhanced by Zemanta

Related articles (or not):

Category: tools Tagged: GNU LaTeX Makefile Writing how to tools