Debian Codegraph @

texmf-dist/tex/plain/ifis-macros/ifisglue.tex

raw
1 % This file is part of the CTAN package named ifis-macros.
2 %
3 % ifisdimension.tex: provide macro \ifisdim to check if a given
4 % input is a valid dimension for \TeX.
5 % Usage: \ifisdim <argument>\Boolend <true branch>\else <false branch>\fi
6 %
7 % Copyright (C) 2025 Udo Wermuth (author)
8 %
9 % This program is free software: you can redistribute it and/or modify
10 % it under the terms of the GNU General Public License as published by
11 % the Free Software Foundation, either version 3 of the License, or
12 % (at your option) any later version.
13 %
14 % This program is distributed in the hope that it will be useful,
15 % but WITHOUT ANY WARRANTY; without even the implied warranty of
16 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 % GNU General Public License for more details.
18 %
19 % You should have received a copy of the GNU General Public License
20 % along with this program. If not, see <http://www.gnu.org/licenses/>.
21 %
22 \input ifisdimension.tex % reuse \ifisdim
23 \catcode`\@=11
24 \newif\ifIImuglue % true: input might be muglue
25 \newif\ifII@sofar % true: glue/muglue OK so far
26 %% helper macros
27 \def\II@kwlc #1{% `plus/minus/fil' to letters
28 \if#1fF\else\if#1FF\else % keep hex. digit `F'
29 \if#1pp\else\if#1Pp\else % otherwise lowercase
30 \if#1ll\else\if#1Ll\else
31 \if#1uu\else\if#1Uu\else
32 \if#1ss\else\if#1Ss\else
33 \if#1mm\else\if#1Mm\else
34 \if#1ii\else\if#1Ii\else
35 \if#1nn\else\if#1Nn\else\if#1W \II@endkwlc
36 \else #1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
37 \fi\fi\fi\fi\II@kwlc}% the `W' stops with a ` '
38 \def\II@endkwlc #1\II@kwlc{\fi\fi\fi\fi\fi\fi\fi
39 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
40 % split the glue into its components
41 \def\II@kwminus #1minus#2 #3\II@end{% get shrink
42 \def\II@X{#3}\ifx\II@X\empty \def\II@skipx{#1}%
43 \else \def\II@skipx{#1 }\fi \def\II@sh{#2 }}
44 \def\II@kwplus #1plus#2 #3\II@end{% get stretch
45 \def\II@st{#2 }\ifx\II@st\space \def\II@nw{#1}%
46 \else \def\II@nw{#1 }\fi}
47 % replace `Fil', `Fill', `Filll', `mu' by `pt'
48 \def\II@uchg{\advance\II@cnt by 1 }%S3.4's count
49 \def\II@fil #1Fi#2 #3\II@end#4#5{% get order of
50 % #4's value, extracted from `#1fi#2 #3', in #5
51 % and replace a <fil dimen> in #4 with unit pt
52 \def#5{#2}\ifx#5\II@l \def#4{#1pt }\II@uchg
53 \else\ifx#5\II@ll \def#4{#1pt }\II@uchg
54 \else\ifx#5\II@lll \def#4{#1pt }\II@uchg
55 \else\def#5{}\fi\fi\fi}
56 \def\II@l{l}\def\II@ll{ll}\def\II@lll{lll}
57 \def\II@mu #1mu#2\II@end#3{% change mu to pt for
58 \def\II@X{#2}% #3, extracted from `#1mu#2'
59 \ifx\II@X\empty\else \def#3{#1pt }\II@uchg\fi}
60 %% main macro
61 \def\ifisglue #1\Boolend{\II@sofarfalse\II@cnt=0
62 \edef\II@skip{\II@kwlc #1W}% S1
63 \edef\II@skip{\expandafter\II@kwlc\II@skip W}%
64 \expandafter\II@kwminus\II@skip minus \II@end
65 \expandafter\II@kwplus\II@skipx plus \II@end%S2
66 \expandafter\II@mu\II@nw mu\II@end\II@nw % S3.1
67 \def\II@sto{}\ifx\II@st\space \II@uchg % S3.2
68 \else \expandafter\II@mu\II@st mu\II@end\II@st
69 \ifx\II@X\empty \expandafter
70 \II@fil\II@st Fi \II@end\II@st\II@sto \fi\fi
71 \def\II@sho{}\ifx\II@sh\space \II@uchg % S3.3
72 \else \expandafter\II@mu\II@sh mu\II@end\II@sh
73 \ifx\II@X\empty \expandafter
74 \II@fil\II@sh Fi \II@end\II@sh\II@sho \fi\fi
75 \ifnum\II@cnt=3 \IImugluetrue % S3.4
76 \else \IImugluefalse \fi
77 \expandafter\ifisdim \II@nw\Boolend % S4.1
78 \II@sofartrue \fi
79 \ifII@sofar \ifx\II@st\space % S4.2
80 \else\expandafter\ifisdim \II@st\Boolend
81 \else \II@sofarfalse \fi\fi\fi
82 \ifII@sofar \ifx\II@sh\space % S4.3
83 \else\expandafter\ifisdim \II@sh\Boolend
84 \else \II@sofarfalse \fi\fi\fi
85 \ifII@sofar % S4.4
86 % use a different pattern for the macro's wlog
87 \wlog{=*= start ignore}\batchmode\begingroup
88 \setbox0=\hbox{\II@font \ifIImuglue \muskip255
89 \else \skip255 \fi=#1}\xdef\II@wd{\the\wd0}%
90 \endgroup\IIcurrentmode\wlog{=*= stop ignore}%
91 \ifdim\II@wd=0pt \else \II@sofarfalse % S4.5
92 \fi\fi \ifII@sofar}
93 \catcode`\@=12