我正在使用中的自定义依赖项latexmk
,但我希望将输出文件分别放在和$aux_dir
中$out_dir
。
我成功地完成了此操作,但latexmk
退出时控制台输出如下:
------------
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
一些行已被删除,但基本行如下:
Latexmk: In running custom-dependency rule
to make 'demofile.tex' from 'demofile.texprototype'
function 'texit' did not make the destination.
即使我相信我明白发生了什么,这个输出仍然很令人恼火:
latexmk
注意到文档中缺少文件。latexmk
运行相应的自定义规则。此规则tmp/demofiles.tex
从源文件生成目标文件./demofile.texprototype
。latexmk
无法验证源的目标是否已经生成,因为无法知道在哪里查找。- 在随后的规则运行中,找到并输入了
pdflatex
该文件,但是由于我设置了,所以记录了一个错误,然后在最后显示该错误。./tmp/demofile.tex
add_cus_dep('texprototype', 'tex', **1**, 'texit');
平均能量损失
.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}
问题
我可以制定自定义规则来latexmk
识别路径以构建目标,从而充分利用$aux_dir
和$output_dir
变量吗?
评论
答案1
在 latexmk 的当前版本(以及以前的版本)中,要求自定义依赖项的输出和输入文件位于同一目录中。因此,您要求的操作不受支持,即将自定义依赖项的输出文件放在 aux 目录中。
原则上,支持这种可能性是个好主意。但需要解决一些重要的向后兼容性问题。
答案2
我发现一个更简单的选项是使用latexmk -outdir=aux
,然后使用 Makefile 将输出文件复制到构建目录。然后您的临时/辅助文件将位于 中aux/
,PDF 将位于 中build/
。要运行,只需键入make
或make pdf
。要重置,请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)