2

I am using a Makefile together with the latexmk utility to build PDFs from LaTeX files. My question is at the bottom. Here is some background:

The relevant parts of my Makefile are the following:

LATEX=pdflatex
LATEXOPT=--shell-escape --file-line-error
NONSTOP=--interaction=nonstopmode
LATEXMK=latexmk
LATEXMKOPT=-quiet -pdf
CONTINUOUS=-pvc

%.pdf: %.tex
    @${LATEXMK} ${LATEXMKOPT} ${CONTINUOUS} \
      -pdflatex="${LATEX} ${LATEXOPT} ${NONSTOP} %O %S" $<

This structure is adapted from the example in this link.

I compile a LaTeX source file.tex into file.pdf using

make file.pdf

This runs latexmk on file.tex and continuously recompiles it (using the -pvc "preview continuously" option) with pdflatex whenever file.tex is modified. Combined with a PDF viewer that updates automatically, this lets me edit file.tex and see the updated PDF whenever I save.

This works perfectly while latexmk runs in the background. The problem is when I want to end latexmk. It tells me

=== Watching for updated files. Use ctrl/C to stop ...

As soon as I type Ctrl-C, make says

make: *** Deleting file `file.pdf'

I believe this is because I stopped building the file.pdf target abruptly, so make thinks something went wrong. Therefore, my question is

How do I preview continuously and exit latexmk, all while using make, without the PDF being deleted?

3

After asking this question I read this from the make documentation. It turns out that make does not delete the dependencies of the special target .PRECIOUS when interrupted. Adding the line

.PRECIOUS: %.pdf

seems to solve my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.