diff options
author | Karl Berry <karl@freefriends.org> | 2013-11-03 23:44:08 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-11-03 23:44:08 +0000 |
commit | 8130b636b82bbc55d48a69eb8c28c4e966d33f1b (patch) | |
tree | b9f66de8625517b6613eca2d8e7733c7c61abc05 /Master/texmf-dist | |
parent | 60d9684691aa95d10a1e12b07b703ccede3f1d9d (diff) |
xint
git-svn-id: svn://tug.org/texlive/trunk@32053 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/generic/xint/README | 2 | ||||
-rw-r--r-- | Master/texmf-dist/doc/generic/xint/xint.pdf | bin | 876954 -> 947380 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/generic/xint/xint.dtx | 3148 | ||||
-rw-r--r-- | Master/texmf-dist/source/generic/xint/xint.ins | 2 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/xint/xint.sty | 621 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/xint/xintbinhex.sty | 12 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/xint/xintcfrac.sty | 4 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/xint/xintexpr.sty | 4 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/xint/xintfrac.sty | 83 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/xint/xintgcd.sty | 12 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/xint/xintseries.sty | 4 |
11 files changed, 2529 insertions, 1363 deletions
diff --git a/Master/texmf-dist/doc/generic/xint/README b/Master/texmf-dist/doc/generic/xint/README index af45d754972..993e05deaa9 100644 --- a/Master/texmf-dist/doc/generic/xint/README +++ b/Master/texmf-dist/doc/generic/xint/README @@ -1,5 +1,5 @@ The xint bundle -Release 1.09d (2013/10/22). +Release 1.09e (2013/10/29). author: Jean-Francois Burnol License: LPPL 1.3c or later. diff --git a/Master/texmf-dist/doc/generic/xint/xint.pdf b/Master/texmf-dist/doc/generic/xint/xint.pdf Binary files differindex f80efa4d0d0..48986e037d5 100644 --- a/Master/texmf-dist/doc/generic/xint/xint.pdf +++ b/Master/texmf-dist/doc/generic/xint/xint.pdf diff --git a/Master/texmf-dist/source/generic/xint/xint.dtx b/Master/texmf-dist/source/generic/xint/xint.dtx index f283c9dc200..25cef379b7a 100644 --- a/Master/texmf-dist/source/generic/xint/xint.dtx +++ b/Master/texmf-dist/source/generic/xint/xint.dtx @@ -1,8 +1,8 @@ % -*- coding: iso-latin-1; -*- %<*doc> -\def\lasttimestamp{Time-stamp <22-10-2013 22:40:55 CEST *>} +\def\lasttimestamp{Time-stamp <29-10-2013 17:57:39 CET *>} %</doc> -% xint.dtx, 1.09d (2013/10/22) +% xint.dtx, 1.09e (2013/10/29) % % Copyright (C) 2013 by Jean-François Burnol % @@ -87,7 +87,7 @@ % %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %<xint>%% xint: Expandable operations on long numbers %<xintfrac>%% xintfrac: Expandable operations on fractions %<xintexpr>%% xintexpr: Expandable expression parser @@ -99,8 +99,8 @@ %%---------------------------------------------------------------- %% %<*doc> -\def\pkgversion{1.09d} -\def\pkgdate{2013/10/22} +\def\pkgversion{1.09e} +\def\pkgdate{2013/10/29} \def\striptimestamp #1 <#2 #3 #4 #5>{#2 at #3 #4} \def\getdocdate #1 <#2-#3-#4 #5>{#4/#3/#2} \edef\docdate{\expandafter\getdocdate\lasttimestamp} @@ -172,51 +172,30 @@ \usepackage{amsmath} % for \cfrac in the documentation \usepackage{varioref} -\usepackage{etoc}[2013/10/16] % I need \etocdepthtag.toc +\usepackage{etoolbox} -% ---- USING ETOC FOR CUSTOM SUBSECTION STYLE (pour 1.04, 21 avril 2013) - -% 27 mai: la position, et la nature, de \toctransition modifiés car je ne mets -% plus les sous-sections des sections de «Commands» dans la Toc. +\usepackage{etoc}[2013/10/16] % I need \etocdepthtag.toc -% 8 juin: je change à nouveau le nom de \toctransition (cf au-dessus) +%---- USE OF ETOC FOR THE TABLES OF CONTENTS \def\gobbletodot #1.{} - -% le 18 octobre 2013, j'ai, dans un premier temps, supprimé le mécanisme qui -% écrivait des chgts annulables de tocdepth dans la toc par une méthode qui -% fonctionne directement dans le style de section. Ça marchait mais c'était un -% peu compliqué car il fallait fermer le groupe créé par multicols mais cela -% supprimait la redéfinition de \contentsline, et supprimait aussi la -% signification de \etocname etc... sans parler qu'il fallait re-exécuter, -% toujours pour la même raison \Etoc@levellist, (*), bref au bout d'un moment je -% me suis dit qu'il valait mieux utiliser les possibilités d'etoc 1.07h qui est -% maintenant installé sur CTAN (bientôt 1.07i). - -% (*) je devrais peut-être ré-examiner dans etoc le fait que la redéfinition de -% \contentsline est faite après le paramètre #1 donné dans \etocsettocstyle. - -% J'ai aussi mis directement dans le style les histoires de \phantomsection etc -% pour les bookmarks. \makeatletter \let\savedsectionline\l@section \makeatother \def\sectioncouleur{{cyan}} +% attention à ce 22 hard codé. 23 maintenant,... + \etocsetstyle{section}{} {} - {\ifnum\etocthenumber=22 \gdef\sectioncouleur{{joli}}\fi + {\ifnum\etocthenumber=23 \gdef\sectioncouleur{{joli}}\fi \savedsectionline{\numberline{\expandafter\textcolor\sectioncouleur {\etocnumber}}\etocname} {{\mdseries\etocpage}}% }% cf l@section en classe scrartcl {}% -% choix de style plus sophistiqué à partir de 1.08a 2013/06/11 -% 18 octobre 2013: -% j'ajoute des \nobreak et j'essaie de jouer avec \rightmargin comme glue pour -% une meilleure apparence des tocs, aussi \MARGEPAGENO \def\MARGEPAGENO {1.5em} \etocsetstyle{subsection} {\begingroup @@ -242,24 +221,9 @@ \makeatother -% 4 juin 2013 - -% je me décide à utiliser les couleurs des liens via hyperref, mais je n'en veux -% pas (des couleurs) dans les TOCs (par contre je veux les liens évidemment). -% Idéalement j'aurais aimé pouvoir avoir pour les TOCs les liens sous la forme -% de rectangles mais je n'ai pas le temps de regarder si on peut dire à hyperref -% de faire cela. J'ai déterminé empiriquement qu'on peut tout-à-fait mettre -% \hypersetup{hidelinks} dans un groupe - -% 10 octobre 2013, -% au lieu d'utiliser le \etocaftertitlehook, c'est plus simple de mettre cette -% instruction carrément directement au début du fichier .toc! - -\AtBeginDocument{\addtocontents{toc}{\protect\hypersetup{hidelinks}}} - -% en effet avec etoc toutes les toc sont faites dans un groupe, donc, c'est très -% bien comme cela. - +\addtocontents{toc}{\protect\hypersetup{hidelinks}} +% je rends le @ actif... après begin document... (donc ok pour aux) +\addtocontents{toc}{\protect\makeatother} %--- TXFONTS: TXTT WILL BE MADE SMALLER AND WILL ALLOW HYPHENATION \usepackage{txfonts} @@ -315,18 +279,8 @@ <->ssub * txtt/bx/ui% }{} -% au bout d'un moment j'ai fini par être mal à l'aise avec le 0 de txtt, pour -% afficher les résultats des calculs faits pas xint. -% -% ***** Attention le - de cmtt est ÉPOUVANTABLE!***** bon, ça le disqualifie. -% le - de lmtt lui n'a PAS ce problème. Et lmtt, à sa taille naturelle, -% correspond bien à mon txtt réduit à 96%. Donc c'est très simple: - \def\digitstt {\bgroup\fontfamily {lmtt}\selectfont\let\next=} -% le nom de \digitstt n'est pas très bien choisi, mais bon il est en effet -% utilisé ici dans 95% des cas pour des nombres uniquement. - \usepackage{xspace} \usepackage[dvipsnames]{color} \usepackage{framed} @@ -336,6 +290,12 @@ \definecolor{BLUE}{RGB}{0,0,255} \definecolor{niceone}{RGB}{38,128,192} +% for the quick sort algorithm illustration +\definecolor{LEFT}{RGB}{216,195,88} +\definecolor{RIGHT}{RGB}{208,231,153} +\definecolor{INERT}{RGB}{199,200,194} +\definecolor{PIVOT}{RGB}{109,8,57} + \usepackage[english]{babel} \usepackage[autolanguage,np]{numprint} \AtBeginDocument{\npthousandsep{,\hskip .5pt plus .1pt minus .1pt}} @@ -356,6 +316,7 @@ pdfpagemode=UseOutlines} %---- \MyMarginNote: a simple macro for some margin notes with no fuss +% je m'aperçois que je peux l'utiliser dans les footnotes... \makeatletter \def\MyMarginNote {\@ifnextchar[\@MyMarginNote{\@MyMarginNote[]}}% \def\@MyMarginNote [#1]#2{% @@ -382,9 +343,7 @@ pdfpagemode=UseOutlines} % A proposito, the \LaTeX \centerline uses \hsize and not \linewidth ! % (which in my humble opinion is bad) -% \ignorespaces ajouté le 9 juin. Cela m'aurait évité des dizaines de % lorsque -% plusieurs \centeredline se suivent (car on reste en mode horizontal si on y -% est au début). +% \ignorespaces ajouté le 9 juin. \makeatletter \newcommand*\centeredline {% @@ -404,53 +363,14 @@ pdfpagemode=UseOutlines} % un \ttfamily hard-coded à la place. [en fin de compte j'utilise dorénavant le % vocable \MicroFont plutôt que \verbatim@font] % -% Par ailleurs j'en ai marre des erreurs dues au fait que mes -% paragraphes reformatés dans emacs passent à la ligne au milieu -% d'un \verb. Je décide donc d'annuler l'effet du \dospecials sur les -% espaces dans la source. Et donc je retire le \verb@eol@error et -% il n'y a donc plus lieu d'un comportement différent pour -% l'impression des blancs, donné par la version étoilée. -% -% Et il n'y avait donc pas de \obeylines puisque la fin de ligne -% devenait un message d'erreur dans \verb@eol@error -% % à propos \do@noligs: % macro:#1->\catcode `#1\active \begingroup \lccode `\~=`#1\relax \lowercase % {\endgroup \def ~{\leavevmode \kern \z@ \char `#1}} % ne manque-t-il pas un espace après le \char `#1? En effet! ça me pose des -% problèmes lorsque l'espace a catcode 10!! +% problèmes lorsque l'espace a catcode 10!! Ils ont voulu optimiser et gagner +% un token mais du coup ça en limite l'employabilité. % -% attention au signe - par contre, on ne veut vraiment *pas* de ligatures avec -% lui, donc pour lui et seulement pour lui je fais le boulot de \do@noligs. OK, -% je pense que la raison pour laquelle je ne le faisais que pour - est celle du -% paragraphe précédent que je viens d'ajouter, donc finalement je fais le -% \do@noligs entier -% \catcode`\-\active \def-{\kern \z@ \char`\- } -% -% 12 et 13 mai 2013. Je dois m'occuper des verbatim, et comme je n'ai (pas ou -% plus) envie de perdre du temps à aller re-regarder verbatim et en particulier -% son emploi de trivlist, avec les conséquences *lamentables* sur les -% espacements verticaux je décide de tester une variante de \verb spécialement -% pour remplacer mes blocs verbatim, particulièrement dans le code commenté. Et -% voilà \lverb! bye bye \begin{verbatim} -% -% bref, pour \lverb: d'abord il est \long. Ensuite j'utilise $ si j'ai besoin de -% control sequences. [sans arguments, sinon il me faudrait avoir des caratères -% de catcode 1 et 2 aussi] En fait j'ai juste eu besoin pour \%. Car le % lui je -% le mets (maintiens, donc la partie implémentation) à ignore. Ah, et -% finalement j'utilise aussi $\. Les espaces sont normaux. -% Enfin, je fais de & un caractère de commentaires. Tout cela c'est pour -% la partie Implémentation. -% -% Pour les verbatim dans la partie user manual, je fais une variante \dverb, qui -% elle respecte les lignes, en utilisant \obeylines. -% -% 8 juin: dans \dverb et aussi dans les shortverb, & est commentaire et * -% est actif et fait \lowast (\makestarlowast). J'utilisais avant ~ comme -% caractère actif dans les shortverbs mais je n'en ai pas besoin finalement, -% c'est plus simple avec un * actif. -% -\def\MicroFont {\ttfamily } +\def\MicroFont {\ttfamily\hyphenchar\font45 } \def\MacroFont {\ttfamily\baselineskip12pt\relax} \makeatletter @@ -480,6 +400,7 @@ pdfpagemode=UseOutlines} \begingroup \lccode `\~=`#1\relax \lowercase {\endgroup \def ~{\leavevmode \kern \z@ \char `#1 }}% }% +% *** \verb utilise \MicroFont \def\verb {% \relax \ifmmode\hbox\else\leavevmode\null\fi @@ -492,16 +413,9 @@ pdfpagemode=UseOutlines} \catcode123 13 \catcode 125 13 \makestarlowast \@jfverb }% -\def\@jfverb #1{\catcode`#1\active - \lccode`\~`#1\lowercase{\def~{\egroup\unskip}}}% -% ATTENTION! -% \def~{\\\relax} cause des problèmes infinis. Donc je vais simplement utiliser -% dans les parties commentées du code $\ puisque $ a catcode 0. -% attention à [, donc $\$relax en un endroit. -% Le choix de $ est ok, car comme c'est dans des parties commentées, le mode -% docTeX de emacs ne fait pas de choses pénibles au-niveau de la coloration -% syntaxique. +% \long\def\lverb % pour utilisation dans la partie implémentation +% *** \lverb utilise \MacroFont (comme \verbatim) {% \relax\par\smallskip\noindent\null \begingroup @@ -516,79 +430,50 @@ pdfpagemode=UseOutlines} \@jfverb } % et voilà. Comme quoi, on peut aussi faire sans \trivlist si on veut. +% Voir aussi la re-définition de \MacroFont au moment du \StopEventually +% *** \dverb utilise \MacroFont (comme \verbatim) \long\def\dverb % pour utilisation dans le manuel de l'utilisateur -% contrairement à \lverb, ici, on fait \obeylines -% à utiliser sous la forme: (ou avec un autre à la place de |)(on aurait pu -% imaginer aussi prendre ^^A ou dans le genre -% \dverb|& -% blahblah -% |% -% pour qu'il y ait bien un dernier end of line, qui est compensé a posteriori {% \relax\par\smallskip \bgroup \parindent0pt - % \parskip0pt \def\par{\@@par\leavevmode\null}% \let\do\do@noligs \verbatim@nolig@list \let\do\@makeother \dospecials - \catcode`\& 14 \makestarlowast - \aftergroup\vskip\aftergroup-\aftergroup\baselineskip - \aftergroup\smallskip - \aftergroup\noindent\aftergroup\ignorespaces + \catcode`\@ 14 \makestarlowast \MacroFont \obeylines \@vobeyspaces \@jfverb } -% Mais j'ai besoin d'un mode verbatim différent pour les nombres car je -% ne veux pas passer en mode mathématique (que j'aime de moins en moins) et je -% ne veux pas les 0 du txtt pour cela. Comme je n'utilise pas de tabulation, je -% vais prendre &. -% Hmm, finalement je supporte de moins en moins les chiffres du roman. J'ai un -% peu de mal à me mettre d'accord sur un style uni de présentation. -% Update 8 juin: finalement je me décide ici aussi pour utiliser lmtt -% Donc dans &..& c'est comme dans \digitstt. Très bien. -\catcode`\& 13 -\def&{\begingroup\fontfamily{lmtt}\selectfont - \let\do\@makeother\dospecials - \catcode`\& 13 - \@jfendshrtverb } -\def\@jfendshrtverb #1&{#1\endgroup } -\makeatother - -% Note: il n'y a plus de \hyphenchar-1 dans le \DeclareFontFamily de t1txtt -% MAIS ATTENTION CEPENDANT À CE QUI SE PASSE EN CAS DE CHANGEMENT DE TAILLE - -% 11 mai 2013: j'utilise dorénavant _ là où avant c'était @ -% 22 octobre 2013: je rajoute des \makestarlowast et modifications -% attenantes comme le \detokenize. Cependant ça ne pourra pas marcher -% dans les têtes de sections ou dans la table des matières. - -% bon, un petit coup de \scantokens en plus et on y arrive. -% La raison du \unskip c'est que je me retrouve avec un espace après le -% \scantokens. à examiner une autre fois. +\def\@jfverb #1{\catcode`#1\active + \lccode`\~`#1\lowercase{\def~{\egroup\unskip}}}% +\makeatother \catcode`\_=11 \def\csa_aux #1{\ttfamily\hyphenchar\font45 \char`\\% - \scantokens{#1}\unskip\endgroup } -\def\csb_aux #1{\hyperref[\detokenize{#1}]{\ttfamily - \hyphenchar\font45 \char`\\% - \scantokens{#1}\unskip}\endgroup } + \scantokens{#1}\endgroup } +\def\csb_aux #1{\hyperref[\detokenize{xint#1}]{\ttfamily + \hyphenchar\font45 \char`\\\mbox{xint}\-% + \scantokens{#1}}\endgroup } \DeclareRobustCommand\csa {\begingroup\catcode`\_=11 - \everyeof{\noexpand}% + \everyeof{\noexpand}\endlinechar -1 + \makeatother \makestarlowast \csa_aux } \DeclareRobustCommand\csbnolk {\begingroup\catcode`\_=11 - \everyeof{\noexpand}% + \everyeof{\noexpand}\endlinechar -1 \makestarlowast + \makeatother \color{blue}% \csa_aux } -\DeclareRobustCommand\csb {\begingroup\catcode`\_=11 - \everyeof{\noexpand}% +\DeclareRobustCommand\csbxint {\begingroup\catcode`\_=11 + \everyeof{\noexpand}\endlinechar -1 \makestarlowast + \makeatother \csb_aux } +\catcode`\_=8 \newcommand\csh[1]{\texorpdfstring{\csa{#1}}{\textbackslash #1}} \newcommand\csbh[1]{\texorpdfstring{\csbnolk{#1}}{\textbackslash #1}} @@ -603,7 +488,6 @@ pdfpagemode=UseOutlines} {#1}% \xspace }% }% -\catcode`\_=8 \frenchspacing \renewcommand\familydefault\sfdefault @@ -640,6 +524,22 @@ pdfpagemode=UseOutlines} \begin{document}\thispagestyle{empty}\rmfamily \pdfbookmark[1]{Title page}{TOP} +% Octobre 2013: le & est devenu assez pénible puisque j'en ai besoin dans mes +% exemples de \xintApplyInline/\xintFor avec des tabulars. Donc je décide +% (après avoir temporairement fait des choses un peu lourdes avec \lverb) de +% le remplacer par @ car il n'y en a quasi pas dans la partie user manual; +% idem pour \dverb. Cependant je dois faire attention avec un @ actif par +% exemple dans les tables de matières. Bon on va voir. +\makeatletter + +\begingroup\lccode`\~=`@ +\lowercase{\endgroup\def~}{\begingroup\fontfamily{lmtt}\selectfont + \let\do\@makeother\dospecials + \catcode`\@ \active + \jfendshrtverb } +\catcode`\@ \active +\def\jfendshrtverb #1@{#1\endgroup } + {\normalfont\Large\parindent0pt \parfillskip 0pt\relax \leftskip 2cm plus 1fil \rightskip 2cm plus 1fil The \xintname bundle\par}% @@ -653,7 +553,7 @@ pdfpagemode=UseOutlines} } \begin{abstract} - The \xintname package implements with expandable \TeX{} macros the basic +The \xintname package implements with expandable \TeX{} macros the basic arithmetic operations of addition, subtraction, multiplication and division, applied to arbitrarily long numbers. The \xintfracname package extends the scope of \xintname to fractional numbers with arbitrarily long numerators and @@ -753,12 +653,12 @@ except if you invoke \TeX{} under the name |tex| in command line. The goal is too compute \emph{exactly}, purely by expansion, without count registers nor assignments nor definitions, with arbitrarily big numbers and fractions. As will be commented upon more later, this works -fine when the data has dozens of digits, but multiplying out two &1000& +fine when the data has dozens of digits, but multiplying out two @1000@ digits numbers under this constraint of expandability is expensive; so in many situations the package will be used for fixed point (rounding or truncating each intermediate result) or floating point computations. The ``floating point'' macros work with a given arbitrary precision (default -is &16& digits; from the remark made above, beyond &100& digits things +is @16@ digits; from the remark made above, beyond @100@ digits things will start becoming too slow if hundreds of computations are needed). The only non-algebraic operation which is currently implemented is the extraction of square roots. @@ -768,7 +668,7 @@ The package macros expand their arguments\footnote{see in completely expandable, this means that one may nest them arbitrarily deep to construct complicated (and still completely expandable) formulas. -But one will presumably prefer to use the \csb{xintexpr}| ... +But one will presumably prefer to use the (expandable!) \csbxint{expr}| ... \relax| parser as it allows infix notations, function names (corresponding to some of the package macros), comparison operators, boolean operators, 2way and 3way conditionals. @@ -776,7 +676,7 @@ boolean operators, 2way and 3way conditionals. When producing very long numbers there is the question of printing them on the page, without going beyond the page limits. In this document, I have most of the time made use of these little macros (not provided by the package:) -\dverb|& +\dverb|@ \def\allowsplits #1% {% \ifx #1\relax \else #1\hskip 0pt plus 1pt\relax @@ -789,48 +689,88 @@ When producing very long numbers there is the question of printing them on %% output) |% An alternative (\autoref{fn:np}) is to suitably configure the thousand separator -with the \href{http://www.ctan.org/pkg/numprint}{numprint} package (does not -work in math mode; I also tried \href{http://www.ctan.org/pkg/siunitx}{siunitx} -but even in text mode could not get it to break numbers accross lines). +with the \href{http://ctan.org/pkg/numprint}{numprint} package (does not work in +math mode; I also tried \href{http://ctan.org/pkg/siunitx}{siunitx} but even in +text mode could not get it to break numbers accross lines). Recently I became +aware of the +\href{http://ctan.org/pkg/seqsplit}{seqsplit} +package\footnote{\url{http://ctan.org/pkg/seqsplit}} +which can be used to achieve this splitting accross lines, and does work +in inline math mode. + +The package \xintname also provides utilities (\autoref{sec:utilsxint}), some +completely expandable, others not, of independent interest. Their use is +illustrated through various examples: among those, it is shown in +\autoref{ssec:quicksort} how to implement in a completely expandable way the +quick sort algorithm and also how to illustrate it graphically. Other examples +include some dynamically constructed alignments with cells giving the prime +numbers (\autoref{ssec:primesI}, \autoref{ssec:primesII}). + +Some other traditional computational examples are \hyperref[ssec:Machin]{the + computations of $\pi$ and $\log 2$} and the computation of the +\hyperlink{e-convergents}{convergents of $e$} with the help of the +\xintcfracname package. + \section{Recent changes} \footnotesize +\noindent Release |1.09e| (|[2013/10/29]|): +\begin{itemize} +\item new \csbxint{integers}, \csbxint{dimensions}, \csbxint{rationals} for + infinite \csbxint{For} loops, interrupted with \csbxint{BreakFor} and + \csbxint{BreakForAndDo}. +\item new \csbxint{ifForFirst}, \csbxint{ifForLast} for the \csa{xintFor} and + \csa{xintFor*} loops, +\item the \csa{xintFor} and \csa{xintFor*} loops are now |\long|, the + replacement text and the items may contain explicit |\par|'s. +\item bug fix, the \csbxint{For} loop (not \csbxint{For*}) did not correctly + detect an + empty list. +\item new conditionals \csbxint{ifCmp}, \csbxint{ifInt}. +\item bug fix, |\xintiSqrt {0}| crashed. |:-((| +\item the documentation has been enriched with various additional examples, + such as the \hyperref[ssec:quicksort]{the quick sort algorithm illustrated} or + the computation of some prime tables (\autoref{ssec:primesI}, + \autoref{ssec:primesII}). +\item the documentation explains with more details various expansion related + issues, particularly in relation to conditionals. +\end{itemize} -\noindent Release |1.09d| (|[2013/10/22]|): +\noindent Release |1.09d| (|[2013/10/22]|):\nobreak \begin{itemize} -\item \csb{xintFor*} is modified to gracefully handle a space token (or +\item \csbxint{For*} is modified to gracefully handle a space token (or more than one) located at the very end of its list argument (as in for example |\xintFor* #1 in {{a}{b}{c}<space>} \do {stuff}|; spaces at other locations were already harmless). Furthermore this new version \fexpan ds the un-braced list items. After |\def\x{{1}{2}}| and |\def\y{{a}\x {b}{c}\x }|, |\y| will appear to -\csb{xintFor*} exactly as if it had been defined as +\csbxint{For*} exactly as if it had been defined as |\def\y{{a}{1}{2}{b}{c}{1}{2}}|. -\item same bug fix in \csb{xintApplyInline}. +\item same bug fix in \csbxint{ApplyInline}. \end{itemize} \noindent Release |1.09c| (|[2013/10/09]|): \begin{itemize} \item added \hyperlink{item:bool}{|bool|} and \hyperlink{item:bool}{|togl|} to the - \csb{xintexpr} syntax; also added \csb{xintboolexpr} and \csb{xintifboolexpr}. -\item added \csb{xintNewNumExpr} and \csb{xintNewBoolExpr}, -\item \csb{xintFor} is a new type of loop, whose replacement text inserts the + \csbxint{expr} syntax; also added \csbxint{boolexpr} and \csbxint{ifboolexpr}. +\item added \csbxint{NewNumExpr} and \csbxint{NewBoolExpr}, +\item \csbxint{For} is a new type of loop, whose replacement text inserts the comma separated values or list items via macro parameters, rather than encapsulated in macros; the loops are nestable up to four levels, and their replacement texts are allowed to close groups as happens with the tabulation in alignments, -\item \csb{xintForpair}, \csb{xintForthree}, \csb{xintForfour} are experimental - variants of \csb{xintFor}, -\item \csb{xintApplyInline} has been enhanced in order to be usable for +\item \csbxint{Forpair}, \csbxint{Forthree}, \csbxint{Forfour} are experimental + variants of \csbxint{For}, +\item \csbxint{ApplyInline} has been enhanced in order to be usable for generating rows (partially or completely) in an alignment, -\item new command \csb{xintSeq} to generate (expandably) arithmetic sequences of +\item new command \csbxint{Seq} to generate (expandably) arithmetic sequences of (short) integers, \item the factorial |!| and branching |?|, |:|, operators (in - \csb{xintexpr}|...\relax|) have now less precedence than a function name + \csbxint{expr}|...\relax|) have now less precedence than a function name located just before: |func(x)!| is the factorial of |func(x)|, not |func(x!)|, \item again various improvements and changes in the documentation. \end{itemize} @@ -841,8 +781,8 @@ version \fexpan ds the un-braced list items. After \item more economical catcode management and re-loading handling, \item removal of all those |[0]|'s previously forcefully added at the end of fractions by various macros of \xintcfracname, -\item \csb{xintNthElt} with a negative index returns from the tail of the list, -\item new macro \csb{xintPRaw} to have something like what |\xintFrac| does in +\item \csbxint{NthElt} with a negative index returns from the tail of the list, +\item new macro \csbxint{PRaw} to have something like what |\xintFrac| does in math mode; i.e. a |\xintRaw| which does not print the denominator if it is one. \end{itemize} @@ -850,8 +790,8 @@ version \fexpan ds the un-braced list items. After \noindent Release |1.09a| (|[2013/09/24]|): \begin{itemize} -\item \csb{xintexpr}|..\relax| and - \csb{xintfloatexpr}|..\relax| admit functions in their +\item \csbxint{expr}|..\relax| and + \csbxint{floatexpr}|..\relax| admit functions in their syntax, with comma separated values as arguments, among them \texttt{reduce, sqr, sqrt, abs, sgn, floor, ceil, quo, rem, round, trunc, float, gcd, lcm, max, min, sum, prd, add, mul, not, all, any, xor}. @@ -864,21 +804,21 @@ version \fexpan ds the un-braced list items. After \y-3^-114\relax}|\hspace{1cm}|\xintthe\z=|\begingroup \def\x{\xintexpr 3^57\relax}\def\y{\xintexpr \x^(-2)\relax}% \def\z{\xintexpr \y-3^-114\relax}\digitstt{\xintthe\z}\endgroup} -\item \csb{xintnumexpr}| .. \relax| is |\xintexpr round( .. ) \relax|. -\item \csb{xintNewExpr} now works with the standard macro parameter character +\item \csbxint{numexpr}| .. \relax| is |\xintexpr round( .. ) \relax|. +\item \csbxint{NewExpr} now works with the standard macro parameter character |#|. \item both regular |\xintexpr|-essions and commands defined by |\xintNewExpr| will work with comma separated lists of expressions, -\item new commands \csb{xintFloor}, \csb{xintCeil}, \csb{xintMaxof}, - \csb{xintMinof} (package \xintfracname), \csb{xintGCDof}, \csb{xintLCM}, - \csb{xintLCMof} (package \xintgcdname), \csb{xintifLt}, \csb{xintifGt}, - \csb{xintifSgn}, \csb{xintANDof}, ... +\item new commands \csbxint{Floor}, \csbxint{Ceil}, \csbxint{Maxof}, + \csbxint{Minof} (package \xintfracname), \csbxint{GCDof}, \csbxint{LCM}, + \csbxint{LCMof} (package \xintgcdname), \csbxint{ifLt}, \csbxint{ifGt}, + \csbxint{ifSgn}, \csbxint{ANDof}, ... \item The arithmetic macros from package \xintname now filter their operands via - \csb{xintNum} which means that they may use directly count registers and + \csbxint{Num} which means that they may use directly count registers and |\numexpr|-essions without having to prefix them by |\the|. This is thus similar to the situation holding previously but with \xintfracname loaded. -\item a bug introduced in |1.08b| made \csb{xintCmp} crash when one of its - arguments was zero. +\item a bug introduced in |1.08b| made \csbxint{Cmp} crash when one of its + arguments was zero. |:-((| \end{itemize} @@ -896,9 +836,9 @@ version \fexpan ds the un-braced list items. After \item Improved efficiency of the basic conversion from exact fractions to floating point numbers, with ensuing speed gains especially for the power function macros - \csb{xintFloatPow} and \csb{xintFloatPower}, -\item Better management by the \xintfracname macros \csb{xintCmp}, - \csb{xintMax}, \csb{xintMin} and \csb{xintGeq} of inputs having big powers + \csbxint{FloatPow} and \csbxint{FloatPower}, +\item Better management by the \xintfracname macros \csbxint{Cmp}, + \csbxint{Max}, \csbxint{Min} and \csbxint{Geq} of inputs having big powers of ten in them. \item Macros for floating point numbers added to the \xintseriesname package. \end{itemize} @@ -906,8 +846,8 @@ version \fexpan ds the un-braced list items. After \noindent Release |1.08| (|[2013/06/07]|): \begin{itemize} \item Extraction of square roots, for floating point numbers - (\csb{xintFloatSqrt}), and also in - a version adapted to integers (\csb{xintiSqrt}). + (\csbxint{FloatSqrt}), and also in + a version adapted to integers (\csbxint{iSqrt}). \item New package \xintbinhexname providing \hyperref[sec:combinhex]{conversion routines} to and from binary and hexadecimal bases. \end{itemize} @@ -915,20 +855,30 @@ version \fexpan ds the un-braced list items. After \noindent Release |1.07| (|[2013/05/25)]|): \begin{itemize} \item The \xintfracname macros accept numbers written in scientific notation, - the \csb{xintFloat} command serves to output its argument with a given number + the \csbxint{Float} command serves to output its argument with a given number |D| of significant figures. The value of |D| is either given as optional - argument to \csb{xintFloat} or set with |\xintDigits := D;|. The default value + argument to \csbxint{Float} or set with |\xintDigits := D;|. The default value is |16|. \item The \xintexprname package is a new core constituent (which loads automatically \xintfracname and \xintname) and implements the expandable - expanding parsers \centeredline{\csb{xintexpr}| . . . \relax|, + expanding parsers \centeredline{\csbxint{expr}| . . . \relax|, and its variant - \csb{xintfloatexpr}| . . . \relax|} allowing on input formulas using the + \csbxint{floatexpr}| . . . \relax|} allowing on input formulas using the standard form with infix operators |+|, |-|, |*|, |/|, and |^|, and arbitrary levels of parenthesizing. Within a float expression the operations are executed - according to the current value of \csb{xintDigits}. Within an + according to the current value of \csbxint{Digits}. Within an |\xintexpr|-ession the binary operators are computed exactly. +\item The floating point precision |D| is set (this is a +local assignment to a |\mathchar| variable) with |\xintDigits := D;| and queried +with |\xinttheDigits|. It may be set to anything up to |32767|.\footnote{but + values higher than 100 or 200 will presumably give too slow evaluations.} The +macro incarnations of the binary operations admit an optional argument which +will replace pointwise |D|; this argument may exceed the |32767| bound. +\item To write the |\xintexpr| parser I benefited from the commented source of + the +\LaTeX3 parser; the |\xintexpr| parser has its own features and peculiarities. +See \hyperref[sec:comexpr]{its documentation}. \end{itemize} % The |\xintexpr..\relax| and |\xintfloatexpr..\relax| are usable as @@ -936,16 +886,7 @@ version \fexpan ds the un-braced list items. After % and % |\xintthefloatexpr|, or equivalently |\xintthe\xintexpr| and % |\xintthe\xintfloatexpr|. -The floating point precision |D| is set (this is a -local assignment to a |\mathchar| variable) with |\xintDigits := D;| and queried -with |\xinttheDigits|. It may be set to anything up to |32767|.\footnote{but - values higher than 100 or 200 will presumably give too slow evaluations.} The -macro incarnations of the binary operations admit an optional argument which -will replace pointwise |D|; this argument may exceed the |32767| bound. -To write the |\xintexpr| parser I benefited from the commented source of the -\LaTeX3 parser; the |\xintexpr| parser has its own features and peculiarities. -See \hyperref[sec:comexpr]{its documentation}. \noindent Release |1.0| (|[2013/03/28]|): initial release. @@ -976,7 +917,7 @@ The main characteristics are: the true limitation is from the \emph{time} taken by the expansion-compatible algorithms, this will be commented upon soon. -As just recalled, ten-digits numbers starting with a &3& already exceed the +As just recalled, ten-digits numbers starting with a @3@ already exceed the \TeX{} bound on integers; and \TeX{} does not have a native processing of floating point numbers (multiplication by a decimal number of a dimension register is allowed --- this is used for example by the @@ -1062,6 +1003,7 @@ function with integer exponent, and the extraction of square-roots. \section{The \csh{xintexpr} math parser (I)} \label{sec:exprsummary} +% 27 octobre 2013 plus de problème avec &... il n'est plus actif (ouf) \xintexprSafeCatcodes \newcommand\formula[3]{\xinttheexpr round((#1 & (#2 | #3)) * (355/113*#3 - (#1 - #2/2)^2), 8)\relax } @@ -1076,12 +1018,12 @@ Here is some random formula, defining a \LaTeX{} command with three parameters, \smallskip Let |a=#1|, |b=#2|, |c=#3| be the parameters. The first term is the logical -operation |a and (b or c)| where a number or fraction has truth value &1& if it -is non-zero, and &0& otherwise. So here it means that |a| must be non-zero as -well as |b| or |c|, for this first operand to be &1&, else the formula returns -&0&. This multiplies a second term which is algebraic. Finally the result (where +operation |a and (b or c)| where a number or fraction has truth value @1@ if it +is non-zero, and @0@ otherwise. So here it means that |a| must be non-zero as +well as |b| or |c|, for this first operand to be @1@, else the formula returns +@0@. This multiplies a second term which is algebraic. Finally the result (where all intermediate computations are done \emph{exactly}) is rounded to a value -with &8& digits after the decimal mark, and printed. +with @8@ digits after the decimal mark, and printed. \centeredline{|\formula {771.3/9.1}{1.51e2}{37.73} expands to| \digitstt{\formula {771.3/9.1}{1.51e2}{37.73}}} @@ -1097,8 +1039,8 @@ with &8& digits after the decimal mark, and printed. |infix| syntax, should not be active (for example if they serve as shorthands for some language in the |Babel| system) at the time of the expressions (if they are in use therein). The command - \csb{xintexprSafeCatcodes} resets these characters to their standard catcodes - and \csb{xintexprRestoreCatcodes} restores the status prevailing at the time + \csbxint{exprSafeCatcodes} resets these characters to their standard catcodes + and \csbxint{exprRestoreCatcodes} restores the status prevailing at the time of the previous \csa{xintexprSafeCatcodes}. \item the formula may be input without |\xinttheexpr| through suitable nesting of various @@ -1110,7 +1052,7 @@ with &8& digits after the decimal mark, and printed. with the inherent difficulty of keeping up with braces and everything... \item if such a formula is used thousands of times in a document (for plots?), this could impact some parts of the \TeX{} program memory (for technical - reasons explained in \autoref{sec:comexpr}). So, a utility \csb{xintNewExpr} + reasons explained in \autoref{sec:comexpr}). So, a utility \csbxint{NewExpr} is provided to do the work of translating an |\xintexpr|-ession with parameters into a chain of macro evaluations.\footnote{As its makes some macro definitions, it is not an expandable command. It does not need protection @@ -1142,7 +1084,7 @@ has no memory impact. of \xintfracname). \item like a |\numexpr|, an |\xintexpr| is not directly printable, one - uses equivalently |\xintthe\xintexpr| or \csb{xinttheexpr}. One may + uses equivalently |\xintthe\xintexpr| or \csbxint{theexpr}. One may for example define: \centeredline{|\def\x {\xintexpr \a + \b \relax} \def\y {\xintexpr \x * \a \relax}|} where |\x| could have been set up equivalently as {|\def\x {( \a + \b )}|} but the earlier method is @@ -1150,20 +1092,20 @@ has no memory impact. \item sometimes one needs an integer, not a fraction or decimal number. The |round| function rounds to the nearest integer (half-integers are rounded towards $\pm\infty$), and |\xintexpr round(...)\relax| has an alternative - syntax as \csb{xintnumexpr}| ... \relax|. There is also - \csb{xintthenumexpr}. The + syntax as \csbxint{numexpr}| ... \relax|. There is also + \csbxint{thenumexpr}. The rounding is applied to the final result only. -\item there is also \csb{xintboolexpr}| ... \relax| and \csb{xinttheboolexpr}| +\item there is also \csbxint{boolexpr}| ... \relax| and \csbxint{theboolexpr}| ... \relax|. Same as regular expression but the final result is converted to - &1& - if it is not zero. See also \csb{xintifboolexpr} + @1@ + if it is not zero. See also \csbxint{ifboolexpr} (\autoref{xintifboolexpr}) and the \hyperlink{item:bool}{discussion} of the |bool| and |togl| functions in \autoref{sec:exprsummary}. Here is an example of use: \xintNewBoolExpr \AssertionA[3]{ #1 & (#2|#3) } \xintNewBoolExpr \AssertionB[3]{ #1 | (#2) } \xintNewBoolExpr \AssertionC[3]{ xor(#1,#2,#3) } -\centeredline{\catcode`& 4 \begin{tabular}{ccc} +\centeredline{\begin{tabular}{ccc} \xintFor #1 in {0,1} \do {% \xintFor #2 in {0,1} \do {% \xintFor #3 in {0,1} \do {% @@ -1173,9 +1115,8 @@ has no memory impact. \end{tabular}} This was obtained with the following input: \begingroup -\def\MacroFont {\ttfamily\parskip0pt \parindent 15pt \baselineskip 12pt - \catcode`& 12 \catcode`+ 14 } -\dverb!+ +\def\MacroFont {\ttfamily\parskip0pt \parindent 15pt \baselineskip 12pt } +\dverb!@ \xintNewBoolExpr \AssertionA[3]{ #1 & (#2|#3) } \xintNewBoolExpr \AssertionB[3]{ #1 | (#2) } \xintNewBoolExpr \AssertionC[3]{ xor(#1,#2,#3) } @@ -1186,15 +1127,13 @@ This was obtained with the following input: #1 AND (#2 OR #3) is \AssertionA {#1}{#2}{#3}& #1 OR (#2 AND #3) is \AssertionB {#1}{#2}{#3}& #1 XOR #2 XOR #3 is \AssertionC {#1}{#2}{#3}\\ }}} -\end{tabular} -!% +\end{tabular}!% \endgroup - -\item there is also \csb{xintfloatexpr}| ... \relax| where the algebra is done +\item there is also \csbxint{floatexpr}| ... \relax| where the algebra is done in floating point approximation (also for each intermediate result). Use the syntax - |\xintDigits:=N;| to set the precision. Default: &16& digits. + |\xintDigits:=N;| to set the precision. Default: @16@ digits. \centeredline{|\xintthefloatexpr 2^100000\relax:| \digitstt{\xintthefloatexpr 2^100000\relax }} The square-root operation can be used in |\xintexpr|, it is computed as a float with the precision set by |\xintDigits| or by the @@ -1229,7 +1168,7 @@ Note that |2^-10| is perfectly accepted input, no need for parentheses. And |-2^-10^-5*3| does |(-((2^(-10))^(-5)))*3|. The characters used in the syntax should not have been made active. Use -\csb{xintexprSafeCatcodes}, \csb{xintexprRestoreCatcodes} if need be (these +\csbxint{exprSafeCatcodes}, \csbxint{exprRestoreCatcodes} if need be (these commands must be exercised out of expansion only context). Apart from that infix operators may be of catcode letter or other, it does not matter, or even of catcode tabulation, math superscript, or math subscript. This should cause no @@ -1238,8 +1177,8 @@ inside the expression. The |A/B[N]| notation is the output format of most \xintfracname macros,\footnote{this format is convenient for nesting macros; when displaying - the final result of a computation one has \csb{xintFrac} in math mode, or - \csb{xintIrr} and also \csb{xintPRaw} for inline text mode.} but for user input in an |\xintexpr..\relax| such + the final result of a computation one has \csbxint{Frac} in math mode, or + \csbxint{Irr} and also \csbxint{PRaw} for inline text mode.} but for user input in an |\xintexpr..\relax| such a fraction should be written with the scientific notation |AeN/B| (possibly within parentheses) or \emph{braces} must be used: |{A/B[N]}|. The square brackets are \emph{not parsable} if not enclosed in braces together with the fraction. @@ -1300,13 +1239,13 @@ The |\relax| at the end of an expression is absolutely \emph{mandatory}. \item[functions with one (numeric) argument] \ctexttt{floor, ceil, reduce, sqr, abs, sgn, ?, !, not}. The |?(x)| function returns - the truth value, &1& if |x<>0|, &0& if |x=0|. The |!(x)| is the logical + the truth value, @1@ if |x<>0|, @0@ if |x=0|. The |!(x)| is the logical not. The |reduce| function puts the fraction in irreducible form. \item[functions with one named argument] \hypertarget{item:bool} {\ctexttt{bool,togl}}. - |bool(name)| returns &1& if the \TeX{} conditional |\ifname| would - act as |\iftrue| and &0& otherwise. This works with conditionals + |bool(name)| returns @1@ if the \TeX{} conditional |\ifname| would + act as |\iftrue| and @0@ otherwise. This works with conditionals defined by |\newif| (in \TeX{} or \LaTeX{}) or with primitive conditionals such as |\ifmmode|. For example: \centeredline{|\xintifboolexpr{25*4-if(bool(mmode),100,75)}{YES}{NO}|} @@ -1314,7 +1253,7 @@ The |\relax| at the end of an expression is absolutely \emph{mandatory}. if executed in math mode (the computation is then $100-100=0$) and \xintifboolexpr{25*4-if(bool(mmode),100,75)}{YES}{NO} if not (the \ctexttt{if} conditional is described below; the - \csb{xintifboolexpr} test automatically encapsulates its first + \csbxint{ifboolexpr} test automatically encapsulates its first argument in an |\xintexpr| and follows the first branch if the result is non-zero (see \autoref{xintifboolexpr})). @@ -1326,7 +1265,7 @@ The |\relax| at the end of an expression is absolutely \emph{mandatory}. |ifsgn| (see also |?| and |:|), which allow arbitrarily complicated combinations of various |bool(name)|. - Similarly |togl(name)| returns &1& + Similarly |togl(name)| returns @1@ if the \LaTeX{} package \href{http://www.ctan.org/pkg/etoolbox}{etoolbox}\footnote{\url{http://www.ctan.org/pkg/etoolbox}} has been used to define a toggle named |name|, and this toggle is @@ -1359,11 +1298,11 @@ The |\relax| at the end of an expression is absolutely \emph{mandatory}. efficiently, the point of |\ifsometest10| is to allow arbitrary boolean combinations using the (described later) \verb+&+ and \verb+|+ logic operators: - \verb+\ifsometest10 & \ifsomeothertest10 | \ifsomethirdtest10+, etc... of - course |YES| or |NO| above stand for material compatible with the + \verb+\ifsometest10 & \ifsomeothertest10 | \ifsomethirdtest10+, etc... |YES| + or |NO| above stand for material compatible with the |\xintexpr| parser syntax. - See also \csb{xintifboolexpr}, in this context. + See also \csbxint{ifboolexpr}, in this context. \item[functions with one mandatory and a second optional argument] \ctexttt{round, trunc,\\ float, sqrt}. For example |round(2^9/3^5,12)=|\digitstt{\xinttheexpr round(2^9/3^5,12)\relax.} @@ -1455,25 +1394,25 @@ of the \xintexprname package. % There is also \xintcfracname for continued fractions computations. -{\color{magenta}&123456^99&: }\\ +{\color{magenta}@123456^99@: }\\ {\color[named]{Purple}\csa{xintiPow}|{123456}{99}|}: \digitstt{\printnumber{\xintiPow {123456}{99}}} {\color{magenta}1234/56789 with 1500 digits after the decimal point: }\\ {\color[named]{Purple}\csa{xintTrunc}|{1500}{1234/56789}\dots|}: \digitstt{\printnumber {\xintTrunc {1500}{1234/56789}}\dots } -{\color{magenta}&0.99^{-100}& with 200 digits after the decimal point:}\\ -{\color[named]{Purple}\csa{xintTrunc}|{200}{\xinttheexpr .99^-100\relax}\dots|}: -\digitstt{\printnumber{\xintTrunc {200}{\xinttheexpr .99^-100\relax}}\dots } +{\color{magenta}@0.99^{-100}@ with 200 digits after the decimal point:}\\ +{\color[named]{Purple}\csa{xinttheexpr trunc}|(.99^-100,200)\relax\dots|}: +\digitstt{\printnumber{\xinttheexpr trunc(.99^-100,200)\relax}\dots } {\color{magenta}Computation of a Bezout identity with |7^200-3^200| and |2^200-1|:}\\ {\color[named]{Purple}|\xintAssign\xintBezout|\\ -\hspace*{2cm}|{\xintNum{\xinttheexpr 7^200-3^200\relax}}|\\ -\hspace*{2cm}|{\xintNum{\xinttheexpr 2^200-1\relax}}\to\A\B\U\V\D|% +\hspace*{2cm}|{\xintthenumexpr 7^200-3^200\relax}|\\ +\hspace*{2cm}|{\xintthenumexpr 2^200-1\relax}\to\A\B\U\V\D|% \centeredline{|\U$\times$(7^200-3^200)+\xintiOpp\V$\times$(2^200-1)=\D|}}% -\xintAssign\xintBezout {\xintNum{\xinttheexpr 7^200-3^200\relax}}{\xintNum{\xinttheexpr 2^200-1\relax}}\to\A\B\U\V\D -\digitstt{\printnumber\U$\times$(&7^200-3^200&)+\printnumber{\xintiOpp\V}$\times$(&2^200-1&)=\printnumber\D } +\xintAssign\xintBezout {\xintthenumexpr 7^200-3^200\relax}{\xintthenumexpr 2^200-1\relax}\to\A\B\U\V\D +\digitstt{\printnumber\U$\times$(@7^200-3^200@)+\printnumber{\xintiOpp\V}$\times$(@2^200-1@)=\printnumber\D } {\color{magenta}The Euclide algorithm applied to \np{179876541573} and \np{66172838904}:}\footnote{this example is computed tremendously faster than @@ -1507,9 +1446,9 @@ than the one above) \xintseriesname to evaluate the sum with \np{100000} terms, obtaining 16 correct decimal digits for the complete sum. The coefficient macro must be redefined to avoid a |\numexpr| overflow, as -|\numexpr| inputs must not exceed &2^31-1&; my choice +|\numexpr| inputs must not exceed @2^31-1@; my choice was: -{\color[named]{Purple}\dverb|& +{\color[named]{Purple}\dverb|@ \def\coeff #1% {\xintiRound {22}{1/\xintiSqr{\xintiMul{\the\numexpr 2*#1-3\relax} {\the\numexpr 2*#1+3\relax}}[0]}} @@ -1540,7 +1479,7 @@ compilation time. Package |bigintcalc| by \textsc{Heiko Oberdiek} already provides expandable arithmetic operations on ``big integers'', -exceeding the \TeX{} limits (of &2^{31}-1&), so why another\footnote{this section was written before the +exceeding the \TeX{} limits (of @2^{31}-1@), so why another\footnote{this section was written before the \xintfracname package; the author is not aware of another package allowing expandable computations with arbitrarily big fractions.} one? @@ -1595,7 +1534,23 @@ process to expand repeatedly the first token seen until hitting against something not further expandable like an unexpandable \TeX-primitive or an opening brace |{| or a (un-active) character. The type of expansion done almost systematically by the package macros to their arguments is - usually the \fexpan sion. However, when the argument is of a type a + usually the \fexpan sion. + + Thus the arguments \emph{must} expand to their complete expansion via an + \fexpan sion.\footnote{\label{fn:expansions}this is particularly important + when one tries to insert \csa{if}|...|\csa{fi}'s inside such arguments; + suitable \csa{expandafter}'s or swapping techniques must be used else the + expansion from a \csa{romannumeral-`0} will not absorb the \csa{else} or + closing \csa{fi}. Therefore it is highly recommended to use the package + provided conditionals such as \csbxint{ifEq}, or, for \LaTeX{} users and + when dealing with short integers the + \href{http://ctan.org/pkg/etoolbox}{etoolbox} expandable conditionals. Use + of non expandable things such as \csa{ifthenelse} is impossible inside the + argument of \xintname macros.} The main exception is inside + |\xintexpr...\relax| where everything is expanded from left to right, + completely. + +However, when the argument is of a type a priori restricted to obey the \TeX{} bound of \digitstt{\number"7FFFFFFF} (in absolute value), then it is fed into a |\numexpr..\relax| and the expansion will be a complete one, not @@ -1603,14 +1558,14 @@ an opening brace |{| or a (un-active) character. The type of expansion As an example of chaining package macros, let us consider the following code snippet with in a file with filename |myfile|: -\dverb|& +\dverb|@ \newwrite\outfile \immediate\openout\outfile \jobname-out\relax \immediate\write\outfile {\xintQuo{\xintPow{2}{1000}}{\xintFac{100}}} % \immediate\closeout\outfile |% The tex run creates a file |myfile-out.tex| -containing the decimal representation of the integer quotient &2^{1000}/100!&. +containing the decimal representation of the integer quotient @2^{1000}/100!@. \edef\x{\xintQuo{\xintPow {2}{1000}}{\xintFac{100}}} \edef\y{\xintLen{\x}} @@ -1618,13 +1573,13 @@ containing the decimal representation of the integer quotient &2^{1000}/100!&. \centeredline{% |\xintLen{\xintQuo{\xintPow{2}{1000}}{\xintFac{100}}}|} \noindent expands (in two steps) -and tells us that &[2^{1000}/100!]& has {\y} digits. This is not so many, let us +and tells us that @[2^{1000}/100!]@ has {\y} digits. This is not so many, let us print them here: \digitstt{\printnumber\x}. For the sake of typesetting this documentation and not have big numbers extend into the margin and go beyond the page physical limits, I use these commands (not provided by the package): -\dverb|& +\dverb|@ \def\allowsplits #1{\ifx #1\relax \else #1\hskip 0pt plus 1pt \relax \expandafter\allowsplits\fi}% \def\printnumber #1{\expandafter\expandafter\expandafter @@ -1651,15 +1606,15 @@ or as Just to show off, let's print 300 digits (after the decimal point) of -the decimal expansion of &0.7^{-25}&:\footnote{the |\string\np| typesetting +the decimal expansion of @0.7^{-25}@:\footnote{the |\string\np| typesetting macro is from the |numprint| package.} \centeredline{|\np {\xinttheexpr trunc(.7^-25,300)\relax}\dots|} \digitstt{\np {\xinttheexpr trunc(.7^-25,300)\relax}\dots } -This computation uses the macro \csb{xintTrunc} from package \xintfracname +This computation uses the macro \csbxint{Trunc} from package \xintfracname wich extends to fractions the basic arithmetic operations defined for -integers by \xintname. It also uses \csb{xinttheexpr} from package +integers by \xintname. It also uses \csbxint{theexpr} from package \xintexprname, which allows to use standard notations. Note that the fraction |.7^-25| is first evaluated exactly; for some more complex inputs, such as |.7123045678952^-243|, the exact evaluation before truncation would @@ -1691,19 +1646,19 @@ Important points, to be noted, related to the expansion of arguments: exceeds the \TeX{} bounds. \begingroup\slshape - With \csb{xinttheexpr} one could write |\xinttheexpr \x+\x\y\relax|, or + With \csbxint{theexpr} one could write |\xinttheexpr \x+\x\y\relax|, or |\xintAdd\x{\xinttheexpr\x\y\relax}|.\hfill \endgroup \item Unfortunately, after |\def\x {12}|, one can not use just {\color{blue}|-\x|} as input to one of the package macros: the rules above explain that the expansion will act only on the minus sign, - hence do nothing. The only way is to use the \csb{xintOpp} + hence do nothing. The only way is to use the \csbxint{Opp} macro, which replaces a number with its opposite. \begingroup\slshape - Again, this is otherwise inside an \csb{xinttheexpr}-ession or - \csb{xintthefloatexpr}-ession. There, the + Again, this is otherwise inside an \csbxint{theexpr}-ession or + \csbxint{thefloatexpr}-ession. There, the minus sign may prefix macros which will expand to numbers (or parentheses etc...) \endgroup @@ -1757,7 +1712,7 @@ steps only, there is no reason to follow these guidelines. Just chain arbitrarily the package macros, and the new ones will be completely expandable and usable one within the other. -Release |1.07| has the \csb{xintNewExpr} command which automatizes the creation +Release |1.07| has the \csbxint{NewExpr} command which automatizes the creation of such expandable macros: \centeredline{|\xintNewExpr\AplusBC[3]{#1+#2*#3}|} creates the |\AplusBC| macro doing the above and expanding in two expansion steps. @@ -1767,12 +1722,12 @@ macro doing the above and expanding in two expansion steps. The core bundle constituents are \xintname, \xintfracname, \xintexprname, each one loading its predecessor. The base constituent \xintname only deals -with integers, of arbitrary sizes, and apart from its macro \csb{xintNum}, +with integers, of arbitrary sizes, and apart from its macro \csbxint{Num}, the input format is rather strict. \begin{framed} With release |1.09a|, arithmetic macros of \xintname parse their arguments - automatically through \csb{xintNum}. This means also that the arguments may + automatically through \csbxint{Num}. This means also that the arguments may already contain infix algebra with count registers, see \hyperlink{useofcount}{Use of count registers}. \end{framed} @@ -1847,7 +1802,7 @@ The allowed input formats for `long numbers' and `fractions' are: \item the strict format is for some macros of \xintname. The number should be a string of digits, optionally preceded by a unique minus sign. The first digit can be zero only if the number is zero. A plus sign is not accepted. - There is a macro \csb{xintNum} which normalizes to this form an input having + There is a macro \csbxint{Num} which normalizes to this form an input having arbitrarily many minus and plus signs, followed by a string of zeros, then digits:\centeredline{|\xintNum {+-+-+----++-++----00000000009876543210}|\digitstt{=\xintNum @@ -1856,11 +1811,11 @@ The allowed input formats for `long numbers' and `fractions' are: \csa{xintNum} which even accepts an empty input). \item the extended integer format is for the arithmetic macros of \xintname which - automatically parse their arguments via \csb{xintNum}, and for the fractions + automatically parse their arguments via \csbxint{Num}, and for the fractions serving as input to the macros of \xintfracname: they are (or expand to) |A/B| (or just an integer |A|), where |A| and |B| will be - automatically given to \csb{xintNum}. + automatically given to \csbxint{Num}. Each of |A| and |B| may be decimal numbers: with a decimal point and digits following it. Here is an example: \centeredline{|\xintAdd {+--0367.8920280/-++278.289287}{-109.2882/+270.12898}|}% @@ -1871,20 +1826,20 @@ The allowed input formats for `long numbers' and `fractions' are: |\xintTrunc {50}| to get fifty digits of the decimal expansion following the decimal mark. Scientific notation is accepted on input both for the numerators and denominators of fractions, and is produced - on output by \csb{xintFloat}: \centeredline{|\xintAdd{10.1e1}{101.010e3}|% + on output by \csbxint{Float}: \centeredline{|\xintAdd{10.1e1}{101.010e3}|% \digitstt{=\xintAdd{10.1e1}{101.010e3}}}% This last example shows that fractions with a denominator equal to one, are -generally printed as fraction. In math mode \csb{xintFrac} will remove such -dummy denominators, and in inline text mode one has \csb{xintPRaw}. +generally printed as fraction. In math mode \csbxint{Frac} will remove such +dummy denominators, and in inline text mode one has \csbxint{PRaw}. \centeredline{|\xintPRaw{\xintAdd{10.1e1}{101.010e3}}|% \digitstt{=\xintPRaw{\xintAdd{10.1e1}{101.010e3}}}} \centeredline{|\xintRaw{1.234e5/6.789e3}|\digitstt{=\xintRaw{1.234e5/6.789e3}}}% \centeredline{|\xintFloat[24]{1/66049}|\digitstt{=\xintFloat[24]{1/66049}}} \end{enumerate} -Of course, even with \xintfracname is loaded, some macros by their nature can +Even with \xintfracname is loaded, some macros by their nature can not accept fractions on input. Starting with release |1.05| most of them have also been extended to accept a fraction actually reducing to an integer. For example it used to be the case with the earlier releases that |\xintQuo -{100/2}{12/3}| would not work (the macro \csb{xintQuo} computes a euclidean +{100/2}{12/3}| would not work (the macro \csbxint{Quo} computes a euclidean quotient). It now does, because its arguments are, after simplification, integers. @@ -1920,14 +1875,21 @@ applies in particular to the number of digits to truncate or round with, to the indices of a series partial sum, \dots The macros dealing with long numbers/fractions for arithmetic operations allow -the use of count registers and even infix algebra with them inside their -arguments: a count register |\mycountA| or |\count 255| is admissible as -numerator or also as denominator, with no need to be prefixed by |\the| or -|\number|. It is possible to have as argument an algebraic expression as would -be acceptable by a |\numexpr...\relax|, under this condition: \emph{each of the - numerator and denominator is expressed with at most \emph{eight} tokens}. The -fraction symbol should be protected by braces else it will be used inside the -|\numexpr| which does a rounded division. Example: +\emph{to some extent} the use of count registers and even infix algebra with +them inside their arguments: a count register |\mycountA| or |\count 255| is +admissible as numerator or also as denominator, with no need to be prefixed by +|\the| or |\number|. It is possible to have as argument an algebraic +expression as would be acceptable by a |\numexpr...\relax|, under this +condition: \emph{each of the numerator and denominator is expressed with at + most \emph{eight} tokens}.\footnote{Attention! there is no problem with a + \LaTeX{} \csa{value}\texttt{\{countername\}} if if comes first, but if it + comes later in the input it will not get expanded, and braces around the + name will be removed and chaos\IMPORTANT{} will ensues inside a + \csa{numexpr}. One should enclose the whole input in + \csa{the}\csa{numexpr}|...|\csa{relax} in such cases.} The slash for rounded +division in a |\numexpr| should be written with braces |{/}| to not be +confused with the \xintfracname delimiter between numerator and denominator +(braces will be removed internally). Example: |\mycountA+\mycountB{/}17/1+\mycountA*\mycountB|, or |\count 0+\count 2{/}17/1+\count 0*\count 2|, but in the latter case the numerator has the maximal allowed number of tokens (the braced slash counts for only one). @@ -1939,7 +1901,7 @@ count registers, there are two possibilities: \item encompass each of the numerator and denominator in |\the\numexpr...\relax|, \item encompass each of the numerator and denominator in |\numexpr {...}\relax|. \end{enumerate} -\dverb|& +\dverb|@ \cnta 100 \cntb 10 \cntc 1 \xintPRaw {\numexpr {\cnta*\cnta+\cntb*\cntb+\cntc*\cntc+ 2*\cnta*\cntb+2*\cnta*\cntc+2*\cntb*\cntc}\relax/% @@ -1958,17 +1920,18 @@ The braces would not be accepted \paragraph {Outputs: } loading \xintfracname not only relaxes the format of the inputs; it also modifies the format of the outputs: except when a - fraction is filtered on output by \csb{xintIrr} or \csb{xintRawWithZeros}, - or \csb{xintPRaw}, or by the truncation or rounding macros, or is given as - argument in math mode to \csb{xintFrac}, the output format is normally of + fraction is filtered on output by \csbxint{Irr} or \csbxint{RawWithZeros}, + or \csbxint{PRaw}, or by the truncation or rounding macros, or is given as + argument in math mode to \csbxint{Frac}, the output format is normally of the \fbox{|A/B[n]|} form (which stands for |(A/B)|$\times$|10^n|). The |A| and |B| may end in zeros (\emph{i.e}, |n| does not represent all powers of ten), and will generally have a common factor. The denominator |B| is always strictly positive. -A macro \csb{xintFrac} is provided -for the typesetting (math-mode only) of such a `raw' output. Of course, the -\csb{xintFrac} itself is not accepted as input to the package macros. +A macro \csbxint{Frac} is provided +for the typesetting (math-mode only) of such a `raw' output. The command +\csbxint{Frac} is not accepted as input to the package macros, it is for +typesetting only (in math mode). Direct user input of things such as |16000/289072[17]| or |3[-4]| is authorized. It is even possible to use |\A/\B[17]| if |\A| expands to |16000| and |\B| to @@ -2010,8 +1973,8 @@ harmless, and even recommended for making the source more legible. Syntax such as |\xintMul\A\B| is accepted and equivalent\footnote{see however near the end of \hyperref[sec:ifcase]{this later section} for the important difference when used in contexts where \TeX{} expects a number, such as - following an \csa{ifcase} or an \csa{ifnum}.} to |\xintMul {\A}{\B}|. Or -course |\xintAdd\xintMul\A\B\C| does not work, the product operation must be put + following an \csa{ifcase} or an \csa{ifnum}.} to |\xintMul {\A}{\B}|. The +input |\xintAdd\xintMul\A\B\C| does not work, the product operation must be put within braces: |\xintAdd{\xintMul\A\B}\C|. It would be nice to have a functional form |\add(x,\mul(y,z))| but this is not provided by the package.\footnote{yes it is with the |1.09a| \csa{xintexpr}, \csa{xintexpr} @@ -2025,22 +1988,22 @@ numbers. They can not serve to prefix macros evaluating to such numbers, \section{More on fractions} -With package \xintfracname loaded, the routines \csb{xintAdd}, \csb{xintSub}, -\csb{xintMul}, \csb{xintPow}, \csb{xintSum}, \csb{xintPrd} are modified to allow -fractions on input,\footnote{of course, the power function does not accept a +With package \xintfracname loaded, the routines \csbxint{Add}, \csbxint{Sub}, +\csbxint{Mul}, \csbxint{Pow}, \csbxint{Sum}, \csbxint{Prd} are modified to allow +fractions on input,\footnote{the power function does not accept a fractional exponent. Or rather, does not expect, and errors will result if one - is provided.}\,\footnote{macros \csb{xintiAdd}, \csb{xintiSub}, - \csb{xintiMul}, \csb{xintiPow}, \csb{xintiSum}, \csb{xintiPrd} are the + is provided.}\,\footnote{macros \csbxint{iAdd}, \csbxint{iSub}, + \csbxint{iMul}, \csbxint{iPow}, \csbxint{iSum}, \csbxint{iPrd} are the original ones dealing only with integers. They are available as synonyms, also - when \xintfracname is not loaded. }\,\footnote{also \csb{xintCmp}, - \csb{xintSgn}, \csb{xintOpp}, \csb{xintAbs}, \csb{xintMax}, \csb{xintMin} are + when \xintfracname is not loaded. }\,\footnote{also \csbxint{Cmp}, + \csbxint{Sgn}, \csbxint{Opp}, \csbxint{Abs}, \csbxint{Max}, \csbxint{Min} are extended to fractions and have their integer-only initial - synonyms.}\,\footnote{and \csb{xintFac}, \csb{xintQuo}, \csb{xintRem}, - \csb{xintDivision}, \csb{xintGeq}, \csb{xintFDg}, \csb{xintLDg}, - \csb{xintOdd}, \csb{xintMON}, \csb{xintMMON} all accept a fractional input as + synonyms.}\,\footnote{and \csbxint{Fac}, \csbxint{Quo}, \csbxint{Rem}, + \csbxint{Division}, \csbxint{Geq}, \csbxint{FDg}, \csbxint{LDg}, + \csbxint{Odd}, \csbxint{MON}, \csbxint{MMON} all accept a fractional input as long as it reduces to an integer.} and produce on output a fractional number |f=A/B[n]| where |A| and |B| are integers, with |B| positive, and |n| is a -signed ``small'' integer (\emph{i.e} less in absolute value than |2^{31}-9|). +``short'' integer (\emph{i.e} less in absolute value than |2^{31}-9|). This represents |(A/B)| times |10^n|. The fraction |f| may be, and generally is, reducible, and |A| and |B| may well end up with zeros (\emph{i.e.} |n| does not contain all powers of 10). Conversely, this format is accepted on input (and is @@ -2049,30 +2012,30 @@ number without denominator).\footnote{at each stage of the computations, the sum of |n| and the length of |A|, or of the absolute value of |n| and the length of |B|, must be kept less than |2\string^\string{31\string}-9|.} -The \csb{xintiAdd}, \csb{xintiSub}, \csb{xintiMul}, \csb{xintiPow}, -\csb{xintiSum}, \csb{xintiPrd}, etc... are the +The \csbxint{iAdd}, \csbxint{iSub}, \csbxint{iMul}, \csbxint{iPow}, +\csbxint{iSum}, \csbxint{iPrd}, etc... are the original\MyMarginNote{\digitstt{1.09a}: the original now also use \csa{xintNum}} un-modified integer-only versions. They have less parsing overhead. -The macro \csb{xintRaw} prints the fraction +The macro \csbxint{Raw} prints the fraction directly from its internal representation in |A/B[n]| form. To convert the trailing |[n]| into explicit zeros either at the numerator or the -denominator, use \csb{xintRawWithZeros}. In both cases the |B| is printed -even if it has value |1|. The macro \csb{xintPRaw} will not print the |[n]| if +denominator, use \csbxint{RawWithZeros}. In both cases the |B| is printed +even if it has value |1|. The macro \csbxint{PRaw} will not print the |[n]| if |n=0| and will not print the |/B| if |B=1|. -Conversely (sort of), the macro \csb{xintREZ} +Conversely (sort of), the macro \csbxint{REZ} puts all powers of ten into the |[n]| (REZ stands for remove zeros). Here also, the |B| is printed even if it has value |1|. -The macro \csb{xintIrr} reduces the fraction to its irreducible form |C/D| +The macro \csbxint{Irr} reduces the fraction to its irreducible form |C/D| (without a trailing |[0]|), and it prints the |D| even if |D=1|. -The macro \csb{xintNum} from package \xintname is extended: it now does like +The macro \csbxint{Num} from package \xintname is extended: it now does like \csa{xintIrr}, raises an error if the fraction did not reduce to an integer, and outputs the numerator. This macro should be used when one knows that necessarily the result of a computation is an @@ -2080,11 +2043,11 @@ integer, and one wants to get rid of its denominator |/1| which would be left by \csa{xintIrr}. -The macro \csb{xintTrunc}|{N}{f}| prints\footnote{`prints' does not at all mean +The macro \csbxint{Trunc}|{N}{f}| prints\footnote{`prints' does not at all mean that this macro is designed for typesetting; I am just using the verb here in analogy to the effect of the functioning of a computing software in console mode. The package does not provide any `printing' facility, besides its - rudimentary \csb{xintFrac} and \csb{xintFwOver} math-mode only macros. To deal + rudimentary \csbxint{Frac} and \csbxint{FwOver} math-mode only macros. To deal with really long numbers, some macros are necessary as \TeX{} by default will print a long number on a single line extending beyond the page limits. The \csa{printnumber} command used in this documentation is just one way to @@ -2107,7 +2070,7 @@ In that case the output is |0|, with no decimal point. \centeredline{|\xintTrunc \edef\z {\xintPow {1.01}{100}} -The macro \csb{xintiTrunc}|{N}{f}| is like \csa{xintTrunc}|{N}{f}| +The macro \csbxint{iTrunc}|{N}{f}| is like \csa{xintTrunc}|{N}{f}| followed by multiplication by |10^N|. Thus, it outputs an integer in a format acceptable by the integer-only macros. To get the integer part of the decimal expansion of |f|, use @@ -2116,12 +2079,12 @@ To get the integer part of the decimal expansion of |f|, use \centeredline{|\xintiTrunc {0}{\xintPow{0.123}{-10}}|\digitstt{=\xintiTrunc {0}{\xintPow{0.123}{-10}}}} -See also the documentations of \csb{xintRound}, \csb{xintiRound} and -\csb{xintFloat}. +See also the documentations of \csbxint{Round}, \csbxint{iRound} and +\csbxint{Float}. \section{\csh{ifcase}, \csh{ifnum}, ... constructs}\label{sec:ifcase} -When using things such as |\ifcase \xintSgn{\A}| one has to leave +When using things such as |\ifcase \xintSgn{\A}| one has to make sure to leave a space after the closing brace for \TeX{} to stop its scanning for a number: once \TeX{} has finished expanding |\xintSgn{\A}| and has so far obtained either |1|, |0|, or |-1|, a @@ -2130,7 +2093,7 @@ digits. Using |\ifcase\xintSgn\A| without the braces is very dangerous, because the blanks (including the end of line) following |\A| will be skipped and not serve to stop the number which |\ifcase| is looking for. With |\def\A{1}|: -\dverb|& +\dverb|@ \ifcase \xintSgn\A 0\or OK\else ERROR\fi ---> gives ERROR \ifcase \xintSgn{\A} 0\or OK\else ERROR\fi ---> gives OK | @@ -2138,26 +2101,51 @@ With |\def\A{1}|: % \ifcase \xintSgn\A 0\or OK\else ERROR\fi\ % \ifcase \xintSgn{\A} 0\or OK\else ERROR\fi -Release |1.07| provides the expandable -\csb{xintSgnFork} which chooses one of three branches according to whether its -argument expands to |-1|, |0| or |1|. This, rather than the corresponding -|\ifcase|, should be used when such a fork is needed as argument to one of the -package macros. - -Release |1.09a| has \csb{xintifSgn} which does not restrict its first argument -to be |-1|, |0|, |1|: the argument, which may be also a count register will be -first replaced by its sign. There are also -\csb{xintifZero}, \csb{xintifNotZero}, \csb{xintifGt}, \csb{xintifLt}, -\csb{xintifEq}. - +In order to use successfully |\if...\fi| constructions either as arguments to +the +\xintname bundle expandable macros, or when building up a completely expandable +macro of one's own, one needs some \TeX nical expertise (this is briefly +commented upon in \autoref{fn:expansions}), and also macros. + +It is thus much to be recommended to opt rather for already existing expandable +branching macros, such as the ones which are provided by \xintname: +\csbxint{SgnFork}, \csbxint{ifSgn}, \csbxint{ifZero}, \csbxint{ifNotZero}, +\csbxint{ifTrueFalse}, \csbxint{ifCmp}, \csbxint{ifGt}, \csbxint{ifLt}, +\csbxint{ifEq}, \csbxint{ifOdd}, and \csbxint{ifInt}. See their respective +documentations. All these conditionals always have either two or three branches, +and empty brace pairs |{}| for unused branches should not be forgotten. + +If these tests are to be applied to standard \TeX{} short integers, it is more +efficient to use (under \LaTeX{}) the equivalent conditional tests from the +\href{http://www.ctan.org/pkg/etoolbox}{etoolbox}\footnote{\url{http://www.ctan.org/pkg/etoolbox}} +package. + +\section{Dimensions} + +\meta{dimen} variables can be converted into (short) integers suitable for the +\xintname macros by prefixing them with |\number|. This transforms a dimension +into an explicit short integer which is its value in terms of the |sp| unit +(@1/65536@\,|pt|). +When |\number| is applied to a \meta{glue} variable, the stretch and shrink +components are lost. + +For \LaTeX{} users: a length is a \meta{glue} variable, prefixing a +length command defined by \csa{newlength} with \csa{number} will thus discard +the |plus| and |minus| glue components and return the dimension component as +described above, and usable in the \xintname bundle macros. + +One may thus compute areas or volumes with no limitations, in units of |sp^2| +respectively |sp^3|, do arithmetic with them, compare them, etc..., and possibly +express some final result back in another unit, with the suitable conversion +factor and a rounding to a given number of decimal places. \section{Multiple outputs}\label{sec:multout} Some macros have an output consisting of more than one number, each one is then -within braces. Examples of multiple-output macros are \csb{xintDivision} which +within braces. Examples of multiple-output macros are \csbxint{Division} which gives first the quotient and then the remainder of euclidean division, -\csb{xintBezout} from the \xintgcdname package which outputs five numbers, -\csb{xintFtoCv} from the \xintcfracname package which returns the list of the +\csbxint{Bezout} from the \xintgcdname package which outputs five numbers, +\csbxint{FtoCv} from the \xintcfracname package which returns the list of the convergents of a fraction, ... the next two sections explain ways to deal, expandably or not, with such outputs. @@ -2179,8 +2167,8 @@ expandability. For example why not allow oneself the two definitions provides \csa{xintDivision} which computes both quotient and remainder at the same time: - \centeredline{\csb{xintAssign}\csa{xintDivision}|{100}{3}|\csbnolk{to}|\A\B|} - \centeredline{\csb{xintAssign}\csa{xintDivision}% + \centeredline{\csbxint{Assign}\csa{xintDivision}|{100}{3}|\csbnolk{to}|\A\B|} + \centeredline{\csbxint{Assign}\csa{xintDivision}% |{\xintiPow {2}{1000}}{\xintFac{100}}|\csbnolk{to}|\A\B|} gives \xintAssign\xintDivision{\xintiPow {2}{1000}}{\xintFac{100}}\to\A\B |\meaning\A|\digitstt{: \expandafter\allowsplits\meaning\A\relax} and @@ -2189,7 +2177,7 @@ expandability. For example why not allow oneself the two definitions Another example (which uses a macro from the \xintgcdname package): - \centeredline{\csb{xintAssign}\csa{xintBezout}|{357}{323}|% + \centeredline{\csbxint{Assign}\csa{xintBezout}|{357}{323}|% \csbnolk{to}|\A\B\U\V\D|} is equivalent to setting |\A| to \digitstt{\tmpA}, |\B| to \digitstt{\tmpB}, |\U| to \digitstt{\tmpU}, |\V| to \digitstt{\tmpV}, and |\D| to \digitstt{\tmpD}. And indeed @@ -2198,7 +2186,7 @@ expandability. For example why not allow oneself the two definitions is a Bezout Identity. \xintAssign\xintBezout{3570902836026}{200467139463}\to\tmpA\tmpB\tmpU\tmpV\tmpD -\centeredline{\csb{xintAssign}\csa{xintBezout}|{3570902836026}{200467139463}|% +\centeredline{\csbxint{Assign}\csa{xintBezout}|{3570902836026}{200467139463}|% \csbnolk{to}|\A\B\U\V\D|} gives then |\U|\digitstt{: \expandafter\allowsplits\meaning\tmpU\relax}, |\V|\digitstt{: @@ -2206,19 +2194,19 @@ expandability. For example why not allow oneself the two definitions When one does not know in advance the number of tokens, one can use \csa{xintAssignArray} or its synonym \csa{xintDigitsOf}: - \centeredline{\csb{xintDigitsOf}\csa{xintiPow}|{2}{100}|\csbnolk{to}\csa{Out}} + \centeredline{\csbxint{DigitsOf}\csa{xintiPow}|{2}{100}|\csbnolk{to}\csa{Out}} This defines \csa{Out} to be macro with one parameter, \csa{Out}|{0}| gives the size |N| of the array and \csa{Out}|{n}|, for |n| from |1| to |N| then - gives the |n|th element of the array, here the |n|th digit of &2^{100}&, from + gives the |n|th element of the array, here the |n|th digit of @2^{100}@, from the most significant to the least significant. As usual, the generated macro \csa{Out} is completely expandable (in two steps). As it wouldn't make much sense to allow indices exceeding the \TeX{} bounds, the macros created by - \csb{xintAssignArray} put their argument inside a + \csbxint{AssignArray} put their argument inside a \csa{numexpr}, so it is completely expanded and may be a count register, not necessarily prefixed by |\the| or |\number|. Consider the following code snippet: -\dverb+& +\dverb+@ \newcount\cnta \newcount\cntb \begingroup @@ -2250,7 +2238,7 @@ the most significant: \cnta = \Out{0} \advance\cnta 1 \repeat -&2^{100}& (=\z) has \Out{0} digits and the sum of +@2^{100}@ (=\z) has \Out{0} digits and the sum of their squares is \the\cntb. These digits are, from the least to the most significant: \cnta = \Out{0} \loop \Out{\cnta}\ifnum \cnta > 1 \advance\cnta -1 , \repeat. @@ -2263,23 +2251,23 @@ additional macros are defined which are \csa{Out0}, \csa{Out00}, the array (which is the value returned by |\Out{0}|; the digits are parts of the names not arguments). -The command \csb{xintRelaxArray}\csa{Out} sets all these macros to +The command \csbxint{RelaxArray}\csa{Out} sets all these macros to \csa{relax}, but it was simpler to put everything withing a group. -Needless to say \csb{xintAssign}, \csb{xintAssignArray} and -\csb{xintDigitsOf} do not do any check on whether the macros they +Needless to say \csbxint{Assign}, \csbxint{AssignArray} and +\csbxint{DigitsOf} do not do any check on whether the macros they define are already defined. In the example above, we deliberately broke all rules of complete expandability, but had we wanted to compute the sum of the digits, not the sum of the squares, we could just have written: -\centeredline{\csb{xintiSum}|{\xintiPow{2}{100}}|\digitstt{=% +\centeredline{\csbxint{iSum}|{\xintiPow{2}{100}}|\digitstt{=% \xintiSum\z}} Indeed, \csa{xintiSum} is usually used as in \centeredline{% - \csb{xintiSum}|{{123}{-345}{\xintFac{7}}{\xintiOpp{\xintRem{3347}{591}}}}|% + \csbxint{iSum}|{{123}{-345}{\xintFac{7}}{\xintiOpp{\xintRem{3347}{591}}}}|% \digitstt{=% \xintiSum{{123}{-345}{\xintFac{7}}{\xintiOpp{\xintRem{3347}{591}}}}}} -but in the example above each digit of &2^{100}& is treated as +but in the example above each digit of @2^{100}@ is treated as would have been a summand enclosed within braces, due to the rules of \TeX{} for parsing macro arguments. @@ -2291,7 +2279,7 @@ a number with its opposite. As a last example with \csa{xintAssignArray} here is one line extracted from the source code of the \xintgcdname macro -\csb{xintTypesetEuclideAlgorithm}: +\csbxint{TypesetEuclideAlgorithm}: \centeredline{|\xintAssignArray\xintEuclideAlgorithm {#1}{#2}\to\U|} This is done inside a group. After this command |\U{1}| contains @@ -2310,15 +2298,15 @@ for typesetting: this is just an example of one way to do it. The package now has more utilities to deal expandably with `lists of things', which were treated un-expandably in the previous section with \csa{xintAssign} and \csa{xintAssignArray}: -\csb{xintReverseOrder} and \csb{xintLength} since the first -release, \csb{xintApply} and \csb{xintListWithSep} since |1.04|, -\csb{xintRevWithBraces}, \csb{xintCSVtoList}, \csb{xintNthElt} with |1.06|, and -\csb{xintApplyUnbraced}, new with |1.06b|. +\csbxint{ReverseOrder} and \csbxint{Length} since the first +release, \csbxint{Apply} and \csbxint{ListWithSep} since |1.04|, +\csbxint{RevWithBraces}, \csbxint{CSVtoList}, \csbxint{NthElt} since |1.06|, and +\csbxint{ApplyUnbraced}, since |1.06b|. \edef\z{\xintiPow {2}{100}} As an example the following code uses only expandable operations: -\dverb+& +\dverb+@ |2^{100}| (=\xintiPow {2}{100}) has \xintLen{\xintiPow {2}{100}}} digits and the sum of their squares is \xintiSum{\xintApply {\xintiSqr}{\xintiPow {2}{100}}}. @@ -2339,14 +2327,18 @@ least significant one is \xintNthElt{7}{\xintRev\z}. % significant digit is \xintNthElt{13}{\xintiPow {2}{100}}. The seventh least % significant one is \xintNthElt{7}{\xintRev{\xintiPow {2}{100}}}. -Of course, it would be nicer to do +It would be nicer to do |\edef\z{\xintiPow {2}{100}}|, and then use |\z| in place of |\xintiPow {2}{100}| everywhere as this would spare the CPU some repetitions. +Expandably computing primes is done in \autoref{xintSeq}. + + \section{A new kind of for loop} -As part of the utilities coming with the \xintname package, there is a new kind -of for loop, \csb{xintFor}. Check it out (\autoref{xintFor}). +As part of the \hyperref[sec:utilsxint]{utilities} coming with the \xintname +package, there is a new kind of for loop, \csbxint{For}. Check it out +(\autoref{xintFor}). \section{Exceptions (error messages)} @@ -2359,7 +2351,7 @@ end of the expansion so as to not disturb further processing of the token stream, after completion of the operation. Generally the problematic operation will output a zero. Possible such error message control sequences: -\dverb|& +\dverb|@ \xintError:ArrayIndexIsNegative \xintError:ArrayIndexBeyondLimit \xintError:FactorialOfNegativeNumber @@ -2411,7 +2403,7 @@ others are more annoying as they may pass through unsignaled. \item generally speaking, using in a context expecting an integer (possibly restricted to the \TeX{} bound) a macro or expression which returns a fraction: |\xinttheexpr 4/2\relax| outputs \digitstt{\xinttheexpr 4/2\relax}, - not &2&. Use |\xintNum {\xinttheexpr 4/2\relax}| or |\xintthenumexpr + not @2@. Use |\xintNum {\xinttheexpr 4/2\relax}| or |\xintthenumexpr 4/2\relax|. \end{itemize} @@ -2421,7 +2413,8 @@ others are more annoying as they may pass through unsignaled. Inner macros of \xintname, \xintfracname, \xintexprname, \xintbinhexname, \xintgcdname, \xintseriesname, and \xintcfracname{} all begin either with |\XINT_| or with |\xint_|.\footnote{starting with release |1.06b| the style - files use for macro names a more modern underscore |\_| rather than the |@| + files use for macro names a more modern underscore |\_| rather than the + \texttt{\char`\@} sign. A handful of private macros starting with |\string\XINT| do not have the underscore for technical reasons: @@ -2434,7 +2427,7 @@ elsewhere, their meaning doesn't matter and is not touched. \section{Loading and usage} -\dverb|& +\dverb|@ Usage with LaTeX: \usepackage{xint} \usepackage{xintfrac} % (loads xint) \usepackage{xintexpr} % (loads xintfrac) @@ -2502,7 +2495,7 @@ compatible. \csa{xintTypesetBezoutAlgorithm} also uses the \section{Installation} -\dverb+& +\dverb+@ Run tex or latex on xint.dtx. This will extract the style files xint.sty, xintfrac.sty, xintexpr.sty, @@ -2541,9 +2534,10 @@ database. In the description of the macros \texttt{\n} (or also \texttt{\m}) stands (except if mentioned otherwise) for a (long) number within braces or for a -control sequence possibly within braces and \fexpan ding to such a number +control sequence possibly within braces and \hyperref[sec:expansions]{\fexpan + ding} to such a number (without the braces!), or for material within braces which \fexpan ds to such -a number, as is acceptable on input by the \csb{xintNum} macro: a sequence of +a number, as is acceptable on input by the \csbxint{Num} macro: a sequence of plus and minus signs, followed by some string of zeros, followed by digits. The letter \texttt{x} stands for something which will be inserted in-between a @@ -2564,10 +2558,10 @@ fractions on input as long as they are integers in disguise; they still produce on output integers without any forward slash mark nor trailing |[n]|. On the other hand macros such as |\xintAdd| will output fractions |A/B[n]|, with |B| present even if its value is one. To remove this unit denominator and -convert the |[n]| part into explicit zeros, one has \csb{xintNum} (if one is -certain to deal with an integer; see also \csb{xintPRaw}). This is mandatory +convert the |[n]| part into explicit zeros, one has \csbxint{Num} (if one is +certain to deal with an integer; see also \csbxint{PRaw}). This is mandatory when the computation result is fetched into a context where \TeX{} expects a -number (assuming it does not exceed &2^31&). See the also the \xintfracname +number (assuming it does not exceed @2^31@). See the also the \xintfracname \hyperref[sec:comfrac]{documentation} for more information on how macros of \xintname are modified after loading \xintfracname (or \xintexprname). @@ -2603,22 +2597,22 @@ behaves the same as the original for integers). \centeredline{|\xintLen{-1e3/5.425}|\digitstt {=\xintLen{-1e3/5.425}}} The length is computed on the |A/B[n]| which would have been returned by -\csb{xintRaw}: |\xintRaw {-1e3/5.425}|\digitstt{=\xintRaw {-1e3/5.425}}. +\csbxint{Raw}: |\xintRaw {-1e3/5.425}|\digitstt{=\xintRaw {-1e3/5.425}}. Let's point out that the whole thing should sum up to -less than circa &2^{31}&, but this is a bit theoretical. +less than circa @2^{31}@, but this is a bit theoretical. -|\xintLen| is only for numbers or fractions. See \csb{xintLength} for counting +|\xintLen| is only for numbers or fractions. See \csbxint{Length} for counting tokens (or rather braced groups), more generally. \subsection{\csbh{xintDigitsOf}}\label{xintDigitsOf} -This is a synonym for \csb{xintAssignArray}, to be used to define +This is a synonym for \csbxint{AssignArray}, to be used to define an array giving all the digits of a given (positive, else the minus sign will be treated as first item) number. \begingroup\xintDigitsOf\xintiPow {7}{500}\to\digits \centeredline{|\xintDigitsOf\xintiPow {7}{500}\to\digits|} -\noindent &7^500& has |\digits{0}=|\digits{0} digits, and the 123rd among them +\noindent @7^500@ has |\digits{0}=|\digits{0} digits, and the 123rd among them (starting from the most significant) is |\digits{123}=|\digits{123}. \endgroup @@ -2903,8 +2897,8 @@ so needless to say this bound is completely irrealistic. Already |2^9999| has does this with |log|/|exp| and is ten times faster (|16| figures only).} so I should perhaps lower the bound to |99999|. -Extended by \xintfracname to fractions (\csb{xintPow}) and also to floats -(\csb{xintFloatPow}). Of course, negative +Extended by \xintfracname to fractions (\csbxint{Pow}) and also to floats +(\csbxint{FloatPow}). Negative exponents do not then cause errors anymore. The float version is able to deal with things such as |2^999999999| without any problem. For example @@ -2913,7 +2907,7 @@ with things such as \digitstt{=\xintFloatPow[4]{2}{999999999}}. \subsection{\csbh{xintSgnFork}}\label{xintSgnFork} -{\small New with release |1.07|. See also \csb{xintifSgn}.\par} +{\small New with release |1.07|. See also \csbxint{ifSgn}.\par} \csa{xintSgnFork}\verb+{-1|0|1}+\marg{A}\marg{B}\marg{C} expandably chooses to execute either the \meta{A}, \meta{B} or \meta{C} code, @@ -2948,44 +2942,60 @@ if the first mandatory argument |N| (a number, possibly a fraction if \xintfracname is loaded, or a macro expanding to one such) is not zero or is zero. It then either executes the first or the second branch. -\subsection{\csbh{xintifTrue}}\label{xintifTrue} -{\small New with release |1.09c|.\par} +\subsection{\csbh{xintifTrueFalse}}\label{xintifTrueFalse} +{\small New with release |1.09c|, renamed in |1.09e|.\par} + +\csa{xintifTrueFalse}\marg{N}\marg{true branch}\marg{false branch} is a synonym +for \csbxint{ifNotZero}. It is also available as \csa{xintifTrue} but this later +name is a bit misleading as the macro must always have a |false| branch, +possibly an empty brace pair |{}|. + +\subsection{\csbh{xintifCmp}}\label{xintifCmp} +{\small New with release |1.09e|.\par} -\csa{xintifTrue}\marg{N}\marg{YES}\marg{NO} is a synonym for -\csb{xintifNotZero}. +\csa{xintifCmp}\marg{A}\marg{B}\marg{if A<B}\marg{if A=B}\marg{if A>B} compares +its two numeric arguments and chooses accordingly the correct branch. \subsection{\csbh{xintifEq}}\label{xintifEq} {\small New with release |1.09a|.\par} \csa{xintifEq}\marg{A}\marg{B}\marg{YES}\marg{NO} checks equality of its -two first arguments (which may be macros but must expand to numbers or -fractions, if \xintfracname is loaded) and does the |YES| or the |NO| branch. +two first arguments (numbers, or fractions if \xintfracname is loaded) and does the |YES| or the |NO| branch. \subsection{\csbh{xintifGt}}\label{xintifGt} {\small New with release |1.09a|.\par} % attention dans la doc du 9 octobre j'avais écrit \geq au lieu de < -\csa{xintifGt}\marg{A}\marg{B}\marg{YES}\marg{NO} checks if $A>B$ -and in that case executes the |YES| branch. +\csa{xintifGt}\marg{A}\marg{B}\marg{YES}\marg{NO} checks if $A>B$ and in that +case executes the |YES| branch. Extended to fractions (in particular decimal +numbers) by \xintfracname. \subsection{\csbh{xintifLt}}\label{xintifLt} {\small New with release |1.09a|.\par} % attention dans la doc du 9 octobre j'avais écrit \leq au lieu de < -\csa{xintifLt}\marg{A}\marg{B}\marg{YES}\marg{NO} checks if $A<B$ -and in that case executes the |YES| branch. +\csa{xintifLt}\marg{A}\marg{B}\marg{YES}\marg{NO} checks if $A<B$ and in that +case executes the |YES| branch. Extended to fractions (in particular decimal +numbers) by \xintfracname. \begin{framed} The macros described next are all integer-only on input. With \xintfracname - loaded their argument is filtered through \csb{xintNum} and may thus be - a fraction, as long as it is an integer in disguise. + loaded their argument is first given to \csbxint{Num} and may thus be + a fraction, as long as it is in fact an integer in disguise. \end{framed} +\subsection{\csbh{xintifOdd}}\label{xintifOdd} +{\small New with release |1.09e|.\par} + +\csa{xintifOdd}\marg{A}\marg{YES}\marg{NO} checks if $A$ is and odd integer +and in that case executes the |YES| branch. + + \subsection{\csbh{xintFac}}\label{xintiFac} \csa{xintFac\x} returns the factorial. It is an error if the -argument is negative or at least &10^6&. It is not recommended to -launch the computation of things such as &100000!&, if you need +argument is negative or at least @10^6@. It is not recommended to +launch the computation of things such as @100000!@, if you need your computer for other tasks. Note that the argument is of the |x| type, it must obey the \TeX{} bounds, but on the other hand may involve count registers and even arithmetic operations as it will be completely expanded inside a @@ -3000,14 +3010,14 @@ integer: |\xintFac {66/3}|\digitstt{=\xintFac {66/3}}. % {2}{3}}}|. % temps obsolètes, mettre à jour -% On my laptop &1000!& (2568 digits) -% is computed in a little less than ten seconds, &2000!& (5736 +% On my laptop @1000!@ (2568 digits) +% is computed in a little less than ten seconds, @2000!@ (5736 % digits) is computed in a little less than one hundred seconds, and -% &3000!& (which has 9131 digits) needs close to seven minutes\dots -% I have no idea how much time &10000!& would need (do rather -% &9999!& if you can, the algorithm has some overhead at the -% transition from &N=9999& to &10000& and higher; &10000!& has 35660 -% digits). Not to mention &100000!& which, from the Stirling formula, +% @3000!@ (which has 9131 digits) needs close to seven minutes\dots +% I have no idea how much time @10000!@ would need (do rather +% @9999!@ if you can, the algorithm has some overhead at the +% transition from @N=9999@ to @10000@ and higher; @10000!@ has 35660 +% digits). Not to mention @100000!@ which, from the Stirling formula, % should have 456574 digits. \subsection{\csbh{xintDivision}}\label{xintDivision} @@ -3020,7 +3030,7 @@ zero is an error (even if |N| vanishes) and returns |{0}{0}|. This macro is integer only (with \xintfracname loaded it accepts fractions on input, but they must be integers in disguise) and not to be -confused with the \xintfracname macro \csb{xintDiv} which divides one +confused with the \xintfracname macro \csbxint{Div} which divides one fraction by another. \subsection{\csbh{xintQuo}}\label{xintQuo} @@ -3087,13 +3097,13 @@ $\sqrt{|N|}$ is $|M|-\frac{|d|}{|2M|}$ (this is a majorant and the error is at most |1/2M|; if |N| is a perfect square |k^2| then |M=k+1| and this gives |k+1/(2k+2)|, not |k|). -Package \xintfracname has \csb{xintFloatSqrt} for square +Package \xintfracname has \csbxint{FloatSqrt} for square roots of floating point numbers. \begin{framed} The macros described next are strictly for integer-only arguments. These - arguments are \emph{not} filtered via \csb{xintNum}. + arguments are \emph{not} filtered via \csbxint{Num}. \end{framed} \subsection{\csbh{xintInc}, \csbh{xintDec}} @@ -3127,9 +3137,9 @@ starting at zero. \csa{xintDSH\x\n} is parametrized decimal shift. When |x| is negative, it is like iterating \csa{xintDSL} \verb+|x|+ times -(\emph{i.e.} multiplication by &10^{-&|x|&}&). When |x| positive, -it is like iterating \csa{DSR} |x| times (and is more efficient of -course), and for a non-negative |N| this is thus the same as the +(\emph{i.e.} multiplication by @10^{-@|x|@}@). When |x| positive, +it is like iterating \csa{DSR} |x| times (and is more efficient), and for a +non-negative |N| this is thus the same as the quotient from the euclidean division by |10^x|. \subsection{\csbh{xintDSHr}, \csbh{xintDSx}}\label{xintDSHr}\label{xintDSx} @@ -3156,7 +3166,7 @@ which is exactly the case when |N| is at most |-10^x|. \csa{xintDSx\x\n} for |x| negative is exactly as -\csa{xintDSH\x\n}, \emph{i.e.} multiplication by &10^{-&|x|&}&. +\csa{xintDSH\x\n}, \emph{i.e.} multiplication by @10^{-@|x|@}@. For |x| zero or positive it returns the two numbers |{Q}{R}| described above, each one within braces. So |Q| is \csa{xintDSH\x\n}, and |R| is \csa{xintDSHr\x\n}, but computed @@ -3206,7 +3216,7 @@ significant digits (\emph{empty} if |x=0|) and the first piece the remaining digits (\emph{empty} when |x| equals or exceeds the length of |N|). Leading zeros in the second piece are not removed. When |x| is negative the first piece contains the \verb+|x|+ most significant digits and the -second piece the remaining digits (\emph{empty} if &|x|& equals or exceeds +second piece the remaining digits (\emph{empty} if @|x|@ equals or exceeds the length of |N|). Leading zeros in this second piece are not removed. So the absolute value of the original number is always the concatenation of the first and second piece. @@ -3253,10 +3263,14 @@ of \csa{xintDecSplit}. \label{sec:utilsxint} The completely expandable utilities come first, up to and including -\csb{xintSeq} (which is listed here because it generates sequences of short +\csbxint{Seq} (which is listed here because it generates sequences of short integers using |\numexpr|, thus does not make use of the big integers macros of \xintname). +This section contains various concrete examples of use of these utilities (such +as \csbxint{ApplyUnbraced}, \csbxint{ApplyInline} and \csbxint{For*}), and ends with a +\hyperref[ssec:quicksort]{completely expandable implementation of the Quick Sort + algorithm} together with a graphical illustration of its action. \localtableofcontents @@ -3308,7 +3322,7 @@ counts how many tokens there are (possibly none). So to use it to count things in the replacement text of a macro one should do |\expandafter\xintLength\expandafter{\x}|. One may also use it inside macros as |\xintLength{#1}|. Things enclosed in braces -count as one. Blanks between tokens are not counted. See \csb{xintNthElt}|{0}| +count as one. Blanks between tokens are not counted. See \csbxint{NthElt}|{0}| for a variant which first \fexpan ds its argument. \centeredline{|\xintLength {\xintiPow {2}{100}}|\digitstt{=\xintLength {\xintiPow{2}{100}}}} @@ -3335,10 +3349,11 @@ Contiguous spaces, tab characters, or other blanc spaces (empty lines not allowed) are collapsed by \TeX{} into single spaces. \fbox{\emph{No attempt} is made to get rid of such spaces} either before or after the commas, as priority has been given to the speed of the conversion (but without impacting -the input stack size). \centeredline{|\xintCSVtoList {1,2,a , b ,c d,x,y - }->|\makeatletter\digitstt{\expandafter\strip@prefix\meaning\X}\makeatother} +the input stack size). +\centeredline{|\xintCSVtoList {1,2,a , b ,c d,x,y }->|% +{\makeatletter\digitstt{\expandafter\strip@prefix\meaning\X}}} \centeredline{|\def\y{a,b,c,d,e} \xintCSVtoList\y->|% - \makeatletter\digitstt{\expandafter\strip@prefix\meaning\z}\makeatother} +{\makeatletter\digitstt{\expandafter\strip@prefix\meaning\z}}} The macro \csa{xintCSVtoListNoExpand} does the same job without the initial expansion. @@ -3360,9 +3375,9 @@ present). \centeredline{|\xintNthElt {3}{{agh}\u{zzz}\v{Z}}| is \texttt{\xintNthElt {3}{{agh}\u{zzz}\v{Z}}}}\centeredline{|\xintNthElt {37}{\xintFac {100}}|\digitstt{=\xintNthElt {37}{\xintFac {100}}} is the - thirty-seventh digit of &100!&.} \centeredline{|\xintNthElt {10}{\xintFtoCv + thirty-seventh digit of @100!@.} \centeredline{|\xintNthElt {10}{\xintFtoCv {566827/208524}}|\digitstt{=\xintNthElt {10}{\xintFtoCv {566827/208524}}}} -is the tenth convergent of &566827/208524& (uses \xintcfracname package). +is the tenth convergent of @566827/208524@ (uses \xintcfracname package). \centeredline{|\xintNthElt {7}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|% \digitstt{=\xintNthElt {7}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}}}% \centeredline{|\xintNthElt {0}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|% @@ -3370,8 +3385,8 @@ is the tenth convergent of &566827/208524& (uses \xintcfracname package). \centeredline{|\xintNthElt {-3}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|% \digitstt{=\xintNthElt {-3}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}}} If |x=0|, the macro returns the \emph{length} of the expanded list: this is not equivalent -to \csb{xintLength} which does no pre-expansion. And it is different from -\csb{xintLen} which is to be used only on integers or fractions. +to \csbxint{Length} which does no pre-expansion. And it is different from +\csbxint{Len} which is to be used only on integers or fractions. If |x<0|, the macro returns the \texttt{|x|}th element from the end of the list. \centeredline{|\xintNthElt @@ -3431,7 +3446,7 @@ arguments to the macro.). Being expandable, |\xintApply| is useful for example inside alignments where implicit groups make standard loops constructs usually fail. In such situation it is often not wished that the new list elements be braced, see -\csb{xintApplyUnbraced}. The |\macro| is not necessarily compatible with +\csbxint{ApplyUnbraced}. The |\macro| is not necessarily compatible with expansion only contexts: |\xintApply| will try to expand it, but the expansion may remain partial. @@ -3454,14 +3469,13 @@ which gave the \meta{list} of braced tokens to which |\macro| is applied. \def\macro #1{\expandafter\def\csname myself#1\endcsname {#1}} \xintApplyUnbraced\macro{{elta}{eltb}{eltc}} -\csa{xintApplyUnbraced}|{\macro}|\marg{list} is like \csb{xintApply}. The +\csa{xintApplyUnbraced}|{\macro}|\marg{list} is like \csbxint{Apply}. The difference is that after having expanded its list argument, and applied |\macro| in turn to each item from the list, it reassembles the outputs without enclosing them in braces. The net effect is the same as doing \centeredline{|\xintListWithSep {}{\xintApply {\macro}|\marg{list}|}|} This is useful for preparing a macro which will itself define some other macros or make assignments. -% sorry also for the silly coding of the following verbatim block \lverb|& $ $ $ $ \def\macro #1{\expandafter\def\csname myself#1\endcsname {#1}}$\ $null$ $ $ $ \xintApplyUnbraced\macro{{elta}{eltb}{eltc}}$\ @@ -3477,16 +3491,22 @@ is applied. \subsection{\csbh{xintSeq}}\label{xintSeq} {\small New with release |1.09c|.\par} -\csa{xintSeq}|[d]{N}{M}| generates expandably |{N}{N+d}...| up to and possibly -including |{M}| if |d>0| or down to and including |{M}| if |d<0|. Naturally -|{M}| is omitted if |M-N| is not a multiple of |d|. If |d=0| the macro returns -|{N}|. If |M-N| and |d| have opposite signs, the macro returns nothing. If the -optional argument |d| is omitted it is taken to be the sign of |M-N|. +\csa{xintSeq}|[d]{x}{y}| generates expandably |{x}{x+d}...| up to and possibly +including |{y}| if |d>0| or down to and including |{y}| if |d<0|. Naturally +|{y}| is omitted if |y-x| is not a multiple of |d|. If |d=0| the macro returns +|{x}|. If |y-x| and |d| have opposite signs, the macro returns nothing. If the +optional argument |d| is omitted it is taken to be the sign of |y-x|. + The current implementation is only for (short) integers; possibly, a future -variant could allow big integers and fractions, although one already has similar -functionality using \csb{xintApply} with an affine transformation to -post-process an integer sequence. \centeredline{|\xintListWithSep{,\hskip2pt +variant could allow big integers and fractions, although one already has +access to similar +functionality using \csbxint{Apply} to get any arithmetic sequence of long +integers. Currently thus, |x| and |y| are expanded inside a +|\numexpr| so they may be count registers or a \LaTeX{} |\value{countername}|, +or arithmetic with such things. + +\centeredline{|\xintListWithSep{,\hskip2pt plus 1pt minus 1pt }{\xintSeq {12}{-25}}|} \noindent\digitstt{\xintListWithSep{,\hskip2pt plus 1pt minus 1pt }{\xintSeq {12}{-25}}} @@ -3497,15 +3517,191 @@ optional argument |d|, works backwards, leaving in the token stream the already constructed integers, from the tail down (or up). But this will provoke a failure of \IMPORTANT{} the |tex| run if the number of such items exceeds the input stack -limit; on my installation this limit is at &5000&. +limit; on my installation this limit is at @5000@. -However, when given the optional argument |d| (which may be &+1& or -&-1&), the macro proceeds differently and does not put stress on the input stack +However, when given the optional argument |d| (which may be @+1@ or +@-1@), the macro proceeds differently and does not put stress on the input stack (but is significantly slower for sequences with thousands of integers, especially if they are somewhat big). For example: |\xintSeq [1]{0}{5000}| works and |\xintiSum{\xintSeq [1]{0}{5000}}| returns the correct value \digitstt{\xintHalf{\xintiMul{5000}{5001}}}. + +\subsection{Completely expandable prime test}\label{ssec:primesI} + +Let us now construct a completely expandable macro which returns @1@ if its +given input is prime and @0@ if not: +\dverb|@ +\def\remainder #1#2{\the\numexpr #1-(#1/#2)*#2\relax } +\def\IsPrime #1{\xintANDof + {\xintApply {\remainder {#1}}{\xintSeq {2}{\xintiSqrt{#1}}}}} +| +This uses \csbxint{iSqrt} and assumes its input is at least @3@. Rather than +\xintname's own \csbxint{Rem} we used a quicker |\numexpr| expression as we +are dealing with short integers. Also we used \csbxint{ANDof} which will +return @1@ only if all the items are non-zero. The macro is a bit +silly with an even input, ok, let's enhance it to detect an even input: +\dverb|@ +\def\IsPrime #1% + {\xintifOdd {#1} + {\xintANDof % odd case + {\xintApply {\remainder {#1}} + {\xintSeq [2]{3}{\xintiSqrt{#1}}}% + }% + } + {\xintifEq {#1}{2}{1}{0}}% + } +| + +We used the \xintname provided expandable tests (on big integers or fractions) +to maintain the complete expanability of |\IsPrime| in a strong +sense\footnote{\label{fn:fullexp}technically, prefixing it with + \csa{romannumeral-`0} must expand it completely; this is the case of all + \xintname expandable macros, and in turn the arguments must be of this + type.}. + +Our integers are short, but without +|\expandafter|'s with \makeatletter|\@firstoftwo|\catcode`@ \active, or some +other related + techniques, direct use of |\ifnum..\fi| tests is dangerous. +So to make the macro more efficient we are going to use the expandable tests +provided by the package +\href{http://ctan.org/pkg/etoolbox}{etoolbox}\footnote{\url{http://ctan.org/pkg/etoolbox}}. +The macro becomes: +\dverb|@ +\def\IsPrime #1% + {\ifnumodd {#1} + {\xintANDof % odd case + {\xintApply {\remainder {#1}}{\xintSeq [2]{3}{\xintiSqrt{#1}}}}} + {\ifnumequal {#1}{2}{1}{0}}} +| + +In the odd case however we have to assume the integer is at least @7@, as +|\xintSeq| generates an empty list if |#1=3| or |5|, and |\xintANDof| returns +@1@ when supplied an empty list. Let us ease up a bit |\xintANDof|'s work by +letting it work on only @0@'s and @1@'s. We could use: +% +\dverb|@ +\def\IsNotDivisibleBy #1#2% + {\ifnum\numexpr #1-(#1/#2)*#2=0 \expandafter 0\else \expandafter1\fi} +|% +% +where the |\expandafter|'s are crucial for this macro to be completely +expandable in the restricted sense mentioned in \autoref{fn:fullexp} which we +want for applying confidently \csbxint{ANDof}. Anyhow, now that we have loaded +\href{http://ctan.org/pkg/etoolbox}{etoolbox}, we might as well use: +\dverb|@ +\newcommand{\IsNotDivisibleBy}[2]{\ifnumequal{#1-(#1/#2)*#2}{0}{0}{1}} +|% +Let us enhance our prime macro to work also on the small primes: +\dverb|@ +\newcommand{\IsPrime}[1] % returns 1 if #1 is prime, and 0 if not + {\ifnumodd {#1} + {\ifnumless {#1}{8} + {\ifnumequal{#1}{1}{0}{1}}% 3,5,7 are primes + {\xintANDof + {\xintApply + { \IsNotDivisibleBy {#1}}{\xintSeq [2]{3}{\xintiSqrt{#1}}}}% + }}% END OF THE ODD BRANCH + {\ifnumequal {#1}{2}{1}{0}}% END OF THE EVEN BRANCH +} +|% +The +input is still assumed positive. There is a deliberate blank before +\csa{IsNotDivisibleBy} to use this +feature of \csbxint{Apply}: a space stops the expansion of the applied macro +(and disappears). This expansion will +be done by \csbxint{ANDof}, which has been designed to skip +everything as soon as it finds a false (i.e. zero) input. This way, the +efficiency is +considerably improved. We did generate via \csbxint{Seq} too many +divisors though; if we really wanted to optimize even further it would be +reasonable to drop the requirement of complete expandability and use the tools +provided by +the \csbxint{For} loop. + + +Let us construct a table of the prime numbers up to @1000@. We need to count +how many we have in order to know how many tab stops one shoud add in the last +row. There is some subtlety for this last row. Turns out to be better to +insert a |\\| only when we know for sure we are starting a new row; this is +how we have designed the |\OneCell| macro. And for the last row, there are +many ways, we use again |\xintApplyUnbraced| but with a macro which gobbles +its argument and replaces it with a tabulation character. The \csbxint{For*} +macro would be more elegant here. +% +\dverb?@ +\newcounter{primecount} +\newcounter{cellcount} +\newcommand{\NbOfColumns}{13} +\newcommand{\OneCell}[1]{% + \ifnumequal{\IsPrime{#1}}{1} + {\stepcounter{primecount} + \ifnumequal{\value{cellcount}}{\NbOfColumns} + {\\\setcounter{cellcount}{1}#1} + {&\stepcounter{cellcount}#1}% + } % was prime + {}% not a prime, nothing to do +} +\newcommand{\OneTab}[1]{&} +\begin{tabular}{|*{\NbOfColumns}{r}|} +\hline +2 \setcounter{cellcount}{1}\setcounter{primecount}{1}% + \xintApplyUnbraced \OneCell {\xintSeq [2]{3}{999}}% + \xintApplyUnbraced \OneTab + {\xintSeq [1]{1}{\the\numexpr\NbOfColumns-\value{cellcount}\relax}}% + \\ +\hline +\end{tabular} +There are \arabic{primecount} prime numbers up to 1000. +?% +% +We had to be careful to use the optional argument |[1]| to \csbxint{Seq} in +this last row to not generate a decreasing sequence from |1| to |0|, but an +empty sequence when the row turns out to already have all its cells. +% +\newcommand{\IsNotDivisibleBy}[2]{\ifnumequal{#1-(#1/#2)*#2}{0}{0}{1}} + +\newcommand{\IsPrime}[1] + {\ifnumodd {#1} + {\ifnumless {#1}{8} + {\ifnumequal{#1}{1}{0}{1}}% 3,5,7 are primes + {\xintANDof + {\xintApply + { \IsNotDivisibleBy {#1}}{\xintSeq [2]{3}{\xintiSqrt{#1}}}}% + }}% END OF THE ODD BRANCH + {\ifnumequal {#1}{2}{1}{0}}% END OF THE EVEN BRANCH +} + +\newcounter{primecount} +\newcounter{cellcount} +\newcommand{\NbOfColumns}{13} +\newcommand{\OneCell}[1] + {\ifnumequal{\IsPrime{#1}}{1} + {\stepcounter{primecount} + \ifnumequal{\value{cellcount}}{\NbOfColumns} + {\\\setcounter{cellcount}{1}#1} + {&\stepcounter{cellcount}#1}% + } % was prime + {}% not a prime nothing to do +} +\newcommand{\OneTab}[1]{&} +\begin{figure*}[ht!] + \centering + \begin{tabular}{|*{\NbOfColumns}{r}|} + \hline + 2\setcounter{cellcount}{1}\setcounter{primecount}{1}% + \xintApplyUnbraced \OneCell {\xintSeq [2]{3}{999}}% + \xintApplyUnbraced \OneTab + {\xintSeq [1]{1}{\the\numexpr\NbOfColumns-\value{cellcount}\relax}}% + \\ + \hline + \end{tabular} +\smallskip +\centeredline{There are \arabic{primecount} prime numbers up to 1000.} +\end{figure*} + + \begin{framed} The next utilities are not compatible with expansion-only context. \end{framed} @@ -3526,9 +3722,9 @@ next item is then handled. This is to be used in situations where one needs to do some repetitive things. It is not expandable and can not be completely expanded inside a macro definition, to prepare material for later execution, contrarily to what -\csb{xintApply} or \csb{xintApplyUnbraced} achieve. +\csbxint{Apply} or \csbxint{ApplyUnbraced} achieve. -\dverb|& +\dverb|@ \def\Macro #1{\advance\cnta #1 , \the\cnta} \cnta 0 0\xintApplyInline\Macro {3141592653}. @@ -3537,7 +3733,6 @@ macro definition, to prepare material for later execution, contrarily to what \cnta 0 Output: 0\xintApplyInline\Macro {3141592653}. -\catcode`\& 4 The first argument |\macro| does not have to be an expandable macro. @@ -3561,9 +3756,7 @@ This tabular for example:\par \smallskip % 38 = &, 43 = +, 36=$, 45 = - was obtained from the following input: -\lverb|$catcode38 12 $catcode43 0 +catcode36 12 +catcode45 14 - -+catcode37 12 +hsize+linewidth +makestarlowast - -+obeylines +parindent 0pt +csname @vobeyspaces+endcsname- +\dverb|@ \begin{tabular}{ccc} $N$ & $N^2$ & $N^3$ \\ \hline \def\Row #1{ #1 & \xintiSqr {#1} & \xintiPow {#1}{3} \\ \hline }% @@ -3574,7 +3767,7 @@ Despite the fact that the first encountered tabulation character in the first row close a group and thus erases |\Row| from \TeX's memory, |\xintApplyInline| knows how to deal with this. -Using \csb{xintApplyUnbraced} is an alternative: the difference is that +Using \csbxint{ApplyUnbraced} is an alternative: the difference is that this would have prepared all rows first and only put them back into the token stream once they are all assembled, whereas with |\xintApplyInline| each row is constructed and immediately fed back into the token stream: when @@ -3585,8 +3778,7 @@ noticeable). One may nest various |\xintApplyInline|'s. For example (see the \hyperref[float]{table} \vpageref{float}):\par -\lverb|$catcode38 12 $catcode37 12 $catcode45 14 $parindent 0pt - -$hsize$linewidth $makestarlowast $obeylines $csname @vobeyspaces$endcsname- +\dverb|@ \def\Row #1{#1:\xintApplyInline {\Item {#1}}{0123456789}\\ }% \def\Item #1#2{&\xintiPow {#1}{#2}}% \begin{tabular}{ccccccccccc} @@ -3606,77 +3798,117 @@ $hsize$linewidth $makestarlowast $obeylines $csname @vobeyspaces$endcsname- One could not move the definition of |\Item| inside the tabular, as it would get lost after the first |&|. But this works: -\lverb|$catcode38 12 $catcode37 12 $catcode45 14 - -$hsize$linewidth $makestarlowast - -$obeylines $parindent 0pt $csname @vobeyspaces$endcsname- +\dverb|@ \begin{tabular}{ccccccccccc} &0&1&2&3&4&5&6&7&8&9\\ \hline \def\Row #1{#1:\xintApplyInline {&\xintiPow {#1}}{0123456789}\\ }% \xintApplyInline \Row {0123456789} \end{tabular}| -\noindent + A limitation is that, contrarily to what one may have expected, the |\macro| for an |\xintApplyInline| can not be used to define the |\macro| for a nested sub-|\xintApplyInline|. For example, this does not work:\par -\lverb|$catcode38 12 $catcode37 12 $catcode45 14 - -$hsize$linewidth $makestarlowast - -$obeylines $parindent 0pt $csname @vobeyspaces$endcsname- +\dverb|@ \def\Row #1{#1:\def\Item ##1{&\xintiPow {#1}{##1}}% \xintApplyInline \Item {0123456789}\\ }% \xintApplyInline \Row {0123456789} % does not work |% -But see \csb{xintFor}. +But see \csbxint{For}. \subsection{\csbh{xintFor}, \csbh{xintFor*}}\label{xintFor}\label{xintFor*} -{\small New with |1.09c|. The macro \csa{xintFor*} is corrected in |1.09d| to - fix a bug when a space token was at the very end of the list. The new - version \fexpan ds the ({unbraced}) items.\par} +{\small New with |1.09c|. Extended in |1.09e| (see \csbxint{BreakFor}).\par} -\csb{xintFor} is a new kind of for loop. Rather than using macros for +\csbxint{For} is a new kind of for loop. Rather than using macros for encapsulating list items, its behavior is more like a macro with parameters: |#1|, |#2|, |#3|, |#4| can be used to represent the items for up to four levels of nested loops. Here is an example: -\dverb|& +\dverb|@ \xintFor #1 in {1,2,3} \do {% \xintFor #2 in {4,5,6} \do {% \xintFor #3 in {7,8,9} \do {% \xintFor #4 in {10,11,12} \do {% $$#1\times#2\times#3\times#4=\xintiPrd{{#1}{#2}{#3}{#4}}$$}}}} |% -The use of either |#1|, |#2|, |#3|, or |#4| to denote the item is -mandatory, but one does not have to use necessarily |#1| as the first -one. Notice that contrarily to what happens in loops where the item is -represented by a macro, here it is truly exactly like in a macro -definition. This may avoid the user quite a few troubles with -|\expandafter|s or other |\edef/\noexpand|s which -one encounters at times when trying to do things with the |\@for| -loop of \LaTeX{}. For example if above, rather than the package's -|\xintiPrd| one had a macro which does not expand its arguments, or -perhaps it does, but not the fourth one, etc\dots - -Allowing |#5|, etc\dots, would have meant more lines of code and also -some more tokens inside the already existing code, I decided to postpone -it to later, if people are interested (on the basis that someone will -actually read these lines, one day; I mean someone besides me). One may -naturally put multiple |\xintFor| loops one after the other inside a -primary one. The replacement text can do quite arbitrary things -in-between such sub-loops (if any). - -The non-starred variant \csb{xintFor} deals with comma separated -values (no effort is done to remove the spaces before and after the -commas) and the comma separated list may be a macro which is just -expanded once. - -The starred variant \csb{xintFor*} deals with token lists and -\fexpan ds each \emph{unbraced} list item. This makes it easy to concatenate -various list macros |\x|, |\y|, ... as if |\x| -expands to |123| and |\y| expands to |456| then |{\x\y}| as argument to -|\xintFor*| has the same effect as |{123456}|. Spaces at the start, end, or -in-between items are gobbled (but naturally not the spaces which may be inside -\emph{braced} items). - -The \csb{xintFor} loops may be used inside alignments or other contexts +The use of either |#1|, |#2|, |#3|, or |#4| to denote the item is mandatory, +but one does not have to use necessarily |#1| as the first one.\footnote{the + reason for not having implemented use of \texttt{\#5}, etc\dots{} is that + this would, in the current implementation, make the code a bit heavier, also + for \texttt{\#1},\dots I decided to postpone it to perhaps later, if people + require such a feature (on the basis that someone will actually read these + lines, one day; I mean someone besides me).} + +The spaces between the various declarative elements are all optional; but +spaces inside the braced comma separated list are obeyed, even around the +commas. The list argument may be a macro |\MyList| which then does not need to +be braced (if it has no arguments!). It will be expanded once to reveal its +comma separated items. + +Contrarily to what happens in loops where the item is represented by a macro, +here it is truly exactly as when defining (in \LaTeX{}) a ``command'' with +parameters |#1|, etc... This may avoid the user quite a few troubles with +|\expandafter|s or other |\edef/\noexpand|s which one encounters at times when +trying to do things with the \LaTeX's {\makeatother|\@for|} or other loops +which encapsulate the item in a macro expanding to that item. + +\begin{framed} + The non-starred variant \csbxint{For} deals with comma separated values + (\emph{no effort is done to remove the spaces before and after the commas}) + and the comma separated list may be a macro which is only expanded once (to + prevent expansion of the first item if the list is input as |{\x,\y,...}| it + should be |{{\x},\y,..}|). The items are not expanded, if the input is + |<stuff>,\x,<stuff>| then |#1| will be at some point |\x| not its expansion + (and not + either a macro with |\x| as replacement text, just the token |\x|). Input + such as |<stuff>,,<stuff>| creates an empty |#1|, the iteration is not + skipped. An + empty list does lead to the use of the replacement text, once, with an empty + |#1|. Except if the list argument is a single token, \fbox{it must be braced.} + + The starred variant \csbxint{For*} deals with token lists and \fexpan ds + each \emph{unbraced} list item. This makes it easy to simulate concatenation + of various list macros |\x|, |\y|, ... If |\x| expands to |{1}{2}{3}| and + |\y| expands to |{4}{5}{6}| then |{\x\y}| as argument to |\xintFor*| has the + same effect as |{{1}{2}{3}{4}{5}{6}}|% +\stepcounter{footnote}% +\makeatletter\hbox {\@textsuperscript {\normalfont \thefootnote }}\makeatother. + Spaces at the start, + end, or in-between items are gobbled (but naturally not the spaces which may + be inside \emph{braced} items). Except if the list argument is a single + token, \fbox{it must be braced.} Each item which is not braced will be fully + expanded (as the |\x| and |\y| in the example above). + + The macro \csbxint{Seq} which generates arithmetic sequences may only be used + with \csbxint{For*} (no commas!). + \centeredline{|\xintFor* #1 in {\xintSeq [+2]{-7}{+2}}\do {stuff with #1}|} + will have |#1=-7,-5,-3,-1, and 1|. The |#1| as issued from the list produced + by \csbxint{Seq} is the litteral representation + as would be produced by |\arabic| on a \LaTeX{} counter, it is not a count + register. When used in |\ifnum| tests or other contexts where \TeX{} looks + for a + number it is recommended to use + |#1\space|\stepcounter{footnote}% +\makeatletter\hbox {\@textsuperscript {\normalfont \thefootnote }}\makeatother. + or |#1\relax| if expandability of the process is not an issue (for example + if the iterated commands do an |\edef| using such a test, |\relax| will not + do). +\end{framed} +\begingroup\makeatletter +\def\@footnotetext #1{\insert\footins {\reset@font \footnotesize \interlinepenalty \interfootnotelinepenalty \splittopskip \footnotesep \splitmaxdepth \dp \strutbox \floatingpenalty \@MM \hsize \columnwidth \@parboxrestore \color@begingroup \@makefntext {\rule \z@ \footnotesep \ignorespaces #1\@finalstrut \strutbox }\color@endgroup }} +\addtocounter{footnote}{-1} +\edef\@thefnmark {\thefootnote} +\@footnotetext{braces around single token items + are optional so this is the same as \texttt{\{123456\}}.} +\stepcounter{footnote} +\edef\@thefnmark {\thefootnote} +\@footnotetext{the \csa{space} will stop the \TeX{} scanning of a number and be + gobbled in the process; the \csa{relax} stops the scanning but is not + gobbled. Or one may do \csa{numexpr}\texttt{\#1}\csa{relax}, and then the + \csa{relax} is gobbled.} +\endgroup +\addtocounter{Hfootnote}{2} + +The \csbxint{For} loops may be used inside alignments or other contexts with the replacement text closing groups. Here is an example (still using \LaTeX's tabular): @@ -3685,19 +3917,19 @@ with the replacement text closing groups. Here is an example #2:\xintFor* #1 in {abcde} \do {&($ #1 \to #2 $)}\\ }% \end{tabular}} -\lverb|$catcode38 12 $catcode43 0 +catcode36 12 +catcode45 14 - -+catcode37 12 +hsize+linewidth +makestarlowast - -+obeylines +parindent 0pt +csname @vobeyspaces+endcsname- +\dverb|@ \begin{tabular}{rccccc} \xintFor #2 in {A,B,C} \do {% #2:\xintFor* #1 in {abcde} \do {&($ #1 \to #2 $)}\\ }% \end{tabular}| It is not an expandable -macro and has some strong cousinage to \csb{xintApplyInline}. +macro and has some strong cousinage to \csbxint{ApplyInline}. When inserted inside a macro for later execution the |#| characters must -be doubled. For example: -\dverb|& +be doubled.\footnote{sometimes what seems to be a macro argument isn't really; + in \csa{raisebox\{1cm\}\{}\csa{xintFor \#1 in \{a,b,c\} }\csa{do \{\#1\}\}} no + doubling should be done.} For example: +\dverb|@ \def\T{\def\z {}% \xintFor* ##1 in {{u}{v}{w}} \do {% \xintFor ##2 in {x,y,z} \do {% @@ -3716,20 +3948,314 @@ be doubled. For example: Similarly when the replacement text of |\xintFor| defines a macro with parameters, the macro character |#| must be doubled. -The advantages of using macro parameters rather than macros for the items -reveals itself in certain circumstances which may concern more the macro -programmer than the general \LaTeX{} (or \TeX{}) user. On the other hand the -capacity of \csb{xintFor} to survive in contexts such as alignments could prove -of more general interest. +It is licit to use inside an \csbxint{For} a |\macro| which itself has +been defined to use internally some other \csbxint{For}. The same macro +parameter |#1| can be used with no conflict (as mentioned above, in the +definition of |\macro| the |#| used in the \csbxint{For} declaration must be +doubled, as is the general rule in \TeX{} with things defined inside other +things). + +The iterated commands as well as the list items are allowed to contain +explicit |\par| tokens. Neither \csbxint{For} nor \csbxint{For*} create groups. +The effect is like piling up the iterated commands with each time |#1| (or +|#2| ...) replaced by an item of the list. However, contrarily to the +completely expandable \csbxint{ApplyUnbraced}, but similarly to the non +completely expandable \csbxint{ApplyInline} each iteration is executed +first before looking at the next |#1| (and the starred variant \csbxint{For*} +keeps on expanding each unbraced item it finds, gobbling spaces). + +\subsection{\csbh{xintifForFirst}, \csbh{xintifForLast}} +\label{xintifForFirst}\label{xintifForLast} +{\small New in |1.09e|.\par} + + +\csbxint{ifForFirst}\,\texttt{\{YES branch\}\{NO branch\}} + and \csbxint{ifForLast}\,\texttt{\{YES + branch\}\hskip 0pt plus 0.2em \{NO branch\}} execute the |YES| or |NO| branch +if the +\csbxint{For} +or \csbxint{For*} loop is currently in its first, respectively last, iteration. + +Designed to work as expected under nesting. Don't forget an empty brace pair +|{}| if a branch is to do nothing. May be used multiple times in the replacement +text of the loop. + +\subsection{ \csbh{xintBreakFor}, \csbh{xintBreakForAndDo}} +\label{xintBreakFor}\label{xintBreakForAndDo} +{\small New in |1.09e|.\par} + +One may immediately terminate an \csbxint{For} or \csbxint{For*} loop with +\csbxint{BreakFor}. As the criterion for breaking will be decided on a +basis of some test, it is recommended to use for this test the syntax of +\href{http://ctan.org/pkg/ifthen}{ifthen}\footnote{\url{http://ctan.org/pkg/ifthen}} +or +\href{http://ctan.org/pkg/etoolbox}{etoolbox}\footnote{\url{http://ctan.org/pkg/etoolbox}} +or the \xintname own conditionals, rather than one of the various +|\if...\fi| of \TeX{}. Else (and this is without even mentioning all the various +pecularities of the +|\if...\fi| constructs), one has to carefully move the break after the closing +of +the conditional, typically with |\expandafter\xintBreakFor\fi|.\footnote{the + difficulties here are similar to those mentioned in \autoref{sec:ifcase}, + although less severe, as complete expandability is not to be maintained; hence + the allowed use of \href{http://ctan.org/pkg/ifthen}{ifthen}.} + +There is also \csbxint{BreakForAndDo}. Both are illustrated by various examples +in the next section which is devoted to ``forever'' loops. + + +\subsection{\csbh{xintintegers}, \csbh{xintdimensions}, \csbh{xintrationals}} +\label{xintegers}\label{xintintegers} +\label{xintdimensions}\label{xintrationals} +{\small New in |1.09e|.\par} + +If the list argument to \csbxint{For} (or \csbxint{For*}, the two are here +completely equivalent) is \csbxint{integers} (equivalently \csbxint{egers}) or +more generally \csbxint{integers}|[||start|\allowbreak|+|\allowbreak|delta||]| + (\emph{within + braces}!), +then \csbxint{For} does an infinite iteration where |#1| (or |#2|, |#3|, |#4|) +will run through the arithmetic sequence of (short) integers with initial value +|start| and increment |delta| (default values: |start=1|, |delta=1|; if the +optional argument is present it must contains both of them, and they may be +explicit integers, or macros or count registers. The |#1| (or |#2|, |#3|, |#4|) +will stand for |\numexpr <opt sign><digits>\relax|, and the litteral +representation as a string of digits can thus be obtained as \fbox{\csa{the\#1}} +or |\number#1|. Such a |#1| can be used in an |\ifnum| test with no need to be +postfixed with a space or a |\relax| and one should \emph{not} add them. + +If the list argument is \csbxint{dimensions} or more generally +\csbxint{dimensions}|[||start|\allowbreak|+|\allowbreak|delta||]| (\emph{within + braces}!), then +\csbxint{For} does an infinite iteration where |#1| (or |#2|, |#3|, |#4|) will +run through the arithmetic sequence of dimensions with initial value +|start| and increment |delta|. Default values: |start=0pt|, |delta=1pt|; if +the optional argument is present it must contain both of them, and they may +be explicit specifications, or macros, or dimen registers, or length commands +in \LaTeX{} (the stretch and shrink components will be discarded). The |#1| +will be |\dimexpr <opt sign><digits>sp\relax|, from which one can get the +litteral (approximate) representation in points via |\the#1|. So |#1| can be +used anywhere \TeX{} expects a dimension (and there is no need in conditionals +to insert a |\relax|, and one should \emph{not} do it), and to print its value +one uses \fbox{\csa{the\#1}}. The chosen representation guarantees exact +incrementation with no rounding errors accumulating from converting into +points at each step. + + +\def\DimToNum #1{\number\dimexpr #1\relax } +% cube +\xintNewNumExpr \FA [2] {{_DimToNum {$2}}^3/{_DimToNum {$1}}^2} %$ +% square root +\xintNewNumExpr \FB [2] {sqrt ({_DimToNum {$2}}*{_DimToNum {$1}})} + +\xintNewExpr \Ratio [2] {trunc({_DimToNum {$2}}/{_DimToNum{$1}},3)} +\centeredline{% +\begingroup +\hspace{\parindent}% +\raisebox{-1cm}{\xintFor #1 in {\xintdimensions [0pt+.2pt]} \do + {\ifdim #1>2cm \expandafter\xintBreakFor\fi + \color [rgb]{\Ratio {2cm}{#1},0,0}% + \vrule width .2pt height \FB {2cm}{#1}sp depth -\FA {2cm}{#1}sp + }% end of For iterated text +}% +\endgroup +\hspace{1cm}% +\begingroup\scriptsize\def\MacroFont {\ttfamily\baselineskip8pt\relax} +\begin{minipage}{\dimexpr\linewidth-3cm-\parindent\relax} +\dverb|@ +\def\DimToNum #1{\number\dimexpr #1\relax } +\xintNewNumExpr \FA [2] {{_DimToNum {$2}}^3/{_DimToNum {$1}}^2} % cube +\xintNewNumExpr \FB [2] {sqrt ({_DimToNum {$2}}*{_DimToNum {$1}})} % sqrt +\xintNewExpr \Ratio [2] {trunc({_DimToNum {$2}}/{_DimToNum{$1}},3)} +\begingroup +\xintFor #1 in {\xintdimensions [0pt+.1pt]} \do + {\ifdim #1>2cm \expandafter\xintBreakFor\fi + \color [rgb]{\Ratio {2cm}{#1},0,0}% + \vrule width .1pt height \FB {2cm}{#1}sp depth -\FA {2cm}{#1}sp + }% end of For iterated text +\endgroup +|% +\end{minipage} +\endgroup +} + +The graphic above, with the code on its right\footnote{the somewhat peculiar + use of |\_| and |\$| is explained in \autoref{xintNewExpr}; they are made + necessary from the fact that \csa{DimToNum} is not a native + package macro, and can not be expanded with a dummy argument. But one can + also define directly the desired function, for + example the constructed \csa{FA} turns out to have meaning + \texttt{\meaning\FA}, where + the \csa{romannumeral} part is only to ensure it expands in only two steps, + and could be removed. Furthermore a handwritten macro would use here + \csa{xintiPow} and not \csa{xintPow}, as we know it has to deal with integers + only. I tried that, and also for \csa{FB} and \csa{Ratio} but obtained only a + |10\%| speed gain.}, is for +illustration only, not only because of pdf rendering artefacts when displaying +adjacent rules (which do \emph{not} show in |dvi| output as rendered by +|xdvi|, and depend from your viewer), but because not using anything but rules +it is quite inefficient and must do lots of computations to not confer a too +ragged look to the borders. With a width of |.5pt| rather than |.1pt| for the +rules, one speeds up the drawing by a factor of five, but the boundary is then +visibly ragged.\footnote{actually, this for loop takes the most time of all + computations done in this entire document!} + +If the list argument to \csbxint{For} (or \csbxint{For*}) is \csbxint{rationals} +or more generally +\csbxint{rationals}|[||start|\allowbreak|+|\allowbreak|delta||]| (\emph{within + braces}!), then \csbxint{For} does an infinite iteration where |#1| (or |#2|, +|#3|, |#4|) will run through the arithmetic sequence of \xintfracname fractions +with initial value |start| and increment |delta| (default values: |start=1/1|, +|delta=1/1|). This loop works \emph{only with \xintfracname loaded}. if the +optional argument is present it must contain both of them, and they may be given +in any of the formats recognized by \xintfracname (fractions, decimal +numbers, numbers in scientific notations, numerators and denominators in +scientific notation, etc...) , or as macros or count registers (if they are +short integers). The |#1| (or |#2|, |#3|, |#4|) will be an |a/b| fraction +(without a |[n]| part), where +the denominator |b| is the product of the denominators of +|start| and |delta| (for reasons of speed |#1| is not reduced to irreducible +form, and for another reason explained later |start| and |delta| are not put +either into irreducible form; the input may use explicitely \csa{xintIrr} to +achieve that). + +\begingroup\small +\noindent\dverb|@ +\xintFor #1 in {\xintrationals [10/21+1/21]} \do +{#1=\xintifInt {#1} + {\begingroup\color{blue}\xintTrunc{10}{#1}\endgroup} + {\xintTrunc{10}{#1}}% in blue if an integer + \xintifGt {#1}{2}{\xintBreakFor}{, }% +}| + +\smallskip +\centeredline{\parbox{\dimexpr\linewidth-3em}{\xintFor #1 in {\xintrationals [10/21+1/21]} \do +{#1=\xintifInt + {#1}{\begingroup\color{blue}\xintTrunc{10}{#1}\endgroup} + {\xintTrunc{10}{#1}}% display in blue if an integer + \xintifGt {#1}{2}{\xintBreakFor}{, }% + }}} +\endgroup + +\smallskip The example above confirms that computations are done exactly, and +illustrates that the two initial (reduced) denominators are not multiplied when +they are found to be equal (so it is recommended to input |start| and |delta| +with a common smallest possible denominator and also this is the reason why +|start| and |delta| are not by default made irreducible). As internally the +computations are done with numerators and denominators completely expanded, one +should be careful not to input numbers in scientific notation with exponents in +the hundreds, as they will get converted into as many zeros. + + +\subsection{Another table of primes}\label{ssec:primesII} + +As a further example, let us dynamically generate a tabular with the first @50@ +prime +numbers after @12345@. First we need a macro to test if a (short) number is +prime. Such a completely expandable macro was given in \autoref{xintSeq}, here +we consider a variant which will be slightly more efficient. This new +|\IsPrime| has two parameters. The first one is a macro which it redefines to +expand to the result of the primality test applied to the second argument. For +convenience we use the \href{http://ctan.org/pkg/etoolbox}{etoolbox} wrappers +to various |\ifnum| tests, although here there isn't anymore the constraint of +complete expandability (but using explicit |\if..\fi| in tabulars has its +quirks); equivalent tests are provided by \xintname, but they have some +overhead as they are able to deal with arbitrarily big integers. + +\def\IsPrime #1#2% +{\edef\TheNumber {\the\numexpr #2}% positive integer + \ifnumodd {\TheNumber} + {\ifnumgreater {\TheNumber}{1} + {\edef\ItsSquareRoot{\xintiSqrt \TheNumber}% + \xintFor ##1 in {\xintintegers [3+2]}\do + {\ifnumgreater {##1}{\ItsSquareRoot} + {\def#1{1}\xintBreakFor} + {}% + \ifnumequal {\TheNumber}{(\TheNumber/##1)*##1} + {\def#1{0}\xintBreakFor } + {}% + }} + {\def#1{0}}}% 1 is not prime + {\ifnumequal {\TheNumber}{2}{\def#1{1}}{\def#1{0}}}% +}% + +\dverb|@ +\def\IsPrime #1#2% +{\edef\TheNumber {\the\numexpr #2}% positive integer + \ifnumodd {\TheNumber} + {\ifnumgreater {\TheNumber}{1} + {\edef\ItsSquareRoot{\xintiSqrt \TheNumber}% + \xintFor ##1 in {\xintintegers [3+2]}\do + {\ifnumgreater {##1}{\ItsSquareRoot} + {\def#1{1}\xintBreakFor} + {}% + \ifnumequal {\TheNumber}{(\TheNumber/##1)*##1} + {\def#1{0}\xintBreakFor } + {}% + }} + {\def#1{0}}}% 1 is not prime + {\ifnumequal {\TheNumber}{2}{\def#1{1}}{\def#1{0}}}% +}| + +%\newcounter{primecount} +%\newcounter{cellcount} +\begin{figure*}[ht!] + \centering\phantomsection\label{primes} + \begin{tabular}{|*{7}c|} + \hline + \setcounter{primecount}{0}\setcounter{cellcount}{0}% + \xintFor #1 in {\xintintegers [12345+2]} \do + {\IsPrime\Result{#1}% + \ifnumgreater{\Result}{0} + {\stepcounter{primecount}% + \stepcounter{cellcount}% + \ifnumequal {\value{cellcount}}{7} + {\the#1 \\\setcounter{cellcount}{0}} + {\the#1 &}} + {}% + \ifnumequal {\value{primecount}}{50} + {\xintBreakForAndDo + {\multicolumn {6}{l|}{These are the first 50 primes after 12345.}\\}} + {}% + }\hline +\end{tabular} +\end{figure*} + +As we used \csbxint{For} inside a macro we had to double the |#| in its |#1| +parameter. Here is now the code which creates the prime table (the table has +been put in a \hyperref[primes]{float}, which appears +\vpageref[above]{primes}): +\dverb?@ +\newcounter{primecount} +\newcounter{cellcount} +\begin{figure*}[ht!] + \centering + \begin{tabular}{|*{7}c|} + \hline + \setcounter{primecount}{0}\setcounter{cellcount}{0}% + \xintFor #1 in {\xintintegers [12345+2]} \do + {\IsPrime\Result{#1}% + \ifnumgreater{\Result}{0} + {\stepcounter{primecount}% + \stepcounter{cellcount}% + \ifnumequal {\value{cellcount}}{7} + {\the#1 \\\setcounter{cellcount}{0}} + {\the#1 &}} + {}% + \ifnumequal {\value{primecount}}{50} + {\xintBreakForAndDo + {\multicolumn {6}{l|}{These are the first 50 primes after 12345.}\\}} + {}% + }\hline +\end{tabular} +\end{figure*}? \subsection{\csbh{xintForpair}, \csbh{xintForthree}, \csbh{xintForfour}}\label{xintForpair}\label{xintForthree}\label{xintForfour} {\small New in |1.09c| and in experimental status.\par} This is experimental and subjected to change. The syntax is illustrated in this example: -\lverb|$catcode38 12 $catcode43 0 +catcode36 12 +catcode45 14 - -+catcode37 12 +hsize+linewidth +makestarlowast - -+obeylines +parindent 0pt +csname @vobeyspaces+endcsname- +\dverb|@ \begin{tabular}{cccc} \xintForpair #1#2 in {(A,a),(B,b),(C,c)} \do {% \xintForpair #3#4 in {(X,x),(Y,y),(Z,z)} \do {% @@ -3737,8 +4263,7 @@ This is experimental and subjected to change. The syntax is illustrated in this #1 & #3\\ #4 & #2\\ \end{tabular}\right)$&}\\\noalign{\vskip1\jot}}% -\end{tabular} -|% +\end{tabular}|% \centeredline{\begin{tabular}{cccc} \xintForpair #1#2 in {(A,a),(B,b),(C,c)} \do {% \xintForpair #3#4 in {(X,x),(Y,y),(Z,z)} \do {% @@ -3749,20 +4274,16 @@ This is experimental and subjected to change. The syntax is illustrated in this \end{tabular}} \smallskip -Only |#1#2|, |#2#3|, |#3#4| are accepted. One can nest with \csb{xintFor}, for -disjoint sets of macro parameters of course. There is also \csa{xintForthree} +Only |#1#2|, |#2#3|, |#3#4| are accepted. One can nest with \csbxint{For}, for +disjoint sets of macro parameters. There is also \csa{xintForthree} (with |#1#2#3| or |#2#3#4|) and \csa{xintForfour} (only with |#1#2#3#4|). These three macros |\xintForpair|, |\xintForthree| and |\xintForfour| are to be considered in experimental status, and may be removed or substantially modified -at some later stage. Actually they may be more of interest for some programming -tasks, where having macro parameters rather than macros may be very helpful in -certain circumstances, than for use by a general audience. +at some later stage. -\catcode`& \active \subsection{\csbh{xintAssign}}\label{xintAssign} - \csa{xintAssign}\meta{braced things}\csa{to}% \meta{as many cs as they are things} defines (without checking if something gets overwritten) the control sequences on the right of @@ -3812,14 +4333,351 @@ and |\Bez{5}| to \digitstt{\Bez5}: \digitstt{(\Bez3)${}\times{}$\Bez1${}-{}$(\Bez4)${}\times{}$\Bez2${}={}$\Bez5.} This macro is incompatible with expansion-only contexts. + \subsection{\csbh{xintRelaxArray}}\label{xintRelaxArray} \csa{xintRelaxArray}\csa{myArray} sets to \csa{relax} all macros which were defined by the previous \csa{xintAssignArray} with \csa{myArray} as array name. +\subsection{The Quick Sort algorithm illustrated}\label{ssec:quicksort} + +First a completely expandable macro which sorts a list of numbers. The |\QSfull| +macro expands its list argument, which may thus be a macro; its items must +expand to possibly big integers (or also decimal numbers or fractions if using +\xintfracname), but if an item is expressed as a computation, this computation +will be redone each time the item is considered! If the numbers have many digits +(i.e. hundreds of digits...), the expansion of |\QSfull| is fastest if each +number, rather than being explicitely given, is represented as a single token +which expands to it in one step. + +If the interest is only in \TeX{} integers, then one should replace the macros +|\QSMore|, |QSEqual|, |QSLess| with versions using the +\href{http://ctan.org/pkg/etoolbox}{etoolbox} (\LaTeX{} only) |\ifnumgreater|, +|\ifnumequal| and |\ifnumless| conditionals rather than \csbxint{ifGt}, +\csbxint{ifEq}, \csbxint{ifLt}. + +\begingroup\makeatletter\let\check@percent\relax +\def\MacroFont{\small\baselineskip12pt \ttfamily } +\begin{verbatim} +% THE QUICK SORT ALGORITHM EXPANDABLY +\input xintfrac.sty +% HELPER COMPARISON MACROS +\def\QSMore #1#2{\xintifGt {#2}{#1}{{#2}}{ }} +% the spaces are there to stop the \romannumeral-`0 originating +% in \xintapplyunbraced when it applies a macro to an item +\def\QSEqual #1#2{\xintifEq {#2}{#1}{{#2}}{ }} +\def\QSLess #1#2{\xintifLt {#2}{#1}{{#2}}{ }} +% +\makeatletter +\def\QSfull {\romannumeral0\qsfull } +\def\qsfull #1{\expandafter\qsfull@a\expandafter{\romannumeral-`0#1}} +\def\qsfull@a #1{\expandafter\qsfull@b\expandafter {\xintLength {#1}}{#1}} +\def\qsfull@b #1{\ifcase #1 + \expandafter\qsfull@empty + \or\expandafter\qsfull@single + \else\expandafter\qsfull@c + \fi +}% +\def\qsfull@empty #1{ } % the space stops the \QSfull \romannumeral0 +\def\qsfull@single #1{ #1} +% for simplicity of implementation, we pick up the first item as pivot +\def\qsfull@c #1{\qsfull@ci #1\undef {#1}} +\def\qsfull@ci #1#2\undef {\qsfull@d {#1}}% #3 is the list, #1 its first item +\def\qsfull@d #1#2{\expandafter\qsfull@e\expandafter + {\romannumeral0\qsfull + {\xintApplyUnbraced {\QSMore {#1}}{#2}}}% + {\romannumeral0\xintapplyunbraced {\QSEqual {#1}}{#2}}% + {\romannumeral0\qsfull + {\xintApplyUnbraced {\QSLess {#1}}{#2}}}% +}% +\def\qsfull@e #1#2#3{\expandafter\qsfull@f\expandafter {#2}{#3}{#1}}% +\def\qsfull@f #1#2#3{\expandafter\space #2#1#3} +\makeatother +% EXAMPLE +\edef\z {\QSfull {{1.0}{0.5}{0.3}{1.5}{1.8}{2.0}{1.7}{0.4}{1.2}{1.4}% + {1.3}{1.1}{0.7}{1.6}{0.6}{0.9}{0.8}{0.2}{0.1}{1.9}}} +\tt\meaning\z +\def\a {3.123456789123456789}\def\b {3.123456789123456788} +\def\c {3.123456789123456790}\def\d {3.123456789123456787} +\expandafter\def\expandafter\z\expandafter + {\romannumeral0\qsfull {{\a}\b\c\d}}% \a is braced to not be expanded +\meaning\z +\end{verbatim} + +% THE QUICK SORT ALGORITHM EXPANDABLY +\def\QSMore #1#2{\xintifGt {#2}{#1}{{#2}}{ }} +% the spaces stop the \romannumeral-`0 done by \xintapplyunbraced each time +% it applies its macro argument to an item +\def\QSEqual #1#2{\xintifEq {#2}{#1}{{#2}}{ }} +\def\QSLess #1#2{\xintifLt {#2}{#1}{{#2}}{ }} +% +\def\QSfull {\romannumeral0\qsfull } +\def\qsfull #1{\expandafter\qsfull@a\expandafter{\romannumeral-`0#1}} +\def\qsfull@a #1{\expandafter\qsfull@b\expandafter {\xintLength {#1}}{#1}} +\def\qsfull@b #1{\ifcase #1 + \expandafter\qsfull@empty + \or\expandafter\qsfull@single + \else\expandafter\qsfull@c + \fi +}% +\def\qsfull@empty #1{ } % the space stops the \QSfull \romannumeral0 +\def\qsfull@single #1{ #1} +\def\qsfull@c #1{\qsfull@ci #1\undef {#1}} % we pick up the first as Pivot +\def\qsfull@ci #1#2\undef {\qsfull@d {#1}} +\def\qsfull@d #1#2{\expandafter\qsfull@e\expandafter + {\romannumeral0\qsfull + {\xintApplyUnbraced {\QSMore {#1}}{#2}}}% + {\romannumeral0\xintapplyunbraced {\QSEqual {#1}}{#2}}% + {\romannumeral0\qsfull + {\xintApplyUnbraced {\QSLess {#1}}{#2}}}% +}% +\def\qsfull@e #1#2#3{\expandafter\qsfull@f\expandafter {#2}{#3}{#1}}% +\def\qsfull@f #1#2#3{\expandafter\space #2#1#3} +\makeatother +% EXAMPLE +\edef\z {\QSfull {{1.0}{0.5}{0.3}{1.5}{1.8}{2.0}{1.7}{0.4}{1.2}{1.4}% + {1.3}{1.1}{0.7}{1.6}{0.6}{0.9}{0.8}{0.2}{0.1}{1.9}}} +\noindent Output:\par +\texttt{\printnumber{\meaning\z}} + +\def\a {3.123456789123456789}\def\b {3.123456789123456788} +\def\c {3.123456789123456790}\def\d {3.123456789123456787} +\expandafter\def\expandafter\z\expandafter + {\romannumeral0\qsfull {{\a}\b\c\d}}% \a is braced to not be expanded +\texttt{\printnumber{\meaning\z}} +\endgroup + +We then turn to a graphical illustration of the algorithm. For simplicity the +pivot is always chosen to be the first list item. We also show later how to +illustrate the variant which picks up the last item of each unsorted +chunk as pivot. + +\begingroup +\makeatletter +\let\check@percent\relax +% il utilise MacroFont +\def\MacroFont{\small\baselineskip 12pt \ttfamily } +\begin{verbatim} +\input xintfrac.sty % if Plain TeX +% +\definecolor{LEFT}{RGB}{216,195,88} +\definecolor{RIGHT}{RGB}{208,231,153} +\definecolor{INERT}{RGB}{199,200,194} +\definecolor{PIVOT}{RGB}{109,8,57} +% +\def\QSMore #1#2{\xintifGt {#2}{#1}{{#2}}{ }}% space will be gobbled +\def\QSEqual #1#2{\xintifEq {#2}{#1}{{#2}}{ }} +\def\QSLess #1#2{\xintifLt {#2}{#1}{{#2}}{ }} +% +\makeatletter +\def\QS@a #1{\expandafter \QS@b \expandafter {\xintLength {#1}}{#1}} +\def\QS@b #1{\ifcase #1 + \expandafter\QS@empty + \or\expandafter\QS@single + \else\expandafter\QS@c + \fi +}% +\def\QS@empty #1{} +\def\QS@single #1{\QSIr {#1}} +\def\QS@c #1{\QS@d #1!{#1}} % we pick up the first as pivot. +\def\QS@d #1#2!{\QS@e {#1}}% #1 = first element, #3 = list +\def\QS@e #1#2{\expandafter\QS@f\expandafter + {\romannumeral0\xintapplyunbraced {\QSMore {#1}}{#2}}% + {\romannumeral0\xintapplyunbraced {\QSEqual {#1}}{#2}}% + {\romannumeral0\xintapplyunbraced {\QSLess {#1}}{#2}}% +}% +\def\QS@f #1#2#3{\expandafter\QS@g\expandafter {#2}{#3}{#1}}% +% Here \QSLr, \QSIr, \QSr have been let to \relax, so expansion stops. +% #2= elements < pivot, #1 = elements = pivot, #3 = elements > pivot +\def\QS@g #1#2#3{\QSLr {#2}\QSIr {#1}\QSRr {#3}}% +% +\def\DecoLEFT #1{\xintFor* ##1 in {#1} \do {\colorbox{LEFT}{##1}}} +\def\DecoINERT #1{\xintFor* ##1 in {#1} \do {\colorbox{INERT}{##1}}} +\def\DecoRIGHT #1{\xintFor* ##1 in {#1} \do {\colorbox{RIGHT}{##1}}} +\def\DecoPivot #1{\begingroup\color{PIVOT}\advance\fboxsep-\fboxrule + \fbox{#1}\endgroup} +\def\DecoLEFTwithPivot #1{% + \xintFor* ##1 in {#1} \do + {\xintifForFirst {\DecoPivot {##1}}{\colorbox{LEFT}{##1}}}% +} +\def\DecoRIGHTwithPivot #1{% + \xintFor* ##1 in {#1} \do + {\xintifForFirst {\DecoPivot {##1}}{\colorbox{RIGHT}{##1}}}% +} +% +\def\QSinitialize #1{\def\QS@list{\QSRr {#1}}% + \let\QSRr\DecoRIGHT +% \QS@list \par +\par\centerline{\QS@list} +} +\def\QSoneStep {\let\QSLr\DecoLEFTwithPivot + \let\QSIr\DecoINERT + \let\QSRr\DecoRIGHTwithPivot +% \QS@list +\centerline{\QS@list} +% \par + \def\QSLr {\noexpand\QS@a}% + \let\QSIr\relax + \def\QSRr {\noexpand\QS@a}% + \edef\QS@list{\QS@list}% + \let\QSLr\relax + \let\QSRr\relax + \edef\QS@list{\QS@list}% + \let\QSLr\DecoLEFT + \let\QSIr\DecoINERT + \let\QSRr\DecoRIGHT +% \QS@list +\centerline{\QS@list} +% \par +} +\begingroup\offinterlineskip +\small +\QSinitialize {{1.0}{0.5}{0.3}{1.5}{1.8}{2.0}{1.7}{0.4}{1.2}{1.4}% + {1.3}{1.1}{0.7}{1.6}{0.6}{0.9}{0.8}{0.2}{0.1}{1.9}} +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\endgroup +\end{verbatim} + +\def\QSMore #1#2{\xintifGt {#2}{#1}{{#2}}{ }}% space will be gobbled +\def\QSEqual #1#2{\xintifEq {#2}{#1}{{#2}}{ }} +\def\QSLess #1#2{\xintifLt {#2}{#1}{{#2}}{ }} +% +\def\QS@a #1{\expandafter \QS@b \expandafter {\xintLength {#1}}{#1}} +\def\QS@b #1{\ifcase #1 + \expandafter\QS@empty + \or\expandafter\QS@single + \else\expandafter\QS@c + \fi +}% +\def\QS@empty #1{} +\def\QS@single #1{\QSIr {#1}} +\def\QS@c #1{\QS@d #1!{#1}} % we pick up the first as pivot. +\def\QS@d #1#2!{\QS@e {#1}}% #1 = first element, #3 = list +\def\QS@e #1#2{\expandafter\QS@f\expandafter + {\romannumeral0\xintapplyunbraced {\QSMore {#1}}{#2}}% + {\romannumeral0\xintapplyunbraced {\QSEqual {#1}}{#2}}% + {\romannumeral0\xintapplyunbraced {\QSLess {#1}}{#2}}% +}% +\def\QS@f #1#2#3{\expandafter\QS@g\expandafter {#2}{#3}{#1}}% +% #2= elements < pivot, #1 = elements = pivot, #3 = elements > pivot +% Here \QSLr, \QSIr, \QSr have been let to \relax, so expansion stops. +\def\QS@g #1#2#3{\QSLr {#2}\QSIr {#1}\QSRr {#3}}% +% +\def\DecoLEFT #1{\xintFor* ##1 in {#1} \do {\colorbox{LEFT}{##1}}} +\def\DecoINERT #1{\xintFor* ##1 in {#1} \do {\colorbox{INERT}{##1}}} +\def\DecoRIGHT #1{\xintFor* ##1 in {#1} \do {\colorbox{RIGHT}{##1}}} +\def\DecoPivot #1{\begingroup\color{PIVOT}\advance\fboxsep-\fboxrule + \fbox{#1}\endgroup} +\def\DecoLEFTwithPivot #1{% + \xintFor* ##1 in {#1} \do + {\xintifForFirst {\DecoPivot {##1}}{\colorbox{LEFT}{##1}}}% +} +\def\DecoRIGHTwithPivot #1{% + \xintFor* ##1 in {#1} \do + {\xintifForFirst {\DecoPivot {##1}}{\colorbox{RIGHT}{##1}}}% +} +% +\def\QSinitialize #1{\def\QS@list{\QSRr {#1}}% + \let\QSRr\DecoRIGHT +% \QS@list \par +\par\centerline{\QS@list} +} +\def\QSoneStep {\let\QSLr\DecoLEFTwithPivot + \let\QSIr\DecoINERT + \let\QSRr\DecoRIGHTwithPivot +% \QS@list +\centerline{\QS@list} +% \par + \def\QSLr {\noexpand\QS@a}% + \let\QSIr\relax + \def\QSRr {\noexpand\QS@a}% + \edef\QS@list{\QS@list}% + \let\QSLr\relax + \let\QSRr\relax + \edef\QS@list{\QS@list}% + \let\QSLr\DecoLEFT + \let\QSIr\DecoINERT + \let\QSRr\DecoRIGHT +% \QS@list +\centerline{\QS@list} +% \par +} + +\begingroup\offinterlineskip +\small +\QSinitialize {{1.0}{0.5}{0.3}{1.5}{1.8}{2.0}{1.7}{0.4}{1.2}{1.4}% + {1.3}{1.1}{0.7}{1.6}{0.6}{0.9}{0.8}{0.2}{0.1}{1.9}} +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\endgroup + + +If one wants rather to have the pivot from the end of the yet to sort chunks, +then one should use the following variants: +\begin{verbatim} +\def\QS@c #1{\expandafter\QS@e\expandafter + {\romannumeral0\xintnthelt {-1}{#1}}{#1}% +}% +\def\DecoLEFTwithPivot #1{% + \xintFor* ##1 in {#1} \do + {\xintifForLast {\DecoPivot {##1}}{\colorbox{LEFT}{##1}}}% +} +\def\DecoRIGHTwithPivot #1{% + \xintFor* ##1 in {#1} \do + {\xintifForLast {\DecoPivot {##1}}{\colorbox{RIGHT}{##1}}}% +} +\def\QSinitialize #1{\def\QS@list{\QSLr {#1}}% + \let\QSLr\DecoLEFT +% \QS@list \par +\par\centerline{\QS@list} +} +\end{verbatim} +\def\QS@c #1{\expandafter\QS@e\expandafter + {\romannumeral0\xintnthelt {-1}{#1}}{#1}% +}% +\def\DecoLEFTwithPivot #1{% + \xintFor* ##1 in {#1} \do + {\xintifForLast {\DecoPivot {##1}}{\colorbox{LEFT}{##1}}}% +} +\def\DecoRIGHTwithPivot #1{% + \xintFor* ##1 in {#1} \do + {\xintifForLast {\DecoPivot {##1}}{\colorbox{RIGHT}{##1}}}% +} +\def\QSinitialize #1{\def\QS@list{\QSLr {#1}}% + \let\QSLr\DecoLEFT +% \QS@list \par +\par\centerline{\QS@list} +} +\begingroup\offinterlineskip +\small +\QSinitialize {{1.0}{0.5}{0.3}{1.5}{1.8}{2.0}{1.7}{0.4}{1.2}{1.4}% + {1.3}{1.1}{0.7}{1.6}{0.6}{0.9}{0.8}{0.2}{0.1}{1.9}} +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\QSoneStep +\endgroup + +\endgroup + +It is possible to modify this code to let it do \csa{QSonestep} repeatedly and +stop automatically when the sort is finished. \section{Commands of the \xintfracname package}\label{sec:comfrac} @@ -3845,19 +4703,31 @@ must expand to an integer obeying the \TeX{} bound. The fraction format on output is the scientific notation for the `float' macros, and the |A/B[n]| format for all other fraction macros, with the exception of -\csb{xintTrunc}, {\color{blue}\string\xint\-Round} (which produce decimal -numbers) and \csb{xintIrr}, \csb{xintJrr}, \csb{xintRawWithZeros} (which returns +\csbxint{Trunc}, {\color{blue}\string\xint\-Round} (which produce decimal +numbers) and \csbxint{Irr}, \csbxint{Jrr}, \csbxint{RawWithZeros} (which returns an |A/B| with no trailing |[n]|, and prints the |B| even if it is |1|), -\csb{xintPRaw} which does not print the |[n]| if |n=0| or the |B| if |B=1|. Use -\csb{xintNum} (or |\xintPRaw| if simplification is not needed) for fractions a +\csbxint{PRaw} which does not print the |[n]| if |n=0| or the |B| if |B=1|. Use +\csbxint{Num} (or |\xintPRaw| if simplification is not needed) for fractions a priori known to simplify to integers: |\xintNum {\xintAdd {2}{3}}| gives \digitstt{\xintNum {\xintAdd {2}{3}}} whereas |\xintAdd {2}{3}| returns -\digitstt{\xintAdd {2}{3}}. Some macros (among them \csb{xintiTrunc}, -\csb{xintiRound}, and \csb{xintFac}) already produce integers on output. +\digitstt{\xintAdd {2}{3}}. Some macros (among them \csbxint{iTrunc}, +\csbxint{iRound}, and \csbxint{Fac}) already produce integers on output. \localtableofcontents +\subsection{\csbh{xintifInt}}\label{xintifInt} +{\small New with release |1.09e|.\par} + +\csa{xintifInt}|{f}{YES branch}{NO branch}| expandably chooses the |YES| branch +if |f| reveals itself after expansion and simplification to be an integer. As +with the other \xintname conditionals, both branches must be present although +one of the two (or both, but why then?) may well be an empty brace pair |{}|. As +will all other \xintname conditionals, spaces in-between the braced things do +not matter, but a space after the closing brace of the |NO| branch is +significant. + + \subsection{\csbh{xintLen}}\label{xintLen} The original macro is extended to accept a fraction on input. @@ -3890,9 +4760,9 @@ does \emph{not} show the |B| if |B=1|. \centeredline{|\xintPRaw \centeredline{|\xintPRaw {\xintIrr{861/123}}=|\digitstt{\xintPRaw{\xintIrr{861/123}}} \ vz.\ |\xintIrr{861/123}=|\digitstt{\xintIrr{861/123}}} See also -\csb{xintFrac} (or \csb{xintFwOver}) for math mode. As is examplified above the -\csb{xintIrr} macro which puts the fraction into irreducible form does not -remove the |/1| if the fraction is an integer. One can use \csb{xintNum} for +\csbxint{Frac} (or \csbxint{FwOver}) for math mode. As is examplified above the +\csbxint{Irr} macro which puts the fraction into irreducible form does not +remove the |/1| if the fraction is an integer. One can use \csbxint{Num} for that, but there will be an error message if the fraction was not an integer; so the combination |\xintPRaw{\xintIrr{f}}| is the way to go. @@ -3924,7 +4794,7 @@ fraction:\footnote{recall that the |[]| construct excludes presence of a decimal \centeredline{|\xintDenominator {178.000/25600000}|\digitstt{=\xintDenominator {178.000/25600000}}} As shown by the examples, no simplification of the input is done. The denominator looks wrong in the last example, but the -numerator was tacitly multiplied by &1000& through the removal of the decimal +numerator was tacitly multiplied by @1000@ through the removal of the decimal point. For a result uniquely associated to the value of the fraction first apply \csa{xintIrr}. @@ -3974,7 +4844,7 @@ fractions being in fact integers.) {\small New with release |1.04|.\par} -This is as \csb{xintFrac} except that a negative fraction has the sign put in +This is as \csbxint{Frac} except that a negative fraction has the sign put in front, not in the numerator. \centeredline{|\[\xintFrac {-355/113}=\xintSignedFrac {-355/113}\]|} \[\xintFrac {-355/113}=\xintSignedFrac {-355/113}\] @@ -3993,7 +4863,7 @@ $\xintFwOver {\xintNum {\xintFac{10}/\xintiSqr{\xintFac {5}}}}$. {\small New with release |1.04|.\par} -This is as \csb{xintFwOver} except that a negative fraction has the sign put in +This is as \csbxint{FwOver} except that a negative fraction has the sign put in front, not in the numerator. \centeredline{|\[\xintFwOver {-355/113}=\xintSignedFwOver {-355/113}\]|} \[\xintFwOver {-355/113}=\xintSignedFwOver {-355/113}\] @@ -4014,7 +4884,7 @@ stupid. Starting with release |1.08|, \csa{xintIrr} does not remove the trailing |/1| when the output is an integer. This was deemed better for various (stupid?) reasons and thus the output format is now \emph{always} |A/B| with |B>0|. Use -\csb{xintPRaw} on top of \csa{xintIrr} if it is needed to get rid of a possible +\csbxint{PRaw} on top of \csa{xintIrr} if it is needed to get rid of a possible trailing |/1|. For display in math mode, use rather |\xintFrac{\xintIrr {f}}| or |\xintFwOver{\xintIrr {f}}|. @@ -4135,12 +5005,12 @@ all superfluous leading zeros.) \subsection{\csbh{xintE}}\label{xintE} {\small New with |1.07|.} -|\xintE {f}{x}| multiplies the fraction |f| by &10^x&. The \emph{second} +|\xintE {f}{x}| multiplies the fraction |f| by @10^x@. The \emph{second} argument |x| must obey the \TeX{} bounds. Example: \centeredline{|\count 255 123456789 \xintE {10}{\count 255}|\digitstt{->\count 255 123456789 \xintE {10}{\count 255}}} Be careful that for obvious reasons such -gigantic numbers should not be given to \csb{xintNum}, or added to something +gigantic numbers should not be given to \csbxint{Num}, or added to something with a widely different order of magnitude, as the package always works to get the \emph{exact} result. There is \emph{no problem} using them for \emph{float} operations:\centeredline{|\xintFloatAdd @@ -4188,7 +5058,7 @@ mode. For this one must use |\xintthefloatexpr|. \subsection{\csbh{xintAdd}}\label{xintAdd} The original macro is extended to accept fractions on input. Its output will now -always be in the form |A/B[n]|. The original is available as \csb{xintiAdd}. +always be in the form |A/B[n]|. The original is available as \csbxint{iAdd}. \subsection{\csbh{xintFloatAdd}}\label{xintFloatAdd} @@ -4204,7 +5074,7 @@ was absent, the result of this computation. The original macro is extended to accept fractions on input. Its output will now always be in the form |A/B[n]|. -The original is available as \csb{xintiSub}. +The original is available as \csbxint{iSub}. \subsection{\csbh{xintFloatSub}}\label{xintFloatSub} @@ -4220,7 +5090,7 @@ was absent, the result of this computation. The original macro is extended to accept fractions on input. Its output will now always be in the form |A/B[n]|. -The original is available as \csb{xintiMul}. +The original is available as \csbxint{iMul}. \subsection{\csbh{xintFloatMul}}\label{xintFloatMul} @@ -4235,7 +5105,7 @@ was absent, the result of this computation. The original macro is extended to accept a fraction on input. Its output will now always be in the form |A/B[n]|. The original is available as -\csb{xintiSqr}. +\csbxint{iSqr}. \subsection{\csbh{xintDiv}}\label{xintDiv} @@ -4260,7 +5130,7 @@ simplify to a integer |n| (non negative and at most |999999|, but already |100000!| is prohibitively time-costly). On output |n!| (no trailing |/1[0]|). The original macro (which has less overhead) is still -available as \csb{xintiFac}. +available as \csbxint{iFac}. \subsection{\csbh{xintPow}}\label{xintPow} @@ -4268,7 +5138,7 @@ available as \csb{xintiFac}. input. The output will now always be in the form |A/B[n]| (even when the exponent vanishes: |\xintPow {2/3}{0}|\digitstt{=\xintPow{2/3}{0}}). The original is available as -\csb{xintiPow}. +\csbxint{iPow}. % \xintDigits:= 3; @@ -4292,7 +5162,7 @@ denominators which can not be computed exactly in a reasonable time. Indeed The exponent |x| will be fed to a |\numexpr|, hence count registers are accepted on input for this |x|. And the absolute value \verb+|x|+ must obey the \TeX{} -bound. For larger exponents use the slightly slower routine \csb{xintFloatPower} +bound. For larger exponents use the slightly slower routine \csbxint{FloatPower} which allows the exponent to be a fraction simplifying to an integer and does not limit its size. This slightly slower routine is the one to which |^| is mapped inside |\xintthefloatexpr...\relax|. @@ -4384,7 +5254,7 @@ available as \csa{xintiPrd}. The macro is extended to fractions. Its output is still either |-1|, |0|, or |1| with no forward slash nor trailing |[n]|. The original, which skips the overhead of -the fraction format parsing, is available as \csb{xintiCmp}. +the fraction format parsing, is available as \csbxint{iCmp}. For choosing branches according to the result of comparing |f| and |g|, the following syntax is recommended: |\xintSgnFork{\xintCmp{f}{g}}{code for @@ -4396,13 +5266,13 @@ dumb version (the earlier version indirectly led to the creation of giant chains of zeros in certain circumstances, causing a serious efficiency impact). \subsection{\csbh{xintIsOne}} -See \csb{xintIsOne} (\autoref{xintIsOne}). +See \csbxint{IsOne} (\autoref{xintIsOne}). \subsection{\csbh{xintGeq}}\label{xintGeq} {\small Rewritten in |1.08a|.\par} The macro is extended to fractions. The original, which skips the overhead of -the fraction format parsing, is available as \csb{xintiGeq}. Beware that the +the fraction format parsing, is available as \csbxint{iGeq}. Beware that the comparison is on the \emph{absolute values} of the fractions. Can be used as: \verb+\xintSgnFork{\xintGeq{f}{g}}{}{code for |f|<|g|}{code for @@ -4410,31 +5280,31 @@ the \emph{absolute values} of the fractions. Can be used as: Same improvements in |1.08a| as for -\csb{xintCmp}. +\csbxint{Cmp}. \subsection{\csbh{xintMax}}\label{xintMax} {\small Rewritten in |1.08a|.\par} The macro is extended to fractions. But now |\xintMax {2}{3}| returns \digitstt{\xintMax {2}{3}}. The original is available as -\csb{xintiMax}. +\csbxint{iMax}. \subsection{\csbh{xintMaxof}} -See \csb{xintMaxof} (\autoref{xintMaxof}). +See \csbxint{Maxof} (\autoref{xintMaxof}). \subsection{\csbh{xintMin}}\label{xintMin} {\small Rewritten in |1.08a|.\par} The macro is extended to fractions. The original is available as -\csb{xintiMin}. +\csbxint{iMin}. \subsection{\csbh{xintMinof}} -See \csb{xintMinof} (\autoref{xintMinof}). +See \csbxint{Minof} (\autoref{xintMinof}). \subsection{\csbh{xintAbs}}\label{xintAbs} The macro is extended to fractions. The original is available as -\csb{xintiAbs}. Note that |\xintAbs {-2}|\digitstt{=\xintAbs {-2}} whereas +\csbxint{iAbs}. Note that |\xintAbs {-2}|\digitstt{=\xintAbs {-2}} whereas |\xintiAbs {-2}|\digitstt{=\xintiAbs {-2}}. \subsection{\csbh{xintSgn}}\label{xintSgn} @@ -4442,12 +5312,12 @@ The macro is extended to fractions. The original is available as The macro is extended to fractions. Its output is still either |-1|, |0|, or |1| with no forward slash nor trailing |[n]|. The original, which skips the overhead of the fraction format parsing, is -available as \csb{xintiSgn}. +available as \csbxint{iSgn}. \subsection{\csbh{xintOpp}}\label{xintOpp} The macro is extended to fractions. The original is available as -\csb{xintiOpp}. Note that |\xintOpp {3}| now outputs \digitstt{\xintOpp {3}}. +\csbxint{iOpp}. Note that |\xintOpp {3}| now outputs \digitstt{\xintOpp {3}}. \subsection{\csbh{xintDivision}, \csbh{xint\-Quo}, \csbh{xint\-Rem}, \csbh{xintFDg}, \csbh{xintLDg}, \csbh{xintMON}, \csbh{xintMMON}, \csbh{xintOdd}} @@ -4463,7 +5333,7 @@ in the accepted format for the inputs. The macro is extended to accept a fraction on input. But this fraction should reduce to an integer. If not an error will be raised. The original is available -as \csb{xintiNum}. It is imprudent to apply \csa{xintNum} to numbers with a +as \csbxint{iNum}. It is imprudent to apply \csa{xintNum} to numbers with a large power of ten given either in scientific notation or with the |[n]| notation, as the macro will add the necessary zeros to get an explicit integer.\centeredline{|\xintNum {1e80}|} @@ -4510,7 +5380,7 @@ also \xintname. An \xintexprname{}ession is a construct -\csb{xintexpr}\meta{expandable\_expression}|\relax| where the expandable +\csbxint{expr}\meta{expandable\_expression}|\relax| where the expandable expression is read and expanded from left to right, and whose constituents\MyMarginNote{See \autoref{sec:exprsummary} for up-to-date information} @@ -4551,8 +5421,8 @@ Such an expression, like a |\numexpr| expression, is not directly printable, nor can it be directly used as argument to the other package macros. For this one uses one of the two equivalent forms: \begin{itemize} -\item \csb{xinttheexpr}\meta{expandable\_expression}|\relax|, or -\item \csb{xintthe}|\xintexpr|\meta{expandable\_expression}|\relax|. +\item \csbxint{theexpr}\meta{expandable\_expression}|\relax|, or +\item \csbxint{the}|\xintexpr|\meta{expandable\_expression}|\relax|. \end{itemize} As with other package macros the computations are done \emph{exactly}, and with @@ -4648,7 +5518,7 @@ decimal point. Active characters will interfere with |\xintexpr|-essions. One may prefix them with |\string| or use the command \csa{xintexprSafeCatcodes} before the |\xintexpr|-essions. This (locally) sets the catcodes of the characters acting -as operators to safe values. The command \csb{xintNewExpr} does it by itself, +as operators to safe values. The command \csbxint{NewExpr} does it by itself, in a group. \subsubsection{\csbh{xintexprRestoreCatcodes}}\label{xintexprRestoreCatcodes} @@ -4712,7 +5582,7 @@ compatible to an expansion only context) to such a fraction or decimal number. The parser creates an undefined control sequence for each intermediate computation (this does not refer to the intermediate steps needed in -the evaluations of the \csb{xintAdd}, \csb{xintMul}, etc... macros corresponding +the evaluations of the \csbxint{Add}, \csbxint{Mul}, etc... macros corresponding to the infix operators, but only to each conversion of such an infix operator into a computation). So, a moderately sized expression might create 10, or 20 such control sequences. On my \TeX{} installation, the memory available for such @@ -4732,12 +5602,12 @@ if some formulas are being used repeatedly, for example inside loops, with counters being incremented, or with data being fetched from a file. So it is the same formula used again and again with varying numbers inside. -With the \csb{xintNewExpr} command, it is possible to convert once and for all +With the \csbxint{NewExpr} command, it is possible to convert once and for all an expression containing parameters into an expandable macro with parameters. -Only this initial definition of this macro actually activates the \csb{xintexpr} +Only this initial definition of this macro actually activates the \csbxint{expr} parser and will (very moderately) impact the hash-table: once this unique parsing is done, a macro with parameters is produced which is built-up -recursively from the \csb{xintAdd}, \csb{xintMul}, etc... macros, exactly as it +recursively from the \csbxint{Add}, \csbxint{Mul}, etc... macros, exactly as it was necessary to do before the availability of the \xintexprname package. \subsection{The \csbh{xintNewExpr} command}\label{xintNewExpr} @@ -4793,14 +5663,14 @@ operators. % if the parameters are to be used within the macros themselves, then the macro % should be code with an underscore |_| rather than a backslash |\|. -\dverb|& -&\xintNewExpr\myformA[4]{ #1 + #2 * #3^#4 } -&\xintNewExpr\myformB[3]{ (#1 + 1.75)^#2 + #3*2.7 } -&\xintNewExpr\myformC[3]{ #1*#1+#2*#2+#3*#3-(#1*#2+#2*#3+#3*#1) } -&\xintNewExpr\myformD[2]{ (1+1.5*#1)^#2 - (1+1.5*#2)^#1 } -&\xintNewExpr\myformE[2]{ -----((((((#1*10-5*#2)))))) } -&\xintNewExpr\myformF[4]{ -#1^-#2*-#3-#4 } -&\xintNewExpr\myformG[4]{ -#1*-#2^-#3-#4 } +\dverb|@ +@\xintNewExpr\myformA[4]{ #1 + #2 * #3^#4 } +@\xintNewExpr\myformB[3]{ (#1 + 1.75)^#2 + #3*2.7 } +@\xintNewExpr\myformC[3]{ #1*#1+#2*#2+#3*#3-(#1*#2+#2*#3+#3*#1) } +@\xintNewExpr\myformD[2]{ (1+1.5*#1)^#2 - (1+1.5*#2)^#1 } +@\xintNewExpr\myformE[2]{ -----((((((#1*10-5*#2)))))) } +@\xintNewExpr\myformF[4]{ -#1^-#2*-#3-#4 } +@\xintNewExpr\myformG[4]{ -#1*-#2^-#3-#4 } \xintNewExpr\DET[9]{ #1*#5*#9+#2*#6*#7+#3*#4*#8-#1*#6*#8-#2*#4*#9-#3*#5*#7 } | @@ -4913,7 +5783,7 @@ equivalent functional forms which are more convenient; but some of the more obscure package macros of \xintname dealing with integers do not have functions pre-defined to be in correspondance with them): -\dverb|& +\dverb|@ \xintNewExpr\myformI[2]{ {_xintRound{$1}{$2}} - {_xintTrunc{$1}{$2}} } | @@ -4935,10 +5805,10 @@ expressions. \csbh{xinttheboolexpr}}\label{xintboolexpr}\label{xinttheboolexpr} {\small New in |1.09c|.\par} -Equivalent to doing |\xintexpr ...\relax| and returning &1& if the result does -not vanish, and &0& is the result is zero (as is the case with |\xintexpr|, this can be used on +Equivalent to doing |\xintexpr ...\relax| and returning @1@ if the result does +not vanish, and @0@ is the result is zero (as is the case with |\xintexpr|, this can be used on comma separated lists of expressions, and will then return a comma -separated list of &0&'s and &1&'s)). +separated list of @0@'s and @1@'s)). \subsection{\csbh{xintifboolexpr}}\label{xintifboolexpr} {\small New in |1.09c|.\par} @@ -4965,7 +5835,7 @@ on whether the outcome was non zero or zero. This will crash if used on an expre \subsection{\csbh{xintfloatexpr}, \csbh{xintthe\-float\-expr}}\label{xintfloatexpr}\label{xintthefloatexpr} -\csb{xintfloatexpr}|...\relax| is exactly like |\xintexpr...\relax| but with the +\csbxint{floatexpr}|...\relax| is exactly like |\xintexpr...\relax| but with the four binary operations and the power function mapped to \csa{xintFloatAdd}, \csa{xintFloatSub}, \csa{xintFloatMul}, \csa{xintFloatDiv} and \csa{xintFloatPower}. The precision is from the current setting of @@ -5042,7 +5912,7 @@ input it as \subsection{\csbh{xintNewFloatExpr}}\label{xintNewFloatExpr} -This is exactly like \csb{xintNewExpr} except that the created formulas are +This is exactly like \csbxint{NewExpr} except that the created formulas are set-up to use |\xintthefloatexpr|. The precision used for numbers fetched as parameters will be the one locally given by |\xintDigits| at the time of use of the created formulas, @@ -5053,12 +5923,12 @@ expression will have been evaluated with the then current setting for \subsection{\csbh{xintNewNumExpr}}\label{xintNewNumExpr} {\small New in |1.09c|.\par } -Like \csb{xintNewExpr} but using |\xintthenumexpr|. +Like \csbxint{NewExpr} but using |\xintthenumexpr|. \subsection{\csbh{xintNewBoolExpr}}\label{xintNewBoolExpr} {\small New in |1.09c|.\par } -Like \csb{xintNewExpr} but using |\xinttheboolexpr|. +Like \csbxint{NewExpr} but using |\xinttheboolexpr|. @@ -5206,7 +6076,7 @@ one hundred hexadecimal digits. This package was included in the original release |1.0| of the \xintname bundle. -Since release |1.09a| the macros filter their inputs through the \csb{xintNum} +Since release |1.09a| the macros filter their inputs through the \csbxint{Num} macro, so one can use count registers, or fractions as long as they reduce to integers. @@ -5308,7 +6178,6 @@ final quotient and last (zero) remainder. \subsection{\csbh{xintBezoutAlgorithm}}\label{xintBezoutAlgorithm} -\catcode`\& 4 \xintAssign {{\xintBezoutAlgorithm {10000}{1113}}}\to\X @@ -5326,7 +6195,6 @@ The first token is the number of steps, the second is |N|, then remainder, the top left entry of the first matrix, the bottom left entry, and then these four things at each step until the end. -\catcode`\& 13 \subsection{\csbh{xintTypesetEuclideAlgorithm}\texorpdfstring{\allowbreak\null\hspace*{.25cm}}{}}% \label{xintTypesetEuclideAlgorithm} @@ -5376,7 +6244,7 @@ The |\coeff| macro must be a one-parameter fully expandable command, taking on input an explicit number |n| and producing some fraction |\coeff{n}|; it is expanded at the time it is needed. -\dverb|& +\dverb|@ \def\coeff #1{\xintiMON{#1}/#1.5} % (-1)^n/(n+1/2) \edef\w {\xintSeries {0}{50}{\coeff}} % we want to re-use it \edef\z {\xintJrr {\w}[0]} % the [0] for a microsecond gain. @@ -5387,24 +6255,24 @@ needed. \[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} = \xintFrac\z \] For info, before action by |\xintJrr| the inner representation of the result has a denominator of |\xintLen {\xintDenominator\w}=|\xintLen -{\xintDenominator\w} digits. This troubled me as &101!!& has only 81 +{\xintDenominator\w} digits. This troubled me as @101!!@ has only 81 digits: |\xintLen {\xintQuo {\xintFac {101}}{\xintiMul {\xintiPow {2}{50}}{\xintFac{50}}}}|\digitstt{=\xintLen {\xintQuo {\xintFac {101}}{\xintiMul {\xintiPow {2}{50}}{\xintFac{50}}}}}. The explanation lies in the too clever to be efficient |#1.5| trick. It -leads to a silly extra &5^{51}& (which has \xintLen {\xintPow {5}{51}} +leads to a silly extra @5^{51}@ (which has \xintLen {\xintPow {5}{51}} digits) in the denominator. See the explanations in the next section. \begin{framed} Note: as soon as the coefficients look like factorials, it is more - efficient to use the \csb{xintRationalSeries} macro whose evaluation + efficient to use the \csbxint{RationalSeries} macro whose evaluation will avoid a denominator build-up; indeed the raw operations of addition and subtraction of fractions blindly multiply out denominators. So the raw evaluation of $\sum_{n=0}^{|N|}1/n!$ with \csa{xintSeries} will have a denominator equal to $\prod_{n=0}^{|N|} n!$. Needless to say this makes it more difficult to compute the exact value of this sum with |N=50|, for example, whereas with - \csb{xintRationalSeries} the denominator does not + \csbxint{RationalSeries} the denominator does not get bigger than $50!$. \footnotesize @@ -5447,7 +6315,7 @@ digits) in the denominator. See the explanations in the next section. % \printnumber\z \setlength{\columnsep}{0pt} -\dverb|& +\dverb|@ \def\coeffleibnitz #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]} \cnta 1 \loop % in this loop we recompute from scratch each partial sum! @@ -5477,7 +6345,7 @@ digits) in the denominator. See the explanations in the next section. \emph{must} expand to a (possibly long) integer, as is acceptable on input by the integer-only \csa{xintiAdd}. -\dverb|& +\dverb|@ \def\coeff #1{\xintiTrunc {40}{\xintMON{#1}/#1.5}}% % better: \def\coeff #1{\xintiTrunc {40} @@ -5493,7 +6361,7 @@ The |#1.5| trick to define the |\coeff| macro was neat, but |1/3.5|, for example, turns internally into |10/35| whereas it would be more efficient to have |2/7|. The second way of coding the wanted coefficient avoids a superfluous factor of five and leads to a faster evaluation. The third way is faster, after -all there is no need to use \csb{xintMON} (or rather \csb{xintiMON} which has +all there is no need to use \csbxint{MON} (or rather \csbxint{iMON} which has less parsing overhead) on integers obeying the \TeX{} bound. The denominator having no sign, we have added the |[0]| as this speeds up (infinitesimally) the parsing. @@ -5506,7 +6374,7 @@ should trash the last two digits, or at least round at 38 digits. It is interesting to compare with the computation where rounding rather than truncation is used, and with the decimal expansion of the exactly computed partial sum of the series: -\dverb|& +\dverb|@ \def\coeff #1{\xintiRound {40} % rounding at 40 {\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}% % (-1)^n/(n+1/2) times 10^40, rounded to an integer. @@ -5549,7 +6417,7 @@ expand to its value after iterated full expansion of its first token. |A| and expressions built with such; they must obey the \TeX{} bound. The initial term |f| may be a macro |\f|, it will be expanded to its value representing |F(A)|. -\dverb|& +\dverb|@ \def\ratio #1{2/#1[0]}% 2/n, to compute exp(2) \cnta 0 % previously declared count \loop \edef\z {\xintRationalSeries {0}{\cnta}{1}{\ratio }}% @@ -5569,11 +6437,11 @@ expressions built with such; they must obey the \TeX{} bound. The initial term \medskip Such computations would become quickly completely inaccessible via the -\csb{xintSeries} macros, as the factorials in the denominators would get +\csbxint{Series} macros, as the factorials in the denominators would get all multiplied together: the raw addition and subtraction on fractions just blindly multiplies denominators! Whereas \csa{xintRationalSeries} evaluate the partial sums via a less silly iterative scheme. -\dverb|& +\dverb|@ \def\ratio #1{-1/#1[0]}% -1/n, comes from the series of exp(-1) \cnta 0 % previously declared count \loop @@ -5602,7 +6470,7 @@ a macro with two parameters: |\def\ratioexp Then, if |\x| expands to some fraction |x|, the command \centeredline{|\xintRationalSeries {0}{b}{1}{\ratioexp{\x}}|} will compute $\sum_{n=0}^{n=b} x^n/n!$:\par -\dverb|& +\dverb|@ \cnta 0 \def\ratioexp #1#2{\xintDiv{#1}{#2}}% #1/#2 \loop @@ -5630,11 +6498,11 @@ for each term of the partial sum. The easiest is thus when |x| can be defined as an |\edef|. If however, you are in an expandable-only context and cannot store in a macro like |\x| the value to be used, a variant of \csa{xintRationalSeries} is needed which will first evaluate this |\x| and then -use this result without recomputing it. This is \csb{xintRationalSeriesX}, +use this result without recomputing it. This is \csbxint{RationalSeriesX}, documented next. Here is a slightly more complicated evaluation: -\dverb|& +\dverb|@ \cnta 1 \loop \edef\z {\xintRationalSeries {\cnta} @@ -5686,10 +6554,10 @@ evaluation is time-costly, but good if |\g| is a big explicit fraction encapsulated in a macro). -The example will use the macro \csb{xintPowerSeries} which computes +The example will use the macro \csbxint{PowerSeries} which computes efficiently exact partial sums of power series, and is discussed in the next section. -\dverb|& +\dverb|@ \def\firstterm #1{1[0]}% first term of the exponential series % although it is the constant 1, here it must be defined as a % one-parameter macro. Next comes the ratio function for exp: @@ -5816,12 +6684,12 @@ stuff in storage box 357''. Hence, truncating the output (or better, rounding) is the only way to go if one needs a general calculus of special functions. This is why the package -\xintseriesname provides, besides \csb{xintSeries}, \csb{xintRationalSeries}, or -\csb{xintPowerSeries} which compute \emph{exact} sums, also has -\csb{xintFxPtPowerSeries} for fixed-point computations. +\xintseriesname provides, besides \csbxint{Series}, \csbxint{RationalSeries}, or +\csbxint{PowerSeries} which compute \emph{exact} sums, also has +\csbxint{FxPtPowerSeries} for fixed-point computations. Update: release |1.08a| of \xintseriesname now includes a tentative naive -\csb{xintFloatPowerSeries}. +\csbxint{FloatPowerSeries}. \subsection{\csbh{xintPowerSeries}}\label{xintPowerSeries} @@ -5849,12 +6717,12 @@ which was plaguing the |1.03| version. \footnote{with powers |f\string^k|, from \begin{framed} Note: as soon as the coefficients look like factorials, it is more efficient - to use the \csb{xintRationalSeries} macro whose evaluation, also based on a + to use the \csbxint{RationalSeries} macro whose evaluation, also based on a similar Horner scheme, will avoid a denominator build-up originating in the coefficients themselves. \end{framed} -\dverb|& +\dverb|@ \def\geom #1{1[0]} % the geometric series \def\f {5/17[0]} \[ \sum_{n=0}^{n=20} \Bigl(\frac 5{17}\Bigr)^n @@ -5867,7 +6735,7 @@ which was plaguing the |1.03| version. \footnote{with powers |f\string^k|, from =\xintFrac{\xintIrr{\xintPowerSeries {0}{20}{\geom}{\f}}} =\xintFrac{\xinttheexpr (17^21-5^21)/12/17^20\relax}\] -\dverb|& +\dverb|@ \def\coefflog #1{1/#1[0]}% 1/n \def\f {1/2[0]}% \[ \log 2 \approx \sum_{n=1}^{20} \frac1{n\cdot 2^n} @@ -5882,7 +6750,7 @@ which was plaguing the |1.03| version. \footnote{with powers |f\string^k|, from {1}{20}{\coefflog}{\f}}}\] \[ \log 2 \approx \sum_{n=1}^{50} \frac1{n\cdot 2^n} = \xintFrac {\xintIrr {\xintPowerSeries {1}{50}{\coefflog}{\f}}}\] -\dverb|& +\dverb|@ \cnta 1 % previously declared count \loop % in this loop we recompute from scratch each partial sum! % we can afford that, as \xintPowerSeries is fast enough. @@ -5902,7 +6770,7 @@ which was plaguing the |1.03| version. \footnote{with powers |f\string^k|, from \endgraf \ifnum \cnta < 30 \advance\cnta 1 \repeat \end{multicols} -\dverb|& +\dverb|@ %\def\coeffarctg #1{1/\the\numexpr\xintMON{#1}*(2*#1+1)\relax }% \def\coeffarctg #1{1/\the\numexpr\ifodd #1 -2*#1-1\else2*#1+1\fi\relax }% % the above gives (-1)^n/(2n+1). The sign being in the denominator, @@ -5927,18 +6795,18 @@ which was plaguing the |1.03| version. \footnote{with powers |f\string^k|, from {\small\hspace*{\parindent}New with release |1.04|.\par} -\noindent This is the same as \csb{xintPowerSeries} apart from the fact that the +\noindent This is the same as \csbxint{PowerSeries} apart from the fact that the last parameter |f| is expanded once and for all before being then used repeatedly. If the |f| parameter is to be an explicit big fraction with many (dozens) digits, rather than using it directly it is slightly better to have some macro |\g| defined to expand to the explicit fraction and then use -\csb{xintPowerSeries} with |\g|; +\csbxint{PowerSeries} with |\g|; but if |f| has not yet been evaluated and will be the output of a complicated expansion of some |\f|, and if, due to an expanding only context, doing |\edef\g{\f}| is no option, then \csa{xintPowerSeriesX} should be used with |\f| as last parameter. -\dverb|& +\dverb|@ \def\ratioexp #1#2{\xintDiv {#1}{#2}}% x/n % These are the (-1)^{n-1}/n of the log(1+h) series: \def\coefflog #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]}% @@ -5985,7 +6853,7 @@ $\sum_{\text{|n=A|}}^{\text{|n=B|}}|\coeff{n}|\cdot |f|^{\,\text{|n|}}$ with eac time it is used inside an \csa{xintTrunc}. The one-parameter macro |\coeff| is similarly expanded at the time it is used inside the computations. Idem for |f|. If |f| itself is some complicated macro it is - thus better to use the variant \csb{xintFxPtPowerSeriesX} which expands it + thus better to use the variant \csbxint{FxPtPowerSeriesX} which expands it first and then uses the result of that expansion. The current (|1.04|) implementation is: the first power |f^A| is @@ -6017,7 +6885,7 @@ $\xintFxPtPowerSeries {0}{\cnta}{\coeffexp}{\f}{20}$\\ \advance\cnta 1 \repeat\par \end{multicols} -\dverb|& +\dverb|@ \def\coeffexp #1{1/\xintFac {#1}[0]}% 1/n! \def\f {-1/2[0]}% [0] for faster input parsing \cnta 0 % previously declared \count register @@ -6065,18 +6933,18 @@ is the result of this which is used in the computations. % Let us illustrate this on the computation of |(1+y)^{5/3}| where % |1+y=(1+x)^{3/5}| and each of the two binomial series is evaluated with ten % terms, the results being computed with |8| digits after the decimal point, and -% &|f|<1/10&. +% @|f|<1/10@. Let us illustrate this on the numerical exploration of the identity \centeredline{|log(1+x) = -log(1/(1+x))|}% Let |L(h)=log(1+h)|, and |D(h)=L(h)+L(-h/(1+h))|. Theoretically thus, |D(h)=0| but we shall evaluate |L(h)| and |-h/(1+h)| keeping only 10 -terms of their respective series. We will assume &|h|<0.5&. With only +terms of their respective series. We will assume @|h|<0.5@. With only ten terms kept in the power series we do not have quite 3 digits -precision as &2^10=1024&. So it wouldn't make sense to evaluate things +precision as @2^10=1024@. So it wouldn't make sense to evaluate things more precisely than, say circa 5 digits after the decimal points. -\dverb|& +\dverb|@ \cnta 0 \def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% (-1)^{n-1}/n \def\coeffalt #1{\the\numexpr\ifodd#1 -1\else1\fi\relax [0]}% (-1)^n @@ -6112,7 +6980,7 @@ digits precision. So we compute with 6 digits precision but return only 4 digits (rounded) after the decimal point. This result with 4 post-decimal points precision is then used as input to the next evaluation. -\dverb|& +\dverb|@ \loop \noindent \hbox to 2.5cm {\hss\texttt{D(\the\cnta/100): }}% \xintRound{4} @@ -6175,7 +7043,7 @@ with |\coeff{n}|, and the sum is done adding one term at a time with \def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% -\dverb+& +\dverb+@ \def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% \xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}+ \centeredline{\digitstt{\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}}} @@ -6190,7 +7058,7 @@ expanded once and for all at the start of the computation, thus allowing efficient chaining of such series evaluations. \def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% -\dverb+& +\dverb+@ \def\coeffexp #1{1/\xintFac {#1}[0]}% 1/n! (exact, not float) \def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% \xintFloatPowerSeriesX [8]{0}{30}{\coeffexp} @@ -6201,8 +7069,8 @@ efficient chaining of such series evaluations. \subsection{Computing \texorpdfstring{$\log 2$}{log(2)} and \texorpdfstring{$\pi$}{pi}}\label{ssec:Machin} -In this final section, the use of \csb{xintFxPtPowerSeries} (and -\csb{xintPowerSeries}) will be +In this final section, the use of \csbxint{FxPtPowerSeries} (and +\csbxint{PowerSeries}) will be illustrated on the (expandable... why make things simple when it is so easy to make them difficult!) computations of the first digits of the decimal expansion of the familiar constants $\log 2$ and $\pi$. @@ -6235,7 +7103,7 @@ correct exact truncated one. % 693147180559945309417232121458176568075500134360255254120680009493 -\dverb|& +\dverb|@ \def\coefflog #1{1/#1[0]}% 1/n \def\xa {13/256[0]}% we will compute log(1-13/256) \def\xb {1/9[0]}% we will compute log(1-1/9) @@ -6296,7 +7164,7 @@ first |D| digits, for all values from |D=0| to |D=100|, except in one case (|D=40|) where the last digit is wrong. For values of |D| higher than |100| it is more efficient to use the code using \csa{xintFxPtPowerSeries}. -\dverb|& +\dverb|@ \def\LogTwo #1% get log(2)=-2log(1-13/256)- 5log(1-1/9) {% \romannumeral0\expandafter\LogTwoDoIt \expandafter @@ -6324,7 +7192,7 @@ algorithm always gets better than |10^{-D}| precision, but again, strings of zeros or nines encountered in the decimal expansion may falsify the ending digits, nines may be zeros (and the last non-nine one should be increased) and zeros may be nine (and the last non-zero one should be decreased). -\dverb|& +\dverb|@ % pi = 16 Arctg(1/5) - 4 Arctg(1/239) (John Machin's formula) \def\coeffarctg #1{\the\numexpr\ifodd#1 -1\else1\fi\relax/% \the\numexpr 2*#1+1\relax [0]}% @@ -6385,7 +7253,7 @@ Here is a variant|\MachinBis|, which evaluates the partial sums \emph{exactly} using \csa{xintPowerSeries}, before their final truncation. No need for a ``|+3|'' then. -\dverb|& +\dverb|@ \def\MachinBis #1{% #1 may be a count register, % the final result will be truncated to #1 digits post decimal point \romannumeral0\expandafter\MachinBisA \expandafter @@ -6420,7 +7288,7 @@ which evaluates the partial sums \emph{exactly} using }}% Let us use this variant for a loop showing the build-up of digits: -\dverb|& +\dverb|@ \cnta 0 % previously declared \count register \loop \MachinBis{\cnta} \endgraf % Plain's \loop does not accept \par @@ -6438,7 +7306,7 @@ Let us use this variant for a loop showing the build-up of digits: You want more digits and have some time? Copy the |\Machin| code to a Plain \TeX{} or \LaTeX{} document loading \xintseriesname, and compile: -\dverb|& +\dverb|@ \newwrite\outfile \immediate\openout\outfile \jobname-out\relax \immediate\write\outfile {\Machin {1000}} @@ -6514,7 +7382,7 @@ Here is a concrete example: \[ \xintFrac {208341/66317}=\xintCFrac {208341/66317}\] But the difference with |amsmath|'s |\cfrac| is that this was input as \centeredline{|\[ \xintFrac {208341/66317}=\xintCFrac - {208341/66317} \]|} The command \csb{xintCFrac} produces in two + {208341/66317} \]|} The command \csbxint{CFrac} produces in two expansion steps the whole thing with the many chained |\cfrac|'s and all necessary braces, ready to be printed, in math mode. This is \LaTeX{} only and with the |amsmath| package (we shall mention another method for @@ -6530,9 +7398,9 @@ example: =\xintCFrac {915286/188421}\] \centeredline{|\[ \xintFrac {915286/188421}=\xintGCFrac {\xintFtoCC {915286/188421}} \]|} -The command \csb{xintGCFrac}, contrarily to -\csb{xintCFrac}, does not compute anything, it just typesets. Here, it is the -command \csb{xintFtoCC} which did the computation of +The command \csbxint{GCFrac}, contrarily to +\csbxint{CFrac}, does not compute anything, it just typesets. Here, it is the +command \csbxint{FtoCC} which did the computation of the centered continued fraction of |f|. Its output has the `inline format' described in the next paragraph. In the display, we also used \csa{xintCFrac} (code not shown), for comparison of the two types of continued fractions. @@ -6549,24 +7417,24 @@ be macros expanding (in two steps) to some number or fractional number. The left hand side was obtained with the following code: \centeredline{|\xintFrac{\xintGCtoF {1+-1/57+\xintPow {-3}{7}/\xintQuo {132}{25}}}|} -It uses the macro \csb{xintGCtoF} to convert a generalized fraction from the +It uses the macro \csbxint{GCtoF} to convert a generalized fraction from the `inline format' to the fraction it evaluates to. A simple continued fraction is a special case of a generalized continued fraction and may be input as such to macros expecting the `inline format', for example |-7+1/6+1/19+1/1+1/33|. There is a simpler comma separated format: -\centeredline{|\xintFrac{\xintCstoF{-7,6,19,1,33}}=& - \xintCFrac{\xintCstoF{-7,6,19,1,33}}|} +\centeredline +{|\xintFrac{\xintCstoF{-7,6,19,1,33}}=\xintCFrac{\xintCstoF{-7,6,19,1,33}}|} \[ \xintFrac{\xintCstoF{-7,6,19,1,33}}=\xintCFrac{\xintCstoF{-7,6,19,1,33}}\] This comma separated format may also be used with fractions among the coefficients: -in that case, computing with \csb{xintFtoCs} from the resulting |f| +in that case, computing with \csbxint{FtoCs} from the resulting |f| its real coefficients will give a new comma separated list with only integers. This list has no spaces: the spaces in the display below arise from the math mode processing. \centeredline{|\xintFrac{1084483/398959}=[\xintFtoCs{1084483/398959}]|} \[\xintFrac{1084483/398959}=[\xintFtoCs{1084483/398959}]\] -If one prefers other separators, one can use \csb{xintFtoCx} whose first +If one prefers other separators, one can use \csbxint{FtoCx} whose first argument will be the separator to be used. \centeredline{|\xintFrac{2721/1001}=\xintFtoCx {+1/(}{2721/1001})\cdots)|} \[\xintFrac{2721/1001}=\xintFtoCx {+1/(}{2721/1001})\cdots)\] @@ -6577,14 +7445,14 @@ People using Plain \TeX{} and |amstex| can achieve the same effect as Using \csa{xintFtoCx} with first argument an empty pair of braces |{}| will return the list of the coefficients of the continued fraction of |f|, without separator, and each one enclosed in a pair of group braces. This can then be -manipulated by the non-expandable macro \csb{xintAssignArray} or the expandable -ones \csb{xintApply} and \csb{xintListWithSep}. +manipulated by the non-expandable macro \csbxint{AssignArray} or the expandable +ones \csbxint{Apply} and \csbxint{ListWithSep}. As a shortcut to using \csa{xintFtoCx} with separator |1+/|, there is -\csb{xintFtoGC}: +\csbxint{FtoGC}: \centeredline{|2721/1001=\xintFtoGC {2721/1001}|}% \centeredline{\digitstt{2721/1001=\xintFtoGC {2721/1001}}} -Let us compare in that case with the output of \csb{xintFtoCC}: +Let us compare in that case with the output of \csbxint{FtoCC}: \centeredline{|2721/1001=\xintFtoCC {2721/1001}|}% \centeredline{\digitstt{2721/1001=\xintFtoCC {2721/1001}}} @@ -6593,7 +7461,7 @@ be useful on long continued fractions. \centeredline{|\printnumber{\xintFtoCC {35037018906350720204351049/%|}% \centeredline{|244241737886197404558180}}|}% \digitstt{\printnumber{\xintFtoCC {35037018906350720204351049/244241737886197404558180}}}. -If we apply \csb{xintGCtoF} to this generalized continued fraction, we +If we apply \csbxint{GCtoF} to this generalized continued fraction, we discover that the original fraction was reducible: \centeredline{|\xintGCtoF {143+1/2+...+-1/9}|\digitstt{=\xintGCtoF{143+1/2+1/5+-1/4+-1/4+-1/4+-1/3+1/2+1/2+1/6+-1/22+1/2+1/10+-1/5+-1/11+-1/3+1/4+-1/2+1/2+1/4+-1/2+1/23+1/3+1/8+-1/6+-1/9}}} @@ -6603,7 +7471,7 @@ discover that the original fraction was reducible: \begingroup \catcode`^\active \def^#1^{\hbox{\fontfamily{lmtt}\selectfont #1}}% -\catcode`\& 4 + When a generalized continued fraction is built with integers, and numerators are only |1|'s or |-1|'s, the produced fraction is irreducible. And if we compute it again with the last sub-fraction @@ -6614,13 +7482,12 @@ and indeed: \[ \begin{vmatrix} ^2897319801297630107^ & ^328124887710626729^\\ ^20197107104701740^ & ^2287346221788023^ - \end{vmatrix} = \digitstt{\xintiSub {\xintiMul {2897319801297630107}{2287346221788023}}{\xintiMul{20197107104701740}{328124887710626729}}}\] + \end{vmatrix} = \mbox{\digitstt{\xintiSub {\xintiMul {2897319801297630107}{2287346221788023}}{\xintiMul{20197107104701740}{328124887710626729}}}}\] \endgroup - More generally the various fractions obtained from the truncation of a continued fraction to its initial terms are called the convergents. The -commands of \xintcfracname such as \csb{xintFtoCv}, \csb{xintFtoCCv}, +commands of \xintcfracname such as \csbxint{FtoCv}, \csbxint{FtoCCv}, and others which compute such convergents, return them as a list of braced items, with no separator. This list can then be treated either with \csa{xint\-AssignArray}, or \csa{xintListWithSep}, or any other way @@ -6636,8 +7503,8 @@ is an example: \centeredline{|{\xintApply{\xintFrac}{\xintFtoCCv{915286/188421}}}$$|} \[ \xintFrac{915286/188421}\to \xintListWithSep {,} {\xintApply\xintFrac{\xintFtoCCv{915286/188421}}}\] We thus see that the -`centered convergents' obtained with \csb{xintFtoCCv} are among the fuller list -of convergents as returned by \csb{xintFtoCv}. +`centered convergents' obtained with \csbxint{FtoCCv} are among the fuller list +of convergents as returned by \csbxint{FtoCv}. Here is a more complicated use of \csa{xintApply} and \csa{xintListWithSep}. We first define a macro which will be applied to each @@ -6654,7 +7521,7 @@ It produces:\par \def\cn #1{\xintiPow {2}{#1}}% -The macro \csb{xintCntoF} allows to specify the coefficients as +The macro \csbxint{CntoF} allows to specify the coefficients as functions of the index. The values to which expand the coefficient function do not have to be integers. \centeredline{|\def\cn #1{\xintiPow {2}{#1}}% 2^n|}% @@ -6671,10 +7538,10 @@ possibilities are |[r]| and (default) |[c]|. \centeredline{| = [\xintFtoCs {\xintCntoF {6}{\cn}}]\]|}% \[\xintFrac{\xintCntoF {6}{\cn}}=\xintGCFrac [r]{\xintCntoGC {6}{\cn}}= [\xintFtoCs {\xintCntoF {6}{\cn}}]\] -We used \csb{xintCntoGC} as we wanted to display also the continued fraction and +We used \csbxint{CntoGC} as we wanted to display also the continued fraction and not only the fraction returned by \csa{xintCntoF}. -There are also \csb{xintGCntoF} and \csb{xintGCntoGC} which allow the same for +There are also \csbxint{GCntoF} and \csbxint{GCntoGC} which allow the same for generalized fractions. The following initial portion of a generalized continued fraction for $\pi$: \def\an #1{\the\numexpr 2*#1+1\relax }% @@ -6683,7 +7550,7 @@ fraction for $\pi$: \cfrac{4}{\xintGCFrac{\xintGCntoGC {5}{\an}{\bn}}} = \xintTrunc {10}{\xintDiv {4}{\xintGCntoF {5}{\an}{\bn}}}\dots\] was obtained with this code: -\dverb|& +\dverb|@ \def\an #1{\the\numexpr 2*#1+1\relax }% \def\bn #1{\the\numexpr (#1+1)*(#1+1)\relax }% \[ \xintFrac{\xintDiv {4}{\xintGCntoF {5}{\an}{\bn}}} = @@ -6692,7 +7559,7 @@ was obtained with this code: | We see that the quality of approximation is not fantastic compared to the simple continued fraction of $\pi$ with about as many terms: -\dverb|& +\dverb|@ \[ \xintFrac{\xintCstoF{3,7,15,1,292,1,1}}= \xintGCFrac{3+1/7+1/15+1/1+1/292+1/1+1/1}= \xintTrunc{10}{\xintCstoF{3,7,15,1,292,1,1}}\dots\] @@ -6704,7 +7571,7 @@ continued fraction of $\pi$ with about as many terms: \hypertarget{e-convergents}{To} conclude this overview of most of the package functionalities, let us explore the convergents of Euler's number $e$. -\dverb|& +\dverb|@ \def\cn #1{\the\numexpr\ifcase \numexpr #1+3-3*((#1+2)/3)\relax 1\or1\or2*(#1/3)\fi\relax } % produces the pattern 1,1,2,1,1,4,1,1,6,1,1,8,... which are the @@ -6721,11 +7588,11 @@ the convergents of Euler's number $e$. \smallskip The volume of computation is kept minimal by the following steps: \begin{itemize} \item a comma separated list of the first 36 coefficients is produced by - \csb{xintCntoCs}, -\item this is then given to \csb{xintiCstoCv} which produces the list of the - convergents (there is also \csb{xintCstoCv}, but our + \csbxint{CntoCs}, +\item this is then given to \csbxint{iCstoCv} which produces the list of the + convergents (there is also \csbxint{CstoCv}, but our coefficients being integers we used the infinitesimally - faster \csb{xintiCstoCv}), + faster \csbxint{iCstoCv}), \item then the whole list was converted into a sequence of one-line paragraphs, each convergent becomes the argument to a macro printing it together with its decimal expansion with 30 digits after the decimal point. @@ -6766,7 +7633,7 @@ convergent already gets 799 digits correct! To allow speedy compilation of the source of this document when the need arises, I limit here to the 200th convergent (getting the 500th took about 1.2s on my laptop last time I tried, and the 200th convergent is obtained ten times faster). -\dverb|& +\dverb|@ \edef\z {\xintCntoF {199}{\cn}}% \begingroup\parindent 0pt \leftskip 2.5cm \indent\llap {Numerator = }{\printnumber{\xintNumerator\z}\par @@ -6794,7 +7661,7 @@ which first computes then displays with the help of |\cfrac| the simple continued fraction corresponding to the given fraction (or macro expanding in two steps to one such). It admits an optional argument which may be |[l]|, |[r]| or (the default) |[c]| to specify the location of the one's in the numerators of -the sub-fractions. Each coefficient is typeset using the \csb{xintFrac} macro +the sub-fractions. Each coefficient is typeset using the \csbxint{Frac} macro from the \xintfracname package. \subsection{\csbh{xintGCFrac}}\label{xintGCFrac} @@ -6805,10 +7672,10 @@ argument as \csa{xintCFrac}. \centeredline{|\[\xintGCFrac {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintFac {6}}\]|} \[\xintGCFrac {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintFac {6}}\] As can be seen this is typesetting macro, although it does proceed to the -evaluation of the coefficients themselves. See \csb{xintGCtoF} if you are +evaluation of the coefficients themselves. See \csbxint{GCtoF} if you are impatient to see this fraction computed. Numerators and denominators are made arguments to the -\csb{xintFrac} macro. +\csbxint{Frac} macro. \subsection{\csbh{xintGCtoGCx}}\label{xintGCtoGCx} {\small New with release |1.05|.\par} @@ -6865,7 +7732,7 @@ user input of generalized continued fractions, the macro was called \subsection{\csbh{xintFtoCv}}\label{xintFtoCv} \csa{xintFtoCv}|{f}| returns the list of the (braced) convergents of |f|, with -no separator. To be treated with \csb{xintAssignArray} or \csb{xintListWithSep}. +no separator. To be treated with \csbxint{AssignArray} or \csbxint{ListWithSep}. \centeredline{% |\[\xintListWithSep{\to}{\xintApply\xintFrac{\xintFtoCv{5211/3748}}}\]|}% \[\xintListWithSep{\to}{\xintApply\xintFrac{\xintFtoCv{5211/3748}}}\] @@ -6873,8 +7740,8 @@ no separator. To be treated with \csb{xintAssignArray} or \csb{xintListWithSep}. \subsection{\csbh{xintFtoCCv}}\label{xintFtoCCv} \csa{xintFtoCCv}|{f}| returns the list of the (braced) centered convergents of -|f|, with no separator. To be treated with \csb{xintAssignArray} or -\csb{xintListWithSep}. +|f|, with no separator. To be treated with \csbxint{AssignArray} or +\csbxint{ListWithSep}. \centeredline{% |\[\xintListWithSep{\to}{\xintApply\xintFrac{\xintFtoCCv{5211/3748}}}\]|}% \[\xintListWithSep{\to}{\xintApply\xintFrac{\xintFtoCCv{5211/3748}}}\] @@ -6918,7 +7785,7 @@ fractions, but otherwise it is not necessarily the case. % is added forcefully by \csa{xintCstoCv} at the last step\dots } but this is % the way \xintfracname likes to reception fractions: this format is best for % further processing by the bundle macros. For `inline' printing, one may apply -% \csb{xintRaw} and for display in math mode \csb{xintFrac}. +% \csbxint{Raw} and for display in math mode \csbxint{Frac}. \centeredline{|\[\xintListWithSep{\to}{\xintApply\xintFrac{\xintCstoCv|}% \centeredline{|{\xintPow {-.3}{-5},7.3/4.57,\xintCstoF{3/4,9,-1/3}}}}\]|}% \[\xintListWithSep{\to}{\xintApply\xintFrac{\xintCstoCv @@ -6931,7 +7798,7 @@ fractions, but otherwise it is not necessarily the case. something expanding to such a list) into an `inline format' continued fraction |{a}+1/{b}+1/...+1/{z}|. The coefficients are just copied and put within braces, without expansion. -The output can then be used in \csb{xintGCFrac} for example. +The output can then be used in \csbxint{GCFrac} for example. \centeredline{|\[\xintGCFrac {\xintCstoGC {-1,1/2,-1/3,1/4,-1/5}}|}% \centeredline{|=\xintSignedFrac {\xintCstoF {-1,1/2,-1/3,1/4,-1/5}}\]|}% \[\xintGCFrac {\xintCstoGC {-1,1/2,-1/3,1/4,-1/5}} = @@ -6943,7 +7810,7 @@ The output can then be used in \csb{xintGCFrac} for example. the inline generalized continued fraction. Coefficients may be fractions but must then be put within braces. They can be macros. The plus signs are mandatory. -\dverb|& +\dverb|@ \[\xintGCFrac {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintFac {6}} = \xintFrac{\xintGCtoF {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintFac {6}}} = \xintFrac{\xintIrr{\xintGCtoF @@ -6952,7 +7819,7 @@ mandatory. \[\xintGCFrac {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintFac {6}} = \xintFrac{\xintGCtoF {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintFac {6}}} = \xintFrac{\xintIrr{\xintGCtoF {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintFac {6}}}}\] -\dverb|& +\dverb|@ \[ \xintGCFrac{{1/2}+{2/3}/{4/5}+{1/2}/{1/5}+{3/2}/{5/3}} = \xintFrac{\xintGCtoF {{1/2}+{2/3}/{4/5}+{1/2}/{1/5}+{3/2}/{5/3}}} \] | @@ -6971,7 +7838,7 @@ then be inside braces. Or they may be macros, too. The convergents will in the general case be reducible. To put them into irreducible form, one needs one more step, for example it can be done with |\xintApply\xintIrr|. -\dverb|& +\dverb|@ \[\xintListWithSep{,}{\xintApply\xintFrac {\xintGCtoCv{3+{-2}/{7/2}+{3/4}/12+{-56}/3}}}\] \[\xintListWithSep{,}{\xintApply\xintFrac{\xintApply\xintIrr @@ -7005,7 +7872,7 @@ with |a(j)=\macroA{j}| and |b(j)=\macroB{j}|. The |N| parameter is given to a |\numexpr|. \[\xintGCFrac{\xintGCntoGC {6}{\coeffA}{\coeffB}} = \xintFrac{\xintGCntoF {6}{\coeffA}{\coeffB}}\] -There is also \csb{xintGCntoGC} to get the `inline format' continued +There is also \csbxint{GCntoGC} to get the `inline format' continued fraction. The previous display was obtained with: \centeredline{|\def\coeffA #1{\the\numexpr #1+4-3*((#1+2)/3)\relax }%|}% \centeredline{|\def\coeffB #1{\xintMON{#1}}% (-1)^n|}% @@ -7051,7 +7918,7 @@ fractions. returns the corresponding |{a0}+{b0}/{a1}+{b1}/{a2}+...+{b(N-1)}/{aN}| inline generalized fraction. |N| is givent to a |\numexpr|. As shown, the coefficients are enclosed into added pairs of braces, and may thus be fractions. -\dverb|& +\dverb|@ \def\an #1{\the\numexpr #1*#1*#1+1\relax}% \def\bn #1{\the\numexpr \xintiMON{#1}*(#1+1)\relax}% $\xintGCntoGC {5}{\an}{\bn}}=\xintGCFrac {\xintGCntoGC {5}{\an}{\bn}} @@ -7080,7 +7947,7 @@ hundreds of coefficients. \csa{xintGCtoGC}|{a+b/c+d/e+f/g+......+v/w+x/y}| expands (with the usual meaning) each one of the coefficients and returns an inline continued fraction of the same type, each expanded coefficient being enclosed withing braces. -\dverb|& +\dverb|@ \edef\x {\xintGCtoGC {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintFac {6}+\xintCstoF {2,-7,-5}/16}} \meaning\x @@ -7092,7 +7959,6 @@ of the same type, each expanded coefficient being enclosed withing braces. To be honest I have, it seems, forgotten why I wrote this macro in the first place. -\catcode`\& 4 \makeatletter \StopEventually{\end{document}\endinput} @@ -7105,7 +7971,15 @@ first place. \newgeometry{hmarginratio=4:3,hscale=0.75} -\def\MacroFont{\ttfamily\small\hyphenchar\font45 +\def\givesomestretch{% +\fontdimen2\font=0.33333\fontdimen6\font +\fontdimen3\font=0.16666\fontdimen6\font +\fontdimen4\font=0.11111\fontdimen6\font +}% + +% will be used by the \lverb things + +\def\MacroFont{\ttfamily\small\givesomestretch\hyphenchar\font45 \baselineskip12pt\relax } \etocdepthtag.toc {implementation} @@ -7123,12 +7997,10 @@ first place. % The commenting of the macros is currently (\docdate) very sparse. % % With release |1.09a| all macros doing arithmetic operations and a few more -% apply -% systematically |\xintnum| to their arguments; this adds a little overhead but -% this is -% more convenient for using count registers even with infix notation; also this -% is what |xintfrac.sty| did all along. Simplifies the discussion in the -% documentation too. +% apply systematically |\xintnum| to their arguments; this adds a little +% overhead but this is more convenient for using count registers even with infix +% notation; also this is what |xintfrac.sty| did all along. Simplifies the +% discussion in the documentation too. % \def\MARGEPAGENO{2.5em} % % \localtableofcontents @@ -7294,9 +8166,10 @@ first place. \fi \XINT_providespackage \ProvidesPackage {xint}% - [2013/10/22 v1.09d Expandable operations on long numbers (jfB)]% + [2013/10/29 v1.09e Expandable operations on long numbers (jfB)]% % \end{macrocode} % \subsection{Token management, constants} +% \lverb|In 1.09e \xint_undef replaced everywhere by \xint_bye.| % \begin{macrocode} \def\xint_gobble_ {}% \def\xint_gobble_i #1{}% @@ -7309,8 +8182,8 @@ first place. \def\xint_gobble_viii #1#2#3#4#5#6#7#8{}% \def\xint_firstofone #1{#1}% \xint_firstofone{\let\XINT_sptoken= } % 1.09d, 2013/10/22 -\def\xint_firstoftwo #1#2{#1}% -\def\xint_secondoftwo #1#2{#2}% +\long\def\xint_firstoftwo #1#2{#1}% made long in 1.09e, 2013/10/28 +\long\def\xint_secondoftwo #1#2{#2}% \def\xint_firstoftwo_andstop #1#2{ #1}% \def\xint_secondoftwo_andstop #1#2{ #2}% \def\xint_exchangetwo_keepbraces_andstop #1#2{ {#2}{#1}}% @@ -7318,6 +8191,7 @@ first place. \def\xint_secondofthree #1#2#3{#2}% \def\xint_thirdofthree #1#2#3{#3}% \def\xint_minus_andstop { -}% +\def\xint_bye #1\xint_bye {}% \def\xint_gob_til_R #1\R {}% \def\xint_gob_til_W #1\W {}% \def\xint_gob_til_Z #1\Z {}% @@ -7327,8 +8201,9 @@ first place. \def\xint_gob_til_minus #1-{}% \def\xint_gob_til_zeros_iii #1000{}% \def\xint_gob_til_zeros_iv #10000{}% +\let\xint_relax\relax +\def\xint_brelax {\xint_relax }% \def\xint_gob_til_relax #1\relax {}% -\def\xint_gob_til_xint_undef #1\xint_undef {}% \def\xint_gob_til_xint_relax #1\xint_relax {}% \def\xint_UDzerofork #10\dummy #2#3\krof {#2}% \def\xint_UDsignfork #1-\dummy #2#3\krof {#2}% @@ -7338,8 +8213,6 @@ first place. \def\xint_UDzerominusfork #10-\dummy #2#3\krof {#2}% \def\xint_UDsignsfork #1--\dummy #2#3\krof {#2}% \def\xint_afterfi #1#2\fi {\fi #1}% -\let\xint_relax\relax -\def\xint_braced_xint_relax {\xint_relax }% \chardef\xint_c_ 0 \chardef\xint_c_i 1 \chardef\xint_c_ii 2 @@ -7361,17 +8234,16 @@ first place. \def\xintrev #1% {% \expandafter\XINT_rev_fork - \romannumeral-`0#1\xint_relax % empty #1 ok - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \romannumeral-`0#1\xint_relax % empty #1 ok, \xint_relax stops expansion + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_rev_fork #1% {% \xint_UDsignfork - #1\dummy {\expandafter\xint_minus_andstop - \romannumeral0\XINT_rord_main {}}% - -\dummy {\XINT_rord_main {}#1}% + #1\dummy {\expandafter\xint_minus_andstop\romannumeral0\XINT_rord_main {}}% + -\dummy {\XINT_rord_main {}#1}% \krof }% \def\XINT_Rev {\romannumeral0\XINT_rev }% @@ -7380,16 +8252,16 @@ first place. {% \XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_rord_main #1#2#3#4#5#6#7#8#9% {% - \xint_gob_til_xint_undef #9\XINT_rord_cleanup\xint_undef + \xint_bye #9\XINT_rord_cleanup\xint_bye \XINT_rord_main {#9#8#7#6#5#4#3#2#1}% }% -\def\XINT_rord_cleanup\xint_undef\XINT_rord_main #1#2\xint_relax +\def\XINT_rord_cleanup\xint_bye\XINT_rord_main #1#2\xint_relax {% \expandafter\space\xint_gob_til_xint_relax #1% }% @@ -7398,7 +8270,12 @@ first place. % \lverb|New with 1.06. Makes the expansion of its argument and then reverses % the % resulting tokens or braced tokens, adding a pair of braces to each (thus, -% maintaining it when it was already there.| +% maintaining it when it was already there. +% +% As in some other places, 1.09e replaces \Z by \xint_bye, although here it is +% just for coherence of notation as \Z would be perfectly safe. The reason for +% \xint_relax, here and in other locations, is in case #1 expands to nothing, +% the \romannumeral-`0 must be stopped| % \begin{macrocode} \def\xintRevWithBraces {\romannumeral0\xintrevwithbraces }% \def\xintRevWithBracesNoExpand {\romannumeral0\xintrevwithbracesnoexpand }% @@ -7406,20 +8283,20 @@ first place. {% \expandafter\XINT_revwbr_loop\expandafter{\expandafter}% \romannumeral-`0#1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \def\xintrevwithbracesnoexpand #1% {% \XINT_revwbr_loop {}% #1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \def\XINT_revwbr_loop #1#2#3#4#5#6#7#8#9% {% \xint_gob_til_xint_relax #9\XINT_revwbr_finish_a\xint_relax \XINT_revwbr_loop {{#9}{#8}{#7}{#6}{#5}{#4}{#3}{#2}#1}% }% -\def\XINT_revwbr_finish_a\xint_relax\XINT_revwbr_loop #1#2\Z +\def\XINT_revwbr_finish_a\xint_relax\XINT_revwbr_loop #1#2\xint_bye {% \XINT_revwbr_finish_b #2\R\R\R\R\R\R\R\Z #1% }% @@ -7447,21 +8324,23 @@ first place. % \xintLen -> fait l'expansion, ne compte PAS le signe.$\ % \xintLength -> ne fait PAS l'expansion, compte le signe.$\ % 1.06: improved code is roughly 20$% faster than the one from earlier -% versions. 1.09a, \xintnum inserted| +% versions. 1.09a, \xintnum inserted. 1.09e: \Z->\xint_bye as this is called +% from \xintNthElt, and there it was necessary not to use \Z. Later use of \Z +% and \W perfectly safe here.| % \begin{macrocode} \def\xintiLen {\romannumeral0\xintilen }% \def\xintilen #1% {% \expandafter\XINT_length_fork \romannumeral0\xintnum{#1}\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \let\xintLen\xintiLen \let\xintlen\xintilen \def\XINT_Len #1% {% \romannumeral0\XINT_length_fork #1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \def\XINT_length_fork #1% {% @@ -7476,7 +8355,7 @@ first place. {% \XINT_length_loop {0}#1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \let\xintLength\XINT_Length \def\XINT_length_loop #1#2#3#4#5#6#7#8#9% @@ -7485,7 +8364,7 @@ first place. \expandafter\XINT_length_loop\expandafter {\the\numexpr #1+8\relax}% }% \def\XINT_length_finish_a\xint_relax - \expandafter\XINT_length_loop\expandafter #1#2\Z + \expandafter\XINT_length_loop\expandafter #1#2\xint_bye {% \XINT_length_finish_b #2\W\W\W\W\W\W\W\Z {#1}% }% @@ -7501,8 +8380,7 @@ first place. #7\XINT_length_finish_c 2% \W\XINT_length_finish_c 1\Z }% -\def\XINT_length_finish_c #1#2\Z #3% - {\expandafter\space\the\numexpr #3-#1\relax}% +\def\XINT_length_finish_c #1#2\Z #3{\expandafter\space\the\numexpr #3-#1\relax}% % \end{macrocode} % \subsection{\csh{xintCSVtoList}} % \lverb|& @@ -7512,7 +8390,7 @@ first place. % is not to be expanded). Blanks either before or after the separator will be % collapsed into one space and the is no % attempt to get rid of those. -% First included in release 1.06.| +% First included in release 1.06. Here, use of \Z (and \R) perfectly safe.| % \begin{macrocode} \def\xintCSVtoList {\romannumeral0\xintcsvtolist }% \def\xintCSVtoListNoExpand {\romannumeral0\xintcsvtolistnoexpand }% @@ -7520,22 +8398,22 @@ first place. {% \expandafter\XINT_csvtol_loop_a\expandafter {\expandafter}\romannumeral-`0#1% - ,\xint_undef,\xint_undef,\xint_undef,\xint_undef - ,\xint_undef,\xint_undef,\xint_undef,\xint_undef,\Z + ,\xint_bye,\xint_bye,\xint_bye,\xint_bye + ,\xint_bye,\xint_bye,\xint_bye,\xint_bye,\Z }% \def\xintcsvtolistnoexpand #1% {% \XINT_csvtol_loop_a - {}#1,\xint_undef,\xint_undef,\xint_undef,\xint_undef - ,\xint_undef,\xint_undef,\xint_undef,\xint_undef,\Z + {}#1,\xint_bye,\xint_bye,\xint_bye,\xint_bye + ,\xint_bye,\xint_bye,\xint_bye,\xint_bye,\Z }% \def\XINT_csvtol_loop_a #1#2,#3,#4,#5,#6,#7,#8,#9,% {% - \xint_gob_til_xint_undef #9\XINT_csvtol_finish_a\xint_undef + \xint_bye #9\XINT_csvtol_finish_a\xint_bye \XINT_csvtol_loop_b {#1}{{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}% }% \def\XINT_csvtol_loop_b #1#2{\XINT_csvtol_loop_a {#1#2}}% -\def\XINT_csvtol_finish_a\xint_undef\XINT_csvtol_loop_b #1#2#3\Z +\def\XINT_csvtol_finish_a\xint_bye\XINT_csvtol_loop_b #1#2#3\Z {% \XINT_csvtol_finish_b #3\R,\R,\R,\R,\R,\R,\R,\Z #2{#1}% }% @@ -7573,27 +8451,30 @@ first place. % single token. It is not expanded. The list may be a macro and it is expanded. % 1.06 modifies the `feature' of returning sep if the list is empty: the output % is now empty in that case. (sep was not used for a one element list, but -% strangely it was for a zero-element list).| +% strangely it was for a zero-element list). +% +% Use of \Z as delimiter was objectively an error, which I fix here in 1.09e, +% now the code uses \xint_bye.| % \begin{macrocode} \def\xintListWithSep {\romannumeral0\xintlistwithsep }% \def\xintListWithSepNoExpand {\romannumeral0\xintlistwithsepnoexpand }% \long\def\xintlistwithsep #1#2% {\expandafter\XINT_lws\expandafter {\romannumeral-`0#2}{#1}}% -\long\def\XINT_lws #1#2{\XINT_lws_start {#2}#1\Z }% -\long\def\xintlistwithsepnoexpand #1#2{\XINT_lws_start {#1}#2\Z }% +\long\def\XINT_lws #1#2{\XINT_lws_start {#2}#1\xint_bye }% +\long\def\xintlistwithsepnoexpand #1#2{\XINT_lws_start {#1}#2\xint_bye }% \long\def\XINT_lws_start #1#2% {% - \xint_gob_til_Z #2\XINT_lws_dont\Z + \xint_bye #2\XINT_lws_dont\xint_bye \XINT_lws_loop_a {#2}{#1}% }% -\long\def\XINT_lws_dont\Z\XINT_lws_loop_a #1#2{ }% +\long\def\XINT_lws_dont\xint_bye\XINT_lws_loop_a #1#2{ }% \long\def\XINT_lws_loop_a #1#2#3% {% - \xint_gob_til_Z #3\XINT_lws_end\Z + \xint_bye #3\XINT_lws_end\xint_bye \XINT_lws_loop_b {#1}{#2#3}{#2}% }% \long\def\XINT_lws_loop_b #1#2{\XINT_lws_loop_a {#1#2}}% -\long\def\XINT_lws_end\Z\XINT_lws_loop_b #1#2#3{ #1}% +\long\def\XINT_lws_end\xint_bye\XINT_lws_loop_b #1#2#3{ #1}% % \end{macrocode} % \subsection{\csh{xintNthElt}} % \lverb|& @@ -7607,6 +8488,13 @@ first place. % initial preparation (if #2 is very long, not good to have it twice), I wanted % to respect the noexpand directive in all cases, and the alternative would be % to define more macros. +% +% At some point I turned the \W's into \xint_relax's but forgot to modify +% accordingly \XINT_nthelt_finish. So in case the index is larger than the +% number of items the macro returned was an \xint_relax token rather than +% nothing. Fixed in 1.09e. I also take the opportunity of this fix to replace +% uses of \Z by \xint_bye. (and as a result I must do the change also in +% \XINT_length_loop and related macros). % | % \begin{macrocode} \def\xintNthElt {\romannumeral0\xintnthelt }% @@ -7646,7 +8534,7 @@ first place. \else \expandafter\XINT_length_loop \fi {#2}#1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \def\XINT_nthelt_loop_a #1% {% @@ -7660,27 +8548,25 @@ first place. \def\XINT_nthelt_loop_b #1#2#3#4#5#6#7#8#9% {% \xint_gob_til_xint_relax #9\XINT_nthelt_silentend\xint_relax - \expandafter\XINT_nthelt_loop_a\expandafter{\the\numexpr #1-8\relax}% + \expandafter\XINT_nthelt_loop_a\expandafter{\the\numexpr #1-8}% }% -\def\XINT_nthelt_silentend #1\Z { }% +\def\XINT_nthelt_silentend #1\xint_bye { }% \def\XINT_nthelt_getit #1% {% \expandafter\expandafter\expandafter\XINT_nthelt_finish \csname xint_gobble_\romannumeral\numexpr#1-1\endcsname }% -\def\XINT_nthelt_finish #1#2\Z -{% - \xint_UDwfork - #1\dummy { }% - \W\dummy { #1}% - \krof -}% +\def\XINT_nthelt_finish #1#2\xint_bye + {\xint_gob_til_xint_relax #1\expandafter\space + \xint_gobble_iii\xint_relax\space #1}% % \end{macrocode} % \subsection{\csh{xintApply}} % \lverb|& % \xintApply {\macro}{{a}{b}...{z}} returns {\macro{a}}...{\macro{b}} % where each instance of \macro is ff-expanded. The list is first -% expanded and may thus be a macro. Introduced with release 1.04.| +% expanded and may thus be a macro. Introduced with release 1.04. +% +% Modified in 1.09e to not use \Z but rather \xint_bye| % \begin{macrocode} \def\xintApply {\romannumeral0\xintapply }% \def\xintApplyNoExpand {\romannumeral0\xintapplynoexpand }% @@ -7689,17 +8575,18 @@ first place. \expandafter\XINT_apply\expandafter {\romannumeral-`0#2}% {#1}% }% -\def\XINT_apply #1#2{\XINT_apply_loop_a {}{#2}#1\Z }% -\def\xintapplynoexpand #1#2{\XINT_apply_loop_a {}{#1}#2\Z }% +\def\XINT_apply #1#2{\XINT_apply_loop_a {}{#2}#1\xint_bye }% +\def\xintapplynoexpand #1#2{\XINT_apply_loop_a {}{#1}#2\xint_bye }% \def\XINT_apply_loop_a #1#2#3% {% - \xint_gob_til_Z #3\XINT_apply_end\Z + \xint_bye #3\XINT_apply_end\xint_bye \expandafter \XINT_apply_loop_b \expandafter {\romannumeral-`0#2{#3}}{#1}{#2}% }% \def\XINT_apply_loop_b #1#2{\XINT_apply_loop_a {#2{#1}}}% -\def\XINT_apply_end\Z\expandafter\XINT_apply_loop_b\expandafter #1#2#3{ #2}% +\def\XINT_apply_end\xint_bye\expandafter\XINT_apply_loop_b + \expandafter #1#2#3{ #2}% % \end{macrocode} % \subsection{\csh{xintApplyUnbraced}} % \lverb|& @@ -7709,7 +8596,9 @@ first place. % are added: this allows for example a non-expandable \def in \macro, without % having to do \gdef. The list is first expanded. Introduced with release 1.06b. % Define \macro to start with a space if it is not expandable or its execution -% should be delayed only when all of \macro{a}...\macro{z} is ready. | +% should be delayed only when all of \macro{a}...\macro{z} is ready. +% +% Modified in 1.09e to use \xint_bye rather than \Z| % \begin{macrocode} \def\xintApplyUnbraced {\romannumeral0\xintapplyunbraced }% \def\xintApplyUnbracedNoExpand {\romannumeral0\xintapplyunbracednoexpand }% @@ -7718,32 +8607,34 @@ first place. \expandafter\XINT_applyunbr\expandafter {\romannumeral-`0#2}% {#1}% }% -\def\XINT_applyunbr #1#2{\XINT_applyunbr_loop_a {}{#2}#1\Z }% +\def\XINT_applyunbr #1#2{\XINT_applyunbr_loop_a {}{#2}#1\xint_bye }% \def\xintapplyunbracednoexpand #1#2% - {\XINT_applyunbr_loop_a {}{#1}#2\Z }% + {\XINT_applyunbr_loop_a {}{#1}#2\xint_bye }% \def\XINT_applyunbr_loop_a #1#2#3% {% - \xint_gob_til_Z #3\XINT_applyunbr_end\Z + \xint_bye #3\XINT_applyunbr_end\xint_bye \expandafter\XINT_applyunbr_loop_b \expandafter {\romannumeral-`0#2{#3}}{#1}{#2}% }% \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\XINT_applyunbr_end\xint_bye\expandafter\XINT_applyunbr_loop_b + \expandafter #1#2#3{ #2}% % \end{macrocode} % \subsection{\csh{xintSeq}} % \lverb|1.09c. Without the optional argument puts stress on the input stack, -% should not be used to generated thousands of terms then.| +% should not be used to generated thousands of terms then. Here also, let's use +% \xint_bye rather than \Z as delimiter (1.09e; necessary change as #1 is used +% prior to being expanded, thus \Z might very well arise here as a macro).| % \begin{macrocode} \def\xintSeq {\romannumeral0\xintseq }% -\def\xintseq #1{\XINT_seq_chkopt #1\Z }% +\def\xintseq #1{\XINT_seq_chkopt #1\xint_bye }% \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% +\def\XINT_seq_noopt #1\xint_bye #2% {% \expandafter\XINT_seq\expandafter {\the\numexpr#1\expandafter}\expandafter{\the\numexpr #2}% @@ -7778,7 +8669,7 @@ first place. \expandafter{\the\numexpr #1+1}{#2}{#1}% }% \def\XINT_seq_e #1#2#3{ }% -\def\XINT_seq_opt [\Z #1]#2#3% +\def\XINT_seq_opt [\xint_bye #1]#2#3% {% \expandafter\XINT_seqo\expandafter {\the\numexpr #2\expandafter}\expandafter @@ -7849,10 +8740,63 @@ first place. }% \def\XINT_seqo_nd #1#2#3#4{\XINT_seqo_nb {#1}{#2}{#3}{#4{#1}}}% % \end{macrocode} +% \subsection{\csh{XINT\_xflet}} +% \lverb|& +% 1.09e: we expand unbraced tokens and swallow arising space tokens +% until the dust settles. For treating cases {<blank>\x<blank>\y...}, with +% guaranteed expansion of the \x (which may itself give space tokens), a +% simpler approach is possible with doubled \romannumeral-`0, this is what I +% first did, but it had the feature that <sptoken><sptoken>\x would not expand +% the \x. At any rate, <sptoken>'s before the list terminator z were all +% correctly moved out of the way, hence the stuff was robust for use in +% \xintApplyInline and \xintFor. Although *two* space tokens would need +% devilishly prepared input, nevertheless I decided to also survive that, so +% here the method is a bit more complicated. The advantage though is that now +% the calling macro does not have to do a check for a space token anymore. But +% I have to store the calling macro in the \XINT_xflet_macro token and use +% \XINT_tokenB additionally to \XINT_token. The thing can still be fooled in +% the sense of not expanding some non space non braced token but it has to be +% very very malicious input... | +% \begin{macrocode} +\def\XINT_xflet #1% +{% + \def\XINT_xflet_macro {#1}\XINT_xflet_get +}% +\def\XINT_xflet_get +{% + \expandafter\futurelet\expandafter\XINT_token + \expandafter\XINT_xflet_sp?\romannumeral-`0% +}% +\def\XINT_xflet_sp? +{% + \ifx\XINT_token\XINT_sptoken + \expandafter\XINT_xflet_get + \else\expandafter\XINT_xflet_getB + \fi +}% +\def\XINT_xflet_getB +{% + \expandafter\futurelet\expandafter\XINT_tokenB + \expandafter\XINT_xflet_spB?\romannumeral-`0% +}% +\def\XINT_xflet_spB? +{% + \ifx\XINT_tokenB\XINT_sptoken + \expandafter\XINT_xflet_getB + \else\expandafter\XINT_xflet_eq? + \fi +}% +\def\XINT_xflet_eq? +{% + \ifx\XINT_token\XINT_tokenB + \expandafter\XINT_xflet_macro + \else\expandafter\XINT_xflet_get + \fi +}% +% \end{macrocode} % \subsection{\csh{xintApplyInline}} % \lverb|& -% 1.09a: -% \xintApplyInline\macro{{a}{b}...{z}} has the same effect as executing +% 1.09a: \xintApplyInline\macro{{a}{b}...{z}} has the same effect as executing % \macro{a} and then applying again \xintApplyInline to the shortened list % {{b}...{z}} until % nothing is left. This is a non-expandable command which will result in @@ -7861,38 +8805,31 @@ first place. % first, which may thus be encapsulated in a macro. % % Release 1.09c has a new \xintApplyInline: the new version, while not -% expandable, does survive to the -% case when the expansion of \macro will close a group, as happens with -% $& in alignments. It uses catcode 3 z as list terminator. +% expandable, is designed to survive when the applied macro closes a group, as +% is the case in alignemnts when it contains a $& or \\. It uses catcode 3 z as +% list terminator. Don't use it among the list items. +% +% 1.09d: the bug which was discovered in \xintFor* regarding space tokens at the +% very end of the item list also was in \xintApplyInline. The new version will +% expand unbraced item elements and this is in fact convenient to simulate +% insertion of lists in others. % -% 1.09d: the same bug with a terminating space token which was discovered -% in \xintFor* also was in \xintApplyInline. I modify it according to -% a similar scheme. The new version will thus expand unbraced item elements. -% This is in fact convenient to insert lists in others. +% 1.09e: the applied macro is allowed to be long, with items containing +% explicit \par's. %| % \begin{macrocode} \catcode`z 3% -\def\XINT_xflet #1% -{% - \expandafter\futurelet\expandafter\XINT_token - \expandafter#1\romannumeral-`0\romannumeral-`0% -}% \def\xintApplyInline #1#2% {% - \expandafter\def\expandafter\XINT_inline_macro\expandafter ##\expandafter 1% - \expandafter {#1{##1}}% - \XINT_xflet\XINT_inline_b #2z% THIS z HAS CATCODE 3 + \long\expandafter\def\expandafter\XINT_inline_macro + \expandafter ##\expandafter 1\expandafter {#1{##1}}% + \XINT_xflet\XINT_inline_b #2z% this z has catcode 3 }% -\def\XINT_inline_b {\futurelet\XINT_token\XINT_inline_c }% \def\XINT_inline_b {% - \ifx\XINT_token\XINT_sptoken - \xint_afterfi{\XINT_xflet\XINT_inline_b }% - \else - \xint_afterfi - {\ifx\XINT_token z\expandafter\xint_gobble_i - \else\expandafter\XINT_inline_d\fi }% - \fi + \ifx\XINT_token z\expandafter\xint_gobble_i + \else\expandafter\XINT_inline_d + \fi }% \def\XINT_inline_d #1% {% @@ -7900,13 +8837,9 @@ first place. }% \def\XINT_inline_e {% - \ifx\XINT_token\XINT_sptoken - \xint_afterfi{\XINT_xflet\XINT_inline_e }% - \else - \xint_afterfi - {\ifx\XINT_token z\expandafter\XINT_inline_w - \else \expandafter\XINT_inline_f\fi }% - \fi + \ifx\XINT_token z\expandafter\XINT_inline_w + \else\expandafter\XINT_inline_f + \fi }% \def\XINT_inline_f {% @@ -7915,19 +8848,21 @@ first place. \def\XINT_inline_g #1% {% \expandafter\XINT_inline_macro\XINT_item - \def\XINT_inline_macro ##1{#1}\XINT_inline_d + \long\def\XINT_inline_macro ##1{#1}\XINT_inline_d }% \def\XINT_inline_w #1% {% \expandafter\XINT_inline_macro\XINT_item }% % \end{macrocode} -% \subsection{\csh{xintFor}, \csh{xintFor*}} -% \lverb|& -% 1.09c: a new kind of loop which uses macro parameters #1, #2, #3, #4 -% rather than macros; while not expandable it survives executing code -% closing groups, like what happens in an alignment with the $& character. When -% inserted in a macro for later use, the # character must be doubled. +% \subsection{\csh{xintFor}, +% \csh{xintFor*}, \csh{xintBreakFor}, \csh{xintBreakForAndDo}} +% \lverb|& +% 1.09c: +% a new kind of loop which uses macro parameters #1, #2, #3, +% #4 rather than macros; while not expandable it survives executing code +% closing groups, like what happens in an alignment with the $& character. +% When inserted in a macro for later use, the # character must be doubled. % % The non-star variant works on a csv list, which it expands once, the % star variant works on a token list, expanded fully. @@ -7936,211 +8871,328 @@ first place. % swallow a space token from blanks before the `in'. Blanks after the `in' % disappear as #3 is not delimited. % -% 1.09d: \xintFor* crashed when a space token was at the very end of the list. -% Indeed it is crucial in this code to not let the ending z be picked up as a -% macro parameter without knowing in advance that it is its turn. Now, we -% conscientiously clean out of the way space tokens. And with the new code, the -% macro ff-expands each item which is not braced. This way, it is very easy to -% simulate concatenation of lists or the fact to insert one within the other -% without having to waste time doing it really. If the list contains two -% consecutive space tokens and then an unbraced token item \x, this \x will not -% be expanded. But if we expanded it we would have the risk to again have one or -% more space token and there could be nothing up to the z. But then the z would -% be picked next time, spaces discarded, and a crash. And for some reasons I -% don't want to do an \ifx to compare with {z}. I could use the technique of my -% completely expandable macros with a gob_til_z. I chose to do it this way, -% which is guaranteed not to crash at the z, with the feature that unbraced -% items consecutive to two or more space tokens (a surely rare case, which would -% require some devilish soul wanting to stress test my package as of course -% consecutive blanks only give _one_ space token) will not get expanded. -% [2013/10/22] -%| -% \begin{macrocode} +% 1.09d: [2013/10/22] \xintFor* crashed when a space token was at the very end +% of the list. It is crucial in this code to not let the ending z be picked up +% as a macro parameter without knowing in advance that it is its turn. So, we +% conscientiously clean out of the way space tokens, but also we ff-expand with +% \romannumeral-`0 (unbraced) items, a process which may create new space +% tokens, so it is iterated. As unbraced items are expanded, it is easy to +% simulate insertion of a list in another. +% Unbraced items consecutive to an even (non-zero) number of space tokens will +% not get expanded. +% +% 1.09e: does this better, no difference between an even or odd number of +% explicit consecutive space tokens. Normal situations anyhow only create at +% most one space token, but well. +% 1.09e: There was a feature in \xintFor (not \xintFor*) from 1.09c that it +% treated an empty list as a list with one, empty, item. This feature is kept in +% 1.09e, knowingly... Also, some macros are made long, the iterated text may +% contain \par and also the looped over items. I thought about providing some +% macro expanding to the loop count, but this complicates things and as the +% \xintFor is not expandable anyhow, there is no loss of generality if the +% iterated commands do themselves the bookkeeping using a count or a LaTeX +% counter. +% +% 1.09e adds \XINT_forever with \xintintegers, \xintdimensions, +% \xintrationals and \xintBreakFor, \xintBreakForAndDo. +% +% 1.09e adds \xintifForFirst, \xintifForLast. On this occasion firstoftwo and +% secondoftwo are made long. +% +% | +% \begin{macrocode} +\long\def\xintBreakFor #1z{}% +\long\def\xintBreakForAndDo #1#2z{#1}% +\catcode`U 3 % with numexpr +\catcode`V 3 % with xintfrac.sty (xint.sty not enough, uses \xintIrr) +\catcode`D 3 % with dimexpr +\catcode`j 3 \def\xintFor {\futurelet\XINT_token\XINT_for_ifstar }% -\def\XINT_for_ifstar {\ifx\XINT_token*\expandafter\XINT_forx +\def\XINT_for_ifstar {\let\xintifForFirst\xint_firstoftwo + \ifx\XINT_token*\expandafter\XINT_forx \else\expandafter\XINT_for \fi }% -\def\XINT_for #1#2in#3#4#5% +\long\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,% THIS z HAS CATCODE 3. + \XINT_toks {\csname XINT_for_d\romannumeral#2\endcsname {#5}}% + \expandafter\futurelet\expandafter\XINT_token + \expandafter\XINT_for_forever? #3,z% this z has catcode 3 }% -\def\XINT_forx *#1#2in#3#4#5% +\long\def\XINT_forx *#1#2in#3#4#5% {% - \XINT_toks \expandafter{\csname XINT_forx_d\romannumeral#2\endcsname {#5}}% - \XINT_xflet\XINT_forx_b #3z% THIS z HAS CATCODE 3. + \XINT_toks {\csname XINT_forx_d\romannumeral#2\endcsname {#5}}% + \XINT_xflet\XINT_forx_forever? #3jz% j and z have catcode 3 }% -\def\XINT_for_b {\futurelet\XINT_token\XINT_for_c }% -\def\XINT_for_c +\def\XINT_to_forever #1\XINT_toks {\fi \XINT_forever }% +\def\XINT_for_forever? {% - \ifx\XINT_token z\expandafter\xint_gobble_iv\fi - \the\XINT_toks + \ifx\XINT_token U\XINT_to_forever\fi + \ifx\XINT_token V\XINT_to_forever\fi + \ifx\XINT_token D\XINT_to_forever\fi + \the\XINT_toks }% -\def\XINT_for_di #1#2,% +\def\XINT_to_forxever #1\XINT_forx_empty? {\fi \XINT_forever }% +\def\XINT_forx_forever? {% - \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 + \ifx\XINT_token U\XINT_to_forxever\fi + \ifx\XINT_token V\XINT_to_forxever\fi + \ifx\XINT_token D\XINT_to_forxever\fi + \XINT_forx_empty? }% -\def\XINT_for_dii #1#2,% +\def\XINT_forx_empty? {% - \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 + \ifx\XINT_token j\expandafter\xint_gobble_iv\fi + \the\XINT_toks +}% +\long\def\XINT_for_di #1#2,% +{% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {#2}{####2}{####3}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_di {#1}}% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_for_diii #1#2,% +\long\def\XINT_for_dii #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 + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{#2}{####3}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_dii {#1}}% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_for_div #1#2,% +\long\def\XINT_for_diii #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 + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{####2}{#2}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_diii {#1}}% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_for_e +\long\def\XINT_for_div #1#2,% +{% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{####2}{####3}{#2}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_div {#1}}% + \futurelet\XINT_token\XINT_for_last? +}% +\def\XINT_for_last? {% - \ifx\XINT_token z\xint_afterfi{\expandafter\XINT_x \xint_gobble_iv}\fi - \the\XINT_toks + \ifx\XINT_token z\xint_afterfi{\let\xintifForLast\xint_firstoftwo + \expandafter\XINT_x\xint_gobble_vi}\fi + \let\xintifForLast\xint_secondoftwo\the\XINT_toks }% -\def\XINT_forx_b +\long\def\XINT_forx_di #1#2% {% - \ifx\XINT_token\XINT_sptoken - \xint_afterfi{\XINT_xflet\XINT_forx_b }% - \else - \xint_afterfi - {\ifx\XINT_token z\expandafter\xint_gobble_iii\fi - \the\XINT_toks }% - \fi + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {#2}{####2}{####3}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_di {#1}}% + \XINT_xflet\XINT_forx_last? }% -\def\XINT_forx_di #1#2% +\long\def\XINT_forx_dii #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}}% - \XINT_xflet\XINT_forx_e + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{#2}{####3}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_dii {#1}}% + \XINT_xflet\XINT_forx_last? }% -\def\XINT_forx_dii #1#2% +\long\def\XINT_forx_diii #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}}% - \XINT_xflet\XINT_forx_e + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{####2}{#2}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_diii {#1}}% + \XINT_xflet\XINT_forx_last? }% -\def\XINT_forx_diii #1#2% +\long\def\XINT_forx_div #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}}% - \XINT_xflet\XINT_forx_e + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{####2}{####3}{#2}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_div {#1}}% + \XINT_xflet\XINT_forx_last? +}% +\def\XINT_forx_last? +{% + \ifx\XINT_token j\xint_afterfi{\let\xintifForLast\xint_firstoftwo + \expandafter\XINT_x\xint_gobble_vii}\fi + \let\xintifForLast\xint_secondoftwo\the\XINT_toks }% -\def\XINT_forx_div #1#2% +\catcode`j 11 +% \end{macrocode} +% \subsection{\csh{XINT\_forever}, \csh{xintintegers}, \csh{xintdimensions}, \csh{xintrationals}} +% \lverb|& +% 1.09e. The apparently complicated \XINT_?expr_D is to maintain optimal +% precision. Well other things now are apparently complicated... the code is +% shared by the three, and this is not easy.| +% \begin{macrocode} +\let\xintegers U% +\let\xintintegers U% +\let\xintdimensions D% +\let\xintrationals V% +\def\XINT_forever #1% +{% + \expandafter\XINT_forever_a + \csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi a\expandafter\endcsname + \csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi i\expandafter\endcsname + \csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi \endcsname +}% +\catcode`U 11 +\catcode`D 11 +\catcode`V 11 +\def\XINT_?expr_Ua #1#2% + {\expandafter{\expandafter\numexpr\the\numexpr #1\expandafter\relax + \expandafter\relax\expandafter}% + \expandafter{\the\numexpr #2}}% +\def\XINT_?expr_Da #1#2% + {\expandafter{\expandafter\dimexpr\number\dimexpr #1\expandafter\relax + \expandafter s\expandafter p\expandafter\relax\expandafter}% + \expandafter{\number\dimexpr #2}}% +\catcode`z 11 +\def\XINT_?expr_Va #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}}% - \XINT_xflet\XINT_forx_e + \expandafter\XINT_?expr_Vb\expandafter + {\romannumeral-`0\xintrawwithzeros{#2}}% + {\romannumeral-`0\xintrawwithzeros{#1}}% }% -\def\XINT_forx_e +\catcode`z 3 +\def\XINT_?expr_Vb #1#2{\expandafter\XINT_?expr_Vc #2.#1.}% +\def\XINT_?expr_Vc #1/#2.#3/#4.% +{% + \xintifEq {#2}{#4} + {\XINT_?expr_Vf {#3}{#1}{#2}} + {\expandafter\XINT_?expr_Vd\expandafter + {\romannumeral0\xintimul {#2}{#4}}% + {\romannumeral0\xintimul {#1}{#4}}% + {\romannumeral0\xintimul {#2}{#3}}}% +}% +\def\XINT_?expr_Vd #1#2#3{\expandafter\XINT_?expr_Ve\expandafter {#2}{#3}{#1}}% +\def\XINT_?expr_Ve #1#2{\expandafter\XINT_?expr_Vf\expandafter {#2}{#1}}% +\def\XINT_?expr_Vf #1#2#3{{#2/#3}{{0}{#1}{#2}{#3}}}% +\def\XINT_?expr_Ui {{\numexpr 1\relax}{1}}% +\def\XINT_?expr_Di {{\dimexpr 0pt\relax}{65536}}% +\def\XINT_?expr_Vi {{1/1}{0111}}% +\def\XINT_?expr_U #1#2% + {\expandafter{\expandafter\numexpr\the\numexpr #1+#2\relax\relax}{#2}}% +\def\XINT_?expr_D #1#2% + {\expandafter{\expandafter\dimexpr\the\numexpr #1+#2\relax sp\relax}{#2}}% +\def\XINT_?expr_V #1#2{\XINT_?expr_Vx #2}% +\def\XINT_?expr_Vx #1#2% {% - \ifx\XINT_token\XINT_sptoken - \xint_afterfi{\XINT_xflet\XINT_forx_e}% - \else - \xint_afterfi - {\ifx\XINT_token z\xint_afterfi{\expandafter\XINT_x \xint_gobble_iii}\fi - \the\XINT_toks }% - \fi + \expandafter\XINT_?expr_Vy\expandafter + {\romannumeral0\xintiadd {#1}{#2}}{#2}% +}% +\def\XINT_?expr_Vy #1#2#3#4% +{% + \expandafter{\romannumeral0\xintiadd {#3}{#1}/#4}{{#1}{#2}{#3}{#4}}% +}% +\def\XINT_forever_a #1#2#3#4% +{% + \ifx #4[\expandafter\XINT_forever_opt_a + \else\expandafter\XINT_forever_b + \fi #1#2#3% +}% +\def\XINT_forever_b #1#2#3#4z{\expandafter\XINT_forever_c\the\XINT_toks #2#3}% +\long\def\XINT_forever_c #1\romannumeral #2#3#4#5#6% +{% + \csname XINT_forever_d\romannumeral#2\expandafter\endcsname #5#6{#4}z% +}% +\def\XINT_forever_opt_a #1#2#3#4+#5]#6z% +{% + \expandafter\expandafter\expandafter + \XINT_forever_opt_c\expandafter\the\expandafter\XINT_toks + \romannumeral-`0#1{#4}{#5}#3% +}% +\long\def\XINT_forever_opt_c #1\romannumeral #2#3#4#5#6#7% +{% + \csname XINT_forever_d\romannumeral#2\endcsname {#5}{#6}#7{#4}z% +}% +\long\def\XINT_forever_di #1#2#3#4% +{% + \long\def\XINT_y ##1##2##3##4{#4}% + \XINT_y {#1}{##2}{##3}{##4}% + \let\xintifForFirst\xint_secondoftwo + \expandafter\XINT_forever_di\romannumeral-`0#3{#1}{#2}#3{#4}% +}% +\long\def\XINT_forever_dii #1#2#3#4% +{% + \long\def\XINT_y ##1##2##3##4{#4}% + \XINT_y {##1}{#1}{##3}{##4}% + \let\xintifForFirst\xint_secondoftwo + \expandafter\XINT_forever_dii\romannumeral-`0#3{#1}{#2}#3{#4}% +}% +\long\def\XINT_forever_diii #1#2#3#4% +{% + \long\def\XINT_y ##1##2##3##4{#4}% + \XINT_y {##1}{##2}{#1}{##4}% + \let\xintifForFirst\xint_secondoftwo + \expandafter\XINT_forever_diii\romannumeral-`0#3{#1}{#2}#3{#4}% +}% +\long\def\XINT_forever_div #1#2#3#4% +{% + \long\def\XINT_y ##1##2##3##4{#4}% + \XINT_y {##1}{##2}{##3}{#1}% + \let\xintifForFirst\xint_secondoftwo + \expandafter\XINT_forever_div\romannumeral-`0#3{#1}{#2}#3{#4}% }% % \end{macrocode} % \subsection{\csh{xintForpair}, \csh{xintForthree}, \csh{xintForfour}} % \lverb|& % 1.09c: experimental status. Particularly I don't know yet if {a}{b} is better -% for the user or worse than (a,b). I prefer the former of course. I am +% for the user or worse than (a,b). I prefer the former. I am % not very motivated to deal with spaces in the (a,b) approach which is % the one (currently) followed here. %| % \begin{macrocode} -\def\xintForpair #1#2#3#4in#5#6#7% +\long\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,% THIS z HAS CATCODE 3 + \XINT_toks \expandafter{\csname XINT_forii_d\romannumeral#2\endcsname {#7}}% + \expandafter\the\expandafter\XINT_toks #5,z% THIS z HAS CATCODE 3 }% -\def\XINT_forii_b {\futurelet\XINT_token\XINT_forii_c }% -\def\XINT_forii_c +\long\def\XINT_forii_di #1(#2,#3),% {% - \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}% + \long\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 + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_forii_dii #1(#2,#3),% +\long\def\XINT_forii_dii #1(#2,#3),% {% - \def\XINT_y ##1##2##3##4{#1}% + \long\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 + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_forii_diii #1(#2,#3),% +\long\def\XINT_forii_diii #1(#2,#3),% {% - \def\XINT_y ##1##2##3##4{#1}% - \def\XINT_x {\XINT_y {####1}{####2}{#2}{#3}}% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\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,% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_foriii_b {\futurelet\XINT_token\XINT_foriii_c }% -\def\XINT_foriii_c +\long\def\xintForthree #1#2#3in#4#5#6% {% - \ifx\XINT_token z\expandafter\xint_gobble_iv\fi - \the\XINT_toks + \XINT_toks \expandafter{\csname XINT_foriii_d\romannumeral#2\endcsname {#6}}% + \expandafter\the\expandafter\XINT_toks #4,z% }% -\def\XINT_foriii_di #1(#2,#3,#4),% +\long\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}}% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {#2}{#3}{#4}{####4}}% \XINT_toks {\XINT_x\XINT_foriii_di {#1}}% - \futurelet\XINT_token\XINT_for_e + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_foriii_dii #1(#2,#3,#4),% +\long\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}}% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{#2}{#3}{#4}}% \XINT_toks {\XINT_x \XINT_foriii_dii {#1}}% - \futurelet\XINT_token\XINT_for_e + \futurelet\XINT_token\XINT_for_last? }% -\def\xintForfour #1#2#3in#4#5#6% +\long\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 + \expandafter\the\expandafter\XINT_toks #4,z% }% -\def\XINT_foriv_di #1(#2,#3,#4,#5),% +\long\def\XINT_foriv_di #1(#2,#3,#4,#5),% {% - \def\XINT_y ##1##2##3##4{#1}% - \def\XINT_x {\XINT_y {#2}{#3}{#4}{#5}}% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {#2}{#3}{#4}{#5}}% \XINT_toks {\XINT_x\XINT_foriv_di {#1}}% - \futurelet\XINT_token\XINT_for_e + \futurelet\XINT_token\XINT_for_last? }% \catcode`z 11 % \end{macrocode} @@ -8227,7 +9279,7 @@ first place. \def\XINT_assignarray_loop #1% {% \def\xint_temp {#1}% - \ifx\xint_braced_xint_relax\xint_temp + \ifx\xint_brelax\xint_temp \expandafter\edef\csname\xint_arrayname 0\endcsname{\the\count 255 }% \expandafter\expandafter\expandafter\XINT_assignarray_end_a \else @@ -8380,8 +9432,8 @@ first place. \expandafter\xint_cleanupzeros_andstop \romannumeral0\XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% % \end{macrocode} @@ -8546,8 +9598,8 @@ first place. % \lverb|& % Expandable three-way fork added in 1.09a. Branches expandably depending on % whether if <0, =0, >0. The use of -% \romannumeral0\xintsgn rather than \xintSgn is related to the (partial) -% acceptability of the ternary operator : in \xintNewExpr | +% \romannumeral0\xintsgn rather than \xintSgn for matters related of the +% transformation of the ternary operator : in \xintNewExpr | % \begin{macrocode} \def\xintifSgn {\romannumeral0\xintifsgn }% \def\xintifsgn #1% @@ -8583,12 +9635,29 @@ first place. \fi }% % \end{macrocode} -% \subsection{\csh{xintifTrue}} +% \subsection{\csh{xintifTrueFalse}} % \begin{macrocode} \let\xintifTrue\xintifNotZero +\let\xintifTrueFalse\xintifNotZero +% \end{macrocode} +% \subsection{\csh{xintifCmp}} +% \lverb|& +% 1.09e +% \xintifCmp {n}{m}{if n<m}{if n=m}{if n>m}. | +% \begin{macrocode} +\def\xintifCmp {\romannumeral0\xintifcmp }% +\def\xintifcmp #1#2% +{% + \ifcase \xintCmp {#1}{#2} + \xint_afterfi{\expandafter\space\xint_secondofthree}% + \or\xint_afterfi{\expandafter\space\xint_thirdofthree}% + \else\xint_afterfi{\expandafter\space\xint_firstofthree}% + \fi +}% % \end{macrocode} % \subsection{\csh{xintifEq}} % \lverb|& +% 1.09a % \xintifEq {n}{m}{YES if n=m}{NO if n<>m}. | % \begin{macrocode} \def\xintifEq {\romannumeral0\xintifeq }% @@ -8601,7 +9670,8 @@ first place. }% % \end{macrocode} % \subsection{\csh{xintifGt}} -% \lverb|\xintifGt {n}{m}{YES if n>m}{NO if n<=m}.| +% \lverb|& +% 1.09a \xintifGt {n}{m}{YES if n>m}{NO if n<=m}.| % \begin{macrocode} \def\xintifGt {\romannumeral0\xintifgt }% \def\xintifgt #1#2% @@ -8613,7 +9683,8 @@ first place. }% % \end{macrocode} % \subsection{\csh{xintifLt}} -% \lverb|\xintifLt {n}{m}{YES if n<m}{NO if n>=m}.| +% \lverb|& +% 1.09a \xintifLt {n}{m}{YES if n<m}{NO if n>=m}.| % \begin{macrocode} \def\xintifLt {\romannumeral0\xintiflt }% \def\xintiflt #1#2% @@ -8624,6 +9695,19 @@ first place. {\expandafter\space\xint_secondoftwo}% }% % \end{macrocode} +% \subsection{\csh{xintifOdd}} +% \lverb|1.09e| +% \begin{macrocode} +\def\xintifOdd {\romannumeral0\xintifodd }% +\def\xintifodd #1% +{% + \if\xintOdd{#1}1% + \xint_afterfi{\expandafter\space\xint_firstoftwo}% + \else + \xint_afterfi{\expandafter\space\xint_secondoftwo}% + \fi +}% +% \end{macrocode} % \subsection{\csh{xintOpp}} % \lverb|\xintnum added in 1.09a| % \begin{macrocode} @@ -8727,7 +9811,7 @@ first place. }% \def\XINT_add_ABE #1#2#3#4#5#6% {% - \expandafter\XINT_add_ABEA\the\numexpr #1+10#5#4#3#2+#6\relax.% + \expandafter\XINT_add_ABEA\the\numexpr #1+10#5#4#3#2+#6.% }% \def\XINT_add_ABEA #1#2#3.#4% {% @@ -8741,7 +9825,7 @@ first place. % \begin{macrocode} \def\xint_add_bz\W\XINT_add_ABE #1#2#3#4#5#6% {% - \expandafter\XINT_add_CC\the\numexpr #1+10#5#4#3#2\relax.% + \expandafter\XINT_add_CC\the\numexpr #1+10#5#4#3#2.% }% \def\XINT_add_CC #1#2#3.#4% {% @@ -8764,8 +9848,8 @@ first place. \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -8776,7 +9860,7 @@ first place. }% \def\XINT_add_CD #1% {% - \expandafter\XINT_add_CC\the\numexpr 1+10#1\relax.% + \expandafter\XINT_add_CC\the\numexpr 1+10#1.% }% \def\xint_add_cz\W\XINT_add_CD #1#2{ 1#2}% % \end{macrocode} @@ -8862,7 +9946,7 @@ first place. }% \def\XINT_addm_ABE #1#2#3#4#5#6% {% - \expandafter\XINT_addm_ABEA\the\numexpr #1+10#5#4#3#2+#6\relax.% + \expandafter\XINT_addm_ABEA\the\numexpr #1+10#5#4#3#2+#6.% }% \def\XINT_addm_ABEA #1#2#3.#4% {% @@ -8879,8 +9963,8 @@ first place. \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -8895,7 +9979,7 @@ first place. }% \def\XINT_addm_CD #1% {% - \expandafter\XINT_addm_CC\the\numexpr 1+10#1\relax.% + \expandafter\XINT_addm_CC\the\numexpr 1+10#1.% }% \def\XINT_addm_CC #1#2#3.#4% {% @@ -8907,7 +9991,7 @@ first place. #3\xint_addm_cz \W\XINT_addm_CD {% - \expandafter\XINT_addm_CDw\the\numexpr 1+#1#2#3\relax.% + \expandafter\XINT_addm_CDw\the\numexpr 1+#1#2#3.% }% \def\XINT_addm_CDw #1.#2#3\X\Y\Z {% @@ -8918,7 +10002,7 @@ first place. #2\xint_addm_cz \W\XINT_addm_CD {% - \expandafter\XINT_addm_CDx\the\numexpr 1+#1#2\relax.% + \expandafter\XINT_addm_CDx\the\numexpr 1+#1#2.% }% \def\XINT_addm_CDx #1.#2#3\Y\Z {% @@ -8928,7 +10012,7 @@ first place. #1\xint_addm_cz \W\XINT_addm_CD {% - \expandafter\XINT_addm_CDy\the\numexpr 1+#1\relax.% + \expandafter\XINT_addm_CDy\the\numexpr 1+#1.% }% \def\XINT_addm_CDy #1.#2#3\Z {% @@ -9267,7 +10351,7 @@ first place. % \begin{macrocode} \def\XINT_sub_onestep #1#2#3#4#5#6% {% - \expandafter\XINT_sub_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i\relax.% + \expandafter\XINT_sub_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i.% }% % \end{macrocode} % \lverb|ON PRODUIT LE RÉSULTAT DANS LE BON ORDRE| @@ -9292,8 +10376,8 @@ first place. \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -9305,7 +10389,7 @@ first place. }% \def\XINT_sub_AC_onestep #1% {% - \expandafter\XINT_sub_backtoC\the\numexpr 11#1-\xint_c_i\relax.% + \expandafter\XINT_sub_backtoC\the\numexpr 11#1-\xint_c_i.% }% \def\XINT_sub_backtoC #1#2#3.#4% {% @@ -9322,8 +10406,8 @@ first place. \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1\W\W\W\W\W\W\W\Z }% @@ -9347,8 +10431,8 @@ first place. \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \W\X\Y\Z #1% }% @@ -9359,7 +10443,7 @@ first place. }% \def\XINT_sub_Eonestep #1#2% {% - \expandafter\XINT_sub_backtoE\the\numexpr 109999-#2+#1\relax.% + \expandafter\XINT_sub_backtoE\the\numexpr 109999-#2+#1.% }% \def\XINT_sub_backtoE #1#2#3.#4% {% @@ -9382,7 +10466,7 @@ first place. }% \def\XINT_sub_Fdec_onestep #1#2% {% - \expandafter\XINT_sub_backtoFdec\the\numexpr 11#2+#1-\xint_c_i\relax.% + \expandafter\XINT_sub_backtoFdec\the\numexpr 11#2+#1-\xint_c_i.% }% \def\XINT_sub_backtoFdec #1#2#3.#4% {% @@ -9399,7 +10483,7 @@ first place. }% \def\XINT_sub_Finc_onestep #1#2% {% - \expandafter\XINT_sub_backtoFinc\the\numexpr 10#2+#1\relax.% + \expandafter\XINT_sub_backtoFinc\the\numexpr 10#2+#1.% }% \def\XINT_sub_backtoFinc #1#2#3.#4% {% @@ -9428,8 +10512,8 @@ first place. \romannumeral0% \XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_sub_KK #1#2#3#4#5#6% @@ -9439,7 +10523,7 @@ first place. }% \def\XINT_sub_KK_onestep #1#2% {% - \expandafter\XINT_sub_backtoKK\the\numexpr 109999-#2+#1\relax.% + \expandafter\XINT_sub_backtoKK\the\numexpr 109999-#2+#1.% }% \def\XINT_sub_backtoKK #1#2#3.#4% {% @@ -9534,7 +10618,7 @@ first place. }% \def\XINT_cmp_onestep #1#2#3#4#5#6% {% - \expandafter\XINT_cmp_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i\relax.% + \expandafter\XINT_cmp_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i.% }% \def\XINT_cmp_backtoA #1#2#3.#4% {% @@ -9790,7 +10874,7 @@ first place. }% \def\XINT_geq_onestep #1#2#3#4#5#6% {% - \expandafter\XINT_geq_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i\relax.% + \expandafter\XINT_geq_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i.% }% \def\XINT_geq_backtoA #1#2#3.#4% {% @@ -10194,7 +11278,7 @@ first place. \def\XINT_mul_Br #1#2#3#4\W\X\Y\Z #5#6#7#8% {% \expandafter\XINT_mul_ABEAr - \the\numexpr #1+10#2+#8#7#6#5\relax.{#3}#4\W\X\Y\Z + \the\numexpr #1+10#2+#8#7#6#5.{#3}#4\W\X\Y\Z }% \def\XINT_mul_ABEAr #1#2#3#4#5#6.#7% {% @@ -10765,8 +11849,8 @@ first place. \fi {#1}{#2}\XINT_pow_posprod \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_pow_BtooBig #1\xint_relax #2\xint_relax @@ -11457,7 +12541,7 @@ first place. \def\XINT_div_sub_onestep #1#2#3#4#5#6% {% \expandafter\XINT_div_sub_backtoA - \the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i\relax.% + \the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i.% }% \def\XINT_div_sub_backtoA #1#2#3.#4% {% @@ -11477,8 +12561,8 @@ first place. \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -11489,7 +12573,7 @@ first place. }% \def\XINT_div_sub_AC_onestep #1% {% - \expandafter\XINT_div_sub_backtoC\the\numexpr 11#1-\xint_c_i\relax.% + \expandafter\XINT_div_sub_backtoC\the\numexpr 11#1-\xint_c_i.% }% \def\XINT_div_sub_backtoC #1#2#3.#4% {% @@ -11505,8 +12589,8 @@ first place. \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -11524,7 +12608,7 @@ first place. % \lverb|& % FIRST DIGIT. Code simplified in 1.05. % And prepared for redefinition by xintfrac to parse through \xintNum. Version -% 1.09a inserts the \xintnum here.| +% 1.09a inserts the \xintnum already here.| % \begin{macrocode} \def\xintiFDg {\romannumeral0\xintifdg }% \def\xintifdg #1% @@ -11549,7 +12633,8 @@ first place. % \subsection{\csh{xintLDg}} % \lverb|& % LAST DIGIT. Simplified in 1.05. And prepared for extension by xintfrac -% to parse through \xintNum. 1.09a has it here.| +% to parse through \xintNum. Release 1.09a adds the \xintnum already here, +% and this propagates to \xintOdd, etc... .| % \begin{macrocode} \def\xintiLDg {\romannumeral0\xintildg }% \def\xintildg #1% @@ -11610,9 +12695,7 @@ first place. }% % \end{macrocode} % \subsection{\csh{xintOdd}} -% \lverb|& -% ODDNESS. 1.05 defines \xintiOdd, so \xintOdd can be modified by -% xintfrac to parse through \xintNum.| +% \lverb|1.05 has \xintiOdd, whereas \xintOdd parses through \xintNum.| % \begin{macrocode} \def\xintiOdd {\romannumeral0\xintiodd }% \def\xintiodd #1% @@ -12199,8 +13282,8 @@ first place. \expandafter\XINT_dec_cleanup \romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -12247,7 +13330,8 @@ first place. \def\XINT_inc_end\W #1\relax #2{ 1#2}% % \end{macrocode} % \subsection{\csh{xintiSqrt}, \csh{xintiSquareRoot}} -% \lverb!v1.08. 1.09a uses \xintnum! +% \lverb|v1.08. 1.09a uses \xintnum. Very embarrassing to discover at the +% time of 1.09e that \xintiSqrt {0} was buggy! | % \begin{macrocode} \def\XINT_dsx_addzerosnofuss #1{\XINT_dsx_zeroloop {#1}{}\Z }% \def\xintiSqrt {\romannumeral0\xintisqrt }% @@ -12266,8 +13350,8 @@ first place. 0-\dummy {\XINT_sqrt #1}% \krof }% -\def\XINT_sqrt_iszero #1\Z { 0}% -\def\XINT_sqrt_isneg #1\Z {\xintError:RootOfNegative\space 0}% +\def\XINT_sqrt_iszero #1\Z { 1.}% 1.09e was wrong from inception in 1.08 :-(( +\def\XINT_sqrt_isneg #1\Z {\xintError:RootOfNegative\space 1.}% \def\XINT_sqrt #1\Z {% \expandafter\XINT_sqrt_start\expandafter @@ -12564,7 +13648,7 @@ first place. % \begin{macrocode} \XINT_providespackage \ProvidesPackage{xintbinhex}% - [2013/10/22 v1.09d Expandable binary and hexadecimal conversions (jfB)]% + [2013/10/29 v1.09e Expandable binary and hexadecimal conversions (jfB)]% % \end{macrocode} % \subsection{Constants, etc...} % \lverb!v1.08! @@ -12861,8 +13945,8 @@ first place. \expandafter\xint_cleanupzeros_andstop \romannumeral0\XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_htd_II_ci #1\XINT_htd_II_ciii @@ -12953,8 +14037,8 @@ first place. \expandafter\XINT_btd_II_c_end \romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_btd_II_c_end #1#2#3#4#5#6% @@ -13267,7 +14351,7 @@ first place. % \begin{macrocode} \XINT_providespackage \ProvidesPackage{xintgcd}% - [2013/10/22 v1.09d Euclide algorithm with xint package (jfB)]% + [2013/10/29 v1.09e Euclide algorithm with xint package (jfB)]% % \end{macrocode} % \subsection{\csh{xintGCD}} % The macros of |1.09a| benefits from the |\xintnum| which has been inserted @@ -13668,8 +14752,8 @@ first place. \romannumeral0% \XINT_rord_main {}#4{{#1}{#3}}% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\xint_euc_end_ #1#2#3% @@ -13770,8 +14854,8 @@ first place. \romannumeral0% \XINT_rord_main {}#8{{#1}{#3}}% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% % \end{macrocode} @@ -13987,7 +15071,7 @@ first place. % \begin{macrocode} \XINT_providespackage \ProvidesPackage{xintfrac}% - [2013/10/22 v1.09d Expandable operations on fractions (jfB)]% + [2013/10/29 v1.09e Expandable operations on fractions (jfB)]% \chardef\xint_c_vi 6 \chardef\xint_c_vii 7 \chardef\xint_c_xviii 18 @@ -14216,8 +15300,8 @@ first place. \expandafter\XINT_cuz_cnt_loop\expandafter {\expandafter}\romannumeral0\XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \R\R\R\R\R\R\R\R\Z }% @@ -14300,8 +15384,8 @@ first place. \expandafter\space\expandafter {\romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }{#1}% }% % \end{macrocode} @@ -14691,6 +15775,20 @@ first place. \fi\space #1% }% % \end{macrocode} +% \subsection{\csh{xintifInt}} +% \lverb|1.09e. xintfrac.sty only| +% \begin{macrocode} +\def\xintifInt {\romannumeral0\xintifint }% +\def\xintifint #1{\expandafter\XINT_ifint\romannumeral0\xintirr {#1}\Z }% +\def\XINT_ifint #1/#2\Z +{% + \if\XINT_isOne {#2}1% + \xint_afterfi{\expandafter\space\xint_firstoftwo}% + \else + \xint_afterfi{\expandafter\space\xint_secondoftwo}% + \fi +}% +% \end{macrocode} % \subsection{\csh{xintJrr}} % \lverb|& % Modified similarly as \xintIrr in release 1.05. 1.08 version does @@ -14897,8 +15995,8 @@ first place. \expandafter\XINT_round_C \romannumeral0\XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \Z }% @@ -14919,8 +16017,8 @@ first place. {% \XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \Z }% \def\XINT_round_Dba #1% @@ -15113,8 +16211,8 @@ first place. \romannumeral0\expandafter\XINT_float_Wa \romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \Z }% \def\XINT_float_Vb #1#2\Z #3% @@ -15235,8 +16333,8 @@ first place. \expandafter#1% \romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \Z }% \def\XINT_infloat_Vb #1#2\Z @@ -15910,46 +17008,6 @@ first place. \def\xintrem {\expandafter\xint_secondoftwo_andstop \romannumeral0\xintdivision }% % \end{macrocode} -% \subsection{\csh{xintFDg}, \csh{xintLDg}, \csh{xintMON}, \csh{xint\-MMON}, \csh{xintOdd}} -% \begin{macrocode} -\def\xintFDg {\romannumeral0\xintfdg }% -\def\xintfdg #1% -{% - \expandafter\XINT_fdg\romannumeral0\xintnum {#1}\W\Z -}% -\def\xintLDg {\romannumeral0\xintldg }% -\def\xintldg #1% -{% - \expandafter\XINT_ldg\expandafter{\romannumeral0\xintnum {#1}}% -}% -\def\xintMON {\romannumeral0\xintmon }% -\def\xintmon #1% -{% - \ifodd\xintLDg {#1} - \xint_afterfi{ -1}% - \else - \xint_afterfi{ 1}% - \fi -}% -\def\xintMMON {\romannumeral0\xintmmon }% -\def\xintmmon #1% -{% - \ifodd\xintLDg {#1} - \xint_afterfi{ 1}% - \else - \xint_afterfi{ -1}% - \fi -}% -\def\xintOdd {\romannumeral0\xintodd }% -\def\xintodd #1% -{% - \ifodd\xintLDg{#1} - \xint_afterfi{ 1}% - \else - \xint_afterfi{ 0}% - \fi -}% -% \end{macrocode} % \subsection{\csh{xintFloatAdd}} % \lverb|1.07| % \begin{macrocode} @@ -16218,8 +17276,8 @@ first place. {% \XINT_flpow_loop {#1}{#2}{#3}{{#1}}\XINT_flpow_prd \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax {#4}% }% \def\XINT_flpow_loop #1#2#3% @@ -16362,8 +17420,8 @@ first place. {% \XINT_flpower_loop {#1}{#2}{#3}{{#1}}\XINT_flpow_prd \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax {#4}% }% \def\XINT_flpower_loop #1#2#3% @@ -16684,7 +17742,7 @@ first place. % \begin{macrocode} \XINT_providespackage \ProvidesPackage{xintseries}% - [2013/10/22 v1.09d Expandable partial sums with xint package (jfB)]% + [2013/10/29 v1.09e Expandable partial sums with xint package (jfB)]% % \end{macrocode} % \subsection{\csh{xintSeries}} % \lverb|& @@ -17220,7 +18278,7 @@ first place. % \begin{macrocode} \XINT_providespackage \ProvidesPackage{xintcfrac}% - [2013/10/22 v1.09d Expandable continued fractions with xint package (jfB)]% + [2013/10/29 v1.09e Expandable continued fractions with xint package (jfB)]% % \end{macrocode} % \subsection{\csh{xintCFrac}} % \begin{macrocode} @@ -18372,7 +19430,7 @@ first place. % \begin{macrocode} \XINT_providespackage \ProvidesPackage{xintexpr}% - [2013/10/22 v1.09d Expandable expression parser (jfB)]% + [2013/10/29 v1.09e Expandable expression parser (jfB)]% % \end{macrocode} % \subsection{Helper macros} % \begin{macrocode} @@ -19397,7 +20455,7 @@ first place. Right bracket \] Circumflex \^ Underscore \_ Grave accent \` Left brace \{ Vertical bar \| Right brace \} Tilde \~} -\CheckSum {19442} +\CheckSum {19783} \makeatletter\check@checksum\makeatother \Finale %% diff --git a/Master/texmf-dist/source/generic/xint/xint.ins b/Master/texmf-dist/source/generic/xint/xint.ins index 5865f2e014c..fecdd376db3 100644 --- a/Master/texmf-dist/source/generic/xint/xint.ins +++ b/Master/texmf-dist/source/generic/xint/xint.ins @@ -1,6 +1,6 @@ %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- %% diff --git a/Master/texmf-dist/tex/generic/xint/xint.sty b/Master/texmf-dist/tex/generic/xint/xint.sty index 30747397538..dca6c247cfb 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.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %% xint: Expandable operations on long numbers %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -152,7 +152,7 @@ \fi \XINT_providespackage \ProvidesPackage {xint}% - [2013/10/22 v1.09d Expandable operations on long numbers (jfB)]% + [2013/10/29 v1.09e Expandable operations on long numbers (jfB)]% \def\xint_gobble_ {}% \def\xint_gobble_i #1{}% \def\xint_gobble_ii #1#2{}% @@ -164,8 +164,8 @@ \def\xint_gobble_viii #1#2#3#4#5#6#7#8{}% \def\xint_firstofone #1{#1}% \xint_firstofone{\let\XINT_sptoken= } % 1.09d, 2013/10/22 -\def\xint_firstoftwo #1#2{#1}% -\def\xint_secondoftwo #1#2{#2}% +\long\def\xint_firstoftwo #1#2{#1}% made long in 1.09e, 2013/10/28 +\long\def\xint_secondoftwo #1#2{#2}% \def\xint_firstoftwo_andstop #1#2{ #1}% \def\xint_secondoftwo_andstop #1#2{ #2}% \def\xint_exchangetwo_keepbraces_andstop #1#2{ {#2}{#1}}% @@ -173,6 +173,7 @@ \def\xint_secondofthree #1#2#3{#2}% \def\xint_thirdofthree #1#2#3{#3}% \def\xint_minus_andstop { -}% +\def\xint_bye #1\xint_bye {}% \def\xint_gob_til_R #1\R {}% \def\xint_gob_til_W #1\W {}% \def\xint_gob_til_Z #1\Z {}% @@ -182,8 +183,9 @@ \def\xint_gob_til_minus #1-{}% \def\xint_gob_til_zeros_iii #1000{}% \def\xint_gob_til_zeros_iv #10000{}% +\let\xint_relax\relax +\def\xint_brelax {\xint_relax }% \def\xint_gob_til_relax #1\relax {}% -\def\xint_gob_til_xint_undef #1\xint_undef {}% \def\xint_gob_til_xint_relax #1\xint_relax {}% \def\xint_UDzerofork #10\dummy #2#3\krof {#2}% \def\xint_UDsignfork #1-\dummy #2#3\krof {#2}% @@ -193,8 +195,6 @@ \def\xint_UDzerominusfork #10-\dummy #2#3\krof {#2}% \def\xint_UDsignsfork #1--\dummy #2#3\krof {#2}% \def\xint_afterfi #1#2\fi {\fi #1}% -\let\xint_relax\relax -\def\xint_braced_xint_relax {\xint_relax }% \chardef\xint_c_ 0 \chardef\xint_c_i 1 \chardef\xint_c_ii 2 @@ -210,17 +210,16 @@ \def\xintrev #1% {% \expandafter\XINT_rev_fork - \romannumeral-`0#1\xint_relax % empty #1 ok - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \romannumeral-`0#1\xint_relax % empty #1 ok, \xint_relax stops expansion + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_rev_fork #1% {% \xint_UDsignfork - #1\dummy {\expandafter\xint_minus_andstop - \romannumeral0\XINT_rord_main {}}% - -\dummy {\XINT_rord_main {}#1}% + #1\dummy {\expandafter\xint_minus_andstop\romannumeral0\XINT_rord_main {}}% + -\dummy {\XINT_rord_main {}#1}% \krof }% \def\XINT_Rev {\romannumeral0\XINT_rev }% @@ -229,16 +228,16 @@ {% \XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_rord_main #1#2#3#4#5#6#7#8#9% {% - \xint_gob_til_xint_undef #9\XINT_rord_cleanup\xint_undef + \xint_bye #9\XINT_rord_cleanup\xint_bye \XINT_rord_main {#9#8#7#6#5#4#3#2#1}% }% -\def\XINT_rord_cleanup\xint_undef\XINT_rord_main #1#2\xint_relax +\def\XINT_rord_cleanup\xint_bye\XINT_rord_main #1#2\xint_relax {% \expandafter\space\xint_gob_til_xint_relax #1% }% @@ -248,20 +247,20 @@ {% \expandafter\XINT_revwbr_loop\expandafter{\expandafter}% \romannumeral-`0#1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \def\xintrevwithbracesnoexpand #1% {% \XINT_revwbr_loop {}% #1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \def\XINT_revwbr_loop #1#2#3#4#5#6#7#8#9% {% \xint_gob_til_xint_relax #9\XINT_revwbr_finish_a\xint_relax \XINT_revwbr_loop {{#9}{#8}{#7}{#6}{#5}{#4}{#3}{#2}#1}% }% -\def\XINT_revwbr_finish_a\xint_relax\XINT_revwbr_loop #1#2\Z +\def\XINT_revwbr_finish_a\xint_relax\XINT_revwbr_loop #1#2\xint_bye {% \XINT_revwbr_finish_b #2\R\R\R\R\R\R\R\Z #1% }% @@ -288,14 +287,14 @@ {% \expandafter\XINT_length_fork \romannumeral0\xintnum{#1}\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \let\xintLen\xintiLen \let\xintlen\xintilen \def\XINT_Len #1% {% \romannumeral0\XINT_length_fork #1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \def\XINT_length_fork #1% {% @@ -310,7 +309,7 @@ {% \XINT_length_loop {0}#1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \let\xintLength\XINT_Length \def\XINT_length_loop #1#2#3#4#5#6#7#8#9% @@ -319,7 +318,7 @@ \expandafter\XINT_length_loop\expandafter {\the\numexpr #1+8\relax}% }% \def\XINT_length_finish_a\xint_relax - \expandafter\XINT_length_loop\expandafter #1#2\Z + \expandafter\XINT_length_loop\expandafter #1#2\xint_bye {% \XINT_length_finish_b #2\W\W\W\W\W\W\W\Z {#1}% }% @@ -335,30 +334,29 @@ #7\XINT_length_finish_c 2% \W\XINT_length_finish_c 1\Z }% -\def\XINT_length_finish_c #1#2\Z #3% - {\expandafter\space\the\numexpr #3-#1\relax}% +\def\XINT_length_finish_c #1#2\Z #3{\expandafter\space\the\numexpr #3-#1\relax}% \def\xintCSVtoList {\romannumeral0\xintcsvtolist }% \def\xintCSVtoListNoExpand {\romannumeral0\xintcsvtolistnoexpand }% \def\xintcsvtolist #1% {% \expandafter\XINT_csvtol_loop_a\expandafter {\expandafter}\romannumeral-`0#1% - ,\xint_undef,\xint_undef,\xint_undef,\xint_undef - ,\xint_undef,\xint_undef,\xint_undef,\xint_undef,\Z + ,\xint_bye,\xint_bye,\xint_bye,\xint_bye + ,\xint_bye,\xint_bye,\xint_bye,\xint_bye,\Z }% \def\xintcsvtolistnoexpand #1% {% \XINT_csvtol_loop_a - {}#1,\xint_undef,\xint_undef,\xint_undef,\xint_undef - ,\xint_undef,\xint_undef,\xint_undef,\xint_undef,\Z + {}#1,\xint_bye,\xint_bye,\xint_bye,\xint_bye + ,\xint_bye,\xint_bye,\xint_bye,\xint_bye,\Z }% \def\XINT_csvtol_loop_a #1#2,#3,#4,#5,#6,#7,#8,#9,% {% - \xint_gob_til_xint_undef #9\XINT_csvtol_finish_a\xint_undef + \xint_bye #9\XINT_csvtol_finish_a\xint_bye \XINT_csvtol_loop_b {#1}{{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}% }% \def\XINT_csvtol_loop_b #1#2{\XINT_csvtol_loop_a {#1#2}}% -\def\XINT_csvtol_finish_a\xint_undef\XINT_csvtol_loop_b #1#2#3\Z +\def\XINT_csvtol_finish_a\xint_bye\XINT_csvtol_loop_b #1#2#3\Z {% \XINT_csvtol_finish_b #3\R,\R,\R,\R,\R,\R,\R,\Z #2{#1}% }% @@ -391,21 +389,21 @@ \def\xintListWithSepNoExpand {\romannumeral0\xintlistwithsepnoexpand }% \long\def\xintlistwithsep #1#2% {\expandafter\XINT_lws\expandafter {\romannumeral-`0#2}{#1}}% -\long\def\XINT_lws #1#2{\XINT_lws_start {#2}#1\Z }% -\long\def\xintlistwithsepnoexpand #1#2{\XINT_lws_start {#1}#2\Z }% +\long\def\XINT_lws #1#2{\XINT_lws_start {#2}#1\xint_bye }% +\long\def\xintlistwithsepnoexpand #1#2{\XINT_lws_start {#1}#2\xint_bye }% \long\def\XINT_lws_start #1#2% {% - \xint_gob_til_Z #2\XINT_lws_dont\Z + \xint_bye #2\XINT_lws_dont\xint_bye \XINT_lws_loop_a {#2}{#1}% }% -\long\def\XINT_lws_dont\Z\XINT_lws_loop_a #1#2{ }% +\long\def\XINT_lws_dont\xint_bye\XINT_lws_loop_a #1#2{ }% \long\def\XINT_lws_loop_a #1#2#3% {% - \xint_gob_til_Z #3\XINT_lws_end\Z + \xint_bye #3\XINT_lws_end\xint_bye \XINT_lws_loop_b {#1}{#2#3}{#2}% }% \long\def\XINT_lws_loop_b #1#2{\XINT_lws_loop_a {#1#2}}% -\long\def\XINT_lws_end\Z\XINT_lws_loop_b #1#2#3{ #1}% +\long\def\XINT_lws_end\xint_bye\XINT_lws_loop_b #1#2#3{ #1}% \def\xintNthElt {\romannumeral0\xintnthelt }% \def\xintNthEltNoExpand {\romannumeral0\xintntheltnoexpand }% \def\xintnthelt #1% @@ -443,7 +441,7 @@ \else \expandafter\XINT_length_loop \fi {#2}#1\xint_relax\xint_relax\xint_relax\xint_relax - \xint_relax\xint_relax\xint_relax\xint_relax\Z + \xint_relax\xint_relax\xint_relax\xint_relax\xint_bye }% \def\XINT_nthelt_loop_a #1% {% @@ -457,21 +455,17 @@ \def\XINT_nthelt_loop_b #1#2#3#4#5#6#7#8#9% {% \xint_gob_til_xint_relax #9\XINT_nthelt_silentend\xint_relax - \expandafter\XINT_nthelt_loop_a\expandafter{\the\numexpr #1-8\relax}% + \expandafter\XINT_nthelt_loop_a\expandafter{\the\numexpr #1-8}% }% -\def\XINT_nthelt_silentend #1\Z { }% +\def\XINT_nthelt_silentend #1\xint_bye { }% \def\XINT_nthelt_getit #1% {% \expandafter\expandafter\expandafter\XINT_nthelt_finish \csname xint_gobble_\romannumeral\numexpr#1-1\endcsname }% -\def\XINT_nthelt_finish #1#2\Z -{% - \xint_UDwfork - #1\dummy { }% - \W\dummy { #1}% - \krof -}% +\def\XINT_nthelt_finish #1#2\xint_bye + {\xint_gob_til_xint_relax #1\expandafter\space + \xint_gobble_iii\xint_relax\space #1}% \def\xintApply {\romannumeral0\xintapply }% \def\xintApplyNoExpand {\romannumeral0\xintapplynoexpand }% \def\xintapply #1#2% @@ -479,17 +473,18 @@ \expandafter\XINT_apply\expandafter {\romannumeral-`0#2}% {#1}% }% -\def\XINT_apply #1#2{\XINT_apply_loop_a {}{#2}#1\Z }% -\def\xintapplynoexpand #1#2{\XINT_apply_loop_a {}{#1}#2\Z }% +\def\XINT_apply #1#2{\XINT_apply_loop_a {}{#2}#1\xint_bye }% +\def\xintapplynoexpand #1#2{\XINT_apply_loop_a {}{#1}#2\xint_bye }% \def\XINT_apply_loop_a #1#2#3% {% - \xint_gob_til_Z #3\XINT_apply_end\Z + \xint_bye #3\XINT_apply_end\xint_bye \expandafter \XINT_apply_loop_b \expandafter {\romannumeral-`0#2{#3}}{#1}{#2}% }% \def\XINT_apply_loop_b #1#2{\XINT_apply_loop_a {#2{#1}}}% -\def\XINT_apply_end\Z\expandafter\XINT_apply_loop_b\expandafter #1#2#3{ #2}% +\def\XINT_apply_end\xint_bye\expandafter\XINT_apply_loop_b + \expandafter #1#2#3{ #2}% \def\xintApplyUnbraced {\romannumeral0\xintapplyunbraced }% \def\xintApplyUnbracedNoExpand {\romannumeral0\xintapplyunbracednoexpand }% \def\xintapplyunbraced #1#2% @@ -497,27 +492,27 @@ \expandafter\XINT_applyunbr\expandafter {\romannumeral-`0#2}% {#1}% }% -\def\XINT_applyunbr #1#2{\XINT_applyunbr_loop_a {}{#2}#1\Z }% +\def\XINT_applyunbr #1#2{\XINT_applyunbr_loop_a {}{#2}#1\xint_bye }% \def\xintapplyunbracednoexpand #1#2% - {\XINT_applyunbr_loop_a {}{#1}#2\Z }% + {\XINT_applyunbr_loop_a {}{#1}#2\xint_bye }% \def\XINT_applyunbr_loop_a #1#2#3% {% - \xint_gob_til_Z #3\XINT_applyunbr_end\Z + \xint_bye #3\XINT_applyunbr_end\xint_bye \expandafter\XINT_applyunbr_loop_b \expandafter {\romannumeral-`0#2{#3}}{#1}{#2}% }% \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\XINT_applyunbr_end\xint_bye\expandafter\XINT_applyunbr_loop_b + \expandafter #1#2#3{ #2}% \def\xintSeq {\romannumeral0\xintseq }% -\def\xintseq #1{\XINT_seq_chkopt #1\Z }% +\def\xintseq #1{\XINT_seq_chkopt #1\xint_bye }% \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% +\def\XINT_seq_noopt #1\xint_bye #2% {% \expandafter\XINT_seq\expandafter {\the\numexpr#1\expandafter}\expandafter{\the\numexpr #2}% @@ -552,7 +547,7 @@ \expandafter{\the\numexpr #1+1}{#2}{#1}% }% \def\XINT_seq_e #1#2#3{ }% -\def\XINT_seq_opt [\Z #1]#2#3% +\def\XINT_seq_opt [\xint_bye #1]#2#3% {% \expandafter\XINT_seqo\expandafter {\the\numexpr #2\expandafter}\expandafter @@ -622,28 +617,53 @@ {#1}{#2}% }% \def\XINT_seqo_nd #1#2#3#4{\XINT_seqo_nb {#1}{#2}{#3}{#4{#1}}}% -\catcode`z 3% \def\XINT_xflet #1% {% + \def\XINT_xflet_macro {#1}\XINT_xflet_get +}% +\def\XINT_xflet_get +{% \expandafter\futurelet\expandafter\XINT_token - \expandafter#1\romannumeral-`0\romannumeral-`0% + \expandafter\XINT_xflet_sp?\romannumeral-`0% +}% +\def\XINT_xflet_sp? +{% + \ifx\XINT_token\XINT_sptoken + \expandafter\XINT_xflet_get + \else\expandafter\XINT_xflet_getB + \fi +}% +\def\XINT_xflet_getB +{% + \expandafter\futurelet\expandafter\XINT_tokenB + \expandafter\XINT_xflet_spB?\romannumeral-`0% +}% +\def\XINT_xflet_spB? +{% + \ifx\XINT_tokenB\XINT_sptoken + \expandafter\XINT_xflet_getB + \else\expandafter\XINT_xflet_eq? + \fi +}% +\def\XINT_xflet_eq? +{% + \ifx\XINT_token\XINT_tokenB + \expandafter\XINT_xflet_macro + \else\expandafter\XINT_xflet_get + \fi }% +\catcode`z 3% \def\xintApplyInline #1#2% {% - \expandafter\def\expandafter\XINT_inline_macro\expandafter ##\expandafter 1% - \expandafter {#1{##1}}% - \XINT_xflet\XINT_inline_b #2z% THIS z HAS CATCODE 3 + \long\expandafter\def\expandafter\XINT_inline_macro + \expandafter ##\expandafter 1\expandafter {#1{##1}}% + \XINT_xflet\XINT_inline_b #2z% this z has catcode 3 }% -\def\XINT_inline_b {\futurelet\XINT_token\XINT_inline_c }% \def\XINT_inline_b {% - \ifx\XINT_token\XINT_sptoken - \xint_afterfi{\XINT_xflet\XINT_inline_b }% - \else - \xint_afterfi - {\ifx\XINT_token z\expandafter\xint_gobble_i - \else\expandafter\XINT_inline_d\fi }% - \fi + \ifx\XINT_token z\expandafter\xint_gobble_i + \else\expandafter\XINT_inline_d + \fi }% \def\XINT_inline_d #1% {% @@ -651,13 +671,9 @@ }% \def\XINT_inline_e {% - \ifx\XINT_token\XINT_sptoken - \xint_afterfi{\XINT_xflet\XINT_inline_e }% - \else - \xint_afterfi - {\ifx\XINT_token z\expandafter\XINT_inline_w - \else \expandafter\XINT_inline_f\fi }% - \fi + \ifx\XINT_token z\expandafter\XINT_inline_w + \else\expandafter\XINT_inline_f + \fi }% \def\XINT_inline_f {% @@ -666,188 +682,288 @@ \def\XINT_inline_g #1% {% \expandafter\XINT_inline_macro\XINT_item - \def\XINT_inline_macro ##1{#1}\XINT_inline_d + \long\def\XINT_inline_macro ##1{#1}\XINT_inline_d }% \def\XINT_inline_w #1% {% \expandafter\XINT_inline_macro\XINT_item }% +\long\def\xintBreakFor #1z{}% +\long\def\xintBreakForAndDo #1#2z{#1}% +\catcode`U 3 % with numexpr +\catcode`V 3 % with xintfrac.sty (xint.sty not enough, uses \xintIrr) +\catcode`D 3 % with dimexpr +\catcode`j 3 \def\xintFor {\futurelet\XINT_token\XINT_for_ifstar }% -\def\XINT_for_ifstar {\ifx\XINT_token*\expandafter\XINT_forx +\def\XINT_for_ifstar {\let\xintifForFirst\xint_firstoftwo + \ifx\XINT_token*\expandafter\XINT_forx \else\expandafter\XINT_for \fi }% -\def\XINT_for #1#2in#3#4#5% +\long\def\XINT_for #1#2in#3#4#5% +{% + \XINT_toks {\csname XINT_for_d\romannumeral#2\endcsname {#5}}% + \expandafter\futurelet\expandafter\XINT_token + \expandafter\XINT_for_forever? #3,z% this z has catcode 3 +}% +\long\def\XINT_forx *#1#2in#3#4#5% {% - \XINT_toks \expandafter{\csname XINT_for_d\romannumeral#2\endcsname {#5}}% - \expandafter\XINT_for_b #3,z,% THIS z HAS CATCODE 3. + \XINT_toks {\csname XINT_forx_d\romannumeral#2\endcsname {#5}}% + \XINT_xflet\XINT_forx_forever? #3jz% j and z have catcode 3 }% -\def\XINT_forx *#1#2in#3#4#5% +\def\XINT_to_forever #1\XINT_toks {\fi \XINT_forever }% +\def\XINT_for_forever? {% - \XINT_toks \expandafter{\csname XINT_forx_d\romannumeral#2\endcsname {#5}}% - \XINT_xflet\XINT_forx_b #3z% THIS z HAS CATCODE 3. + \ifx\XINT_token U\XINT_to_forever\fi + \ifx\XINT_token V\XINT_to_forever\fi + \ifx\XINT_token D\XINT_to_forever\fi + \the\XINT_toks }% -\def\XINT_for_b {\futurelet\XINT_token\XINT_for_c }% -\def\XINT_for_c +\def\XINT_to_forxever #1\XINT_forx_empty? {\fi \XINT_forever }% +\def\XINT_forx_forever? {% - \ifx\XINT_token z\expandafter\xint_gobble_iv\fi - \the\XINT_toks + \ifx\XINT_token U\XINT_to_forxever\fi + \ifx\XINT_token V\XINT_to_forxever\fi + \ifx\XINT_token D\XINT_to_forxever\fi + \XINT_forx_empty? }% -\def\XINT_for_di #1#2,% +\def\XINT_forx_empty? {% - \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 + \ifx\XINT_token j\expandafter\xint_gobble_iv\fi + \the\XINT_toks }% -\def\XINT_for_dii #1#2,% +\long\def\XINT_for_di #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 + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {#2}{####2}{####3}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_di {#1}}% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_for_diii #1#2,% +\long\def\XINT_for_dii #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 + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{#2}{####3}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_dii {#1}}% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_for_div #1#2,% +\long\def\XINT_for_diii #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 + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{####2}{#2}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_diii {#1}}% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_for_e +\long\def\XINT_for_div #1#2,% {% - \ifx\XINT_token z\xint_afterfi{\expandafter\XINT_x \xint_gobble_iv}\fi - \the\XINT_toks + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{####2}{####3}{#2}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_div {#1}}% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_forx_b +\def\XINT_for_last? {% - \ifx\XINT_token\XINT_sptoken - \xint_afterfi{\XINT_xflet\XINT_forx_b }% - \else - \xint_afterfi - {\ifx\XINT_token z\expandafter\xint_gobble_iii\fi - \the\XINT_toks }% - \fi + \ifx\XINT_token z\xint_afterfi{\let\xintifForLast\xint_firstoftwo + \expandafter\XINT_x\xint_gobble_vi}\fi + \let\xintifForLast\xint_secondoftwo\the\XINT_toks }% -\def\XINT_forx_di #1#2% +\long\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}}% - \XINT_xflet\XINT_forx_e + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {#2}{####2}{####3}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_di {#1}}% + \XINT_xflet\XINT_forx_last? }% -\def\XINT_forx_dii #1#2% +\long\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}}% - \XINT_xflet\XINT_forx_e + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{#2}{####3}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_dii {#1}}% + \XINT_xflet\XINT_forx_last? }% -\def\XINT_forx_diii #1#2% +\long\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}}% - \XINT_xflet\XINT_forx_e + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{####2}{#2}{####4}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_diii {#1}}% + \XINT_xflet\XINT_forx_last? }% -\def\XINT_forx_div #1#2% +\long\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}}% - \XINT_xflet\XINT_forx_e + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{####2}{####3}{#2}}% + \XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_div {#1}}% + \XINT_xflet\XINT_forx_last? }% -\def\XINT_forx_e +\def\XINT_forx_last? {% - \ifx\XINT_token\XINT_sptoken - \xint_afterfi{\XINT_xflet\XINT_forx_e}% - \else - \xint_afterfi - {\ifx\XINT_token z\xint_afterfi{\expandafter\XINT_x \xint_gobble_iii}\fi - \the\XINT_toks }% - \fi + \ifx\XINT_token j\xint_afterfi{\let\xintifForLast\xint_firstoftwo + \expandafter\XINT_x\xint_gobble_vii}\fi + \let\xintifForLast\xint_secondoftwo\the\XINT_toks +}% +\catcode`j 11 +\let\xintegers U% +\let\xintintegers U% +\let\xintdimensions D% +\let\xintrationals V% +\def\XINT_forever #1% +{% + \expandafter\XINT_forever_a + \csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi a\expandafter\endcsname + \csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi i\expandafter\endcsname + \csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi \endcsname }% -\def\xintForpair #1#2#3#4in#5#6#7% +\catcode`U 11 +\catcode`D 11 +\catcode`V 11 +\def\XINT_?expr_Ua #1#2% + {\expandafter{\expandafter\numexpr\the\numexpr #1\expandafter\relax + \expandafter\relax\expandafter}% + \expandafter{\the\numexpr #2}}% +\def\XINT_?expr_Da #1#2% + {\expandafter{\expandafter\dimexpr\number\dimexpr #1\expandafter\relax + \expandafter s\expandafter p\expandafter\relax\expandafter}% + \expandafter{\number\dimexpr #2}}% +\catcode`z 11 +\def\XINT_?expr_Va #1#2% +{% + \expandafter\XINT_?expr_Vb\expandafter + {\romannumeral-`0\xintrawwithzeros{#2}}% + {\romannumeral-`0\xintrawwithzeros{#1}}% +}% +\catcode`z 3 +\def\XINT_?expr_Vb #1#2{\expandafter\XINT_?expr_Vc #2.#1.}% +\def\XINT_?expr_Vc #1/#2.#3/#4.% +{% + \xintifEq {#2}{#4} + {\XINT_?expr_Vf {#3}{#1}{#2}} + {\expandafter\XINT_?expr_Vd\expandafter + {\romannumeral0\xintimul {#2}{#4}}% + {\romannumeral0\xintimul {#1}{#4}}% + {\romannumeral0\xintimul {#2}{#3}}}% +}% +\def\XINT_?expr_Vd #1#2#3{\expandafter\XINT_?expr_Ve\expandafter {#2}{#3}{#1}}% +\def\XINT_?expr_Ve #1#2{\expandafter\XINT_?expr_Vf\expandafter {#2}{#1}}% +\def\XINT_?expr_Vf #1#2#3{{#2/#3}{{0}{#1}{#2}{#3}}}% +\def\XINT_?expr_Ui {{\numexpr 1\relax}{1}}% +\def\XINT_?expr_Di {{\dimexpr 0pt\relax}{65536}}% +\def\XINT_?expr_Vi {{1/1}{0111}}% +\def\XINT_?expr_U #1#2% + {\expandafter{\expandafter\numexpr\the\numexpr #1+#2\relax\relax}{#2}}% +\def\XINT_?expr_D #1#2% + {\expandafter{\expandafter\dimexpr\the\numexpr #1+#2\relax sp\relax}{#2}}% +\def\XINT_?expr_V #1#2{\XINT_?expr_Vx #2}% +\def\XINT_?expr_Vx #1#2% +{% + \expandafter\XINT_?expr_Vy\expandafter + {\romannumeral0\xintiadd {#1}{#2}}{#2}% +}% +\def\XINT_?expr_Vy #1#2#3#4% +{% + \expandafter{\romannumeral0\xintiadd {#3}{#1}/#4}{{#1}{#2}{#3}{#4}}% +}% +\def\XINT_forever_a #1#2#3#4% +{% + \ifx #4[\expandafter\XINT_forever_opt_a + \else\expandafter\XINT_forever_b + \fi #1#2#3% +}% +\def\XINT_forever_b #1#2#3#4z{\expandafter\XINT_forever_c\the\XINT_toks #2#3}% +\long\def\XINT_forever_c #1\romannumeral #2#3#4#5#6% +{% + \csname XINT_forever_d\romannumeral#2\expandafter\endcsname #5#6{#4}z% +}% +\def\XINT_forever_opt_a #1#2#3#4+#5]#6z% +{% + \expandafter\expandafter\expandafter + \XINT_forever_opt_c\expandafter\the\expandafter\XINT_toks + \romannumeral-`0#1{#4}{#5}#3% +}% +\long\def\XINT_forever_opt_c #1\romannumeral #2#3#4#5#6#7% +{% + \csname XINT_forever_d\romannumeral#2\endcsname {#5}{#6}#7{#4}z% +}% +\long\def\XINT_forever_di #1#2#3#4% +{% + \long\def\XINT_y ##1##2##3##4{#4}% + \XINT_y {#1}{##2}{##3}{##4}% + \let\xintifForFirst\xint_secondoftwo + \expandafter\XINT_forever_di\romannumeral-`0#3{#1}{#2}#3{#4}% +}% +\long\def\XINT_forever_dii #1#2#3#4% {% - \XINT_toks \expandafter{% - \csname XINT_forii_d\romannumeral#2\endcsname {#7}}% - \expandafter\XINT_forii_b #5,z,% THIS z HAS CATCODE 3 + \long\def\XINT_y ##1##2##3##4{#4}% + \XINT_y {##1}{#1}{##3}{##4}% + \let\xintifForFirst\xint_secondoftwo + \expandafter\XINT_forever_dii\romannumeral-`0#3{#1}{#2}#3{#4}% }% -\def\XINT_forii_b {\futurelet\XINT_token\XINT_forii_c }% -\def\XINT_forii_c +\long\def\XINT_forever_diii #1#2#3#4% {% - \ifx\XINT_token z\expandafter\xint_gobble_iv\fi - \the\XINT_toks + \long\def\XINT_y ##1##2##3##4{#4}% + \XINT_y {##1}{##2}{#1}{##4}% + \let\xintifForFirst\xint_secondoftwo + \expandafter\XINT_forever_diii\romannumeral-`0#3{#1}{#2}#3{#4}% }% -\def\XINT_forii_di #1(#2,#3),% +\long\def\XINT_forever_div #1#2#3#4% {% - \def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_y ##1##2##3##4{#4}% + \XINT_y {##1}{##2}{##3}{#1}% + \let\xintifForFirst\xint_secondoftwo + \expandafter\XINT_forever_div\romannumeral-`0#3{#1}{#2}#3{#4}% +}% +\long\def\xintForpair #1#2#3#4in#5#6#7% +{% + \XINT_toks \expandafter{\csname XINT_forii_d\romannumeral#2\endcsname {#7}}% + \expandafter\the\expandafter\XINT_toks #5,z% THIS z HAS CATCODE 3 +}% +\long\def\XINT_forii_di #1(#2,#3),% +{% + \long\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 + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_forii_dii #1(#2,#3),% +\long\def\XINT_forii_dii #1(#2,#3),% {% - \def\XINT_y ##1##2##3##4{#1}% + \long\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 + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_forii_diii #1(#2,#3),% +\long\def\XINT_forii_diii #1(#2,#3),% {% - \def\XINT_y ##1##2##3##4{#1}% - \def\XINT_x {\XINT_y {####1}{####2}{#2}{#3}}% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\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,% + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_foriii_b {\futurelet\XINT_token\XINT_foriii_c }% -\def\XINT_foriii_c +\long\def\xintForthree #1#2#3in#4#5#6% {% - \ifx\XINT_token z\expandafter\xint_gobble_iv\fi - \the\XINT_toks + \XINT_toks \expandafter{\csname XINT_foriii_d\romannumeral#2\endcsname {#6}}% + \expandafter\the\expandafter\XINT_toks #4,z% }% -\def\XINT_foriii_di #1(#2,#3,#4),% +\long\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}}% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {#2}{#3}{#4}{####4}}% \XINT_toks {\XINT_x\XINT_foriii_di {#1}}% - \futurelet\XINT_token\XINT_for_e + \futurelet\XINT_token\XINT_for_last? }% -\def\XINT_foriii_dii #1(#2,#3,#4),% +\long\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}}% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {####1}{#2}{#3}{#4}}% \XINT_toks {\XINT_x \XINT_foriii_dii {#1}}% - \futurelet\XINT_token\XINT_for_e + \futurelet\XINT_token\XINT_for_last? }% -\def\xintForfour #1#2#3in#4#5#6% +\long\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 + \expandafter\the\expandafter\XINT_toks #4,z% }% -\def\XINT_foriv_di #1(#2,#3,#4,#5),% +\long\def\XINT_foriv_di #1(#2,#3,#4,#5),% {% - \def\XINT_y ##1##2##3##4{#1}% - \def\XINT_x {\XINT_y {#2}{#3}{#4}{#5}}% + \long\def\XINT_y ##1##2##3##4{#1}% + \long\def\XINT_x {\XINT_y {#2}{#3}{#4}{#5}}% \XINT_toks {\XINT_x\XINT_foriv_di {#1}}% - \futurelet\XINT_token\XINT_for_e + \futurelet\XINT_token\XINT_for_last? }% \catcode`z 11 \def\xintAssign #1\to @@ -909,7 +1025,7 @@ \def\XINT_assignarray_loop #1% {% \def\xint_temp {#1}% - \ifx\xint_braced_xint_relax\xint_temp + \ifx\xint_brelax\xint_temp \expandafter\edef\csname\xint_arrayname 0\endcsname{\the\count 255 }% \expandafter\expandafter\expandafter\XINT_assignarray_end_a \else @@ -1049,8 +1165,8 @@ \expandafter\xint_cleanupzeros_andstop \romannumeral0\XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_cuz #1% @@ -1193,6 +1309,16 @@ \fi }% \let\xintifTrue\xintifNotZero +\let\xintifTrueFalse\xintifNotZero +\def\xintifCmp {\romannumeral0\xintifcmp }% +\def\xintifcmp #1#2% +{% + \ifcase \xintCmp {#1}{#2} + \xint_afterfi{\expandafter\space\xint_secondofthree}% + \or\xint_afterfi{\expandafter\space\xint_thirdofthree}% + \else\xint_afterfi{\expandafter\space\xint_firstofthree}% + \fi +}% \def\xintifEq {\romannumeral0\xintifeq }% \def\xintifeq #1#2% {% @@ -1217,6 +1343,15 @@ {\expandafter\space\xint_secondoftwo}% {\expandafter\space\xint_secondoftwo}% }% +\def\xintifOdd {\romannumeral0\xintifodd }% +\def\xintifodd #1% +{% + \if\xintOdd{#1}1% + \xint_afterfi{\expandafter\space\xint_firstoftwo}% + \else + \xint_afterfi{\expandafter\space\xint_secondoftwo}% + \fi +}% \def\xintiiOpp {\romannumeral0\xintiiopp }% \def\xintiiopp #1% {% @@ -1272,7 +1407,7 @@ }% \def\XINT_add_ABE #1#2#3#4#5#6% {% - \expandafter\XINT_add_ABEA\the\numexpr #1+10#5#4#3#2+#6\relax.% + \expandafter\XINT_add_ABEA\the\numexpr #1+10#5#4#3#2+#6.% }% \def\XINT_add_ABEA #1#2#3.#4% {% @@ -1280,7 +1415,7 @@ }% \def\xint_add_bz\W\XINT_add_ABE #1#2#3#4#5#6% {% - \expandafter\XINT_add_CC\the\numexpr #1+10#5#4#3#2\relax.% + \expandafter\XINT_add_CC\the\numexpr #1+10#5#4#3#2.% }% \def\XINT_add_CC #1#2#3.#4% {% @@ -1297,8 +1432,8 @@ \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -1309,7 +1444,7 @@ }% \def\XINT_add_CD #1% {% - \expandafter\XINT_add_CC\the\numexpr 1+10#1\relax.% + \expandafter\XINT_add_CC\the\numexpr 1+10#1.% }% \def\xint_add_cz\W\XINT_add_CD #1#2{ 1#2}% \def\XINT_addr_A #1#2#3#4#5#6% @@ -1372,7 +1507,7 @@ }% \def\XINT_addm_ABE #1#2#3#4#5#6% {% - \expandafter\XINT_addm_ABEA\the\numexpr #1+10#5#4#3#2+#6\relax.% + \expandafter\XINT_addm_ABEA\the\numexpr #1+10#5#4#3#2+#6.% }% \def\XINT_addm_ABEA #1#2#3.#4% {% @@ -1389,8 +1524,8 @@ \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -1405,7 +1540,7 @@ }% \def\XINT_addm_CD #1% {% - \expandafter\XINT_addm_CC\the\numexpr 1+10#1\relax.% + \expandafter\XINT_addm_CC\the\numexpr 1+10#1.% }% \def\XINT_addm_CC #1#2#3.#4% {% @@ -1417,7 +1552,7 @@ #3\xint_addm_cz \W\XINT_addm_CD {% - \expandafter\XINT_addm_CDw\the\numexpr 1+#1#2#3\relax.% + \expandafter\XINT_addm_CDw\the\numexpr 1+#1#2#3.% }% \def\XINT_addm_CDw #1.#2#3\X\Y\Z {% @@ -1428,7 +1563,7 @@ #2\xint_addm_cz \W\XINT_addm_CD {% - \expandafter\XINT_addm_CDx\the\numexpr 1+#1#2\relax.% + \expandafter\XINT_addm_CDx\the\numexpr 1+#1#2.% }% \def\XINT_addm_CDx #1.#2#3\Y\Z {% @@ -1438,7 +1573,7 @@ #1\xint_addm_cz \W\XINT_addm_CD {% - \expandafter\XINT_addm_CDy\the\numexpr 1+#1\relax.% + \expandafter\XINT_addm_CDy\the\numexpr 1+#1.% }% \def\XINT_addm_CDy #1.#2#3\Z {% @@ -1727,7 +1862,7 @@ }% \def\XINT_sub_onestep #1#2#3#4#5#6% {% - \expandafter\XINT_sub_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i\relax.% + \expandafter\XINT_sub_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i.% }% \def\XINT_sub_backtoA #1#2#3.#4% {% @@ -1749,8 +1884,8 @@ \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -1762,7 +1897,7 @@ }% \def\XINT_sub_AC_onestep #1% {% - \expandafter\XINT_sub_backtoC\the\numexpr 11#1-\xint_c_i\relax.% + \expandafter\XINT_sub_backtoC\the\numexpr 11#1-\xint_c_i.% }% \def\XINT_sub_backtoC #1#2#3.#4% {% @@ -1779,8 +1914,8 @@ \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1\W\W\W\W\W\W\W\Z }% @@ -1801,8 +1936,8 @@ \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \W\X\Y\Z #1% }% @@ -1813,7 +1948,7 @@ }% \def\XINT_sub_Eonestep #1#2% {% - \expandafter\XINT_sub_backtoE\the\numexpr 109999-#2+#1\relax.% + \expandafter\XINT_sub_backtoE\the\numexpr 109999-#2+#1.% }% \def\XINT_sub_backtoE #1#2#3.#4% {% @@ -1836,7 +1971,7 @@ }% \def\XINT_sub_Fdec_onestep #1#2% {% - \expandafter\XINT_sub_backtoFdec\the\numexpr 11#2+#1-\xint_c_i\relax.% + \expandafter\XINT_sub_backtoFdec\the\numexpr 11#2+#1-\xint_c_i.% }% \def\XINT_sub_backtoFdec #1#2#3.#4% {% @@ -1853,7 +1988,7 @@ }% \def\XINT_sub_Finc_onestep #1#2% {% - \expandafter\XINT_sub_backtoFinc\the\numexpr 10#2+#1\relax.% + \expandafter\XINT_sub_backtoFinc\the\numexpr 10#2+#1.% }% \def\XINT_sub_backtoFinc #1#2#3.#4% {% @@ -1882,8 +2017,8 @@ \romannumeral0% \XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_sub_KK #1#2#3#4#5#6% @@ -1893,7 +2028,7 @@ }% \def\XINT_sub_KK_onestep #1#2% {% - \expandafter\XINT_sub_backtoKK\the\numexpr 109999-#2+#1\relax.% + \expandafter\XINT_sub_backtoKK\the\numexpr 109999-#2+#1.% }% \def\XINT_sub_backtoKK #1#2#3.#4% {% @@ -1967,7 +2102,7 @@ }% \def\XINT_cmp_onestep #1#2#3#4#5#6% {% - \expandafter\XINT_cmp_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i\relax.% + \expandafter\XINT_cmp_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i.% }% \def\XINT_cmp_backtoA #1#2#3.#4% {% @@ -2157,7 +2292,7 @@ }% \def\XINT_geq_onestep #1#2#3#4#5#6% {% - \expandafter\XINT_geq_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i\relax.% + \expandafter\XINT_geq_backtoA\the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i.% }% \def\XINT_geq_backtoA #1#2#3.#4% {% @@ -2478,7 +2613,7 @@ \def\XINT_mul_Br #1#2#3#4\W\X\Y\Z #5#6#7#8% {% \expandafter\XINT_mul_ABEAr - \the\numexpr #1+10#2+#8#7#6#5\relax.{#3}#4\W\X\Y\Z + \the\numexpr #1+10#2+#8#7#6#5.{#3}#4\W\X\Y\Z }% \def\XINT_mul_ABEAr #1#2#3#4#5#6.#7% {% @@ -2920,8 +3055,8 @@ \fi {#1}{#2}\XINT_pow_posprod \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_pow_BtooBig #1\xint_relax #2\xint_relax @@ -3418,7 +3553,7 @@ \def\XINT_div_sub_onestep #1#2#3#4#5#6% {% \expandafter\XINT_div_sub_backtoA - \the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i\relax.% + \the\numexpr 11#5#4#3#2-#6+#1-\xint_c_i.% }% \def\XINT_div_sub_backtoA #1#2#3.#4% {% @@ -3438,8 +3573,8 @@ \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -3450,7 +3585,7 @@ }% \def\XINT_div_sub_AC_onestep #1% {% - \expandafter\XINT_div_sub_backtoC\the\numexpr 11#1-\xint_c_i\relax.% + \expandafter\XINT_div_sub_backtoC\the\numexpr 11#1-\xint_c_i.% }% \def\XINT_div_sub_backtoC #1#2#3.#4% {% @@ -3466,8 +3601,8 @@ \romannumeral0% \XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -4036,8 +4171,8 @@ \expandafter\XINT_dec_cleanup \romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax #1% }% @@ -4095,8 +4230,8 @@ 0-\dummy {\XINT_sqrt #1}% \krof }% -\def\XINT_sqrt_iszero #1\Z { 0}% -\def\XINT_sqrt_isneg #1\Z {\xintError:RootOfNegative\space 0}% +\def\XINT_sqrt_iszero #1\Z { 1.}% 1.09e was wrong from inception in 1.08 :-(( +\def\XINT_sqrt_isneg #1\Z {\xintError:RootOfNegative\space 1.}% \def\XINT_sqrt #1\Z {% \expandafter\XINT_sqrt_start\expandafter diff --git a/Master/texmf-dist/tex/generic/xint/xintbinhex.sty b/Master/texmf-dist/tex/generic/xint/xintbinhex.sty index 5b2695c4103..caadf6f105e 100644 --- a/Master/texmf-dist/tex/generic/xint/xintbinhex.sty +++ b/Master/texmf-dist/tex/generic/xint/xintbinhex.sty @@ -22,7 +22,7 @@ %% in the same archive or directory.) %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %% xintbinhex: Expandable binary and hexadecimal conversions %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -105,7 +105,7 @@ \XINTsetupcatcodes% \XINT_providespackage \ProvidesPackage{xintbinhex}% - [2013/10/22 v1.09d Expandable binary and hexadecimal conversions (jfB)]% + [2013/10/29 v1.09e Expandable binary and hexadecimal conversions (jfB)]% \chardef\xint_c_xvi 16 \chardef\xint_c_ii^v 32 \chardef\xint_c_ii^vi 64 @@ -390,8 +390,8 @@ \expandafter\xint_cleanupzeros_andstop \romannumeral0\XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_htd_II_ci #1\XINT_htd_II_ciii @@ -478,8 +478,8 @@ \expandafter\XINT_btd_II_c_end \romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\XINT_btd_II_c_end #1#2#3#4#5#6% diff --git a/Master/texmf-dist/tex/generic/xint/xintcfrac.sty b/Master/texmf-dist/tex/generic/xint/xintcfrac.sty index b8b934b9294..7019c7af6b3 100644 --- a/Master/texmf-dist/tex/generic/xint/xintcfrac.sty +++ b/Master/texmf-dist/tex/generic/xint/xintcfrac.sty @@ -22,7 +22,7 @@ %% in the same archive or directory.) %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %% xintcfrac: Expandable continued fractions with xint package %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -105,7 +105,7 @@ \XINTsetupcatcodes% \XINT_providespackage \ProvidesPackage{xintcfrac}% - [2013/10/22 v1.09d Expandable continued fractions with xint package (jfB)]% + [2013/10/29 v1.09e Expandable continued fractions with xint package (jfB)]% \def\xintCFrac {\romannumeral0\xintcfrac }% \def\xintcfrac #1% {% diff --git a/Master/texmf-dist/tex/generic/xint/xintexpr.sty b/Master/texmf-dist/tex/generic/xint/xintexpr.sty index ccc877a888d..2abe4875295 100644 --- a/Master/texmf-dist/tex/generic/xint/xintexpr.sty +++ b/Master/texmf-dist/tex/generic/xint/xintexpr.sty @@ -22,7 +22,7 @@ %% in the same archive or directory.) %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %% xintexpr: Expandable expression parser %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -105,7 +105,7 @@ \XINTsetupcatcodes% \XINT_providespackage \ProvidesPackage{xintexpr}% - [2013/10/22 v1.09d Expandable expression parser (jfB)]% + [2013/10/29 v1.09e Expandable expression parser (jfB)]% \def\xint_gob_til_dot #1.{}% \def\xint_gob_til_dot_andstop #1.{ }% \def\xint_gob_til_! #1!{}% nota bene: ! is of catcode 11 diff --git a/Master/texmf-dist/tex/generic/xint/xintfrac.sty b/Master/texmf-dist/tex/generic/xint/xintfrac.sty index b4ab5fbe664..36ea3fd20c6 100644 --- a/Master/texmf-dist/tex/generic/xint/xintfrac.sty +++ b/Master/texmf-dist/tex/generic/xint/xintfrac.sty @@ -22,7 +22,7 @@ %% in the same archive or directory.) %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %% xintfrac: Expandable operations on fractions %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -105,7 +105,7 @@ \XINTsetupcatcodes% \XINT_providespackage \ProvidesPackage{xintfrac}% - [2013/10/22 v1.09d Expandable operations on fractions (jfB)]% + [2013/10/29 v1.09e Expandable operations on fractions (jfB)]% \chardef\xint_c_vi 6 \chardef\xint_c_vii 7 \chardef\xint_c_xviii 18 @@ -306,8 +306,8 @@ \expandafter\XINT_cuz_cnt_loop\expandafter {\expandafter}\romannumeral0\XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \R\R\R\R\R\R\R\R\Z }% @@ -390,8 +390,8 @@ \expandafter\space\expandafter {\romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }{#1}% }% \def\xintRaw {\romannumeral0\xintraw }% @@ -706,6 +706,16 @@ \xintError:NotAnInteger \fi\space #1% }% +\def\xintifInt {\romannumeral0\xintifint }% +\def\xintifint #1{\expandafter\XINT_ifint\romannumeral0\xintirr {#1}\Z }% +\def\XINT_ifint #1/#2\Z +{% + \if\XINT_isOne {#2}1% + \xint_afterfi{\expandafter\space\xint_firstoftwo}% + \else + \xint_afterfi{\expandafter\space\xint_secondoftwo}% + \fi +}% \def\xintJrr {\romannumeral0\xintjrr }% \def\xintjrr #1% {% @@ -897,8 +907,8 @@ \expandafter\XINT_round_C \romannumeral0\XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \Z }% @@ -919,8 +929,8 @@ {% \XINT_rord_main {}#1% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \Z }% \def\XINT_round_Dba #1% @@ -1095,8 +1105,8 @@ \romannumeral0\expandafter\XINT_float_Wa \romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \Z }% \def\XINT_float_Vb #1#2\Z #3% @@ -1198,8 +1208,8 @@ \expandafter#1% \romannumeral0\XINT_rord_main {}#2% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax \Z }% \def\XINT_infloat_Vb #1#2\Z @@ -1745,43 +1755,6 @@ \romannumeral0\xintdivision }% \def\xintrem {\expandafter\xint_secondoftwo_andstop \romannumeral0\xintdivision }% -\def\xintFDg {\romannumeral0\xintfdg }% -\def\xintfdg #1% -{% - \expandafter\XINT_fdg\romannumeral0\xintnum {#1}\W\Z -}% -\def\xintLDg {\romannumeral0\xintldg }% -\def\xintldg #1% -{% - \expandafter\XINT_ldg\expandafter{\romannumeral0\xintnum {#1}}% -}% -\def\xintMON {\romannumeral0\xintmon }% -\def\xintmon #1% -{% - \ifodd\xintLDg {#1} - \xint_afterfi{ -1}% - \else - \xint_afterfi{ 1}% - \fi -}% -\def\xintMMON {\romannumeral0\xintmmon }% -\def\xintmmon #1% -{% - \ifodd\xintLDg {#1} - \xint_afterfi{ 1}% - \else - \xint_afterfi{ -1}% - \fi -}% -\def\xintOdd {\romannumeral0\xintodd }% -\def\xintodd #1% -{% - \ifodd\xintLDg{#1} - \xint_afterfi{ 1}% - \else - \xint_afterfi{ 0}% - \fi -}% \def\xintFloatAdd {\romannumeral0\xintfloatadd }% \def\xintfloatadd #1{\XINT_fladd_chkopt \xintfloat #1\Z }% \def\XINTinFloatAdd {\romannumeral0\XINTinfloatadd }% @@ -2013,8 +1986,8 @@ {% \XINT_flpow_loop {#1}{#2}{#3}{{#1}}\XINT_flpow_prd \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax {#4}% }% \def\XINT_flpow_loop #1#2#3% @@ -2153,8 +2126,8 @@ {% \XINT_flpower_loop {#1}{#2}{#3}{{#1}}\XINT_flpow_prd \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax {#4}% }% \def\XINT_flpower_loop #1#2#3% diff --git a/Master/texmf-dist/tex/generic/xint/xintgcd.sty b/Master/texmf-dist/tex/generic/xint/xintgcd.sty index 87f1880991d..1660cda8541 100644 --- a/Master/texmf-dist/tex/generic/xint/xintgcd.sty +++ b/Master/texmf-dist/tex/generic/xint/xintgcd.sty @@ -22,7 +22,7 @@ %% in the same archive or directory.) %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %% xintgcd: Euclidean algorithm with xint package %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -105,7 +105,7 @@ \XINTsetupcatcodes% \XINT_providespackage \ProvidesPackage{xintgcd}% - [2013/10/22 v1.09d Euclide algorithm with xint package (jfB)]% + [2013/10/29 v1.09e Euclide algorithm with xint package (jfB)]% \def\xintGCD {\romannumeral0\xintgcd }% \def\xintgcd #1% {% @@ -372,8 +372,8 @@ \romannumeral0% \XINT_rord_main {}#4{{#1}{#3}}% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\xint_euc_end_ #1#2#3% @@ -431,8 +431,8 @@ \romannumeral0% \XINT_rord_main {}#8{{#1}{#3}}% \xint_relax - \xint_undef\xint_undef\xint_undef\xint_undef - \xint_undef\xint_undef\xint_undef\xint_undef + \xint_bye\xint_bye\xint_bye\xint_bye + \xint_bye\xint_bye\xint_bye\xint_bye \xint_relax }% \def\xint_bezalg_end_ #1#2#3#4% diff --git a/Master/texmf-dist/tex/generic/xint/xintseries.sty b/Master/texmf-dist/tex/generic/xint/xintseries.sty index 2e2deaa7ec9..dec1e89498c 100644 --- a/Master/texmf-dist/tex/generic/xint/xintseries.sty +++ b/Master/texmf-dist/tex/generic/xint/xintseries.sty @@ -22,7 +22,7 @@ %% in the same archive or directory.) %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09d of October 22, 2013) +%% The xint bundle (version 1.09e of October 29, 2013) %% xintseries: Expandable partial sums with xint package %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -105,7 +105,7 @@ \XINTsetupcatcodes% \XINT_providespackage \ProvidesPackage{xintseries}% - [2013/10/22 v1.09d Expandable partial sums with xint package (jfB)]% + [2013/10/29 v1.09e Expandable partial sums with xint package (jfB)]% \def\xintSeries {\romannumeral0\xintseries }% \def\xintseries #1#2% {% |