I am working with custom dependencies in latexmk, but I want the output files to be placed in $aux_dir and $out_dir, respectively.
I managed to do this sucessfully, but latexmk exits with the following console output:
------------
Run number 1 of rule 'cusdep texprototype tex demofile'
------------
Latexmk: In running custom-dependency rule
to make 'demofile.tex' from 'demofile.texprototype'
function 'texit' did not make the destination.
Latexmk: Some rule(s) failed, but user file(s) changed so keep trying
...
Latexmk: Moving 'tmp/mwe.pdf' to 'build/mwe.pdf'
Latexmk: Moving 'tmp/mwe.synctex.gz' to 'build/mwe.synctex.gz'
Latexmk: Getting log file 'tmp/mwe.log'
Latexmk: Examining 'tmp/mwe.fls'
Latexmk: Examining 'tmp/mwe.log'
Latexmk: Log file says output to 'tmp/mwe.pdf'
Latexmk: All targets () are up-to-date
Collected error summary (may duplicate other messages):
cusdep texprototype tex demofile: Command for 'cusdep texprototype tex demofile' gave return code -1
Some lines have been stripped away, but the essential lines are these:
Latexmk: In running custom-dependency rule
to make 'demofile.tex' from 'demofile.texprototype'
function 'texit' did not make the destination.
This output is quite irritating, even if I believe I understand what is going on:
latexmknotices the missing file in the document.latexmkruns the corresponding custom rule. This rule generates a target filetmp/demofiles.texfrom the source file./demofile.texprototype.latexmkcannot verify, that the target for the source has been made, because it has no way of knowing where to look.- In subsequent runs for
pdflatexrule, the file./tmp/demofile.texis found and inputted, however since I setadd_cus_dep('texprototype', 'tex', **1**, 'texit');, an error is logged, which is then displayed at the end.
MWE
.latexmkrc
# Set the program used to generate the PDF
# 1: pdflatex
# 2: postscript conversion, don't use this
# 3: dvi conversion, don't use this
# 4: lualatex
# 5: xelatex
$pdf_mode = 1;
Move all axuiliary files to a separate directory, so they do not clutter up the project directory
$emulate_aux = 1;
$aux_dir = "tmp";
Move the compiled files (and synctex) to a separate directory
$out_dir = 'build';
Add custom dependency.
latexmk checks whether a file with ending as given in the 2nd
argument exists ('toextension'). If yes, check if file with
ending as in first argument ('fromextension') exists. If yes,
run subroutine as given in fourth argument.
Third argument is whether file MUST exist. If 0, no action taken.
add_cus_dep('texprototype', 'tex', 1, "texit");
show custom dependencies for debugging
show_cus_dep();
set_tex_cmds("--shell-escape -interaction=batchmode -synctex=1 ");
custom sub handling the loading of the preamble and dumping it into $base.fmt
sub texit {
my ( $base) = @_;
# create the missing tex file
$ret = system ("echo \"This is the demo file content.\" > $aux_dir1$base.tex");
# if there were errors, return the error codes
if ($ret) { return $ret; }
}
mwe.tex
\documentclass{scrbook}
\begin{document}
\title{Toil and Trouble}
\subtitle{with latexmk and \textit{$aux_dir}}
\subject{Case Studies}
\date{\today}
\maketitle{}
\input{demofile.tex}
\end{document}
Question
Can I make my custom rules of latexmk recognize paths to build targets to fully make use of the $aux_dir and $output_dir variables?
Comment
- This is a follow-up question to my previous question and answer. In theory, I want to solve the dependency and path problem for the setup in this other question, but I felt it would be more suitable to split it into its own problem, which can be investigated and solved individually.
$aux_dirvariable is a major hassle, regarding a lot of tools I use, e.g. gnuplot, pgfplotstable, externalize, or just plain pdflatex in this case. However, I am a firm believer of separation between artifacts and source, so I think it is natural to desire the same for latex projects. Collegues have handed over abysmal projects to me, with a lot of files where I now have to decide whether they belong to the project or are artifacts. I want to try out separation and make it work. – marc Jul 07 '23 at 09:35$aux_dirto the same directory structure as in the source files, but I am not pleased if the artifacts are required to reside alongside the source. – marc Jul 07 '23 at 09:38