From 3364dcae66a703d52a1a30f21e324f988eb37d73 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 10 Oct 2013 22:28:42 +0000 Subject: xint (10oct13) git-svn-id: svn://tug.org/texlive/trunk@31876 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/generic/xint/xint.sty | 403 +++++++++++++++++++++++++--- 1 file changed, 367 insertions(+), 36 deletions(-) (limited to 'Master/texmf-dist/tex/generic/xint/xint.sty') diff --git a/Master/texmf-dist/tex/generic/xint/xint.sty b/Master/texmf-dist/tex/generic/xint/xint.sty index ead0a68fb9c..bb99f667863 100644 --- a/Master/texmf-dist/tex/generic/xint/xint.sty +++ b/Master/texmf-dist/tex/generic/xint/xint.sty @@ -22,7 +22,7 @@ %% in the same archive or directory.) %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09b of October 3, 2013) +%% The xint bundle (version 1.09c of October 9, 2013) %% xint: Expandable operations on long numbers %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -143,20 +143,16 @@ }% \XINT_setcatcodes }% -\begingroup - \catcode58=12 % : (does not matter, actually) - \expandafter\ifx\csname ProvidesPackage\endcsname\relax - \def\x{\endgroup - \def\XINT_providespackage ##1##2[##3]% - {\immediate\write-1{Package: ##2 ##3}% - \expandafter\xdef\csname ver@##2.sty\endcsname{##3}}}% - \else - \def\x{\endgroup\let\XINT_providespackage\relax }% - \fi -\x +\ifdefined\ProvidesPackage + \let\XINT_providespackage\relax +\else + \def\XINT_providespackage #1#2[#3]% + {\immediate\write-1{Package: #2 #3}% + \expandafter\xdef\csname ver@#2.sty\endcsname{#3}}% +\fi \XINT_providespackage \ProvidesPackage {xint}% - [2013/10/03 v1.09b Expandable operations on long numbers (jfB)]% + [2013/10/09 v1.09c Expandable operations on long numbers (jfB)]% \def\xint_gobble_ {}% \def\xint_gobble_i #1{}% \def\xint_gobble_ii #1#2{}% @@ -166,6 +162,7 @@ \def\xint_gobble_vi #1#2#3#4#5#6{}% \def\xint_gobble_vii #1#2#3#4#5#6#7{}% \def\xint_gobble_viii #1#2#3#4#5#6#7#8{}% +\def\xint_firstofone #1{#1}% \def\xint_firstoftwo #1#2{#1}% \def\xint_secondoftwo #1#2{#2}% \def\xint_firstoftwo_andstop #1#2{ #1}% @@ -181,7 +178,7 @@ \def\xint_gob_til_zero #10{}% \def\xint_gob_til_one #11{}% \def\xint_gob_til_G #1G{}% -\def\xint_gob_til_minus #1-{}% was missing since 1.06b, \xintDSR could not work. +\def\xint_gob_til_minus #1-{}% \def\xint_gob_til_zeros_iii #1000{}% \def\xint_gob_til_zeros_iv #10000{}% \def\xint_gob_til_relax #1\relax {}% @@ -207,6 +204,7 @@ \chardef\xint_c_ix 9 \chardef\xint_c_x 10 \newcount\xint_c_x^viii \xint_c_x^viii 100000000 +\newtoks\XINT_toks \def\xintRev {\romannumeral0\xintrev }% \def\xintrev #1% {% @@ -409,34 +407,41 @@ \long\def\XINT_lws_end\Z\XINT_lws_loop_b #1#2#3{ #1}% \def\xintNthElt {\romannumeral0\xintnthelt }% \def\xintNthEltNoExpand {\romannumeral0\xintntheltnoexpand }% -\def\xintnthelt #1#2% +\def\xintnthelt #1% {% - \expandafter\XINT_nthelt_a\expandafter {\the\numexpr #1\expandafter}% - \expandafter {\romannumeral-`0#2}% + \expandafter\XINT_nthelt_a\expandafter {\the\numexpr #1}% }% -\def\xintntheltnoexpand #1#2% +\def\xintntheltnoexpand #1% {% - \expandafter\XINT_nthelt_a\expandafter {\the\numexpr #1}{#2}% + \expandafter\XINT_ntheltnoexpand_a\expandafter {\the\numexpr #1}% }% -\def\XINT_nthelt_a #1% +\def\XINT_nthelt_a #1#2% {% \ifnum #1<0 - \expandafter\XINT_nthelt_b\else\expandafter\XINT_nthelt_c - \fi {#1}% + \xint_afterfi{\expandafter\XINT_nthelt_c\expandafter + {\romannumeral0\xintrevwithbraces {#2}}{-#1}}% + \else + \xint_afterfi{\expandafter\XINT_nthelt_c\expandafter + {\romannumeral-`0#2}{#1}}% + \fi }% -\def\XINT_nthelt_b #1#2% +\def\XINT_ntheltnoexpand_a #1#2% {% - \expandafter\XINT_nthelt_c\expandafter - {\the\numexpr -#1\expandafter}\expandafter - {\romannumeral0\xintrevwithbraces {#2}}% + \ifnum #1<0 + \xint_afterfi{\expandafter\XINT_nthelt_c\expandafter + {\romannumeral0\xintrevwithbracesnoexpand {#2}}{-#1}}% + \else + \xint_afterfi{\expandafter\XINT_nthelt_c\expandafter + {#2}{#1}}% + \fi }% \def\XINT_nthelt_c #1#2% {% - \ifnum #1>\xint_c_ - \xint_afterfi {\XINT_nthelt_loop_a {#1}}% + \ifnum #2>\xint_c_ + \expandafter\XINT_nthelt_loop_a \else - \xint_afterfi {\XINT_length_loop {0}}% - \fi #2\xint_relax\xint_relax\xint_relax\xint_relax + \expandafter\XINT_length_loop + \fi {#2}#1\xint_relax\xint_relax\xint_relax\xint_relax \xint_relax\xint_relax\xint_relax\xint_relax\Z }% \def\XINT_nthelt_loop_a #1% @@ -503,17 +508,327 @@ \def\XINT_applyunbr_loop_b #1#2{\XINT_applyunbr_loop_a {#2#1}}% \def\XINT_applyunbr_end\Z \expandafter\XINT_applyunbr_loop_b\expandafter #1#2#3{ #2}% +\def\xintSeq {\romannumeral0\xintseq }% +\def\xintseq #1{\XINT_seq_chkopt #1\Z }% +\def\XINT_seq_chkopt #1% +{% + \ifx [#1\expandafter\XINT_seq_opt + \else\expandafter\XINT_seq_noopt + \fi #1% +}% +\def\XINT_seq_noopt #1\Z #2% +{% + \expandafter\XINT_seq\expandafter + {\the\numexpr#1\expandafter}\expandafter{\the\numexpr #2}% +}% +\def\XINT_seq #1#2% +{% + \ifcase\xintiSgn{\the\numexpr #2-#1\relax} + \expandafter\xint_firstoftwo_andstop + \or + \expandafter\XINT_seq_p + \else + \expandafter\XINT_seq_n + \fi + {#2}{#1}% +}% +\def\XINT_seq_p #1#2% +{% + \ifnum #1>#2 + \xint_afterfi{\expandafter\XINT_seq_p}% + \else + \expandafter\XINT_seq_e + \fi + \expandafter{\the\numexpr #1-1}{#2}{#1}% +}% +\def\XINT_seq_n #1#2% +{% + \ifnum #1<#2 + \xint_afterfi{\expandafter\XINT_seq_n}% + \else + \expandafter\XINT_seq_e + \fi + \expandafter{\the\numexpr #1+1}{#2}{#1}% +}% +\def\XINT_seq_e #1#2#3{ }% +\def\XINT_seq_opt [\Z #1]#2#3% +{% + \expandafter\XINT_seqo\expandafter + {\the\numexpr #2\expandafter}\expandafter + {\the\numexpr #3\expandafter}\expandafter + {\the\numexpr #1}% +}% +\def\XINT_seqo #1#2% +{% + \ifcase\xintiSgn{\the\numexpr #2-#1\relax} + \expandafter\XINT_seqo_a + \or + \expandafter\XINT_seqo_pa + \else + \expandafter\XINT_seqo_na + \fi + {#1}{#2}% +}% +\def\XINT_seqo_a #1#2#3{ {#1}}% +\def\XINT_seqo_o #1#2#3#4{ #4}% +\def\XINT_seqo_pa #1#2#3% +{% + \ifcase\XINT_Sgn {#3} + \expandafter\XINT_seqo_o + \or + \expandafter\XINT_seqo_pb + \else + \xint_afterfi{\expandafter\space\xint_gobble_iv}% + \fi + {#1}{#2}{#3}{{#1}}% +}% +\def\XINT_seqo_pb #1#2#3% +{% + \expandafter\XINT_seqo_pc\expandafter{\the\numexpr #1+#3}{#2}{#3}% +}% +\def\XINT_seqo_pc #1#2% +{% + \ifnum#1>#2 + \expandafter\XINT_seqo_o + \else + \expandafter\XINT_seqo_pd + \fi + {#1}{#2}% +}% +\def\XINT_seqo_pd #1#2#3#4{\XINT_seqo_pb {#1}{#2}{#3}{#4{#1}}}% +\def\XINT_seqo_na #1#2#3% +{% + \ifcase\XINT_Sgn {#3} + \expandafter\XINT_seqo_o + \or + \xint_afterfi{\expandafter\space\xint_gobble_iv}% + \else + \expandafter\XINT_seqo_nb + \fi + {#1}{#2}{#3}{{#1}}% +}% +\def\XINT_seqo_nb #1#2#3% +{% + \expandafter\XINT_seqo_nc\expandafter{\the\numexpr #1+#3}{#2}{#3}% +}% +\def\XINT_seqo_nc #1#2% +{% + \ifnum#1<#2 + \expandafter\XINT_seqo_o + \else + \expandafter\XINT_seqo_nd + \fi + {#1}{#2}% +}% +\def\XINT_seqo_nd #1#2#3#4{\XINT_seqo_nb {#1}{#2}{#3}{#4{#1}}}% +\catcode`z 3% \def\xintApplyInline #1#2% {% - \def\XINT_apply_themacro {#1}% - \expandafter\XINT_applyinline_a\romannumeral-`0#2:% + \expandafter\def\expandafter\XINT_inline_macro\expandafter ##\expandafter 1% + \expandafter {#1{##1}}% + \expandafter\XINT_inline_b\romannumeral-`0#2z% +}% +\def\XINT_inline_b {\futurelet\XINT_token\XINT_inline_c }% +\def\XINT_inline_c +{% + \ifx\XINT_token z\expandafter\xint_gobble_i + \else \expandafter\XINT_inline_d + \fi +}% +\def\XINT_inline_d #1% +{% + \def\XINT_item{{#1}}\futurelet\XINT_token\XINT_inline_e +}% +\def\XINT_inline_e +{% + \ifx\XINT_token z% + \expandafter\XINT_inline_w + \else + \expandafter\XINT_inline_f + \fi +}% +\def\XINT_inline_f +{% + \expandafter\XINT_inline_g\expandafter{\XINT_inline_macro {##1}}% +}% +\def\XINT_inline_g #1% +{% + \expandafter\XINT_inline_macro\XINT_item + \def\XINT_inline_macro ##1{#1}\XINT_inline_d +}% +\def\XINT_inline_w #1% swallows list terminator +{% + \expandafter\XINT_inline_macro\XINT_item +}% +\def\xintFor {\futurelet\XINT_token\XINT_for_ifstar }% +\def\XINT_for_ifstar {\ifx\XINT_token*\expandafter\XINT_forx + \else\expandafter\XINT_for \fi }% +\def\XINT_for #1#2in#3#4#5% +{% + \XINT_toks \expandafter{\csname XINT_for_d\romannumeral#2\endcsname {#5}}% + \expandafter\XINT_for_b #3,z,% +}% +\def\XINT_forx *#1#2in#3#4#5% +{% + \XINT_toks \expandafter{\csname XINT_forx_d\romannumeral#2\endcsname {#5}}% + \expandafter\XINT_forx_b\romannumeral-`0#3z% +}% +\def\XINT_for_b {\futurelet\XINT_token\XINT_for_c }% +\def\XINT_for_c +{% + \ifx\XINT_token z\expandafter\xint_gobble_iv\fi + \the\XINT_toks +}% +\def\XINT_for_di #1#2,% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {#2}{####2}{####3}{####4}}% + \XINT_toks {\XINT_x\XINT_for_di {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\XINT_for_dii #1#2,% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{#2}{####3}{####4}}% + \XINT_toks {\XINT_x \XINT_for_dii {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\XINT_for_diii #1#2,% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{####2}{#2}{####4}}% + \XINT_toks {\XINT_x \XINT_for_diii {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\XINT_for_div #1#2,% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{####2}{####3}{#2}}% + \XINT_toks {\XINT_x \XINT_for_div {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\XINT_for_e +{% + \ifx\XINT_token z\xint_afterfi{\expandafter\XINT_x \xint_gobble_iv}\fi + \the\XINT_toks +}% +\def\XINT_forx_b {\futurelet\XINT_token\XINT_forx_c }% +\def\XINT_forx_c +{% + \ifx\XINT_token z\expandafter\xint_gobble_iii\fi + \the\XINT_toks +}% +\def\XINT_forx_di #1#2% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {#2}{####2}{####3}{####4}}% + \XINT_toks {\XINT_x \XINT_forx_di {#1}}% + \futurelet\XINT_token\XINT_forx_e +}% +\def\XINT_forx_dii #1#2% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{#2}{####3}{####4}}% + \XINT_toks {\XINT_x \XINT_forx_dii {#1}}% + \futurelet\XINT_token\XINT_forx_e +}% +\def\XINT_forx_diii #1#2% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{####2}{#2}{####4}}% + \XINT_toks {\XINT_x \XINT_forx_diii {#1}}% + \futurelet\XINT_token\XINT_forx_e +}% +\def\XINT_forx_div #1#2% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{####2}{####3}{#2}}% + \XINT_toks {\XINT_x \XINT_forx_div {#1}}% + \futurelet\XINT_token\XINT_forx_e +}% +\def\XINT_forx_e +{% + \ifx\XINT_token z\xint_afterfi{\expandafter\XINT_x \xint_gobble_iii}\fi + \the\XINT_toks +}% +\def\xintForpair #1#2#3#4in#5#6#7% +{% + \XINT_toks \expandafter{% + \csname XINT_forii_d\romannumeral#2\endcsname {#7}}% + \expandafter\XINT_forii_b #5,z,% +}% +\def\XINT_forii_b {\futurelet\XINT_token\XINT_forii_c }% +\def\XINT_forii_c +{% + \ifx\XINT_token z\expandafter\xint_gobble_iv\fi + \the\XINT_toks +}% +\def\XINT_forii_di #1(#2,#3),% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {#2}{#3}{####3}{####4}}% + \XINT_toks {\XINT_x\XINT_forii_di {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\XINT_forii_dii #1(#2,#3),% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{#2}{#3}{####4}}% + \XINT_toks {\XINT_x \XINT_forii_dii {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\XINT_forii_diii #1(#2,#3),% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{####2}{#2}{#3}}% + \XINT_toks {\XINT_x \XINT_forii_diii {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\xintForthree #1#2#3in#4#5#6% +{% + \XINT_toks \expandafter{% + \csname XINT_foriii_d\romannumeral#2\endcsname {#6}}% + \expandafter\XINT_foriii_b #4,z,% +}% +\def\XINT_foriii_b {\futurelet\XINT_token\XINT_foriii_c }% +\def\XINT_foriii_c +{% + \ifx\XINT_token z\expandafter\xint_gobble_iv\fi + \the\XINT_toks +}% +\def\XINT_foriii_di #1(#2,#3,#4),% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {#2}{#3}{#4}{####4}}% + \XINT_toks {\XINT_x\XINT_foriii_di {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\XINT_foriii_dii #1(#2,#3,#4),% +{% + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {####1}{#2}{#3}{#4}}% + \XINT_toks {\XINT_x \XINT_foriii_dii {#1}}% + \futurelet\XINT_token\XINT_for_e +}% +\def\xintForfour #1#2#3in#4#5#6% +{% + \XINT_toks {\XINT_foriv_di {#6}}% + \expandafter\XINT_foriv_b #4,z,% +}% +\def\XINT_foriv_b {\futurelet\XINT_token\XINT_foriv_c }% +\def\XINT_foriv_c +{% + \ifx\XINT_token z\expandafter\xint_gobble_iv\fi + \the\XINT_toks }% -\def\XINT_applyinline_a {\futurelet\XINT_apply_nexttoken\XINT_applyinline_b }% -\def\XINT_applyinline_b #1% +\def\XINT_foriv_di #1(#2,#3,#4,#5),% {% - \ifx\XINT_apply_nexttoken :\expandafter\xint_gobble_iii\fi - \XINT_apply_themacro {#1}\XINT_applyinline_a + \def\XINT_y ##1##2##3##4{#1}% + \def\XINT_x {\XINT_y {#2}{#3}{#4}{#5}}% + \XINT_toks {\XINT_x\XINT_foriv_di {#1}}% + \futurelet\XINT_token\XINT_for_e }% +\catcode`z 11 \def\xintAssign #1\to {% \expandafter\XINT_assign_a\romannumeral-`0#1{}\to @@ -818,6 +1133,9 @@ 0-\dummy { 1}% \krof }% +\def\xintBool #1{\romannumeral-`0% + \csname if#1\endcsname\expandafter1\else\expandafter0\fi }% +\def\xintToggle #1{\romannumeral-`0\iftoggle{#1}{1}{0}}% \def\xintSgnFork {\romannumeral0\xintsgnfork }% \def\xintsgnfork #1% {% @@ -853,6 +1171,7 @@ \xint_afterfi{\expandafter\space\xint_secondoftwo}% \fi }% +\let\xintifTrue\xintifNotZero \def\xintifEq {\romannumeral0\xintifeq }% \def\xintifeq #1#2% {% @@ -1681,6 +2000,18 @@ \def\xintiszero #1{\xintifsgn {#1}{0}{1}{0}}% \def\xintIsNotZero {\romannumeral0\xintisnotzero }% \def\xintisnotzero #1{\xintifsgn {#1}{1}{0}{1}}% +\let\xintIsTrue\xintIsNotZero +\let\xintNot\xintIsZero +\def\xintIsTrue:csv #1{\expandafter\XINT_istrue:_a\romannumeral-`0#1,,^}% +\def\XINT_istrue:_a {\XINT_istrue:_b {}}% +\def\XINT_istrue:_b #1#2,% + {\expandafter\XINT_istrue:_c\romannumeral-`0#2,{#1}}% +\def\XINT_istrue:_c #1{\if #1,\expandafter\XINT_istrue:_f + \else\expandafter\XINT_istrue:_d\fi #1}% +\def\XINT_istrue:_d #1,% + {\expandafter\XINT_istrue:_e\romannumeral0\xintisnotzero {#1},}% +\def\XINT_istrue:_e #1,#2{\XINT_istrue:_b {#2,#1}}% +\def\XINT_istrue:_f ,#1#2^{\xint_gobble_i #1}% \def\xintAND {\romannumeral0\xintand }% \def\xintand #1#2{\xintifzero {#1}{0}{\xintifzero {#2}{0}{1}}}% \def\xintOR {\romannumeral0\xintor }% -- cgit v1.2.3