pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.14k stars 108 forks source link

External library spawns figures inside math environment #759

Open Turgon-Aran-Gondolin opened 5 years ago

Turgon-Aran-Gondolin commented 5 years ago

I was using the following code to externalize the tikz-feynman diagrams

\usepackage{shellesc}
\usetikzlibrary{external}
\tikzexternalize[
    shell escape=-enable-write18,
    prefix=./,
    system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"},
    up to date check=md5,
]

When the diagrams are in figure environment everything works fine. But those in align environment were generated twice. So my working dir is now filled with duplicated figures. While the md5 of those duplicated figures are exactly the same, they continue to exist and the compiling effort is doubled. Is there any way to resolve this?

Mo-Gul commented 5 years ago

It would be nice if you could add a full working minimal example (MWE) which will make it much easier to see the issue and than hopefully provide a solution or fix.

Turgon-Aran-Gondolin commented 5 years ago

This should reproduce what I described:

\documentclass{article}
\usepackage{amsmath}
\usepackage[compat=1.1.0]{tikz-feynman}
\usepackage{shellesc}
\usetikzlibrary{external}
\tikzexternalize[shell escape=-enable-write18,prefix=./,system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"},up to date check=md5]

\begin{document}
\begin{align}
    \begin{tikzpicture}
        \begin{feynman}
            \node[dot] (a);
            \node[right=1 in of a,dot] (b);
            \diagram*{
                (a) -- (b);
            };
        \end{feynman}
    \end{tikzpicture}
\end{align}
\end{document}
davidcarlisle commented 5 years ago

align (like all AMS environments) evaluates its body twice, with \ifmeasuring@ being true the first time and false the second, so probably you want to avoid the external calls on the second pass.

Turgon-Aran-Gondolin commented 5 years ago

Thanks for pointing this out. Do you have a solution for this? I'm not really familiar with options of the external library and I'm not sure which one can achieve this.

Turgon-Aran-Gondolin commented 4 years ago

After updated to 3.15a, there's a new problem. If there're multiple figures in one math environment, the first one will get evaluated every single pass despite it remains unchanged.

MWE:

\RequirePackage{luatex85}
\documentclass{article}
\usepackage{amsmath}
\usepackage[compat=1.1.0]{tikz-feynman}
\usetikzlibrary{external}
\tikzexternalize[shell escape=-enable-write18,prefix=./,system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"},up to date check=diff]
\begin{document}

\begin{align}
    \feynmandiagram{
    a -- b[dot];
    };\qquad                               & \int \qquad
    \feynmandiagram{
    a[dot] -- b;
    };
\end{align}
\end{document}
Turgon-Aran-Gondolin commented 4 years ago

Also all figures inside one math environment got merged into the first figure file (one figure per page). And all except the first figure files are still generated normally.

hmenke commented 4 years ago

Okay, it looks like this has become unusable. I will revert the fix and publish a new release.