use latexmk to build PDF docs?

101 views
Skip to first unread message

John H Palmieri

unread,
Jan 31, 2011, 6:09:49 PM1/31/11
to sphin...@googlegroups.com
The perl script latexmk (http://www.phys.psu.edu/~collins/software/latexmk-jcc/) runs LaTeX the 'correct' number of times on a given document. It shouldn't be too hard to get Sphinx to use it instead of running LaTeX: if latexmk is installed, then I think it should be enough to change the file texinputs/Makefile as follows:

-# The number of LaTeX runs is quite conservative, but I don't expect it
-# to get run often, so the little extra time won't hurt.
 %.dvi: %.tex
- latex $(LATEXOPTS) '$<'
- latex $(LATEXOPTS) '$<'
- latex $(LATEXOPTS) '$<'
- -makeindex -s python.ist '$(basename $<).idx'
- latex $(LATEXOPTS) '$<'
- latex $(LATEXOPTS) '$<'
+ latexmk -dvi $(LATEXOPTS) '$<'
 
 %.pdf: %.tex
- pdflatex $(LATEXOPTS) '$<'
- pdflatex $(LATEXOPTS) '$<'
- pdflatex $(LATEXOPTS) '$<'
- -makeindex -s python.ist '$(basename $<).idx'
- pdflatex $(LATEXOPTS) '$<'
- pdflatex $(LATEXOPTS) '$<'
+ latexmk -pdf $(LATEXOPTS) '$<'

Would this be a good idea?  I suppose there would be two choices: include latexmk with Sphinx, or test for its presence in the Makefile and if present, use it.

I'm asking because in Sage, one of our Sphinx documents (generated using autodoc) is over 5000 pages long, running pdflatex on it three times instead of five (for instance) is significant.

-- 
John

Guenter Milde

unread,
Feb 1, 2011, 2:56:42 AM2/1/11
to sphin...@googlegroups.com
On 2011-01-31, John H Palmieri wrote:

> The perl script latexmk (


> http://www.phys.psu.edu/~collins/software/latexmk-jcc/) runs LaTeX the
> 'correct' number of times on a given document. It shouldn't be too hard to
> get Sphinx to use it instead of running LaTeX

I suggest using the Python package "rubber"
(https://launchpad.net/rubber) instead. This makes integration into
Sphinx easier and saves us a dependency on Perl.

There is a rubber back and to Docutils under
http://docutils.sourceforge.net/sandbox/rst2pdf-rubber/rst2pdf.py

Günter

John H Palmieri

unread,
Feb 1, 2011, 1:16:01 PM2/1/11
to sphin...@googlegroups.com
On Monday, January 31, 2011 11:56:42 PM UTC-8, Guenter Milde wrote:
On 2011-01-31, John H Palmieri wrote:

> The perl script latexmk (
> http://www.phys.psu.edu/~collins/software/latexmk-jcc/) runs LaTeX the
> 'correct' number of times on a given document. It shouldn't be too hard to
> get Sphinx to use it instead of running LaTeX

I suggest using the Python package "rubber"
(https://launchpad.net/rubber) instead. This makes integration into
Sphinx easier and saves us a dependency on Perl.


I'll take a look at rubber. I actually think it might better if Sphinx didn't include any extra scripts, but the Makefile should test to see if rubber (or latemk) is present and use it if so.  I'm very far from an expert in Makefiles, but this sort of testing shouldn't be too hard.  Here's one way which seems to work, and I would not be at all surprised if there were better ways:


TRY_LATEXMK = $(shell command -v latexmk)
%.pdf: %.tex
ifneq (,$(TRY_LATEXMK))
latexmk -pdf $(LATEXOPTS) '$<'
else
pdflatex $(LATEXOPTS) '$<'
       pdflatex $(LATEXOPTS) '$<'
pdflatex $(LATEXOPTS) '$<'
-makeindex -s python.ist '$(basename $<).idx'
pdflatex $(LATEXOPTS) '$<'
pdflatex $(LATEXOPTS) '$<'
endif

-- 
John

Reply all
Reply to author
Forward
0 new messages