Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external generates pdf file with multiple copies of the same image #1372

Closed
mocenigo opened this issue Nov 4, 2024 · 4 comments
Closed

external generates pdf file with multiple copies of the same image #1372

mocenigo opened this issue Nov 4, 2024 · 4 comments

Comments

@mocenigo
Copy link

mocenigo commented Nov 4, 2024

Brief outline of the bug

Please look at the MWE and run it.
Have a look at the externalized file "a-triangle.pdf".
Then delete "a-triangle.pdf" and change the align environment to equation.

In the first case there are two copies of the same file.
In the second case there is only one.

It seems that if there are more instances of \tikzsetnextfilename in a document with the same output name, the outputs are re-run and written to the same file. align needs to run its contents twice while equation does not.

This is a variation of what is discussed here: https://tex.stackexchange.com/questions/668448/tikz-externalize-creating-pdf-with-repeated-images

In my opinion this is a bug, since the TikZ picture is not supposed to change during re-runs. Alternatively, I could use a workaround: how can I tell tikz to generate only one copy of the triangle in the externalised output and reuse it immediately?

Minimal working example (MWE)

\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}

\usetikzlibrary{external}
\tikzexternalize[prefix=./]

\begin{document}

\begin{align}
   \tikzsetnextfilename{a-triangle}
   \scalebox{0.5667}{%
    \begin{tikzpicture}
    \draw (0,0) -- (1,0) -- (0,1) -- cycle;
    \end{tikzpicture}}
\end{align}

\end{document}
@muzimuzhi
Copy link
Member

I guess the cause here is that the amsmath environment align gets typeset twice, see texdoc amsmath.pdf (v2.17s, 2024/10/30), p.48 in sec. 17.2 Preliminaries

\ifmeasuring@

All display environments get typeset twice—once during a “measuring” phase
and then again during a “production” phase; \ifmeasuring@ will be used to
determine which case we’re in, so we can take appropriate action.

\newif\ifmeasuring@

@hmenke hmenke added the external label Nov 4, 2024
@hmenke
Copy link
Member

hmenke commented Nov 4, 2024

The external library is currently unmaintained and it is unlikely that any bugs are going to be fixed in the future, due to the inherent defective design of the library. However, there are other third-party libraries for externalization which have learned from these past mistakes and which seem to be quite usable:

Both are included in TeX Live 2024.

@hmenke
Copy link
Member

hmenke commented Nov 4, 2024

Duplicate of #759

@hmenke hmenke marked this as a duplicate of #759 Nov 4, 2024
@hmenke hmenke closed this as completed Nov 4, 2024
@mocenigo
Copy link
Author

mocenigo commented Nov 4, 2024

The external library is currently unmaintained and it is unlikely that any bugs are going to be fixed in the future, due to the inherent defective design of the library. However, there are other third-party libraries for externalization which have learned from these past mistakes and which seem to be quite usable:

Both are included in TeX Live 2024.

Thank you.
I moved my code to memoize and it was a breeze! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants