summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/xint/xintexpr.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/xint/xintexpr.sty')
-rw-r--r--Master/texmf-dist/tex/generic/xint/xintexpr.sty139
1 files changed, 116 insertions, 23 deletions
diff --git a/Master/texmf-dist/tex/generic/xint/xintexpr.sty b/Master/texmf-dist/tex/generic/xint/xintexpr.sty
index 239625f466c..8c6a99fc993 100644
--- a/Master/texmf-dist/tex/generic/xint/xintexpr.sty
+++ b/Master/texmf-dist/tex/generic/xint/xintexpr.sty
@@ -21,7 +21,7 @@
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%%----------------------------------------------------------------
-%% The xint bundle (version 1.09j of January 9, 2014)
+%% The xint bundle (version 1.09k of January 21, 2014)
%% xintexpr: Expandable expression parser
%% Copyright (C) 2013-2014 by Jean-Francois Burnol
%%----------------------------------------------------------------
@@ -101,10 +101,11 @@
\XINTsetupcatcodes%
\XINT_providespackage
\ProvidesPackage{xintexpr}%
- [2014/01/09 v1.09j Expandable expression parser (jfB)]%
-\def\xint_gob_til_! #1!{}% nota bene: this ! has catcode 11
-\edef\XINT_expr_lock #1!%
- {\noexpand\expandafter\space\noexpand\csname .=#1\noexpand\endcsname }%
+ [2014/01/21 v1.09k Expandable expression parser (jfB)]%
+\def\xint_gob_til_! #1!{}% nota bene: this ! has catcode 11
+\expandafter\def\expandafter
+\XINT_expr_lock\expandafter#\expandafter1\expandafter !\expandafter
+ {\expandafter\expandafter\space\csname .=#1\endcsname }%
\def\XINT_expr_unlock {\expandafter\XINT_expr_unlock_a\string }%
\def\XINT_expr_unlock_a #1.={}%
\def\XINT_expr_unexpectedtoken {\xintError:ignored }%
@@ -223,8 +224,11 @@
{%
\ifnum \xint_c_ix<1#1
\expandafter\XINT_expr_scandec_I
- \else % We assume we are dealing with a function name!!
- \expandafter\XINT_expr_scanfunc
+ \else
+ \if #1"\expandafter\expandafter\expandafter\XINT_expr_scanhex_I
+ \else % We assume we are dealing with a function name!!
+ \expandafter\expandafter\expandafter\XINT_expr_scanfunc
+ \fi
\fi #1%
}%
\def\XINT_expr_scanfunc
@@ -269,13 +273,14 @@
\XINT_expr_lock\romannumeral-`0\XINT_expr_scanfracpart_b
}%
\def\XINT_expr_scanintpart_a #1% Please no braced material: 123{FORBIDDEN}
-{% careful that ! has catcode letter... spaces needed after <cs>...
- \ifcat #1\relax
- \expandafter !% stop number scan if \relax, \count, \numexpr, or
- \else \xint_afterfi{\ifx !#1\expandafter !\else % also \xintexpr etc..
- \expandafter\expandafter\expandafter
- \XINT_expr_scanintpart_aa\expandafter\string\fi }%
- \fi #1%
+{% careful that ! has catcode letter here
+ \ifcat #1\relax\else
+ \ifx !#1\else
+ \expandafter\expandafter\expandafter
+ \xint_thirdofthree
+ \fi\fi
+ \xint_firstoftwo !% this stops the scan
+ {\expandafter\XINT_expr_scanintpart_aa\string }#1%
}%
\def\XINT_expr_scanintpart_aa #1%
{%
@@ -296,19 +301,20 @@
\expandafter #1\romannumeral-`0\expandafter
\XINT_expr_scanintpart_a\romannumeral-`0\romannumeral-`0%
}%
-\def\XINT_expr_scandec_transition #1%
+\def\XINT_expr_scandec_transition .%
{%
\expandafter.\romannumeral-`0\expandafter
\XINT_expr_scanfracpart_a\romannumeral-`0\romannumeral-`0%
}%
\def\XINT_expr_scanfracpart_a #1%
{%
- \ifcat #1\relax
- \expandafter !% stop number scan
- \else \xint_afterfi{\ifx !#1\expandafter !\else
- \expandafter\expandafter\expandafter
- \XINT_expr_scanfracpart_aa\expandafter\string\fi }%
- \fi #1%
+ \ifcat #1\relax\else
+ \ifx !#1\else
+ \expandafter\expandafter\expandafter
+ \xint_thirdofthree
+ \fi\fi
+ \xint_firstoftwo !% this stops the scan
+ {\expandafter\XINT_expr_scanfracpart_aa\string }#1%
}%
\def\XINT_expr_scanfracpart_aa #1%
{%
@@ -324,6 +330,87 @@
\expandafter #1\romannumeral-`0\expandafter
\XINT_expr_scanfracpart_a\romannumeral-`0\romannumeral-`0%
}%
+\def\XINT_expr_scanhex_I #1%
+{%
+ \expandafter\XINT_expr_getop\romannumeral-`0\expandafter
+ \XINT_expr_lock\expandafter\XINT_expr_inhex
+ \romannumeral-`0\XINT_expr_scanhexI_a
+}%
+\def\XINT_expr_inhex #1.#2#3;% expanded inside \csname..\endcsname
+{%
+ \if#2I\xintHexToDec{#1}%
+ \else
+ \xintiiMul{\xintiiPow{625}{\xintLength{#3}}}{\xintHexToDec{#1#3}}%
+ [\the\numexpr-4*\xintLength{#3}]%
+ \fi
+}%
+\def\XINT_expr_scanhexI_a #1%
+{%
+ \ifcat #1\relax\else
+ \ifx !#1\else
+ \expandafter\expandafter\expandafter
+ \xint_thirdofthree
+ \fi\fi
+ \xint_firstoftwo {.I;!}%
+ {\expandafter\XINT_expr_scanhexI_aa\string }#1%
+}%
+\def\XINT_expr_scanhexI_aa #1%
+{%
+ \if\ifnum`#1>`/
+ \ifnum`#1>`9
+ \ifnum`#1>`@
+ \ifnum`#1>`F
+ 0\else1\fi\else0\fi\else1\fi\else0\fi 1%
+ \expandafter\XINT_expr_scanhexI_b
+ \else
+ \if .#1%
+ \expandafter\xint_firstoftwo
+ \else % gather what we got so far, leave catcode 12 #1 in stream
+ \expandafter\xint_secondoftwo
+ \fi
+ {\expandafter\XINT_expr_scanhex_transition}%
+ {\xint_afterfi {.I;!}}%
+ \fi
+ #1%
+}%
+\def\XINT_expr_scanhexI_b #1%
+{%
+ \expandafter #1\romannumeral-`0\expandafter
+ \XINT_expr_scanhexI_a\romannumeral-`0\romannumeral-`0%
+}%
+\def\XINT_expr_scanhex_transition .%
+{%
+ \expandafter.\expandafter.\romannumeral-`0\expandafter
+ \XINT_expr_scanhexII_a\romannumeral-`0\romannumeral-`0%
+}%
+\def\XINT_expr_scanhexII_a #1%
+{%
+ \ifcat #1\relax\else
+ \ifx !#1\else
+ \expandafter\expandafter\expandafter
+ \xint_thirdofthree
+ \fi\fi
+ \xint_firstoftwo {;!}% this stops the scan
+ {\expandafter\XINT_expr_scanhexII_aa\string }#1%
+}%
+\def\XINT_expr_scanhexII_aa #1%
+{%
+ \if\ifnum`#1>`/
+ \ifnum`#1>`9
+ \ifnum`#1>`@
+ \ifnum`#1>`F
+ 0\else1\fi\else0\fi\else1\fi\else0\fi 1%
+ \expandafter\XINT_expr_scanhexII_b
+ \else
+ \xint_afterfi {;!}%
+ \fi
+ #1%
+}%
+\def\XINT_expr_scanhexII_b #1%
+{%
+ \expandafter #1\romannumeral-`0\expandafter
+ \XINT_expr_scanhexII_a\romannumeral-`0\romannumeral-`0%
+}%
\def\XINT_expr_getop #1% this #1 is the current locked computed value
{% full expansion of next token, first swallowing a possible space
\expandafter\XINT_expr_getop_a\expandafter #1%
@@ -337,8 +424,12 @@
{\ifx #2\relax\expandafter\xint_firstofthree
\else\expandafter\xint_secondofthree % tacit multiplication
\fi }%
- {\ifx !#2\expandafter\xint_secondofthree % tacit multiplication
- \else\expandafter\xint_thirdofthree
+ {\ifx !#2\expandafter\xint_secondofthree % tacit multiplication
+ \else % 1.09k adds tacit multiplication in front of (
+ \if (#2\expandafter\expandafter\expandafter\xint_secondofthree
+ \else
+ \expandafter\expandafter\expandafter\xint_thirdofthree
+ \fi
\fi }%
{\XINT_expr_foundend #1}%
{\XINT_expr_foundop *#1#2}%
@@ -1033,6 +1124,7 @@
\def\xintexprSafeCatcodes
{% for end user.
\edef\xintexprRestoreCatcodes {%
+ \catcode34=\the\catcode34 % "
\catcode63=\the\catcode63 % ?
\catcode124=\the\catcode124 % |
\catcode38=\the\catcode38 % &
@@ -1055,6 +1147,7 @@
\catcode61=\the\catcode61 % =
\catcode32=\the\catcode32\relax % space
}% it's hard to know where to stop...
+ \catcode34=12 % "
\catcode63=12 % ?
\catcode124=12 % |
\catcode38=4 % &