1

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:

  1. latexmk notices the missing file in the document.
  2. latexmk runs the corresponding custom rule. This rule generates a target file tmp/demofiles.tex from the source file ./demofile.texprototype.
  3. latexmk cannot verify, that the target for the source has been made, because it has no way of knowing where to look.
  4. In subsequent runs for pdflatex rule, the file ./tmp/demofile.tex is found and inputted, however since I set add_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.
marc
  • 701
  • @DavidCarlisle From my (limited) experience you are right. Using the $aux_dir variable 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
  • That said, I am fine with restricting the output below $aux_dir to 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

2 Answers2

3

In the current version (and previous versions) of latexmk, it is required that the output and input files of a custom dependency are in the same directory. So what you ask for isn't supported, i.e., to put the output files of custom dependencies in the aux directory.

In principle, it would be a good idea to support this possibility. But there would be some non-trivial backward compatibility issues to sort out.

John Collins
  • 11,183
  • 3
  • 32
  • 33
  • Thank you, although this is not the answer I wanted to hear. At least I know I can stop looking for now or move from a dependency to manually generate the files in the desired location using regular subroutine calls. – marc Jul 10 '23 at 09:37
1

One option that I find simpler is to use latexmk -outdir=aux and then use a Makefile to copy the output file to a build directory. Then your temporary/auxiliary files will be in aux/ and the PDF will be in build/. To run, just type make or make pdf. To reset, make clean.

Makefile

dirs = aux build
tex_in = $(wildcard *.tex)
tex_out = $(addprefix build/,$(tex_in:%.tex=%.pdf))

.PHONY : all clean

all : $(tex_out)

build/%.pdf : aux/%.pdf cp -u $< $@

aux/%.pdf : %.tex | $(dirs) latexmk -outdir=aux -pdf $<

$(dirs) : mkdir -p $(dirs)

clean : rm -rf $(dirs)

musarithmia
  • 12,463
  • Thank you for the comment and suggestion, but I specifically asked for latexmk. Your makefile suggestion provides a valuable alternative and has me reconsider my LaTeX toolchain choices, however it is not the answer to the question I posed. – marc Jul 10 '23 at 09:40