1

The following mwe does produce an invalid makefile when used with latexmk's -output-directory option. (The example is from the pgfplots manual)

latexmk mwe.tex -output-directory=build

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize[mode=list and make]

\begin{document}

\input{tikz/figure.tikz}

\end{document}

and a file under tikz/figure.tikz

\begin{figure}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{Our first external graphics example}
\end{figure}

with the makefile beeing at build/mwe.makefile

ALL_FIGURE_NAMES=$(shell cat mwe.figlist)
ALL_FIGURES=$(ALL_FIGURE_NAMES:%=%.pdf)

allimages: $(ALL_FIGURES)
    @echo All images exist now. Use make -B to re-generate them.

FORCEREMAKE:

include $(ALL_FIGURE_NAMES:%=%.dep)

%.dep:
    mkdir -p "$(dir $@)"
    touch "$@" # will be filled later.

mwe-figure0.pdf: 
    pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "mwe-figure0" "\def\tikzexternalrealjob{mwe}\input{mwe}"

mwe-figure0.pdf: mwe-figure0.md5

as the mwe.tex file is not in the build directory, running the make command from the build directory will not work; also running it from the projcts "root" directory will not work, as there is no mwe.figlist there.

1 Answer 1

0

This solution is a dirty hack, so I will not accept it, hoping for someone to provide a better answer.

A current workaround I have is modifying the commands used to create the makefile; this idea is from here and modify the commands including moving up a directory cd .. && and setting the output-directory --output-directory=./build as follows:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize[mode=list and make]

\tikzset{%
    external/system call={cd .. && pdflatex \tikzexternalcheckshellescape --halt-on-error --interaction=batchmode --output-directory=./build --jobname "\image" "\texsource"},
    /pgf/images/include external/.code={%
        \includegraphics{build/#1}%
    },
}
\begin{document}

\input{tikz/figure.tikz}

\end{document}

generating the new makefile


ALL_FIGURE_NAMES=$(shell cat mwe.figlist)
ALL_FIGURES=$(ALL_FIGURE_NAMES:%=%.pdf)

allimages: $(ALL_FIGURES)
        @echo All images exist now. Use make -B to re-generate them.

FORCEREMAKE:

include $(ALL_FIGURE_NAMES:%=%.dep)

%.dep:
        mkdir -p "$(dir $@)"
        touch "$@" # will be filled later.

mwe-figure0.pdf: 
        cd .. && pdflatex -shell-escape --halt-on-error --interaction=batchmode --output-directory=./build --jobname "mwe-figure0" "\def\tikzexternalrealjob{mwe}\input{mwe}"

mwe-figure0.pdf: mwe-figure0.md5

which now can be built from the build directory with make -f mwe.makefile.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .