diff --git a/doc/generic/pgf/CHANGELOG.md b/doc/generic/pgf/CHANGELOG.md index 5b4cff84c..bbffe35d4 100644 --- a/doc/generic/pgf/CHANGELOG.md +++ b/doc/generic/pgf/CHANGELOG.md @@ -81,6 +81,8 @@ lot of contributed changes. Thanks to everyone who volunteered their time! - Make `graphdrawing` work with `name prefix` and `name suffix` options #1087 - pgfkeys was a bit too relaxed around `\relax` #1132 - Remove spurious spaces for `3d view` #1151 +- Add shortcuts defined by `\tikzaddtikzonlycommandshortcut(def|let)` to + uninstallcommands #1160 ### Changed diff --git a/testfiles/gh-pull-1160.lvt b/testfiles/gh-pull-1160.lvt new file mode 100644 index 000000000..9845cbaa5 --- /dev/null +++ b/testfiles/gh-pull-1160.lvt @@ -0,0 +1,79 @@ +\documentclass{minimal} +\input{pgf-regression-test} + +\RequirePackage{tikz} + +\begin{document} + +\START + +\def\myspecialsauce{\node{specialsauce}} +\let\UNDEFINED\undefined + +\def\AssertInner{\AssertEquals\specialsauce\specialsauceINNER} +\def\AssertOuter{\AssertEquals\specialsauce\specialsauceOUTER} + +\def\test{% + \AssertOuter + \begin{tikzpicture} + \AssertInner + \specialsauce; + \node at (0,1) + {\AssertOuter \tikz {\AssertInner\node {\AssertOuter};} \AssertOuter}; + \tikz {\AssertInner \node {\AssertOuter};} + \end{tikzpicture} + \AssertOuter +} + +% shortcut is \specialsauce +\BEGINTEST{shortcutlet, shortcut undefined ouside} + \let\specialsauceINNER=\myspecialsauce + \tikzaddtikzonlycommandshortcutlet{\specialsauce}{\myspecialsauce} + + \test +\ENDTEST + +\BEGINTEST{shortcutlet, shortcut defined outside before doing shortcutlet} + \let\specialsauceINNER=\myspecialsauce + \def\specialsauceOUTER{outer definition} + \let\specialsauce\specialsauceOUTER + \tikzaddtikzonlycommandshortcutlet{\specialsauce}{\myspecialsauce} + + \test +\ENDTEST + +\BEGINTEST{shortcutlet, shortcut defined outside after doing shortcutlet} + \let\specialsauceINNER=\myspecialsauce + \def\specialsauceOUTER{outer definition} + \tikzaddtikzonlycommandshortcutlet{\specialsauce}{\myspecialsauce} + \let\specialsauce\specialsauceOUTER + + \test +\ENDTEST + +\BEGINTEST{shortcutdef, shortcut undefined outside} + \def\specialsauceINNER{\myspecialsauce} + \tikzaddtikzonlycommandshortcutdef{\specialsauce}{\myspecialsauce} + + \test +\ENDTEST + +\BEGINTEST{shortcutdef, shortcut defined outside before doing shortcutdef} + \def\specialsauceINNER{\myspecialsauce} + \def\specialsauceOUTER{outer definition} + \let\specialsauce\specialsauceOUTER + \tikzaddtikzonlycommandshortcutdef{\specialsauce}{\myspecialsauce} + + \test +\ENDTEST + +\BEGINTEST{shortcutdef, shortcut defined outside after doing shortcutdef} + \def\specialsauceINNER{\myspecialsauce} + \def\specialsauceOUTER{outer definition} + \tikzaddtikzonlycommandshortcutdef{\specialsauce}{\myspecialsauce} + \let\specialsauce\specialsauceOUTER + + \test +\ENDTEST + +\END diff --git a/testfiles/gh-pull-1160.tlg b/testfiles/gh-pull-1160.tlg new file mode 100644 index 000000000..c5b673cf9 --- /dev/null +++ b/testfiles/gh-pull-1160.tlg @@ -0,0 +1,80 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +============================================================ +TEST 1: shortcutlet, shortcut undefined ouside +============================================================ +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +============================================================ +============================================================ +TEST 2: shortcutlet, shortcut defined outside before doing shortcutlet +============================================================ +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +============================================================ +============================================================ +TEST 3: shortcutlet, shortcut defined outside after doing shortcutlet +============================================================ +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +============================================================ +============================================================ +TEST 4: shortcutdef, shortcut undefined outside +============================================================ +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +============================================================ +============================================================ +TEST 5: shortcutdef, shortcut defined outside before doing shortcutdef +============================================================ +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +============================================================ +============================================================ +TEST 6: shortcutdef, shortcut defined outside after doing shortcutdef +============================================================ +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +PASSED +============================================================ diff --git a/testfiles/support/pgf-regression-test.tex b/testfiles/support/pgf-regression-test.tex index 9b2aa9573..8df928f9a 100644 --- a/testfiles/support/pgf-regression-test.tex +++ b/testfiles/support/pgf-regression-test.tex @@ -38,4 +38,22 @@ \ENDTEST } +% more typeout commands +\def\PASSED {\TYPE{PASSED}} +\def\FAILED {\TYPE{FAILED}} +\long\def\FAILEDAT#1{\TYPE{FAILED at #1}} + +% more assert commands, which if fails will typeout more diagnostic info +\protected\long\def\AssertEquals#1#2{% + \ifx#1#2% + \PASSED + \else + \FAILEDAT{\string\AssertEquals\detokenize{{#1}{#2}}}% + \TYPE{% + - Expected: \meaning#1^^J% + - Actual: \space\space \meaning#2% + }% + \fi +} + \TIMO diff --git a/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex b/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex index 9b76858b3..dc0889ed3 100644 --- a/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex +++ b/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex @@ -1727,7 +1727,11 @@ \let\tikz@atend@picture=\pgfutil@empty% \let\tikz@transform=\relax% \def\tikz@time{.5}% - \tikz@installcommands% + \iftikz@inside@picture + \else + \tikz@installcommands% + \tikz@inside@picturetrue + \fi \scope[every picture,#1]% \iftikz@handle@active@code% \tikz@switchoff@shorthands% @@ -1899,17 +1903,41 @@ % #1: shortcut command inside of tikzpicture % #2: real command name \def\tikzaddtikzonlycommandshortcutlet#1#2{% - \expandafter\def\expandafter\tikz@installcommands\expandafter{\tikz@installcommands - \let#1=#2% + \ifcsname tikz@orig\detokenize{#1}\endcsname + \let\pgfutil@tempa=\pgfutil@empty + \else + \def\pgfutil@tempa{% + \expandafter\let\csname tikz@orig\detokenize{#1}\endcsname\pgfutil@undefined + } + \fi + \edef\tikz@installcommands{\pgfutil@unexpanded\expandafter{\tikz@installcommands}% + \let\expandafter\noexpand\csname tikz@orig\detokenize{#1}\endcsname=\noexpand#1% + \pgfutil@unexpanded{\let#1=#2}% }% + \edef\tikz@uninstallcommands{\pgfutil@unexpanded\expandafter{\tikz@uninstallcommands}% + \let\noexpand#1\expandafter\noexpand\csname tikz@orig\detokenize{#1}\endcsname + }% + \pgfutil@tempa }% % Has the same effect as \tikzaddtikzonlycommandshortcutlet but uses % \def#1{#2} instead of \let. \def\tikzaddtikzonlycommandshortcutdef#1#2{% - \expandafter\def\expandafter\tikz@installcommands\expandafter{\tikz@installcommands - \def#1{#2}% + \ifcsname tikz@orig\detokenize{#1}\endcsname + \let\pgfutil@tempa=\pgfutil@empty + \else + \def\pgfutil@tempa{% + \expandafter\let\csname tikz@orig\detokenize{#1}\endcsname\pgfutil@undefined + } + \fi + \edef\tikz@installcommands{\pgfutil@unexpanded\expandafter{\tikz@installcommands}% + \let\expandafter\noexpand\csname tikz@orig\detokenize{#1}\endcsname=\noexpand#1% + \pgfutil@unexpanded{\def#1{#2}}% + }% + \edef\tikz@uninstallcommands{\pgfutil@unexpanded\expandafter{\tikz@uninstallcommands}% + \let\noexpand#1\expandafter\noexpand\csname tikz@orig\detokenize{#1}\endcsname }% + \pgfutil@tempa }% %