-
Notifications
You must be signed in to change notification settings - Fork 111
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
pgfkeys
: Undefined .@cmd
handler check is not robust
#1131
Comments
pgfkeys
: Undefined .@cmd
handler check is pgfkeys
: Undefined .@cmd
handler check is not robust
This definition of |
The underlying problem comes from Till's original definition of pgf/generic/pgf/utilities/pgfkeys.code.tex Lines 17 to 21 in 641a883
My proposed patch is very simple. Just check diff --git a/tex/generic/pgf/utilities/pgfkeys.code.tex b/tex/generic/pgf/utilities/pgfkeys.code.tex
index c0877e22..4a3d0791 100644
--- a/tex/generic/pgf/utilities/pgfkeys.code.tex
+++ b/tex/generic/pgf/utilities/pgfkeys.code.tex
@@ -200,10 +200,10 @@
% \pgfkeysifdefined{/tikz/length}{key exists}{does not exist}
\long\def\pgfkeysifdefined#1{%
- \ifcsname pgfk@#1\endcsname
- \expandafter\pgfkeys@firstoftwo
- \else
+ \expandafter\ifx\csname pgfk@#1\endcsname\relax
\expandafter\pgfkeys@secondoftwo
+ \else
+ \expandafter\pgfkeys@firstoftwo
\fi
} With this patch you will get the expected
|
There is another, imho, more elegant option to fix this (the code is slightly slower, though): \long\def\pgfkeysifdefined#1%
{%
\expandafter
\ifx\csname\ifcsname pgfk@#1\endcsname pgfk@#1\else relax\endcsname\relax
\expandafter\pgfkeys@secondoftwo
\else
\expandafter\pgfkeys@firstoftwo
\fi
} This doesn't create a hash table entry if its unncessary. As to how I stumbled upon this: Of course by playing with code and trying different things, accidentally creating a hash table entry for an undefined macro :) |
Thanks, I'll add this to my book of tricks, but for this to actually be useful in |
As Henri mentioned, a pgf/tex/generic/pgf/utilities/pgfkeys.code.tex Lines 379 to 384 in 4cba1da
\documentclass{article}
\usepackage{pgfkeys}
% just to make things trip
% make sure its arg-spec ends with \pgfeov
\expandafter\def\csname pgfk@/foo/.@cmd\endcsname\pgfeov{}
\begin{document}
\pgfkeys{/foo} % error since no default value is specified
\pgfkeys{/foo=} % ok
\pgfkeysifdefined{/foo/.@cmd}{true}{false} % leaves "true"
\end{document} If a smarter error message is expected here, then what's needed is to check whether the arg-spec ends with |
@muzimuzhi #1132 does not check for invalid arg specs and doesn't try to. Instead it restores old behaviour as Henri pointed out already (that was changed in 2007) in a more robust way. The thing is that the PR doesn't change anything about expected or planned behaviour but it allows to correctly detect undefined keys reliably. |
@muzimuzhi The problem at hand and the fix proposed in #1132 is to remove the asymmetry between \pgfkeysgetvalue{/foo/.@cmd}\foodef
\pgfkeys{/foo} The first statement will let EDIT: This is essentially what Skillmon just said. |
Of course that's not the entire truth about the PR, it also makes changes to other usages of |
@Skillmon @hmenke The proposed change will change something. \pgfkeyslet{/bar}{\relax} % or \pgfkeys{/bar/.initial=\relax}
\pgfkeys{/bar}
With a wrongly defined For the hash table entry thing, I checked all the use of |
Brief outline of the bug
If the internal
.@cmd
-handler got defined to do nothing (or is\relax
) a stray\pgfeov
might end up in the input stream leading to aUndefined control sequence
error.Minimal working example (MWE)
Possible fix: Do
\let\pgfeov\relax
(I haven't thoroughly checked whether this might have side effects, but doubt it).The text was updated successfully, but these errors were encountered: