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.sty117
1 files changed, 99 insertions, 18 deletions
diff --git a/Master/texmf-dist/tex/generic/xint/xintexpr.sty b/Master/texmf-dist/tex/generic/xint/xintexpr.sty
index 8f2f4e5ac61..84db61a81a1 100644
--- a/Master/texmf-dist/tex/generic/xint/xintexpr.sty
+++ b/Master/texmf-dist/tex/generic/xint/xintexpr.sty
@@ -21,8 +21,8 @@
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% ---------------------------------------------------------------
-%% The xint bundle 1.4j 2021/07/13
-%% Copyright (C) 2013-2021 by Jean-Francois Burnol
+%% The xint bundle 1.4k 2022/05/18
+%% Copyright (C) 2013-2022 by Jean-Francois Burnol
%% xintexpr: Expandable expression parser
%% ---------------------------------------------------------------
\begingroup\catcode61\catcode48\catcode32=10\relax%
@@ -82,7 +82,7 @@
\XINTsetupcatcodes%
\XINT_providespackage
\ProvidesPackage{xintexpr}%
- [2021/07/13 v1.4j Expandable expression parser (JFB)]%
+ [2022/05/18 v1.4k Expandable expression parser (JFB)]%
\catcode`! 11
\let\XINT_Cmp \xintiiCmp
\def\XINTfstop{\noexpand\XINTfstop}%
@@ -318,7 +318,6 @@
\def\XINT_flexpr_wrap {\XINTfstop\XINTflexprprint}%
\protected\def\XINTexprprint.%
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintexprPrintOne}%
-\let\xintexprPrintOne\xintFracToSci
\protected\def\XINTiexprprint.%
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintiexprPrintOne}%
\let\xintiexprPrintOne\xintDecToString
@@ -367,12 +366,34 @@
\expanded\XINT:NEhook:x:mapwithin\XINT:expr:mapwithin{\XINTinFloatSdigits_braced}%
}%
\def\XINTinFloatSdigits_braced#1{{\XINTinFloatS[\XINTdigits]{#1}}}%
+\let\xint_relax\relax
\def\xinteval #1%
{\expanded\expandafter\XINTexprprint\expandafter.\romannumeral0\xintbareeval#1\relax}%
-\def\xintieval #1%
- {\expanded\expandafter\xint_gobble_i\romannumeral`&&@\xintiexpr#1\relax}%
-\def\xintfloateval #1%
- {\expanded\expandafter\xint_gobble_i\romannumeral`&&@\xintfloatexpr#1\relax}%
+\def\xintieval
+ {\expanded\expandafter\xint_ieval_chkopt\string}%
+\def\xint_ieval_chkopt #1%
+{%
+ \ifx [#1\expandafter\xint_ieval_opt
+ \else\expandafter\xint_ieval_noopt
+ \fi #1%
+}%
+\def\xint_ieval_opt [#1]#2%
+ {\expandafter\xint_gobble_i\romannumeral`&&@\xintiexpr[#1]#2\relax}%
+\def\xint_ieval_noopt #1{\expandafter\xint_ieval\expandafter{\iffalse}\fi}%
+\def\xint_ieval#1%
+ {\expandafter\xint_gobble_i\romannumeral`&&@\xintiexpr#1\relax}%
+\def\xintfloateval {\expanded\expandafter\xint_floateval_chkopt\string}%
+\def\xint_floateval_chkopt #1%
+{%
+ \ifx [#1\expandafter\xint_floateval_opt
+ \else\expandafter\xint_floateval_noopt
+ \fi #1%
+}%
+\def\xint_floateval_opt [#1]#2%
+ {\expandafter\xint_gobble_i\romannumeral`&&@\xintfloatexpr[#1]#2\relax}%
+\def\xint_floateval_noopt #1{\expandafter\xint_floateval\expandafter{\iffalse}\fi}%
+\def\xint_floateval#1%
+ {\expandafter\xint_gobble_i\romannumeral`&&@\xintfloatexpr#1\relax}%
\def\xintiieval #1%
{\expanded\expandafter\XINTiiexprprint\expandafter.\romannumeral0\xintbareiieval#1\relax}%
\def\xintboolexpr
@@ -391,6 +412,69 @@
\def\xintifsgnexpr #1{\romannumeral0\xintiiifsgn {\xinttheexpr #1\relax}}%
\def\xintifsgnfloatexpr #1{\romannumeral0\xintiiifsgn {\xintthefloatexpr #1\relax}}%
\def\xintifsgniiexpr #1{\romannumeral0\xintiiifsgn {\xinttheiiexpr #1\relax}}%
+\def\xintFracToSci #1{\expandafter\XINT_FracToSci\romannumeral`&&@#1/\W[\R}%
+\def\XINT_FracToSci #1/#2#3[#4%
+{%
+ \xint_gob_til_W #2\XINT_FracToSci_noslash\W
+ \xint_gob_til_R #4\XINT_FracToSci_slash_noN\R
+ \XINT_FracToSci_slash_N #1/#2#3[#4%
+}%
+\def\XINT_FracToSci_noslash#1\XINT_FracToSci_slash_N #2[#3%
+{%
+ \xint_gob_til_R #3\XINT_FracToSci_noslash_noN\R
+ \XINT_FracToSci_noslash_N #2[#3%
+}%
+\def\XINT_FracToSci_noslash_noN\R\XINT_FracToSci_noslash_N #1/\W[\R{#1}%
+\def\XINT_FracToSci_noslash_N #1[#2]/\W[\R%
+{%
+ \ifnum#2=\xint_c_ #1\else
+ \romannumeral0\expandafter\XINT_pfloat_keeptrimmed_fork\romannumeral0\xintrez{#1[#2]}%
+ \fi
+}%
+\def\XINT_FracToSci_slash_noN\R\XINT_FracToSci_slash_N #1#2/#3/\W[\R%
+{%
+ #1\xint_gob_til_zero#1\expandafter\iffalse\xint_gobble_ii0\iftrue
+ #2\if\XINT_isOne{#3}1\else/#3\fi\fi
+}%
+\def\XINT_FracToSci_slash_N #1#2/#3[#4]/\W[\R%
+{%
+ \ifnum#4=\xint_c_ #1#2\else
+ \romannumeral0\expandafter\XINT_pfloat_keeptrimmed_fork\romannumeral0\xintrez{#1#2[#4]}%
+ \fi
+ \if\XINT_isOne{#3}1\else\if#10\else/#3\fi\fi
+}%
+\let\xintexprPrintOne\xintFracToSci
+\def\xintFracToDecimal #1{\expandafter\XINT_FracToDecimal\romannumeral`&&@#1/\W[\R}%
+\def\XINT_FracToDecimal #1/#2#3[#4%
+{%
+ \xint_gob_til_W #2\XINT_FracToDecimal_noslash\W
+ \xint_gob_til_R #4\XINT_FracToDecimal_slash_noN\R
+ \XINT_FracToDecimal_slash_N #1/#2#3[#4%
+}%
+\def\XINT_FracToDecimal_noslash#1\XINT_FracToDecimal_slash_N #2[#3%
+{%
+ \xint_gob_til_R #3\XINT_FracToDecimal_noslash_noN\R
+ \XINT_FracToDecimal_noslash_N #2[#3%
+}%
+\def\XINT_FracToDecimal_noslash_noN\R\XINT_FracToDecimal_noslash_N #1/\W[\R{#1}%
+\def\XINT_FracToDecimal_noslash_N #1[#2]/\W[\R%
+{%
+ \ifnum#2=\xint_c_ #1\else
+ \romannumeral0\expandafter\XINT_dectostr\romannumeral0\xintrez{#1[#2]}%
+ \fi
+}%
+\def\XINT_FracToDecimal_slash_noN\R\XINT_FracToDecimal_slash_N #1#2/#3/\W[\R%
+{%
+ #1\xint_gob_til_zero#1\expandafter\iffalse\xint_gobble_ii0\iftrue
+ #2\if\XINT_isOne{#3}1\else/#3\fi\fi
+}%
+\def\XINT_FracToDecimal_slash_N #1#2/#3[#4]/\W[\R%
+{%
+ \ifnum#4=\xint_c_ #1#2\else
+ \romannumeral0\expandafter\XINT_dectostr\romannumeral0\xintrez{#1#2[#4]}%
+ \fi
+ \if\XINT_isOne{#3}1\else\if#10\else/#3\fi\fi
+}%
\def\XINT_embrace#1{{#1}}%
\def\xint_gob_til_! #1!{}% ! with catcode 11
\def\xintError:noopening
@@ -3632,11 +3716,11 @@
\ifnum\xintLength:f:csv{\XINT_defufunc_tmpd}=\xint_c_i
\expandafter#6%
\else
- \xintMessage {xintexpr}{ERROR}
+ \xintMessage {xintexpr}{ERROR}
{Universal functions must be functions of one argument only,
but the declaration of \XINT_defufunc_tmpa\space
- has \xintLength:f:csv{\XINT_defufunc_tmpd} of them. Cancelled.}%
- \xintexprRestoreCatcodes
+ has \xintLength:f:csv{\XINT_defufunc_tmpd} of them. Canceled.}%
+ \xintexprRestoreCatcodes
\fi
}% end of \xint_defufunc_b
\def #6{%
@@ -3655,6 +3739,7 @@
with \ifxintglobaldefs global \fi meaning \expandafter\meaning
\csname XINT_#2_userufunc_\XINT_defufunc_tmpa\endcsname}%
\fi
+ \xintexprRestoreCatcodes
}% end of \xint_defufunc_c
}%
\def\xintdefufunc {\xintexprSafeCatcodes\xintdefufunc_a}%
@@ -4435,11 +4520,9 @@
}@
\catcode`% 14
\XINTsetcatcodes % clean up to avoid surprises if something changes
-\newif\ifxintexprsafecatcodes
-\let\xintexprRestoreCatcodes\empty
+\def\xintexprRestoreCatcodes{}%
\def\xintexprSafeCatcodes
{%
- \unless\ifxintexprsafecatcodes
\edef\xintexprRestoreCatcodes {%
\endlinechar=\the\endlinechar
\catcode59=\the\catcode59 % ;
@@ -4465,11 +4548,9 @@
\catcode44=\the\catcode44 % ,
\catcode61=\the\catcode61 % =
\catcode96=\the\catcode96 % `
- \catcode32=\the\catcode32\relax % space
- \noexpand\xintexprsafecatcodesfalse
+ \catcode32=\the\catcode32 % space
+ \def\noexpand\xintexprRestoreCatcodes{\unexpanded\expandafter{\xintexprRestoreCatcodes}}%
}%
- \fi
- \xintexprsafecatcodestrue
\endlinechar=13 %
\catcode59=12 % ;
\catcode34=12 % "