-
Notifications
You must be signed in to change notification settings - Fork 109
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
Handler config 'full or existing' can set non-existent keys when '.search also' is in effect. #1143
Comments
My first idea to fix this is the following. I'm not sure whether it is viable, because I imagine it could lead to searching the search paths multiple times (maybe even I think I'll just try to compile the pgfmanual with this and see where it goes.
|
Okay, so I compiled both the pgf manual and the pgfplots manual (which makes heavier use of Findings:
However, this does not guarantee that there is not some legacy code out there that would not break if this is changed. Especially the fact that setting On the other hand, EDIT: Also, my fears of quadratic run time were not confirmed, at least in the MWE above, because |
Make .expand* handlers use relative paths if the original path was relative. Fixes pgf-tikz#1143
In case anyone needs it, here is a (hopefully robust) approach which applies the fix proposed above, but only if it can reproduce the behavior of the bug. It will complain with a warning if something goes wrong. % This file enables a hotfix for https://github.com/pgf-tikz/pgf/issues/1143,
% but only if the bug can be reproduced. To use it, save this file as
% pgfkeys-fix1143.sty somewhere where LaTeX can find it (e.g. current folder).
% Then write \usepackage{pgfkeys-fix1143} somewhere in your preamble.
\RequirePackage{pgfkeys}
\def\pgfkeys@HotfixForSearchAlsoReproduceBug{%
\begingroup% Keep all side effects of checking local to this group
\pgfkeys{
/handler config=full or existing,
/other path/.unknown/.code={\gdef\pgfkeys@HotfixForSearchAlsoFixed{}},
/test path/.unknown/.code={\gdef\pgfkeys@HotfixForSearchAlsoFixed{}},
/test path/.search also={/other path},
/test path/.cd,
non existent key/.style={},% If the bug is fixed, this should trigger one of the .unknown handlers
}%
\endgroup% End of hotfix group
}%
\pgfkeys@HotfixForSearchAlsoReproduceBug
\ifx\pgfkeys@HotfixForSearchAlsoFixed\@undefined% If bug is not yet fixed in pgfkeys...
\long\def\pgfkeys@exp@call@old@definition#1{\pgfkeysalso{\pgfkeyscurrentpath={#1}}}% The original definition before the hotfix.
\ifx\pgfkeys@exp@call\pgfkeys@exp@call@old@definition% only apply the fix if the original definition was not modified
\PackageInfo{pgfkeys}{issues 1143 hotfix done}%
\long\def\pgfkeys@exp@call#1{% Define the fixed version of the macro (globally, to escape the current group)
\ifpgfkeysaddeddefaultpath% If the original key was a relative path, do the expanded assignment also with a relative path
\pgfkeys@pathtoks{}%
\expandafter\pgfkeys@splitter\pgfkeyscurrentkeyRAW//% Removes the /.expand* component of the original relative key.
\fi%
\pgfkeysalso{\pgfkeyscurrentpath={#1}}%
}%
\else
\PackageWarning{pgfkeys}{issue 1143 hotfix FAILED. The definition of \detokenize{\pgfkeys@exp@call} is not as expected, but the bug is still there.}%
\fi
\pgfkeys@HotfixForSearchAlsoReproduceBug% Check if bug is actually fixed after applying the fix
\ifx\pgfkeys@HotfixForSearchAlsoFixed\@undefined% bug is still not fixed, something went wrong!
\PackageWarning{pgfkeys}{issue 1143 hotfix did not work.}%
\else
\PackageInfo{pgfkeys}{issue 1143 hotfix works}%
\fi
\else
\PackageInfo{pgfkeys}{issue 1143 fixed, skipping hotfix}%
\fi |
Brief outline of the bug
With
/handler config=full or existing
, an assignment likekey/.style={stuff}
should only set the style ifkey
exists in the current path or somewhere in the search paths set with.search also
. However, when one or more paths are passed to.search also
, andkey
does not exist in the current path,key/.style={stuff}
will always be executed it in the first search path, regardless of whether it exists there or not. It will never fail, like it should when the key on which the handler is called does not exist.In the example below, the first case (with color=green) appears to work. The style
every foo
is set in/main path
, because the style did not exist in/second path
. However, in the second example you can see it fail:every foo
is set in/third path
although it did not exist there before, despite the handler config.Cause of the bug
If you look at the log file, you can see the cause of the issue (thanks to the patched commands):
.search also
executes\pgfqkeys{/third path}{every foo/.style/.try/.expand once=value}
(defined in\pgfkeys@searchalso@appendentry
).\pgfkeys@add@path@as@needed
prepends/third path
and sets\ifpgfkeysaddeddefaultpath=\iftrue
(in\pgfkeys@addpath
).\pgfkeys@ifexecutehandler@handlefullorexisting
executes.expand once
because it exempt from/handler config
..expand once
executes\pgfkeysalso{/third path/every foo/.style/.try=value}
.\pgfkeysalso
calls\pgfkeys@add@path@as@needed
, which sees an absolute path and sets\ifpgfkeysaddeddefaultpath=\iffalse
(in\pgfkeys@nevermind
)..try
calls\pgfkeys@ifexecutehandler@handlefullorexisting
with\pgfkeyscurrentpath=/third path/every foo/.style
, which succeeds because\ifpgfkeysaddeddefaultpath
is false.Log file excerpt:
Minimal working example (MWE)
The text was updated successfully, but these errors were encountered: