diff --git a/doc/generic/pgf/CHANGELOG.md b/doc/generic/pgf/CHANGELOG.md index 63068af68..9d6707bc9 100644 --- a/doc/generic/pgf/CHANGELOG.md +++ b/doc/generic/pgf/CHANGELOG.md @@ -57,7 +57,9 @@ lot of contributed changes. Thanks to everyone who volunteered their time! - Update Debian installation instructions - Suppress white space at line end when `datavisualization` reads from a file #1112 -- Form-only patterns have no specified color #1122 +- Form-only patterns have no specified color #1122 +- Functions defined by `/pgf/declare function` now allow spaces in their arg + list #1123 ### Changed diff --git a/testfiles/pgfmath-gh1123.lvt b/testfiles/pgfmath-gh1123.lvt new file mode 100644 index 000000000..d0325fa0f --- /dev/null +++ b/testfiles/pgfmath-gh1123.lvt @@ -0,0 +1,33 @@ +\documentclass{minimal} +\input{pgf-regression-test} + +\RequirePackage{pgfmath} + +\makeatletter +\csname protected\endcsname\long\def\ASSERTPGFMATHFUNCTIONS#1#2{% + \pgfexpl@tl@if@eq@@ccTF{pgfmath#1@}{pgfmath#2@}{% + \TYPE{PASSED}% + \TYPE{\pgfexpl@cs@meaning@@c{pgfmath#1@}}% + }{% + \TYPE{FAILED}% + \TYPE{\pgfexpl@cs@meaning@@c{pgfmath#1@}}% + \TYPE{\pgfexpl@cs@meaning@@c{pgfmath#2@}}% + }% +} +\makeatother + +\START + +\BEGINTEST{/pgf/declare function, space(s) in arg list} + \pgfkeys{ + /pgf/declare function={ + funcA( \x,\y) = sqrt((\x)^2 + (\y)^2); + funcB( \x, \y) = sqrt((\x)^2 + (\y)^2); + funcX(\x,\y) = sqrt((\x)^2 + (\y)^2); + } + } + \ASSERTPGFMATHFUNCTIONS{funcA}{funcX} + \ASSERTPGFMATHFUNCTIONS{funcB}{funcX} +\ENDTEST + +\END diff --git a/testfiles/pgfmath-gh1123.tlg b/testfiles/pgfmath-gh1123.tlg new file mode 100644 index 000000000..c3e01f552 --- /dev/null +++ b/testfiles/pgfmath-gh1123.tlg @@ -0,0 +1,10 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +============================================================ +TEST 1: /pgf/declare function, space(s) in arg list +============================================================ +PASSED +macro:#1#2->\pgfmathparse {sqrt((#1)^2+(#2)^2)} +PASSED +macro:#1#2->\pgfmathparse {sqrt((#1)^2+(#2)^2)} +============================================================ diff --git a/tex/generic/pgf/math/pgfmathfunctions.code.tex b/tex/generic/pgf/math/pgfmathfunctions.code.tex index 6e5d079c6..714cab3f8 100644 --- a/tex/generic/pgf/math/pgfmathfunctions.code.tex +++ b/tex/generic/pgf/math/pgfmathfunctions.code.tex @@ -184,7 +184,7 @@ \expandafter\pgfmath@toks\expandafter=\expandafter{\pgfmath@local@body}% \else% \pgfmath@toks={}% - \expandafter\pgfmath@local@function@@body\pgfmath@local@args,,% + \expandafter\pgfmath@local@function@@body@trimspaces\pgfmath@local@args,,% \fi% \xdef\pgfmath@local@temp{% \noexpand\pgfmathnotifynewdeclarefunction{\pgfmath@local@name}{\the\c@pgf@counta}% @@ -202,7 +202,13 @@ \pgfmathdeclarefunction{#1}{#2}{\pgfmathparse{#3}}% }% -\def\pgfmath@local@function@@body#1,{% +\def\pgfmath@local@function@@body@trimspaces#1,{% + % strip spaces on both sides of #1 in case it starts with a space, + % e.g., #1 is ` \y` which comes from `func(\x, \y)=...;` + \pgfexpl@exp@args@@Ne\pgfmath@local@function@@body{\pgfutil@trimspaces@noexp{#1}}% +} + +\def\pgfmath@local@function@@body#1{% \def\pgfmath@local@test{#1}% \ifx\pgfmath@local@test\pgfutil@empty% \let\pgfmath@local@next=\relax% @@ -215,7 +221,7 @@ \pgfmath@toks={}% \expandafter\pgfmath@local@function@@@body\pgfmath@local@body @% \edef\pgfmath@local@body{\the\pgfmath@toks}% - \let\pgfmath@local@next=\pgfmath@local@function@@body% + \let\pgfmath@local@next=\pgfmath@local@function@@body@trimspaces% \fi% \pgfmath@local@next% } diff --git a/tex/generic/pgf/utilities/pgfutil-common.tex b/tex/generic/pgf/utilities/pgfutil-common.tex index 952af70f5..da94284cf 100644 --- a/tex/generic/pgf/utilities/pgfutil-common.tex +++ b/tex/generic/pgf/utilities/pgfutil-common.tex @@ -49,6 +49,15 @@ \def\pgfutil@trimspaces@@#1Q#2{#1} \catcode`\Q=11 +% \pgfutil@trimspaces@noexp{} +% +% Variant of \pgfutil@trimspaces that after full expansion leaves stripped +% original text unexpanded in the input stream. Same as \trim@spaces@noexp +% in trimspaces.sty +\def\pgfutil@trimspaces@noexp#1{% + \pgfutil@unexpanded\expandafter\expandafter\expandafter{\pgfutil@trimspaces{#1}}% +} + % \pgfutil@ifx{}{}{}{} % % This macro is expandable. @@ -909,6 +918,77 @@ \pgfmath@smuggleone#1% \endgroup }% + +% +% Utility commands that are drop-in replacements for expl3 macros +% +% Naming conventions: +% pgf_cs = "pgfexpl@" + expl3_cs.replace("_", "@").replace(":", "@@") +% For example, +% expl3_cs: \exp_args:Ne, \tl_put_right:Nn +% pgf_cs: \pgfexpl@exp@args@@Ne, \pgfexpl@tl@put@right@@Nn + + +% +% l3basics package +% + +% \cs_meaning:c +\long\def\pgfexpl@cs@meaning@@c#1{% + \ifcsname #1\endcsname + \expandafter\pgfutil@firstoftwo + \else + \expandafter\pgfutil@secondoftwo + \fi + {\pgfexpl@exp@args@@Nc\meaning{#1}} + {\detokenize{undefined}}% +} + +% +% l3tl package +% + +% \tl_if_eq:NNTF +\long\def\pgfexpl@tl@if@eq@@NNTF#1#2{% + \ifx#1#2\pgfexpl@@@prg@TF@true@@w\fi\pgfutil@secondoftwo +} + +% \tl_if_eq:ccTF +\long\def\pgfexpl@tl@if@eq@@ccTF{% + \pgfexpl@exp@args@@Ncc\pgfexpl@tl@if@eq@@NNTF +} + +% \__prg_TF_true:w +\long\def\pgfexpl@@@prg@TF@true@@w\fi\pgfutil@secondoftwo{% + \fi\pgfutil@firstoftwo +} + +% +% l3expan package +% + +% \exp_args:Nc +\long\def\pgfexpl@exp@args@@Nc#1#2{% + \expandafter#1\csname #2\endcsname +} + +% \exp_args:No +\long\def\pgfexpl@exp@args@@No#1#2{% + \expandafter#1\expandafter{#2}% +} + +% \exp_args:Ne +\long\def\pgfexpl@exp@args@@Ne#1#2{% + \expandafter#1\pgfutil@expanded{{#2}}% +} + +% \exp_args:Ncc +\long\def\pgfexpl@exp@args@@Ncc#1#2#3{% + \expandafter#1\csname #2\expandafter\endcsname\csname #3\endcsname +} + +% End of pgfexpl staff + \input pgfutil-common-lists.tex \endinput diff --git a/tex/generic/pgf/utilities/pgfutil-context.def b/tex/generic/pgf/utilities/pgfutil-context.def index eddab09ab..75748531b 100644 --- a/tex/generic/pgf/utilities/pgfutil-context.def +++ b/tex/generic/pgf/utilities/pgfutil-context.def @@ -365,9 +365,10 @@ \def\pgfutil@translate#1{#1} % \translate works very different in ConTeXt -% e-TeX primitives +% e-TeX primitives and beyond \let\pgfutil@protected\normalprotected \let\pgfutil@unexpanded\normalunexpanded +\let\pgfutil@expanded\normalexpanded \endinput diff --git a/tex/generic/pgf/utilities/pgfutil-latex.def b/tex/generic/pgf/utilities/pgfutil-latex.def index e88cfb942..da59a8bf4 100644 --- a/tex/generic/pgf/utilities/pgfutil-latex.def +++ b/tex/generic/pgf/utilities/pgfutil-latex.def @@ -209,9 +209,10 @@ \def\pgfutil@translate#1{\translate{#1}} \fi -% e-TeX primitives +% e-TeX primitives and beyond \let\pgfutil@protected\protected \let\pgfutil@unexpanded\unexpanded +\let\pgfutil@expanded\expanded \endinput diff --git a/tex/generic/pgf/utilities/pgfutil-plain.def b/tex/generic/pgf/utilities/pgfutil-plain.def index 2d08c5303..9be4f3b07 100644 --- a/tex/generic/pgf/utilities/pgfutil-plain.def +++ b/tex/generic/pgf/utilities/pgfutil-plain.def @@ -335,9 +335,10 @@ \def\pgfutil@translate#1{#1} % is there a translator package for plain? -% e-TeX primitives +% e-TeX primitives and beyond \let\pgfutil@protected\protected \let\pgfutil@unexpanded\unexpanded +\let\pgfutil@expanded\expanded \endinput