Skip to content

Commit

Permalink
Provide a convenient workaround for pgf-tikz#508 (also pgf-tikz#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmenke committed Sep 2, 2020
1 parent c5a6dbb commit d07657b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
24 changes: 24 additions & 0 deletions doc/generic/pgf/text-en/pgfmanual-en-math-algorithms.tex
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,27 @@ \section{Customizing the Mathematical Engine}
\end{codeexample}
%
\end{key}

\begin{key}{/pgf/declare function/execute at begin function=\meta{tokens}}
These \meta{tokens} are inserted just before |\pgfmathdeclarefunction|
scans the body of the function definition. This is a rather low-level
option, so you should read the implementation to figure out where the
\meta{tokens} are inserted.
\end{key}

\begin{key}{/pgf/declare function/execute at end function=\meta{tokens}}
These \meta{tokens} are inserted just after |\pgfmathdeclarefunction| has
finished scanning the body of the function definition. This is a rather
low-level option, so you should read the implementation to figure out where
the \meta{tokens} are inserted.
\end{key}

\begin{key}{/pgf/declare function/ignore spaces=\meta{boolean}}
Uses the two keys |/pgf/declare function/execute at begin function| and
|/pgf/declare function/execute at end function| to install catcodes such
that spaces inside the body of the function definition of
|\pgfmathdeclarefunction| are ignored. The usual \TeX\ tokenization rules
apply, so if the body of the function had already been tokenized by other
means this will become ineffective. If you want to use a space you can use
|~| in the function body which has its catcode set to 10 (space).
\end{key}
24 changes: 23 additions & 1 deletion tex/generic/pgf/math/pgfmathfunctions.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
{\expandafter\noexpand\csname pgfmath#1@\endcsname}%
{\csname pgfmath@operation@#1@arity\endcsname}%
}%
\pgfkeysvalueof{/pgf/declare function/execute at begin function}%
\pgfmath@marshal%
}

Expand All @@ -61,6 +62,7 @@
% #4 - code for function <name>.
%
\def\pgfmath@@declarefunction#1#2#3#4{% Function of arity 0 - 9.
\pgfkeysvalueof{/pgf/declare function/execute at end function}%
\ifcase#3\relax%
\def#1{#2}%
\def\pgfmath@@head{\def#2}%
Expand Down Expand Up @@ -109,7 +111,27 @@
\pgfkeys{%
/pgf/declare function/.code={%
\pgfmath@local@functions#1@=@;%
}
},
/pgf/declare function/execute at begin function/.initial={},
/pgf/declare function/execute at end function/.initial={},
/pgf/declare function/ignore spaces/.is choice,
/pgf/declare function/ignore spaces/.default=true,
/pgf/declare function/ignore spaces/true/.style={%
/pgf/declare function/execute at begin function={%
\begingroup
\catcode`\^^I=9\relax
\catcode`\ =9\relax
\catcode`\~=10\relax
\endlinechar=`\ \relax
},
/pgf/declare function/execute at end function={%
\endgroup
},
},
/pgf/declare function/ignore spaces/false/.style={%
/pgf/declare function/execute at begin function={},
/pgf/declare function/execute at end function={},
},
}

\def\pgfmath@local@gobbleone#1{}
Expand Down

0 comments on commit d07657b

Please sign in to comment.