0

I'm trying to build my main.tex that includes a standalone pic.pdf. Special is, that pic.pdf needs to be built by latexmk (via the -use-make flag) while actually building main.tex.

The problem appears to be, that the latexmk invocation for main.tex stops after building pic.pdf through make. Log output states due to errors, though pic.pdf was built fine before.

Here is my 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}

To reproduce the problem, run

make clean && make

This stops with an error after building main.pdf and pic.pdf, but should actually just re-build main.pdf once again and everything should be fine.

Question: How can I configure latexmk to re-try building main.pdf after its requirement pic.pdf has (successfully) been generated?

For the reference, here my log output (manually shortened; omitted stuff indicated via [...]):

[...]
------------
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

In case of interest, I'm using the following versions of contributing components:

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
0

The problem seems to be that latexmk thinks the error

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

is non recoverable. To bypass that, we can include pic.pdf iff it exists and print a warning for latexmk otherwise. More precisely, after changing the main.tex in the MWE to:

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

the problem is resolved: make clean && make finishes without errors after building main.pdf twice. In the first round, the file doesn't yet exist, but we still compile fine and only print a message on the missing file.

(In the real world you will probably define a new command that handles the \IfFileExists.)

Idea taken from this related question on \input (instead of \includegraphics). All credit to @JohnCollins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.