I wanna use automatic variables to prepare a Makefile for several latex documents.

In other words, i have foo.tex, bar.tex, bee.tex, otherdoc.tex ...

I wanna use a single Makefile to process all of them in the same manner, say process with latex, dvips, ps2pdf ...

I do not want to process all of them at once, but individually.

The base name of my project, say foo.tex, will be supplied at the command line when running make. Reading this basename from the command line is my problem at the moment.

How do i do that?

Sure i can write a Makefile for each document, but it sucks ...

Thx a lot

  • 3
    Take a look at latexmk. Jul 15, 2019 at 13:01
  • 1
    @user152037 You can have a variable declaration such as SRC_BASE_NAME := default-name in your Makefile (with stuff such as SRC := $(SRC_BASE_NAME).tex and $(SRC_BASE_NAME).pdf: $(SRC) etc. ← rule that describes how to produce a PDF file from $(SRC)). Then you can call Make like this: make SRC_BASE_NAME=foobar in order to produce foobar.pdf from foobar.tex. Not sure the Make-fu is on topic here, though.
    – frougon
    Jul 15, 2019 at 13:02
  • @user152037 Note: since I used make SRC_BASE_NAME=foobar on the command line in my example, this just sets the SRC_BASE_NAME Make variable and builds the default target of the Makefile; but I didn't say what the default target is. This is the first target in the Makefile. Therefore, with my notations, you could start your Makefile with, for instance, .PHONY: all and all: $(SRC_BASE_NAME).pdf or, in case you also defined rules following the same pattern to produce, say, DVI output: all: $(SRC_BASE_NAME).pdf $(SRC_BASE_NAME).dvi.
    – frougon
    Jul 15, 2019 at 13:14
  • @user152037 I've put a sample Makefile illustrating this on pastebin.com (it has other improvements I didn't describe here), but you'll have to recover the tab characters: they have all been destroyed by the stupid site (or HTML browser). AFAIK, sites from the stackexchange network also eat tabs in the Markdown, so there wouldn't be that much to gain by posting it here. With this Makefile, you can write on the command line make, make SRC_BASE_NAME=foobar, make pdf, make SRC_BASE_NAME=foobar pdf ps, etc.
    – frougon
    Jul 15, 2019 at 13:24

1 Answer 1


I really advise using latexmk (or similar tools, like arara).

The reason is that latexmk will automatically track dependencies for you, it will know if the document need recompilation or not, and will call the various bibtex & Co. without having to write complex tests in Makefile.

Moreover, it can run in background, so that the document is automatically compiled and the preview refreshed every time you save the document, and it is normally well integrated in editors (works a treat with vim and vimtex).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .