This question is motivated by the behavior of the tikzmark macro created by Andrew Stacey, and a recent discussion with David Carlisle on chat.
I have noticed that LaTeX code using tikzmark typically requires more than one compilation run. After the first run, a picture is drawn, but there is no indication in the LaTeX output that a second run is required. Automated tools and humans too, depend on the LaTeX output to determine whether more recompilations are necessary. David tells me it is possible to add code to a macro so that it outputs a suitable message to the LaTeX logs, saying the code needs to be rerun or similar. I use AucTeX inside emacs, and that certainly uses information from the output to determine whether LaTeX needs to be run again.
I don't know how the tikzmark macro works or how difficult it is to tell when the code needs to be rerun, but does anyone know how to add code to the tikzmark macro to make this happen?
See for example, Peter Grill's solution to How to draw arrows between parts of an equation to show the Math Distributive Property (Multiplication)?
Note: Andrew Stacey has added tikzmark to the tex-sx project on Launchpad. The repository is located at http://bazaar.launchpad.net/~tex-sx/tex-sx/development/files. The actual file is tikzmark.dtx (do tex tikzmark.dtx to generate the files). There's also tikzmark_test.tex which is the test file and which might give some hints as to how to use it.
UPDATE: For AucTeX users, note that AucTeX looks for a very specific string, as noted by Heiko. Changing
\immediate\write\@auxout{Rerun Latex tikz mark #1 changed}
to
\immediate\write\@auxout{LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.}
in David's example makes AucTeX notice, and force a rerun of LaTeX.
As regards Heiko's solution, you can find instructions about detaching hopgf.dtx from hopgf-1.0.pdf in section 4.5 of the PDF file hopgf-1.0.pdf. I could not figure out how to use Acrobat Reader to detach the file, but the alternative
pdftk hopgf-1.0.pdf unpack_files output .
works. The style file hopgf.sty is then extracted with
tex hopgf.dtx
Then just putting \usepackage{hopgf} in any example using \tikzmark, like Peter Grill's example linked to earlier in this question, will make the usual LaTeX warning
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
appear, as Heiko says. This works, because, as cyberSingularity mentioned in the comments, \tikzmark works by writing \pgfsyspdfmark to the aux file, and hopgf.sty, if I understand correctly, rewrites this macro to output this warning. This seems like a good general solution, and I hope Heiko's patches can be incorporated in PGF/TikZ.
tikzmark, but rather theremember picturefeature oftikzthat it uses. Could you add a link to sometikzmarkexamples? Probably thererunfilecheckpackage could be employed here. – cyberSingularity Nov 09 '12 at 11:04\pgfsyspdfmarks to theauxfile. Therefore normal tools for checking if theauxfile has changed are suitable for determining if another run is needed, but LaTeX itself doesn't issue any notifications about this. – cyberSingularity Nov 09 '12 at 11:10\usepackage[aux=true]{rerunfilecheck}. – cyberSingularity Nov 09 '12 at 11:13auctexisn't that smart. See this answer. Some of the other solutions to that question may work out better for you. – cyberSingularity Nov 09 '12 at 11:29rerunfilecheck, and only works withpdftexandluatexengines. Smarter tools likelatexmkcan just sense that theauxfile has changed and do not need the message in the log file to detect that, so this dependency is not needed in those cases. And it seems it doesn't help withauctexas that appears not to attempt to detect if reruns are needed by any means, even if the log issues a rerun warning. – cyberSingularity Nov 09 '12 at 11:39