Skip to content

Commit

Permalink
\pgfmath@ensureregister produced missing characters #400
Browse files Browse the repository at this point in the history
  • Loading branch information
hmenke committed Nov 27, 2019
1 parent 94be30e commit d9e677f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
66 changes: 45 additions & 21 deletions tex/generic/pgf/math/pgfmathutil.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,48 @@

\def\pgfmathincluded{}

% Helper macros for \pgfmath@ifregister
%
\def\pgfmath@grabv#1#2#3#4#5#6#7\pgfmath@grabv{#2#3#4#5\ifx#6!!\fi}
\def\pgfmath@ifskip@extract#1{\expandafter\pgfmath@grabv\meaning#1!!!!!!\pgfmath@grabv}
\def\pgfmath@iftoks@extract#1{\expandafter\pgfmath@grabv\meaning#1!!!!!!\pgfmath@grabv}

\def\pgfmath@grabvi#1#2#3#4#5#6#7#8\pgfmath@grabvi{#2#3#4#5#6\ifx#7!!\fi}
\def\pgfmath@ifdimen@extract#1{\expandafter\pgfmath@grabvi\meaning#1!!!!!!\pgfmath@grabvi}
\def\pgfmath@ifcount@extract#1{\expandafter\pgfmath@grabvi\meaning#1!!!!!!\pgfmath@grabvi}

\def\pgfmath@grabvii#1#2#3#4#5#6#7#8#9\pgfmath@grabvii{#2#3#4#5#6#7\ifx#8!!\fi}
\def\pgfmath@ifmuskip@extract#1{\expandafter\pgfmath@grabvii\meaning#1!!!!!!\pgfmath@grabvii}

% \pgfmath@ifdimen@unguarded
%
% Check if #2 is a register of type #1.
% Credits to Frank: https://tex.stackexchange.com/a/56905
%
% #1 register type (count, dimen, skip, muskip, toks)
% #2 single token
%
\def\pgfmath@ifregister@unguarded#1#2{%
\expandafter\ifx\csname\csname pgfmath@if#1@extract\endcsname{#2}\expandafter\endcsname\csname #1\endcsname
\expandafter\pgfutil@firstoftwo
\else
\expandafter\pgfutil@secondoftwo
\fi}

% \pgfmath@ifregister
%
% Checks if a token is a a certain type of register
%
% #1 register type (count, dimen, skip, muskip, toks)
% #2 single token
%
\def\pgfmath@ifregister#1#2{%
\pgfutil@IfUndefined{pgfmath@if#1@extract}%
{\errmessage{Package PGF Math Error: Cannot test for #1 register}}%
{\pgfutil@IfUndefined{\csname pgfmath@if#1@extract\endcsname{#2}}%
{\pgfutil@secondoftwo}}%
{\pgfmath@ifregister@unguarded{#1}{#2}}}

% \pgfmath@ensureregister
%
% Ensure a control sequence exists as a TeX count/dimen register.
Expand All @@ -21,27 +63,9 @@
% #2 - a control sequence.
%
\def\pgfmath@ensureregister#1#2{%
\begingroup%
\setbox0=\hbox\bgroup\begingroup% In case #2 is a defined macro. Unlikely, but you never know...
\afterassignment\pgfmath@@ensureregister%
\noexpand#20.0pt\let\pgfmath@temp\relax\relax\pgfmath@#2#1\pgfmath@}

\def\pgfmath@@ensureregister#1#2\pgfmath@#3#4#5\pgfmath@{%
\endgroup\egroup%
\endgroup%
\ifx#4c%
\ifx#1.% Already a count register.
\else%
\csname newcount\endcsname#3% This gets round \outer in plain TeX.
\fi%
\else%
\ifx#4d%
\ifx\let#1% Already a dimen register.
\else%
\csname newdimen\endcsname#3%
\fi%
\fi%
\fi%
\pgfmath@ifregister{#1}{#2}%
{}%
{\csname new#1\endcsname#2}%
}

% Check registers exist. If not, create them.
Expand Down
9 changes: 4 additions & 5 deletions tex/generic/pgf/utilities/pgfutil-common.tex
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@
\fi}

% A variant of \pgfutil@ifundefined which will NOT let #1 to \relax it
% is undefined. However, this macro is not expandable.
% is undefined.
\def\pgfutil@IfUndefined#1{%
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname#1\endcsname\relax
\expandafter\pgfutil@firstoftwo
\else
\ifcsname#1\endcsname
\expandafter\pgfutil@secondoftwo
\else
\expandafter\pgfutil@firstoftwo
\fi
}
\long\def\pgfutil@firstofone#1{#1}
Expand Down

0 comments on commit d9e677f

Please sign in to comment.