pgf-tikz / pgf

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

Suggestion: raise an error if `\path` is used in `\pgfextra` without `\pgfinterruptpath` #1328

Closed user202729 closed 6 months ago

user202729 commented 6 months ago

As in the title.

Disadvantage is that it will incur an additional check i.e. runtime penalty. Advantage is that it will prevent inadvertent errors in the code which can save user/developer's time.

muzimuzhi commented 6 months ago

Or, in a more general way, execute \tikz@uninstallcommands and \tikz@installcommands at the beginning and ending of \pgfextra code, respectively? In this way, \path and other tikz commands used in \pgfextra code would take their definitions outside of tikzpicture. https://github.com/pgf-tikz/pgf/blob/12f17834c849a659b8829bbc9122bc459f585917/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex#L2558-L2566

Related to

muzimuzhi commented 6 months ago

Or, in a more general way, execute \tikz@uninstallcommands and \tikz@installcommands at the beginning and ending of \pgfextra code, respectively?

Hmm, No. The suggested way would disable (at least make it harder) use of

\pgfextra{\pgfinterruptpath \path ...; \endpgfinterruptpath}
hmenke commented 6 months ago

This would break existing documents, therefore unfortunately rejected.

user202729 commented 6 months ago

I think a document that issues \path without \pgfinterruptpath is buggy and should be fixed anyway.

Adding Tikz node in pgfextra triggers double drawing of containing path - TeX - LaTeX Stack Exchange (not exactly the same issue but related)

That said, we can just make it a warning. I see no harm (cf. pgfplots run in stable mode by default, but upgrading pgfplots may make the document issue an extra warning)