Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In the manual of latexmk I read that

[latexmk] can also, if needed, call an external program to do other postprocessing on the generated files.

How can I call qpdf with latexmk? I want to do qpdf --linearize on the file that latexmk is operating on. Preferably latexmk will call qpdf only when it is called with a specific flag such as -l.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

The possibility of postprocessing mentioned in the latexmk documentation is only for dvi and postscript files. (See the description of the -dF and -pF options, and of the configuration variables $dvi_filter and $ps_filter.) I need to correct the documentation on this point. I could improve latexmk to also do this for pdf files.

But there is a simpler and more general method. Just define the $pdflatex command to include the invocation of qpdf. For example, you could put the following in one of latexmk's initialization files:

$pdflatex = 'pdflatex %O %S && qpdf -linearize %D tmp.pdf && mv tmp.pdf %D';

(This is in a form suitable for Unix-like operating systems, it will need to be changed for MS-Windows, probably.) When latexmk uses this, it executes the pdflatex command; if successful it invokes qpdf, putting the result in a temporary file; if that is successful the temporary file is moved to replace the originally generated pdf file.

I don't have qpdf installed on my computer, so I am working from its documentation to write a suitable invocation of it.

If you want a command line option to control the use of qpdf, put the above line in its own file, e.g., useqpdf. Then you can invoke latexmk to read this file when needed:

latexmk -r useqpdf foo.tex
share|improve this answer
    
I tested both the approach of changing $pdflatex in a configuration file and invoking a file via the -r option and both work as expected. It would be more elegant if it was possible to configure options for an arbitrary flag in the configuration file instead of having to remember the correct path for the -r flag. (Of course this could be fixed with shell hacks.) –  N.N. Jan 24 '12 at 18:09
    
The problem with this approach is that you run the postprocessing as many times as you run pdflatex. It would be nice to be able to apply it only to the final .pdf, after the citations and references are resolved. –  T. Verron Apr 15 at 13:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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