| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Module: ZzTeX Horizontal Mode Facilities |
| 4 |
% |
| 5 |
% Synopsis: This module provides various facilities that operate in |
| 6 |
% horizontal mode, within a paragraph. See also ZZHMODE. |
| 7 |
% |
| 8 |
% Author: Paul C. Anagnostopoulos |
| 9 |
% Created: 11 January 1994 |
| 10 |
% |
| 11 |
% Copyright 1989--2020 by Paul C. Anagnostopoulos |
| 12 |
% under The MIT License (opensource.org/licenses/MIT) |
| 13 |
% |
| 14 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 15 |
|
| 16 |
% Basic Tools |
| 17 |
% ----- ----- |
| 18 |
|
| 19 |
|
| 20 |
\def \llap #1{\hbox to 0pt{\hss #1}}% {text} |
| 21 |
\def \rlap #1{\hbox to 0pt{#1\hss}}% {text} |
| 22 |
\def \clap #1{\hbox to 0pt{\hss #1\hss}}% {text} |
| 23 |
|
| 24 |
\def \minhbox to #1#2#3#4{% to width{text}{space-in}{space-out} |
| 25 |
\measuretextwidth{\tdimena}{#2\hspace{#3}}% |
| 26 |
\if \dimgtrp{\tdimena}{#1}% |
| 27 |
{#2}\hspace{#4}% |
| 28 |
\else |
| 29 |
\hbox to #1{#2\hfil}% |
| 30 |
\fi} |
| 31 |
|
| 32 |
% Drop Capitals |
| 33 |
% ---- -------- |
| 34 |
|
| 35 |
|
| 36 |
\def \dropcapital #1#2#3{% {height}{lines}{text} |
| 37 |
\setbox \zboxa = \hbox{#3}% |
| 38 |
\tdimena = \ht\zboxa |
| 39 |
\advance \tdimena by -#1\relax |
| 40 |
\setbox \zboxa = \hbox{\lower \tdimena \box\zboxa}% |
| 41 |
\dp\zboxa = 0pt |
| 42 |
\def \zdropshape {0pt,\naturalwidth}% |
| 43 |
\tcounta = #2\relax |
| 44 |
\loop |
| 45 |
\decrement \tcounta |
| 46 |
\if \posp{\tcounta}% |
| 47 |
\edef \zdropshape {\zdropshape ,\the\wd\zboxa,\naturalwidth}% |
| 48 |
\repeat |
| 49 |
\expandafter\shapepar\expandafter{\zdropshape,0pt,\naturalwidth}% |
| 50 |
\noindent \box\zboxa} |
| 51 |
|
| 52 |
% Enclosing Text |
| 53 |
% --------- ---- |
| 54 |
|
| 55 |
|
| 56 |
\def \enclose #1#2#3{% {thickness}{separation}{text} |
| 57 |
\ensurepar |
| 58 |
\hbox{\vrule width #1% |
| 59 |
\vtop{\vbox{\hrule height #1% |
| 60 |
\kern #2% |
| 61 |
\hbox{\kern #2#3\kern #2}}% |
| 62 |
\kern #2% |
| 63 |
\hrule height #1}% |
| 64 |
\vrule width #1}} |
| 65 |
|
| 66 |
\def \colorenclose #1#2#3#4{% {color}{thickness}{separation}{text} |
| 67 |
\ensurepar |
| 68 |
\hbox{\color{#1}\vrule width #2 \endcolor |
| 69 |
\vtop{\vbox{\color{#1}\hrule height #2 \endcolor |
| 70 |
\kern #3% |
| 71 |
\hbox{\kern #3#4\kern #3}}% |
| 72 |
\kern #3% |
| 73 |
\color{#1}\hrule height #2 \endcolor}% |
| 74 |
\color{#1}\vrule width #2 \endcolor}} |
| 75 |
|
| 76 |
% Fractions |
| 77 |
% --------- |
| 78 |
|
| 79 |
|
| 80 |
% This macro is specifically designed to work in math mode, too. |
| 81 |
|
| 82 |
\def \piecefraction #1{% |
| 83 |
\ztfrac #1/} |
| 84 |
|
| 85 |
\def \ztfrac #1/#2/{% |
| 86 |
\ensurepar |
| 87 |
{\measuretextwidth{\tdimena}{/}% |
| 88 |
\raise .5ex \hbox{$\scriptstyle #1$}% |
| 89 |
\kern -.2\tdimena \raise .3ex \hbox{$\scriptstyle /$}\kern -.2\tdimena% |
| 90 |
\hbox{$\scriptstyle #2$}}} |
| 91 |
|
| 92 |
\let \textfraction = \piecefraction % For compatibility. |
| 93 |
|
| 94 |
% Leaders |
| 95 |
% ------- |
| 96 |
|
| 97 |
|
| 98 |
\def \alignedleaders #1{% {box-or-rule} |
| 99 |
\leaders #1\hfill} |
| 100 |
|
| 101 |
\def \dotleaders {% |
| 102 |
\alignedleaders{\hbox to 1em{\hss.\hss}}} |
| 103 |
|
| 104 |
\def \ruleleaders #1{% {rule} |
| 105 |
\alignedleaders{#1}} |
| 106 |
|
| 107 |
\def \centeredleaders #1{% {box-or-rule} |
| 108 |
\cleaders #1\hfill} |
| 109 |
|
| 110 |
\def \spreadleaders #1{% {box-or-rule} |
| 111 |
\xleaders #1\hfill} |
| 112 |
|
| 113 |
% Paragraph Dingbats |
| 114 |
% --------- -------- |
| 115 |
|
| 116 |
|
| 117 |
\def \pardingbat #1#2{% {space}{dingbat} |
| 118 |
{\unskip \unbreakable\hfil \allowbreak |
| 119 |
\hspace{#1}\retain\unbreakable\hfill |
| 120 |
#2% |
| 121 |
\finalhyphendemerits = 0 \par}} |
| 122 |
|
| 123 |
% Rules |
| 124 |
% ----- |
| 125 |
|
| 126 |
|
| 127 |
\def \rule #1{% {dimensions} |
| 128 |
\if \vmodep |
| 129 |
\hrule #1\relax |
| 130 |
\else |
| 131 |
\vrule #1\relax |
| 132 |
\fi} |
| 133 |
|
| 134 |
\def \colorrule #1#2{% {color}{dimensions} |
| 135 |
\if \vmodep |
| 136 |
\color{#1} |
| 137 |
\nobreak |
| 138 |
\hrule #2\relax |
| 139 |
\endcolor |
| 140 |
\else |
| 141 |
\color{#1}\vrule #2\relax\endcolor |
| 142 |
\fi} |
| 143 |
|
| 144 |
\def \slug #1#2{% {width}{height} |
| 145 |
\rule{height #2 depth 0pt width #1}} |
| 146 |
|
| 147 |
% Shapes |
| 148 |
% ------ |
| 149 |
|
| 150 |
|
| 151 |
\def \rectangle #1#2#3#4{% {rise}{width}{height}{thickness} |
| 152 |
{\tdimena = #2\relax |
| 153 |
\advance \tdimena by -#4\relax |
| 154 |
\advance \tdimena by -#4\relax |
| 155 |
\raise #1 \hbox{% |
| 156 |
\vrule height #3 depth 0pt width #4\relax |
| 157 |
\vbox to #3{% |
| 158 |
\hrule height #4 depth 0pt width \tdimena\relax |
| 159 |
\vfil |
| 160 |
\hrule height #4 depth 0pt width \tdimena\relax}% |
| 161 |
\vrule height #3 depth 0pt width #4}}} |
| 162 |
|
| 163 |
% Underlining & Overstriking |
| 164 |
% ----------- - ------------ |
| 165 |
|
| 166 |
|
| 167 |
\def \fakebold #1{% {text} |
| 168 |
\hbox{\rlap{#1}% |
| 169 |
\rlap{\lower .009em \hbox{\kern .009em #1}}% |
| 170 |
\lower .018em \hbox{\kern .018em #1}}} |
| 171 |
|
| 172 |
\def \multiunderline #1#2#3#4#5{% {count}{drop1}{drop2}{thickness}{text} |
| 173 |
\ensurepar |
| 174 |
{\setbox\zboxa = \hbox{#5}% |
| 175 |
\rlap{\lower #2 \hbox{\vrule height #4 depth 0pt width \the\wd\zboxa}}% |
| 176 |
\tcounta = #1\relax |
| 177 |
\tdimena = #2\relax |
| 178 |
\loop |
| 179 |
\decrement \tcounta |
| 180 |
\if \posp{\tcounta}% |
| 181 |
\advance \tdimena by #3\relax |
| 182 |
\rlap{\lower \tdimena \hbox{\vrule height #4 depth 0pt |
| 183 |
width \the\wd\zboxa}}% |
| 184 |
\repeat |
| 185 |
\box\zboxa}} |
| 186 |
|
| 187 |
\def \overstrike #1#2{% {text1}{text2} |
| 188 |
\ensurepar |
| 189 |
{\setbox\zboxa = \hbox{#1}% |
| 190 |
\setbox\zboxb = \hbox{#2}% |
| 191 |
\tdimena = \wd\zboxa |
| 192 |
\advance \tdimena by -\wd\zboxb |
| 193 |
\divide \tdimena by 2 |
| 194 |
\rlap{\kern \tdimena \box\zboxb}\box\zboxa}} |
| 195 |
|
| 196 |
\def \strikethrough #1{% {text} |
| 197 |
\ensurepar |
| 198 |
{\setbox\zboxa = \hbox{#1}% |
| 199 |
\rlap{\raise .45ex \hbox{\vrule height .1ex depth 0pt |
| 200 |
width \the\wd\zboxa}}% |
| 201 |
\box\zboxa}} |
| 202 |
|
| 203 |
\let \zunline = \underline |
| 204 |
|
| 205 |
\def \underline #1{% {text} |
| 206 |
\relax |
| 207 |
\if \mathmodep |
| 208 |
\zunline{#1}% |
| 209 |
\else |
| 210 |
\multiunderline{1}{.4ex}{0pt}{.1ex}{#1}% |
| 211 |
\fi} |
| 212 |
|
| 213 |
% Vertical Centering |
| 214 |
% -------- --------- |
| 215 |
|
| 216 |
|
| 217 |
\def \centeroncapheight #1{% {text} |
| 218 |
\ensurepar |
| 219 |
{\setbox\zboxa = \hbox{#1}% |
| 220 |
\measurecapheight{\tdimena}% % Calculate ht(CAP) - ht(text) |
| 221 |
\advance \tdimena by -\ht\zboxa % ------------------ |
| 222 |
\divide \tdimena by 2 % 2 |
| 223 |
\raise \tdimena \box\zboxa}} |
| 224 |
|
| 225 |
\def \centerondigitheight #1{% {text} |
| 226 |
\ensurepar |
| 227 |
{\setbox\zboxa = \hbox{#1}% |
| 228 |
\measuredigitheight{\tdimena}% % Calculate ht(123) - ht(text) |
| 229 |
\advance \tdimena by -\ht\zboxa % ------------------ |
| 230 |
\divide \tdimena by 2 % 2 |
| 231 |
\raise \tdimena \box\zboxa}} |
| 232 |
|
| 233 |
\def \centeronxheight #1{% {text} |
| 234 |
\ensurepar |
| 235 |
{\setbox\zboxa = \hbox{#1}% |
| 236 |
\tdimena = 1ex % Calculate 1ex - ht(text) |
| 237 |
\advance \tdimena by -\ht\zboxa % -------------- |
| 238 |
\divide \tdimena by 2 % 2 |
| 239 |
\raise \tdimena \box\zboxa}} |