Programming TeX macros so that they output instructions to rerun the compilation

I have written a new package hopgf, where I try to collect some fixes for PGF/TikZ. Also the missing rerun warning is addressed. It is solved by using LaTeX's \@newl@bel that does the work for LaTeX's reference system. By using pgf@sys@df@mark@pos as reference class no new internal macros are needed for the reference.

If the positioning labels of PGF change, then the usual LaTeX warning is given:

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

The package is currently available as hopgf-1.0.pdf and will be put on CTAN at the next time I update my bundle. The .dtx is attachted to the PDF file and running tex (not latex) extracts the package file hopgf.sty.

Comments and other suggestions what can be added to the package are welcome. It would be even better, of course, if the fixed and features can be added upstream in PGF/TikZ.


Taking the posted example, adding the following check seems to work

\documentclass{article}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,shapes}

\makeatletter
\AtEndDocument{%
\let\oldpgfsyspdfmark\pgfsyspdfmark
\def\pgfsyspdfmark#1#2#3{%
  \expandafter\let\expandafter\tmp\csname pgf@sys@pdf@mark@pos@#1\endcsname
  \oldpgfsyspdfmark{#1}{#2}{#3}%
  \expandafter\ifx\csname pgf@sys@pdf@mark@pos@#1\endcsname\tmp\else
  \immediate\write\@auxout{Rerun Latex tikz mark #1 changed}%
  \fi
}}


\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawBox}[4]{%
  \begin{tikzpicture}[overlay,remember picture,-latex,shorten >=5pt,shorten <=5pt,out=70,in=130]
    \draw[distance=0.45cm,#1] (a.north) to (b.north);
    \draw[distance=0.65cm,#2] (a.north) to (c.north);
    \draw[distance=0.9cm, #3] (a.north) to (d.north);
    \draw[distance=1.1cm, #4] (a.north) to (e.north);
  \end{tikzpicture}
}
\begin{document}
\begin{gather*}
(\tikzmark{a}l_{1}) \vee \big( (p \vee\tikzmark{b} q) \wedge (\neg p \vee\tikzmark{c} q) \wedge (p \vee\tikzmark{d} \neg q) \wedge (\neg p \vee\tikzmark{e} \neg q)\big) \DrawBox{red}{blue}{green}{orange}\\
(l_{1} \vee p \vee q) \wedge (l_{1} \vee \neg p \vee q) \wedge (l_{1} \vee p \vee \neg q) \wedge (l_{1} \vee \neg p \vee \neg q)
\end{gather*}
\end{document}

On the first run you get

$ grep Rerun tk93.log
Rerun Latex tikz mark pgfid7 changed
Rerun Latex tikz mark pgfid8 changed
Rerun Latex tikz mark pgfid9 changed
Rerun Latex tikz mark pgfid10 changed
Rerun Latex tikz mark pgfid11 changed
Rerun Latex tikz mark pgfid12 changed

on the second run

$ grep Rerun tk93.log

If you would rather the first run just had a single message change

  \immediate\write\@auxout{Rerun Latex tikz mark #1 changed}%

to

  \let\pgfsyspdfmark\oldpgfsyspdfmark
  \immediate\write\@auxout{Rerun Latex tikz marks changed}%

so after the first warning the macro is restored to its original definition and no further checks are made.