Makefile for Graphics in LaTeX Documents

If you are writing papers or thesis with LaTeX or are preparing talks with the beamer package, you will usually use a sophisticated program to generate graphics. For example you could use Inkscape to generate high quality vector graphics. To include them into a LaTeX document you will have to convert the files to eps (for latex) and/or pdf (with pdflatex). Below you find a makefile wich can help you with the conversion.

  • Copy the makefile below to your picture folder. The name should be Makefile
  • To generate for example for all *.svg files the corresponding *.pdf just type make
  • If you change one source file, type make, and only this file is made. This can save a lot of time.


  • If you write \includegraphics{file} without extension, then you can use latex and pdflatex for your document. The programs will pick the suitable extension while the makefile had generated the necessary *.(e)ps and *.pdf files.
  • There are tabs inside the makefile which are essential! If you are doing Copypasta, replace the spaces by a tab. Be careful, some editors always replace tabs by spaces.


Feel free to add further rules.

# This is a usefull makefile to generate pictures in eps and pdf
# from different input formats
# (i.e. neato (GraphViz, undirected graphs), gnuplot (data and function plotting ), inkscape (svg))
# to use the graphics in LaTeX documents.
# Peter Husemann
#Targets that will not result in a real file
.PHONY = all ps pdf svg
#Define different input files: *.svg, *.gnuplot, *.neato
INKSCAPE_FILES = $(wildcard *.svg)
GNUPLOT_FILES = $(wildcard *.gnuplot)
NEATO_FILES = $(wildcard *.neato)

# The main target: create all ps, eps and pdf files. The pdf/(e)ps files can then be included
# into latex documents.
# These targets are made, if just 'make' is called.
all: ps eps pdf

## Definition of the interesting targets. 'make' automatically determines what to do to create
# one of the targets files from the rules below
pdf: $(NEATO_FILES:.neato=.pdf) $(GNUPLOT_FILES:.gnuplot=.pdf) $(INKSCAPE_FILES:.svg=.pdf)
ps: $(
eps: $(GNUPLOT_FILES:.gnuplot=.eps) $(INKSCAPE_FILES:.svg=.eps)
svg: $(NEATO_FILES:.neato=.svg)

### Rules to create files from other input files. 
# If file.svg exists, then 'make file.pdf' produces the pdf by
# applying the following rules automatically
# create an eps file out of a svg image:
%.eps: %.svg
        inkscape  --export-eps=$@  --export-bbox-page  $<
# $@ refers to the output file (i.e. file.eps),
# whereas $<  is the input file (i.e. file.svg)

## (e)ps to pdf
#create pdf from postscript
        epstopdf $<
#dito (but eps)
%.pdf: %.eps
        epstopdf $<

## graphviz
#create postscript from neato (GraphViz) %.neato
        neato -Tps $< -o $@
# one could do that directly with pdf, but only newer versions of graphviz allow that
# (uncomment it if you want to use this)
# %.pdf: %.neato
#       neato -Tpdf $< -o $@
# if the graph should be edited  we can output it it to a svg file
# %.svg: %.neato
#         neato -Tsvg $< -o $@

## gnuplot to eps
# this functions only if the gnuplot script writes an eps file
%.eps: %.gnuplot
        gnuplot $<
# therefore the gnuplot script (file.gnuplot) should contain something like this:
# set terminal dumb
# plot x
# set output "file.eps"
# set terminal postscript eps enhanced color solid lw 1 "Helvetica" 16
# replot
# unset output
# set terminal dumb