Skip to content

Commit

Permalink
fix(pgfmath): Strip spaces around each function arg pgf-tikz#1123
Browse files Browse the repository at this point in the history
Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
  • Loading branch information
muzimuzhi committed Jan 10, 2022
1 parent f811952 commit 7d5cc95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tex/generic/pgf/math/pgfmathfunctions.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}%
Expand All @@ -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)=...;`
\expandafter\pgfmath@local@function@@body\expanded{{\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%
Expand All @@ -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%
}
Expand Down
9 changes: 9 additions & 0 deletions tex/generic/pgf/utilities/pgfutil-common.tex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
\def\pgfutil@trimspaces@@#1Q#2{#1}
\catcode`\Q=11

% \pgfutil@trimspaces@noexp{<token list>}
%
% 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{%
\unexpanded\expandafter\expandafter\expandafter{\pgfutil@trimspaces{#1}}%
}

% \pgfutil@ifx{<token 1>}{<token 2>}{<true code>}{<false code>}
%
% This macro is expandable.
Expand Down

0 comments on commit 7d5cc95

Please sign in to comment.