#StackBounty: #tikz-pgf #tikz-external #externalize Tikz externalize resulting in legends with wrong style

Bounty: 50

I have an issue that has already been discussed in some form for example here and here but I have not been able to resolve it with the hints/solutions given there.

Please consider the following example:

% !TeX TS-program = pdflatex
documentclass{article}

usepackage{tikz,pgfplots,filecontents,tikzscale}
usetikzlibrary{external}
usepgfplotslibrary{external}
tikzexternalize[mode=list and make,prefix=tikz/]

begin{filecontents*}{fig1.tikz}
    begin{tikzpicture}
        begin{axis}[domain=0:2]
            addplot[red,mark=o] {sin(x)};
            label{pgf:plot1}
        end{axis}
    end{tikzpicture}
end{filecontents*}

begin{filecontents*}{fig2.tikz}
    begin{tikzpicture}
        begin{axis}[domain=0:2, legend to name=mylegend]
            addplot[blue,mark=square] {cos(x)};
            addlegendentry{cos}
            addlegendimage{/pgfplots/refstyle={pgf:plot1}}addlegendentry{sin}%
        end{axis}
    end{tikzpicture}
end{filecontents*}

begin{document}
    begin{figure}
        tikzsetnextfilename{mylegend}%
        ref{mylegend}\
        tikzsetnextfilename{fig1}%
        includegraphics{fig1.tikz}
        tikzsetnextfilename{fig2}%
        includegraphics{fig2.tikz}
    end{figure}
end{document}

To be sure that I always recompile with sufficient prior pdflatex runs, I used the following dummy script:

#!/bin/bash

function c () {
        echo "========== PDFLATEX ========="
        pdflatex -shell-escape -synctex=1 -interaction=nonstopmode "main".tex
        echo "========== END PDFLATEX ========"
}

rm tikz/*
rm main.aux
rm main.figlist
rm main.makefile
rm fig1*
rm fig2*
rm main-figure*


mkdir tikz

c
c

make -f main.makefile -j4 # to compile fig1, fig2

c
c

make -f main.makefile -j4 # to compile the legend (and for some reasons also again fig2)

c

which results for me in the results given here
enter image description here

where the legend for sin does not have the right line and marker style.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.