I've made a new version of latexmk, which supports -aux-directory
and -output-directory
. It's v. 4.27a and can be found at
http://www.phys.psu.edu/~collins/latexmk/versions.html
This version will be submitted to CTAN fairly soon, but some feedback would be useful, since I have not tested the new features extensively, especially as I don't have current access to MiKTeX or a more recent one can be found on CTAN as well.
Latexmk now has options -auxdir
, -aux-directory
, -outdir
, and -out-directory
, plus corresponding configuration variables $aux_dir
and $out_dir
. See the documentation for more details. To achieve what the original poster wanted, it's sufficient to put
$aux_dir = 'C:/Users/doncherry/Documents/LaTeX/AUXI_global';
in a latexmkrc file. (I've used forward slashes in directory names since these are acceptable to MS-Windows, and avoid running afoul of quoting conventions.)
I've done some tests with the -output-directory
option, and the only problem that needs sorting out is that the combination of biblatex with bibtex doesn't work because a file needed by bibtex isn't in its usual place. (Biblatex with biber works, as do ordinary uses of bibtex.) If you don't use biblatex, the last issue doesn't affect you.
You can make either solution work:
With your first solution (with the internal subroutine to run lhsTeX
and pdflatex
), arrange to add a line to the .fls
file to inform latexmk
that the .lhs
file is an effective source file for running pdflatex
. A suitable .latexmkrc
file is
# Use subroutine to do preprocessing and running pdflatex
$pdflatex = 'internal mylatex %B %O';
sub mylatex {
my $base = shift @_;
my $tex = "$base.tex";
# Run the preprocessor
system('lhs2TeX', '--poly', '-o', $tex, "$base.lhs") == 0 or return $?;
# Run pdflatex
my $return = system('pdflatex', @_, $tex);
system "echo INPUT $base.lhs >> $aux_dir1$base.fls";
return $return;
}
I would also delete the line putting tex
in @generated_exts
. The .tex
file is too important to latexmk
for it to be useful to treat the .tex
file as generated.
With the custom dependency solution:
- In the
.latexmkrc
file, remove the line setting $cleanup_includes_cusdep_generated
. This is important. For creation of the custom dependency rule, the output file of the custom dependency needs to exist, so that latexmk
knows that there is something to make. So removing the .tex
file prevents latexmk
from discovering the need for a custom dependency.
- Before your first run, apply
lhs2TeX
manually to create the .tex
file. This primes the process of latexmk
detecting the dependency between the .lhs
and .tex
files.
Better solutions can be made, but the ones I can think of need use of latexmk
internals or modifications to latexmk
.
Best Answer
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:(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: