LaTex Makefile with TexShop

Today I wanted to change the build process of my LaTex project in TexShop. First I thought, that there must be some kind of script within TexShop that I could change but it turned out that this is not the case. After some research, Lars told me that using a makefile would be the tool of choice to solve this issue. Since this was not as easy as I first thought, here is a little tutorial on how I finally solved it.

Makefile for building LaTex projects

The following Makefile solves the following issues, often faced in LaTex projects:


  • Building the BibTex bibliography
  • Creating index
  • Building table of contents

Since TexShop uses pdflatex for creating pdf output, I used pdflatex in the Makefile. Please remind that the Makefile repeats the call to pdflatex until all these issues are done.

# set latexfile to the name of the main file without the .tex
latexfile = diplomarbeit

# Use this line, if you want to use latex command
# TEX = latex -interaction=nonstopmode --src-specials
# Use this line, if you want to use pdflatex command
TEX = pdflatex -interaction=nonstopmode --shell-escape --src-specials

.PHONY : clean

all : $(latexfile).pdf $(latexfile).aux

	rm -f *.aux *.log *.dvi $(latexfile).ps *.bak $(latexfile).ps.gz $(latexfile).ps.bz2
	rm -f *.bbl *.blg
	rm -f *.toc *.lof *.lot
	rm -f *.thm *.out
	rm -f *.ind *.idx *.ilg

$(latexfile).aux : $(latexfile).tex
	$(TEX) $(latexfile)

# reruns latex if needed.  to get rid of this capability, delete the
# three lines after the rule.  Delete .bbl dependency if not using
# BibTeX references.
# idea from
$(latexfile).pdf : $(latexfile).tex $(latexfile).bbl $(latexfile).blg $(latexfile).toc index
	while ($(TEX) $(latexfile) ; \
	grep -q "Rerun to get cross" $(latexfile).log ) do true ; \

$(latexfile).toc $(latexfile).aux: $(latexfile).tex
	$(TEX) $(latexfile)

$(latexfile).bbl  $(latexfile).blg: $(latexfile).aux
	bibtex $(latexfile)

%.bbl: %.aux
	bibtex $(basename $<)

index : $(latexfile).ind

$(latexfile).ind : $(latexfile).aux
	makeindex $(latexfile)

Please remind that you have to set the name of your main .tex file in the second line of the Makefile. After that, you can either add your latex bin directory (/usr/texbin on my machine) in your $PATH variable or you have to use absolute paths in the TEX macro within the Makefile.

Setting up TexShop to use Makefile

The next step is to set up TexShop to use your Makefile instead of directly using pdflatex. Since I have an older version of TexShop, things might differ a little from newer versions, but for me the following steps worked out fine:


  • Go to TexShop -> Settings dialog
  • In "Miscellaneous" tab set "make" as personal script within "LaTex program"
  • Save settings
  • Put the little script below into your /usr/texbin directory and make it executable

This script should call the make command within your current working directory which is all you need to build your LaTex project:


Notes and Credits

Even if I'm ashamed to admit that - this was my first Makefile ever. So if you have any ideas on how to improve it, please leave some comments. Lars send me the first draft of the script and I mainly removed some lines of code that I did not use - so basically it's Lars's script.

A very useful introduction to makefiles can be found at O'Reilly's website under

Inhalt © Michael Knoll 2009-2019  •  Powered by TYPO3  •  TypoScript Blogging by Fabrizio Branca  •  TYPO3 Photo Gallery Management by yag  •  Impressum