pgf-tikz / pgf

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

Generation of dependency files in external library does depend on content of file itself #866

Open christianlupus opened 4 years ago

christianlupus commented 4 years ago

Brief outline of the bug

The externalization library produces wrong dependency files in mode list and make.

I am not relying on the update checking mechanism using md5 as it involves a compile run of the main file to update the md5 sums. Normally, I keep it active, but while developing on the images it is much more convenient for me if I can simply call make images and all required images are rebuilt without the whole project. This is especially true for beamer presentations with overlays where not only one image but a series might be built.

Minimal working example (MWE)

The MWE consists of three files in total as I need to focus on the dependency file generation by the tikz external library.

% mwe.tex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[mode=list and make,up to date check=simple]

\newcommand{\importtikz}[1]{
    \typeout{Externalizing #1}
    \tikzpicturedependsonfile{#1} % <--- Occurrence (1) of tikzpicturedependsonfile
    \input{#1}
}

\begin{document}
\importtikz{imgb.tikz}
\end{document}

The idea here is to just import a tikz external file into the document by a self-written macro. This will do other things as well in the real world but here this is sufficient.

% imgb.tikz

% Occurrences of tikzpicturedependsonfile (2)
% \tikzpicturedependsonfile{imga.tikz}
% \tikzpicturedependsonfile{imgb.tikz}
\begin{tikzpicture}
% Occurances of tikzpicturedependsonfile (3)
% \tikzpicturedependsonfile{imga.tikz}
% \tikzpicturedependsonfile{imgb.tikz}
\draw (0,0) circle (2cm);
\end{tikzpicture}

Just some arbitrary image code. Please note that the dependency declarations are commented out for now.

Further, I need a file imga.tikz. You can simply copy the code over from imgb.tikz.

Now do the following steps

  1. Compile with pdflatex and make as is
  2. Uncomment any occurrence in (2) and recompile
  3. Recomment the occurrences in (2) and uncomment the occurrence in (3) for imgb and recompile
  4. Uncomment the occurrence in (3) for imga and recompile
  5. Recomment all occurrences in (3) and recompile

What I expect

Each time the mwe.* files are updated and the make command will build a mwe-figure0.* bundle. I am focusing now on the mwe-figure0.dep file.

  1. After the first run it should contain a line rendering mwe-figure0.pdf dependent on imgb.tikz.
  2. The same after the second (maybe doubled but ok)
  3. Also the same
  4. An additional dependency on imga.tikz
  5. The exact same result as after step 1

What I get

  1. After the first step the file mwe-figure0.dep is empty
  2. No change in the file content, it stays empty
  3. Now a dependency is added as expected
  4. The additional dependency is added
  5. The dependencies keep their state: It is still dependent on both files

You can test any combination in (3), compile it, and comment all in (3): You will always get the same dependencies as if the file was not touched at all. I cannot tell, if this is really the case or not.

Additional comments

The occurrences in (1) and (2) are somehow redundant. I just wanted to avoid that it needs to be exactly before the tikzpicture itself.

In fact, there are 2 sub concerns that I assume to be related (thus one bug report):

  1. The dependency is only taken into account if defined inside the corresponding tikzpicture. According to the manual it should also work for the next picture.
  2. If no dependencies are explicitly specified, the dep file is not altered at all.
hmenke commented 4 years ago

I'm pretty sure that the generation of the dependency files is deterministic. It's just wrong.

christianlupus commented 4 years ago

Yeah, I should have written appears non-deterministic to the user without further research. I was first a bit stunned as I assumed the file content would only depend on the TeX file but not the state of the dep file itself.

hmenke commented 4 years ago

It also doesn't “appear non-deterministic” to the user. Non-determinism has an entirely different meaning.