# LaTeX compilation

Posted on

If like me, you are tired of getting many temporary files when you compile your Latex project, you can use the following method. I’m sure it can be improved by a lot, but it’s still a very good start.

## Folder hierarchy

Several folders are necessary in order to carry out the compilation, here mine but it can be adapted to your needs:

/document
|--/build
|--/img
|--/src


The /build folder will receive all the compilation files such as *.aux, *.log, … The /img will obviously contains all you images in several formats (jpg, pdf and even tikz for the LaTeX gurus). Finally, the /src folder will contain all you tex files and local styles (the *.sty files).

## Minimal required latex packages

There are several tools out there but not all of them have options for using a separate build path for the compilation. My configuration uses these applications:

• pdflatex: to create the pdf output,
• biber: to check the sanity and link the bibliography file,
• makeglossaries: to create the glossary (always useful for long documents)

Of course you can adapt or have a more complex toolchain.

## The Makefile

At the moment I use a make file located in the /src folder written by hand. It’s possible to use a more formal toolchain in order to have a portable system and less prone to specific user configuration that would create bugs elsewhere. Nevertheless, this Makefile can be placed in any folder following the hierarchy described above as long as you are adapting the paths.

.PHONY: clean, mrproper

.SUFFIXES:

NAME    = index

BUILD = ../build

pdf:
pdflatex -output-directory=$(BUILD) -draftmode$(NAME)
biber --bblencoding=utf-8 $(BUILD)/$(NAME)
makeglossaries -d $(BUILD)$(BUILD)/$(NAME) pdflatex -output-directory=$(BUILD) $(NAME) cp$(BUILD)/$(NAME).pdf ../$(NAME).pdf

mrproper:
rm -f \$(BUILD)/*


Now, you just have to go to your /src folder and run make pdf. The pdf output will appeared at the root of the folder.