summaryrefslogtreecommitdiff
path: root/macros/plain/contrib
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-05-10 03:00:55 +0000
committerNorbert Preining <norbert@preining.info>2024-05-10 03:00:55 +0000
commit889ef8595dafee235cb1106ec4efbdd3169481c2 (patch)
tree45863693da937beb703aee0e4407cc51cfc9956b /macros/plain/contrib
parent1feed955eca29818ea536dba591c12b7b3b55003 (diff)
CTAN sync 202405100300
Diffstat (limited to 'macros/plain/contrib')
-rw-r--r--macros/plain/contrib/ifis-macros/README21
-rw-r--r--macros/plain/contrib/ifis-macros/ifis-macros-doc.pdfbin0 -> 22463 bytes
-rw-r--r--macros/plain/contrib/ifis-macros/ifis-macros-doc.tex138
-rw-r--r--macros/plain/contrib/ifis-macros/ifisdimension.tex93
-rw-r--r--macros/plain/contrib/ifis-macros/ifisinteger.tex44
5 files changed, 296 insertions, 0 deletions
diff --git a/macros/plain/contrib/ifis-macros/README b/macros/plain/contrib/ifis-macros/README
new file mode 100644
index 0000000000..69dd99e9fb
--- /dev/null
+++ b/macros/plain/contrib/ifis-macros/README
@@ -0,0 +1,21 @@
+
+
+This package contains two files with macros. The first contains a
+macro to test an input string if it represents a valid number for
+TeX. The second checks if an input string is a valid dimension for
+TeX.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 3 of the License.
+
+The package consists of the following files:
+
+ifisinteger.tex -- 1st macro file
+ifisdimension.tex -- 2nd macro file
+ifis-macros-doc.pdf -- instructions
+ifis-macros-doc.tex -- the source of ifis-macros-doc.pdf
+README -- this file
+
+Copyright (C) 2024 Udo Wermuth (author)
+ u dot wermuth (at) icloud dot com
diff --git a/macros/plain/contrib/ifis-macros/ifis-macros-doc.pdf b/macros/plain/contrib/ifis-macros/ifis-macros-doc.pdf
new file mode 100644
index 0000000000..e79469e555
--- /dev/null
+++ b/macros/plain/contrib/ifis-macros/ifis-macros-doc.pdf
Binary files differ
diff --git a/macros/plain/contrib/ifis-macros/ifis-macros-doc.tex b/macros/plain/contrib/ifis-macros/ifis-macros-doc.tex
new file mode 100644
index 0000000000..a5b3c21942
--- /dev/null
+++ b/macros/plain/contrib/ifis-macros/ifis-macros-doc.tex
@@ -0,0 +1,138 @@
+% This file is part of the CTAN package named isIntDim.
+%
+% info.tex: instructions for two macro packages: ifisinteger.tex
+% and ifisdimension.tex
+%
+% Copyright (C) 2024 Udo Wermuth (author)
+%
+% This program is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% This program is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+% %%%
+% %%% verbatim macros (from manmac.tex)
+% %%%
+\newskip\ttglue {\tt\global\ttglue=0.5em plus 0.25em minus 0.15em }
+\def\ttverbatim{\begingroup \frenchspacing
+ \catcode`\\=12 \catcode`\{=12 \catcode`\}=12 \catcode`\$=12 \catcode`\&=12
+ \catcode`\#=12 \catcode`\%=12 \catcode`\~=12 \catcode`\_=12 \catcode`\^=12
+ \obeyspaces \obeylines \tt}
+\def\verbatimspace{\ifvmode\indent\fi\space}
+{\obeyspaces \gdef\makespaceverbspace{\def {\verbatimspace}}}
+\outer\def\verbatim{$$\ifdim\parskip>0pt
+ \abovedisplayskip=\parskip \abovedisplayshortskip=\parskip
+ \belowdisplayskip=\parskip \belowdisplayshortskip=\parskip
+ \else
+ \abovedisplayskip=3pt \abovedisplayshortskip=3pt
+ \belowdisplayskip=3pt \belowdisplayshortskip=3pt
+ \fi
+ \let\par=\endgraf \ttverbatim \makespaceverbspace \parskip=0pt
+ \catcode`\§=0 \advance\leftskip by 10pt \ttfinish}
+{\catcode`\§=0 §catcode`§\=12 % § is temporary escape character
+ §obeylines % end of line is active
+ §gdef§ttfinish#1^^M#2\endverbatim{§vbox{#2}§endgroup$$}}
+\catcode`\|=\active
+{\obeylines \gdef|{\ttverbatim \spaceskip\ttglue \let^^M=\ \let|=\endgroup}}
+
+\def\noitem{\item{\phantom{0.}}}
+
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\font\titlefont=cmssdc10 at 36pt
+\font\subtitlefont=cmssdc10 at 17pt
+%
+\centerline{\titlefont ifis-macros}
+\bigskip
+\centerline{\subtitlefont Version 1.0, 7.04.2024}
+\bigskip
+\centerline{Macros for plain \TeX}
+\medskip
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\noindent
+There are two main macros in the files {\tt ifisinteger.tex} and {\tt
+ifisdimension.tex}. The macro |\ifisint| tests if a given input string
+represents a number for \TeX. The macro |\ifisdim| does this for
+dimensions.
+
+Both macros generate errors but hide them from the terminal as they
+work in |\batchmode|. There is one configuration parameter:
+|\IIcurrentmode|. The default is |\errorstopmode|. Change this if you
+call the macros in a different interaction mode so that they can
+return to this mode.
+
+\bigskip
+
+\beginsection 0.\ Installation
+
+To use the macro |\ifisint| load via |\input ifisinteger.tex| the file
+that contains the code. For |\ifisdim| use |\input ifisdimension.tex|.
+
+\bigskip
+
+\beginsection 1.\ File {\tt ifisinteger.tex}
+
+The main macro is called |\ifisint| and must be used like an
+|\if|-conditional except that its argument is delimited by |\Boolend|:
+|\ifisint <argument>\Boolend <true branch>\else <false branch>\fi|.
+
+\medskip
+
+The implemented algorithm has four steps:
+\smallskip
+\item{1.}1)~Remove signs with or without braces; add sentinel |W|.
+\noitem 2)~Test that the input isn't now |"W|, etc.; otherwise
+ return false.
+\item{2.}Create a canonical form with a leading zero.
+\item{3.}1)~Assign the input to a |\count| register inside an
+ |\hbox|.
+\noitem 2)~Test that the box width is the width of the sentinel.
+\noitem 3)~Otherwise return false.
+\item{4.}1)~Return true if the number isn't \TeX's maximum.
+\noitem 2)~Otherwise test if the canonical form is \TeX's maximum.
+ If yes, return true.
+\noitem 3)~Otherwise return false.
+\medskip
+
+For more details see my article in TUGboat {\bf45}:1 (2024), 106--109.
+
+\bigskip
+
+\beginsection 2.\ File {\tt ifisdimension.tex}
+
+The main macro is called |\ifisdim| and must be used like an
+|\if|-conditional except that its argument is delimited by |\Boolend|:
+|\ifisdim <argument>\Boolend <true branch>\else <false branch>\fi|.
+
+\medskip
+
+The implemented algorithm has four steps:
+\smallskip
+\item{1.}1)~Remove signs with or without braces; add sentinel |mm|.
+\noitem 2)~Exclude trivial non-numerics as done in |\ifisint|.
+\noitem 3)~Otherwise return false.
+\item{2.}1)~Get the integer part.
+\noitem 2)~Get fraction and the unit.
+\noitem 3)~Get the width of the unit.
+\item{3.}1)~Assign the input to a |\dimen| register inside an
+ |\hbox|.
+\noitem 2)~Test that the box width is the width of the sentinel.
+\noitem 3)~Otherwise return false.
+\item{4.}1)~Return true if the dimension isn't \TeX's |\maxdimen|.
+\noitem 2)~Otherwise test if the coerced sum of the integer part
+ and the fraction expressed in the unit |sp| is |\maxdimen|.
+\noitem 3)~If no, return false.
+\noitem 4)~Otherwise return true.
+\medskip
+
+For more details see my article in TUGboat {\bf45}:1 (2024), 109--112.
+
+\bye
diff --git a/macros/plain/contrib/ifis-macros/ifisdimension.tex b/macros/plain/contrib/ifis-macros/ifisdimension.tex
new file mode 100644
index 0000000000..35ba85b134
--- /dev/null
+++ b/macros/plain/contrib/ifis-macros/ifisdimension.tex
@@ -0,0 +1,93 @@
+\catcode`\@=11
+\newif\ifII@itis %% reused from \ifisint %%
+\def\II@rmsign #1{\ifx#1+\else\ifx#1-\else %%
+ \II@endrm#1\fi\fi\II@rmsign}% remove signs: %%
+\def\II@endrm #1\fi\fi#2{\fi\fi#1}% `+' & `-' %%
+\let\Boolend=\iffalse \font\II@font=cmr10 % %%
+\let\IIcurrentmode=\errorstopmode % CONFIGURE %%
+\def\II@W{W}\def\II@octW{'W}\def\II@hexW{"W}% %%
+%% declarations
+\newdimen\II@frac
+\countdef\II@cnt=255 \dimendef\II@dim=255
+%% helper macros; some use \ifisint's sentinel W
+\def\II@bad #1#2#3#4#5#6\II@end{% numeric part
+ \def\II@id{#1W}% is missing but maybe with unit
+ \edef\II@X{#6}\ifx\II@X\empty
+ \edef\II@X{#5}\ifx\II@X\empty\else\II@Bad\fi
+ \else \edef\II@X{\II@mklc#2#3#4W}%
+ \ifx\II@X\II@rueW
+ \else\ifx\II@X\II@truW\II@Bad
+ \else \II@itistrue
+ \fi\fi\fi}
+\def\II@rueW{rueW}\def\II@truW{truW}
+\def\II@Bad{\ifx\II@id\II@W
+ \else\ifx\II@id\II@octW
+ \else\ifx\II@id\II@hexW
+ \else \II@itistrue
+ \fi\fi\fi}
+\def\II@mklc #1{\if#1pp\else\if#1Pp\else
+ \if#1tt\else\if#1Tt\else
+ \if#1bb\else\if#1Bb\else
+ \if#1ss\else\if#1Ss\else
+ \if#1rr\else\if#1Rr\else
+ \if#1uu\else\if#1Uu\else
+ \if#1ee\else\if#1Ee\else
+ \II@endlc#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
+ \fi\fi\fi \II@mklc}% `W' and `m' stop \II@mklc
+\def\II@endlc #1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
+ \fi\fi\fi\fi#2{\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
+ \fi\fi\fi\fi#1}
+\def\II@getfrac #1mm\II@end{\global\II@frac=0#1}
+\def\II@getcalc{%\II@calc=coerced\II@int\II@frac
+ \ifdim\II@unit=26.11119pt % \II@unit is ``pt''
+ \II@dim=\ifnum\II@int<16384
+ \II@int\else 0\fi pt
+ \else\ifdim\II@unit=27.77786pt % it is ``bp''
+ \II@dim=\ifnum\II@int<16323
+ \II@int\else 0\fi bp
+ \else\ifdim\II@unit=26.16673pt % it is ``sp''
+ \II@dim=\ifnum\II@int<1073741824
+ \II@int\else 0\fi sp
+ \else \II@dim=0pt \fi\fi\fi
+ \II@cnt=\II@dim \advance\II@cnt by \II@frac
+ \edef\II@calc{\number\II@cnt}}
+\def\II@point #1#2\II@end{% assign digits of the
+ \afterassignment\II@mklc % fraction to \II@cnt
+ \ifx#1.\II@cnt=0#2%
+ \else\ifx#1,\II@cnt=0#2%
+ \else \II@cnt=0#1#2%
+ \fi\fi}
+\def\II@getunit #1{\afterassignment\II@hdlfrac
+ \II@cnt=#1\relax}
+\def\II@rmtrue{\ifdim\wd0>40pt \the\II@dim
+ \else \the\wd0 \fi}
+%% main macro
+\def\ifisdim #1\Boolend{\II@itisfalse % S1.3
+ \edef\II@dist{\II@rmsign#1mm}% S1.1
+ \edef\II@dist{\expandafter\II@rmsign\II@dist}%
+ \expandafter\II@bad
+ \II@dist\empty\empty\empty\empty\II@end % S1.2
+ \ifII@itis % S4.1, S4.4
+ \wlog{=== start ignore}\batchmode\begingroup
+ \setbox0=\hbox{\II@font
+ \afterassignment\II@getfrac
+ \II@cnt=\II@dist\II@end % S2.2
+ \xdef\II@int{\the\II@cnt}}% S2.1
+ \setbox0=\hbox{\II@font
+ \afterassignment\II@point
+ \II@cnt=\II@dist\II@end}\II@dim=\wd0
+ \advance\II@dim by -17.80559pt % width `true'
+ \xdef\II@unit{\II@rmtrue}% S2.3
+ \setbox0=\hbox{\II@font\II@dim=#1mm% S3.1
+ \xdef\II@val{\ifdim\II@dim<0pt-\fi
+ \the\II@dim}}%
+ \xdef\II@wd{\the\wd0}%
+ \endgroup\IIcurrentmode\wlog{=== stop ignore}%
+ \ifdim\II@wd=16.66672pt % width ``mm'' S3.2
+ \ifdim\II@val=\maxdimen \II@getcalc
+ \ifnum\II@calc=1073741823 % S4.2
+ \else \II@itisfalse % S4.3
+ \fi\fi
+ \else \II@itisfalse % S3.3
+ \fi\fi \ifII@itis}
+\catcode`\@=12
diff --git a/macros/plain/contrib/ifis-macros/ifisinteger.tex b/macros/plain/contrib/ifis-macros/ifisinteger.tex
new file mode 100644
index 0000000000..5249c2fa6c
--- /dev/null
+++ b/macros/plain/contrib/ifis-macros/ifisinteger.tex
@@ -0,0 +1,44 @@
+\catcode`\@=11 % use the private prefix ``II@''
+\newif\ifII@itis % main result of the macro
+%% helper macros
+\def\II@rmsign #1{\ifx#1+\else\ifx#1-\else
+ \II@endrm#1\fi\fi\II@rmsign}
+\def\II@endrm #1\fi\fi#2{\fi\fi#1}
+\def\II@zeros #1{\ifx#1''\else\ifx#1""\else
+ \II@cont#1\fi\fi\II@zeros}
+\def\II@cont #1\fi\fi#2{\fi\fi\II@hdlzero#1}
+\def\II@hdlzero #1{\ifx#10 \else
+ \II@xchgfi #1\fi\II@hdlzero}
+\def\II@xchgfi #1\fi#2{\fi\ifx#1`\else0\fi#1}
+%% constants with the sentinel `W'
+\def\II@cfd{02147483647W}% canonical forms with
+\def\II@cfh{"07FFFFFFFW}% W of TeX's max integer
+\def\II@cfo{'017777777777W}% in dec, hex, oct
+\def\II@W{W}\def\II@hexW{"W}% all unsigned input
+\def\II@octW{'W}% with W for which TeX inserts 0
+%% assignments
+\let\Boolend=\iffalse \font\II@font=cmr10
+\let\IIcurrentmode=\errorstopmode % CONFIGURE
+%% main macro
+\def\ifisint #1\Boolend{\II@itisfalse % see S1.2
+ \edef\II@digs{\II@rmsign#1W}% S1.1 with 2 \edef
+ \edef\II@digs{\expandafter\II@rmsign\II@digs}%
+ \ifx\II@digs\II@W\else\ifx\II@digs\II@octW
+ \else\ifx\II@digs\II@hexW\else % S1.2 finished
+ \edef\II@cf{\expandafter\II@zeros\II@digs}% S2
+ \wlog{=== start ignore}\batchmode\begingroup
+ \setbox0=\hbox{\count255=\II@cf
+ \xdef\II@val{\the\count255}}%
+ \setbox0=\hbox{\II@font\count255=#1W}% S3.1
+ \xdef\II@wd{\the\wd0}%
+ \endgroup\IIcurrentmode\wlog{=== stop ignore}%
+ \ifdim\II@wd=10.2778pt % \wd of hbox `W'; S3.2
+ \II@itistrue \ifnum\II@val=2147483647 % S4.1
+ \ifx\II@cf\II@cfd
+ \else\ifx\II@cf\II@cfh
+ \else\ifx\II@cf\II@cfo % S4.2
+ \else \II@itisfalse % S4.3
+ \fi\fi\fi\fi
+ \else \II@itisfalse % S3.3
+ \fi\fi\fi\fi \ifII@itis}
+\catcode`\@=12