LaTeX Link and Makefile

I use Makefile to create PDF files from .tex .

When links were used in my LaTeX files. sometimes i get something like

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

I know that restarting the LaTeX compilation command can fix this problem with the link, but in my Makefile , %.pdf depends only on %.tex , so just running make does not fix the problem again (nothing changed in the .tex file). I need to do make clean to recreate the PDF again.

Here is my Makefile

 TEX := $(wildcard *.tex) default: $(TEX:.tex=.pdf) %.pdf: %.tex xelatex $< .PHONY: clean clean: rm -v *.aux *.toc *.log *.out 

How to solve this problem? Thanks.

UPDATE:

Here are some thoughts I found from Google

  • Change the default target as .PHONY . This is not a good solution (because there might be a latex file, and I just need to recompile one file)
  • Change the %.pdf dependency to include %.aux . But I do not know if it is possible to do this in GNU? (depends on the %.aux file, if it exists, otherwise ignore the %.aux )
  • Make grep in the .log file and find the specific warning. If it exists, restart the compilation command.
+8
makefile latex
source share
2 answers

I use a simple rule in all my LaTeX makefiles

 .DELETE_ON_ERROR: %.pdf %.aux %.idx: %.tex pdflatex $< while grep 'Rerun to get ' $*.log ; do pdflatex $< ; done 

This repeats pdflatex as often as possible. I found that all of the various LaTeX messages that require re-writing contain a common “Retry to Receive” line in the log file, so you can simply check for the presence of this file with grep in the while loop.

The value ".DELETE_ON_ERROR:" is important: it ensures that any remaining incomplete pdf / aux / idx files are automatically deleted whenever TeX is interrupted with an error, so they cannot confuse make the next time you invoke it.

When I use DVI and not PDF as the output format, I use the equivalent

 %.dvi %.aux %.idx: %.tex latex $< while grep 'Rerun to get ' $*.log ; do latex $< ; done -killall -USR1 -r xdvi || true 

The last line causes any xdvi to restart its input file for instant visual control.

+10
source share

Either set a “default” fake target (add a “default” to the line starting with .PHONY), or create a more complex dependency structure that starts automatically (I can’t say how to do this, sorry).

+1
source share

All Articles