使用 latexmk 和 -use-make 生成独立图形

使用 latexmk 和 -use-make 生成独立图形

我正在尝试构建main.tex包含独立 的pic.pdf。特别的是,需要在实际构建 时通过(通过标志)pic.pdf构建。latexmk-use-makemain.tex

问题似乎是,通过 make构建后,latexmk调用停止。日志输出状态由于错误,尽管之前构建得很好。main.texpic.pdfpic.pdf

这是我的 MWE:


Makefile

main.pdf: main.tex
    latexmk -interaction=nonstopmode -pdf -use-make -M -MP -MF $(@:.pdf=.d) $<

pic.pdf: pic.tex
    latexmk -interaction=nonstopmode -pdf -M -MP -MF $(@:.pdf=.d) $<

-include main.d
-include pic.d

clean:
    find . -not -name "*.tex" -not -name Makefile -delete

main.tex

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]\includegraphics{pic.pdf}\end{figure}
\end{document}

pic.tex

\documentclass[crop]{standalone}
\usepackage{tikz}
\begin{document}
 \tikz \fill [orange] (0,0) rectangle (6,2);
\end{document}

要重现该问题,请运行

make clean && make

main.pdf在构建和之后,这会因错误而停止pic.pdf,但实际上应该再次重新构建main.pdf,一切都会好起来。

问题:在生成其要求(成功)后,如何配置latexmk以重新尝试构建?main.pdfpic.pdf

作为参考,这里是我的日志输出(手动缩短;省略了通过指示的内容[...]):

[...]
------------
Running 'pdflatex  -interaction=nonstopmode -recorder  "main.tex"'
------------
Latexmk: applying rule 'pdflatex'...
[...]
LaTeX Warning: File `pic.pdf' not found on input line 5.
! Package pdftex.def Error: File `pic.pdf' not found.
[...]
l.5  \includegraphics{pic.pdf}
[...]
===========Latexmk: Missing input file: 'pic.pdf' from line
  'LaTeX Warning: File `pic.pdf' not found on input line 5.'
Latexmk: Missing input file: 'pic.pdf' from line
  'LaTeX Warning: File `pic.pdf' not found on input line 5.'
Latexmk: Log file says output to 'main.pdf'
------------
Running 'make "pic.pdf"'
------------
=== TeX engine is 'pdfTeX'
Latexmk: 'pdflatex': source file 'pic.pdf' doesn't exist. I'll try making it...
make[1]: Entering directory '...'
[...]
------------
Running 'pdflatex  -interaction=nonstopmode -recorder  "pic.tex"'
------------
Latexmk: applying rule 'pdflatex'...
Output written on pic.pdf (1 page, 1116 bytes).
[...] (no errors, everything fine)
Transcript written on pic.log.
Latexmk: Log file says output to 'pic.pdf'
=== TeX engine is 'pdfTeX'
Latexmk: All targets (pic.pdf) are up-to-date
make[1]: Leaving directory '...'
Collected error summary (may duplicate other messages):
  pdflatex: Command for 'pdflatex' gave return code 1
      Refer to 'main.log' for details
Latexmk: Use the -f option to force complete processing,
 unless error was exceeding maximum runs of latex/pdflatex.
Latexmk: Errors, so I did not complete making targets
make: *** [Makefile:2: main.pdf] Error 12

如果感兴趣的话,我正在使用以下版本的贡献组件:

latexmk:  Latexmk, John Collins, 19 Jan. 2017. Version 4.52c
pdflatex: pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017/TeX Live for SUSE Linux)
make:     GNU Make 4.2.1

答案1

问题似乎是latexmk认为错误

Package pdftex.def Error: File `pic.pdf' not found.

是不可恢复的。为了绕过这一点,我们可以pic.pdf在它存在时包含它,并在其他情况下打印警告。更准确地说,在将 MWE 中latexmk的更改为:main.tex

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
 \IfFileExists{pic.pdf}{\includegraphics{pic.pdf}}{\typeout{No file pic.pdf.}}
\end{figure}
\end{document}

问题已解决:make clean && make构建两次后无错误完成main.pdf。在第一轮中,文件尚不存在,但我们仍然可以编译,并且只会在丢失的文件上打印一条消息。

(在现实世界中,您可能会定义一个处理的新命令\IfFileExists。)

想法取自这个相关问题\input而不是\includegraphics)。所有功劳都归于@JohnCollins

相关内容