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

Document brace stripping in pgfkeys #912

Closed
hmenke opened this issue Aug 27, 2020 · 2 comments
Closed

Document brace stripping in pgfkeys #912

hmenke opened this issue Aug 27, 2020 · 2 comments

Comments

@hmenke
Copy link
Member

hmenke commented Aug 27, 2020

Version: 3.1.5b

pgfkeys will strip braces around single arguments, e.g.

\pgfset{
  /test/foo/.code=bar,
  /test/.style n args={1}{/test/.cd,#1},
  /test={foo},
}

will result in

! Package pgfkeys Error: I do not know the key '/test/f' and I am going to igno
re it. Perhaps you misspelled it.

This is totally expected when you know that /.style handlers are implemented in terms of /.code handlers and usual TeX argument brace stripping applies. However, this is not mentioned clearly in the manual.

@hmenke hmenke added the manual label Aug 27, 2020
@hmenke hmenke added this to the 3.1.6 milestone Aug 27, 2020
@muzimuzhi
Copy link
Member

With current implementation, to successfully pass foo to key /test, one has to use four extra pair of braces \pgfkeys{/test={{{{foo}}}}}, which is rather inconvenient.

Since this only happens to keys defined by <key>/.style n args={1}{...} (although this kind of usage is fully avoidable), how about specially treat #2 == 1 in definition of \pgfkeysdefnargs@? For example,

diff --git a/tex/generic/pgf/utilities/pgfkeys.code.tex b/tex/generic/pgf/utilities/pgfkeys.code.tex
index f2288175..6d1027db 100644
--- a/tex/generic/pgf/utilities/pgfkeys.code.tex
+++ b/tex/generic/pgf/utilities/pgfkeys.code.tex
@@ -717,7 +717,11 @@
   % (with expansion of '#1'):
   \edef\pgfkeys@tempargs{\noexpand\pgfkeysvalueof{#1/.@@body}}%
   \def\pgfkeys@temp{\pgfkeysdef{#1}}%
-  \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
+  \ifnum#2=1\relax
+    \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs{##1}}%
+  \else
+    \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
+  \fi
   #5{#1/.@body}{#3}%
 }

PS: In your example, it seems \pgfset should be \pgfkeys.

@hmenke
Copy link
Member Author

hmenke commented Aug 29, 2020

That's a good idea. Can you submit that as a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants