I'm using Makefile to generate PDF from .tex files.
When references was 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 re-run LaTeX compile command can fix this reference problem, but in my Makefile, %.pdf only depends on %.tex,thus just run make again doesn't fix the problem (nothing changed in .tex file). I need to do a make clean to re-generate PDF again.
Here's 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? Thank you.
UPDATE:
Here's some thought I found from Google
default target to be a .PHONY. Which is not a very good solution (because there's so may latex file there, and I just need to re-compile a single file)%.pdf's dependency to include %.aux. But I don't know if it's possible in GNU make? (depends on %.aux file if it exists, otherwise ignore the dependency on %.aux)grep to the .log file and find the specific warning. If it exists, re-run compile command.I use in all my LaTeX makefiles the simple rule
.DELETE_ON_ERROR:
%.pdf %.aux %.idx: %.tex
pdflatex $<
while grep 'Rerun to get ' $*.log ; do pdflatex $< ; done
This repeats pdflatex as often as necessary. I found that all the different LaTeX messages that call for a rerun contain the common string "Rerun to get " in the log file, so you can just test for its presence with grep in a while loop.
The ".DELETE_ON_ERROR:" setting is important: it ensures that make automatically deletes any remaining incomplete pdf/aux/idx files whenever TeX aborts with an error, such that they cannot confuse make when you call it next time.
When I use DVI rather than PDF as the output format, I use equivalently
%.dvi %.aux %.idx: %.tex
latex $<
while grep 'Rerun to get ' $*.log ; do latex $< ; done
-killall -USR1 -r xdvi || true
The last line causes any running xdvi to reload its input file, for instant visual inspection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With