typo-scr.mkxl /size: 8722 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=typo-scr,
3%D        version=2012.01.23, % very old ... 1995.10.10 .. moved from core-mis
4%D          title=\CONTEXT\ Typesetting Macros,
5%D       subtitle=Scripts,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Typesetting Macros / Scripts}
15
16\unprotect
17
18%D I addition to the commands implemented here, we have alternative commands
19%D \type {shiftup} and \type {shiftdown} that can work across paragraphs.
20
21%D \macros
22%D   {low, high, definelow, definehigh, setuplow, setuphigh}
23%D
24%D Although \TEX\ is pretty well aware of super- and subscripts, its mechanism
25%D is mainly tuned for math mode. The next few commands take care of script
26%D texts both modes.
27%D
28%D \startbuffer
29%D The higher\high{one goes} the lower\low{one drops}, or\lohi{yes}{no}?
30%D \stopbuffer
31%D
32%D \typebuffer
33%D \getbuffer
34%D
35%D Note the different placement of \type {\lohi}, where we need a bit more
36%D space. The implementation looks a bit fuzzy, since some \type {\fontdimen}'s
37%D are involved to determine the optimal placement.
38
39\installcorenamespace {low}
40\installcorenamespace {high}
41
42\installcommandhandler \??low  {low}  \??low
43\installcommandhandler \??high {high} \??high
44
45\setuplow [\c!style=\tx,\c!distance=\zeropoint,\c!down=.48\exheight] % historical
46\setuphigh[\c!style=\tx,\c!distance=\zeropoint,\c!up  =.86\exheight] % values
47
48\appendtoks \frozen\protected\edefcsname\currentlow \endcsname{\typo_scripts_low [\currentlow ]}\to \everydefinelow
49\appendtoks \frozen\protected\edefcsname\currenthigh\endcsname{\typo_scripts_high[\currenthigh]}\to \everydefinehigh
50
51\def\typo_scripts_distance#1%
52  {\edef\p_distance{#1\c!distance}%
53   \ifx\p_distance\v!tight
54     \tightfitboundary
55   \else
56     \kern\p_distance\relax
57   \fi}
58
59%D \startbuffer
60%D \setuplow [distance=\zeropoint]
61%D \setuphigh[distance=\zeropoint]
62%D
63%D {\showglyphs f\high{x}\quad p\high{x}\quad}
64%D
65%D \setuplow [\c!distance=\v!tight]
66%D \setuphigh[\c!distance=\v!tight]
67%D
68%D {\showglyphs f\high{x}\quad p\high{x}\quad}
69%D \stopbuffer
70%D
71%D \typebuffer {\getbuffer}
72
73% \type{f\kern\tightfitcompensation\high{x}}
74% \type{f\tightfitboundary         \high{x}}
75
76\protected\def\typo_scripts_low[#1]#2%
77  {\dontleavehmode
78   \begingroup
79   \cdef\currentlow{#1}%
80   \typo_scripts_distance\lowparameter
81   \setbox\scratchbox\runninghbox\bgroup
82     \lower\lowparameter\c!down\hbox\bgroup
83       \ifempty\fontsize
84         \ifmmode
85           \mr % no color yet
86         \else
87           \uselowstyleandcolor\c!style\c!color
88         \fi
89       \else
90         \uselowstyleandcolor\c!style\c!color
91       \fi
92       \dostarttagged\t!sub\currentlow
93       #2%
94       \dostoptagged
95     \egroup
96   \egroup
97   \ht\scratchbox\strutht
98   \dp\scratchbox\strutdp
99   \box\scratchbox
100   \endgroup}
101
102\protected\def\typo_scripts_high[#1]#2%
103  {\dontleavehmode
104   \begingroup
105   \cdef\currenthigh{#1}%
106   \typo_scripts_distance\highparameter
107   \setbox\scratchbox\runninghbox\bgroup
108     \raise\highparameter\c!up\hbox\bgroup
109       \ifempty\fontsize
110         \ifmmode
111           \mr % no color yet
112         \else
113           \usehighstyleandcolor\c!style\c!color
114         \fi
115       \else
116         \usehighstyleandcolor\c!style\c!color
117       \fi
118       \dostarttagged\t!sup\currenthigh
119       #2%
120       \dostoptagged
121     \egroup
122   \egroup
123   \ht\scratchbox\strutht
124   \dp\scratchbox\strutdp
125   \box\scratchbox
126   \endgroup}
127
128\permanent\protected\def\low {\typo_scripts_low []}
129\permanent\protected\def\high{\typo_scripts_high[]}
130
131%D \macros
132%D   {lohi, hilo, definelohi, setuplohi}
133%D
134%D You can provide an optional keyword \type {left}, in which case the super and
135%D subscripts will be aligned in a way that permits placement at the left of a word
136%D (which means that it will be right aligned).
137%D
138%D \startbuffer
139%D \lohi {aha} {ah} test \lohi {aha} {ah} test
140%D \lohi [left] {aha} {ah} test \lohi [left] {aha} {ah} test
141%D \lohi {aha} {ah} test \lohi {aha} {ah} test
142%D \lohi [left] {aha} {ah}test \lohi [left] {aha} {ah} test
143%D \stopbuffer
144%D
145%D \typebuffer
146%D \getbuffer
147
148\installcorenamespace {lowhigh}
149
150\installcommandhandler \??lowhigh {lowhigh} \??lowhigh
151
152\setuplowhigh
153  [\c!style=\tx,
154   \c!distance=.1\exheight,  % these are
155   \c!up=.96\exheight,       % historical
156   \c!down=.58\exheight]     % values
157
158\appendtoks
159    \frozen\edefcsname\currentlowhigh\endcsname{\typo_scripts_lowhigh[\currentlowhigh]}%
160\to \everydefinelowhigh
161
162\tolerant\protected\def\typo_scripts_lowhigh[#1]#*[#2]#:#3#4% todo: align .. [#1] is compatible hack
163  {\dontleavehmode
164   \runninghbox\bgroup
165   \cdef\currentlowhigh{#1}%
166   \typo_scripts_distance\lowhighparameter
167   \dostarttagged\t!subsup\currentlowhigh
168   \setbox\plusfour\hpack{\typo_scripts_lowhigh_low_high\lower\c!down\t!sub{#3}}%
169   \setbox\plussix \hpack{\typo_scripts_lowhigh_low_high\raise\c!up  \t!sup{#4}}%
170   \edef\p_align{#2}%
171   \ifx\p_align\v!left
172     \ifdim\wd\plusfour<\wd\plussix
173       \setbox\plusfour\hpack to \wd\plussix {\hss\box\plusfour}%
174     \else
175       \setbox\plussix \hpack to \wd\plusfour{\hss\box\plussix }%
176     \fi
177   \fi
178   \ifdim\wd\plusfour<\wd\plussix
179     \wd\plusfour\zeropoint
180     \box\plusfour
181     \box\plussix
182   \else
183     \wd\plussix\zeropoint
184     \box\plussix
185     \box\plusfour
186   \fi
187   \dostoptagged
188   \egroup}
189
190\def\typo_scripts_lowhigh_low_high#1#2#3#4%
191  {\setbox\scratchbox\hpack\bgroup
192     #1\lowhighparameter#2\hbox\bgroup
193       \ifempty\fontsize
194         \ifmmode
195           \mr % no color yet
196         \else
197           \uselowhighstyleandcolor\c!style\c!color
198         \fi
199       \else
200         \uselowhighstyleandcolor\c!style\c!color
201       \fi
202       \dostarttagged#3\empty
203       #4%
204       \dostoptagged
205     \egroup
206   \egroup
207   \ht\scratchbox\strutht
208   \dp\scratchbox\strutdp
209   \box\scratchbox}
210
211\permanent\tolerant\protected\def\typo_scripts_highlow[#1]#*[#2]#:#3#4%
212  {\typo_scripts_lowhigh[#1][#2]{#4}{#3}}
213
214\permanent\protected\def\lohi{\typo_scripts_lowhigh[]}
215\permanent\protected\def\hilo{\typo_scripts_highlow[]}
216
217%D \macros
218%D   {lowmidhigh, definelowmidhigh, setuplowmidhigh}
219%D
220%D The previous command originally didn't have definers. These were introduced when
221%D the next showed up:
222%D
223%D \startbuffer
224%D \definelow       [MyLow]   [style=\txx]
225%D \definehigh      [MyHigh]  [style=\txx]
226%D \definelowhigh   [MyLoHi]  [style=\txx]
227%D \definelowmidhigh[MyLoMiHi][style=\txx]
228%D
229%D We have
230%D     \ruledhbox{\low         {L}} and \ruledhbox{\MyLow         {L}} and
231%D     \ruledhbox{\high        {H}} and \ruledhbox{\MyHigh        {H}} and
232%D     \ruledhbox{\lohi     {L}{H}} and \ruledhbox{\MyLoHi     {L}{H}} and
233%D     \ruledhbox{\lomihi{L}{M}{H}} and \ruledhbox{\MyLoMiHi{L}{M}{H}}.
234%D \stopbuffer
235%D
236%D \typebuffer \getbuffer
237
238\installcorenamespace {lowmidhigh}
239
240\installcommandhandler \??lowmidhigh {lowmidhigh} \??lowmidhigh
241
242\setuplowmidhigh
243  [\c!style=\tx,
244   \c!up=.8\struthtdp,
245   \c!down=.8\struthtdp]
246
247\appendtoks
248    \frozen\edefcsname\currentlowmidhigh\endcsname{\typo_scripts_lowmidhigh[\currentlowmidhigh]}%
249\to \everydefinelowmidhigh
250
251\protected\def\typo_scripts_lowmidhigh[#1]#2#3#4%
252  {\dontleavehmode
253   \runninghbox\bgroup
254     \cdef\currentlowmidhigh{#1}%
255     \dostarttagged\t!subsup\currentlowmidhigh
256     \uselowmidhighstyleandcolor\c!style\c!color
257     \setstrut
258     \setbox\plustwo \hbox{\strut\dostarttagged\t!sub\empty#2\dostoptagged}%
259     \setbox\plusfour\hbox{\strut\dostarttagged\t!mid\empty#3\dostoptagged}% inefficient
260     \setbox\plussix \hbox{\strut\dostarttagged\t!sup\empty#4\dostoptagged}%
261     \scratchdimen \wd
262        \ifdim\wd\plustwo>\wd\plusfour
263          \ifdim\wd\plustwo>\wd\plussix
264             \plustwo
265          \else
266             \plussix
267          \fi
268        \else
269          \ifdim\wd\plusfour>\wd\plussix
270             \plusfour
271          \else
272             \plussix
273          \fi
274        \fi
275     \relax
276     \setbox\plustwo \hpack to \scratchdimen{\hss\lower\lowmidhighparameter\c!down\box\plustwo \hss}%
277     \setbox\plusfour\hpack to \scratchdimen{\hss                                 \box\plusfour\hss}%
278     \setbox\plussix \hpack to \scratchdimen{\hss\raise\lowmidhighparameter\c!up  \box\plussix \hss}%
279     \wd\plustwo \zeropoint
280     \wd\plusfour\zeropoint
281     \box\plusfour
282     \box\plustwo
283     \box\plussix
284     \dostoptagged
285   \egroup}
286
287\permanent\protected\def\lomihi      {\typo_scripts_lowmidhigh[]}
288\permanent\protected\def\himilo#1#2#3{\typo_scripts_lowmidhigh[]{#3}{#2}{#1}}
289
290\protect \endinput
291