I want to preprocess an input file before compiling it with, say, pdflatex.
I found one way to do this using the "internal" specification described in the latexmk manual, but I expected there to be a simpler and more flexible way using custom dependencies.
I'm using the preprocessor lhs2TeX (version 1.18.1) with the file extension .lhs
. My latexmk version is 4.37 (2 July 2013).
The "internal" way
A document input.lhs
:
\documentclass{article}
%include polycode.fmt
\begin{document}
Hello, |world|! % The | and | are used by lhs2TeX.
\end{document}
The .latexmkrc
:
push @generated_exts, 'tex'; # Remove generated .tex on clean-up
# 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
return system('pdflatex', @_, $tex);
}
At the command line:
$ latexmk -silent -pdf input.lhs
Latexmk: Run number 1 of rule 'pdflatex'
Latexmk: calling mylatex( input -interaction=batchmode -recorder )
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
restricted \write18 enabled.
entering extended mode
This successfully produces an appropriate input.pdf
. But it also required me to hardcode pdflatex
.
A failed attempt using custom dependencies
The .latexmkrc
:
$cleanup_includes_cusdep_generated = 1; # Remove generated .tex on clean-up
# Set preprocessor as a custom dependency
add_cus_dep('lhs', 'tex', 1, 'run_lhs2TeX');
sub run_lhs2TeX {
my $base = shift @_;
# Run the preprocessor
return system('lhs2TeX', '--poly', '-o', "$base.tex", "$base.lhs");
}
The rule created here never fires. I'm guessing this doesn't work because latexmk doesn't use dependencies for the initial inputs, only for files included within other files (e.g. via \input
).
Conclusion
Is there a simple way, possibly similar to the above custom dependency attempt, to configure latexmk to use a preprocessor? It shouldn't require hardcoding the compiler. (I could do this with a Makefile, but if I'm using latexmk anyway, then I would prefer to do everything with latexmk.)