Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add shortcuts to uninstallcommands #1160

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/generic/pgf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
79 changes: 79 additions & 0 deletions testfiles/gh-pull-1160.lvt
Original file line number Diff line number Diff line change
@@ -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
80 changes: 80 additions & 0 deletions testfiles/gh-pull-1160.tlg
Original file line number Diff line number Diff line change
@@ -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
============================================================
18 changes: 18 additions & 0 deletions testfiles/support/pgf-regression-test.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 33 additions & 5 deletions tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand Down Expand Up @@ -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
}%

%
Expand Down