typo-scr.mkxl /size: 8838 b    last modification: 2025-02-21 11:03
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\setuplow [\c!distance=\v!tight] % tested for a while in cont-exp
132\setuphigh[\c!distance=\v!tight] % idem
133
134%D \macros
135%D   {lohi, hilo, definelohi, setuplohi}
136%D
137%D You can provide an optional keyword \type {left}, in which case the super and
138%D subscripts will be aligned in a way that permits placement at the left of a word
139%D (which means that it will be right aligned).
140%D
141%D \startbuffer
142%D \lohi {aha} {ah} test \lohi {aha} {ah} test
143%D \lohi [left] {aha} {ah} test \lohi [left] {aha} {ah} test
144%D \lohi {aha} {ah} test \lohi {aha} {ah} test
145%D \lohi [left] {aha} {ah}test \lohi [left] {aha} {ah} test
146%D \stopbuffer
147%D
148%D \typebuffer
149%D \getbuffer
150
151\installcorenamespace {lowhigh}
152
153\installcommandhandler \??lowhigh {lowhigh} \??lowhigh
154
155\setuplowhigh
156  [\c!style=\tx,
157   \c!distance=.1\exheight,  % these are
158   \c!up=.96\exheight,       % historical
159   \c!down=.58\exheight]     % values
160
161\appendtoks
162    \frozen\edefcsname\currentlowhigh\endcsname{\typo_scripts_lowhigh[\currentlowhigh]}%
163\to \everydefinelowhigh
164
165\tolerant\protected\def\typo_scripts_lowhigh[#1]#*[#2]#:#3#4% todo: align .. [#1] is compatible hack
166  {\dontleavehmode
167   \runninghbox\bgroup
168   \cdef\currentlowhigh{#1}%
169   \typo_scripts_distance\lowhighparameter
170   \dostarttagged\t!subsup\currentlowhigh
171   \setbox\plusfour\hpack{\typo_scripts_lowhigh_low_high\lower\c!down\t!sub{#3}}%
172   \setbox\plussix \hpack{\typo_scripts_lowhigh_low_high\raise\c!up  \t!sup{#4}}%
173   \edef\p_align{#2}%
174   \ifx\p_align\v!left
175     \ifdim\wd\plusfour<\wd\plussix
176       \setbox\plusfour\hpack to \wd\plussix {\hss\box\plusfour}%
177     \else
178       \setbox\plussix \hpack to \wd\plusfour{\hss\box\plussix }%
179     \fi
180   \fi
181   \ifdim\wd\plusfour<\wd\plussix
182     \wd\plusfour\zeropoint
183     \box\plusfour
184     \box\plussix
185   \else
186     \wd\plussix\zeropoint
187     \box\plussix
188     \box\plusfour
189   \fi
190   \dostoptagged
191   \egroup}
192
193\def\typo_scripts_lowhigh_low_high#1#2#3#4%
194  {\setbox\scratchbox\hpack\bgroup
195     #1\lowhighparameter#2\hbox\bgroup
196       \ifempty\fontsize
197         \ifmmode
198           \mr % no color yet
199         \else
200           \uselowhighstyleandcolor\c!style\c!color
201         \fi
202       \else
203         \uselowhighstyleandcolor\c!style\c!color
204       \fi
205       \dostarttaggednodetail#3%
206       #4%
207       \dostoptagged
208     \egroup
209   \egroup
210   \ht\scratchbox\strutht
211   \dp\scratchbox\strutdp
212   \box\scratchbox}
213
214\permanent\tolerant\protected\def\typo_scripts_highlow[#1]#*[#2]#:#3#4%
215  {\typo_scripts_lowhigh[#1][#2]{#4}{#3}}
216
217\permanent\protected\def\lohi{\typo_scripts_lowhigh[]}
218\permanent\protected\def\hilo{\typo_scripts_highlow[]}
219
220%D \macros
221%D   {lowmidhigh, definelowmidhigh, setuplowmidhigh}
222%D
223%D The previous command originally didn't have definers. These were introduced when
224%D the next showed up:
225%D
226%D \startbuffer
227%D \definelow       [MyLow]   [style=\txx]
228%D \definehigh      [MyHigh]  [style=\txx]
229%D \definelowhigh   [MyLoHi]  [style=\txx]
230%D \definelowmidhigh[MyLoMiHi][style=\txx]
231%D
232%D We have
233%D     \ruledhbox{\low         {L}} and \ruledhbox{\MyLow         {L}} and
234%D     \ruledhbox{\high        {H}} and \ruledhbox{\MyHigh        {H}} and
235%D     \ruledhbox{\lohi     {L}{H}} and \ruledhbox{\MyLoHi     {L}{H}} and
236%D     \ruledhbox{\lomihi{L}{M}{H}} and \ruledhbox{\MyLoMiHi{L}{M}{H}}.
237%D \stopbuffer
238%D
239%D \typebuffer \getbuffer
240
241\installcorenamespace {lowmidhigh}
242
243\installcommandhandler \??lowmidhigh {lowmidhigh} \??lowmidhigh
244
245\setuplowmidhigh
246  [\c!style=\tx,
247   \c!up=.8\struthtdp,
248   \c!down=.8\struthtdp]
249
250\appendtoks
251    \frozen\edefcsname\currentlowmidhigh\endcsname{\typo_scripts_lowmidhigh[\currentlowmidhigh]}%
252\to \everydefinelowmidhigh
253
254\protected\def\typo_scripts_lowmidhigh[#1]#2#3#4%
255  {\dontleavehmode
256   \runninghbox\bgroup
257     \cdef\currentlowmidhigh{#1}%
258     \dostarttagged\t!subsup\currentlowmidhigh
259     \uselowmidhighstyleandcolor\c!style\c!color
260     \setstrut
261     \setbox\plustwo \hbox{\strut\dostarttaggednodetail\t!sub#2\dostoptagged}%
262     \setbox\plusfour\hbox{\strut\dostarttaggednodetail\t!mid#3\dostoptagged}% inefficient
263     \setbox\plussix \hbox{\strut\dostarttaggednodetail\t!sup#4\dostoptagged}%
264     \scratchdimen \wd
265        \ifdim\wd\plustwo>\wd\plusfour
266          \ifdim\wd\plustwo>\wd\plussix
267             \plustwo
268          \else
269             \plussix
270          \fi
271        \else
272          \ifdim\wd\plusfour>\wd\plussix
273             \plusfour
274          \else
275             \plussix
276          \fi
277        \fi
278     \relax
279     \setbox\plustwo \hpack to \scratchdimen{\hss\lower\lowmidhighparameter\c!down\box\plustwo \hss}%
280     \setbox\plusfour\hpack to \scratchdimen{\hss                                 \box\plusfour\hss}%
281     \setbox\plussix \hpack to \scratchdimen{\hss\raise\lowmidhighparameter\c!up  \box\plussix \hss}%
282     \wd\plustwo \zeropoint
283     \wd\plusfour\zeropoint
284     \box\plusfour
285     \box\plustwo
286     \box\plussix
287     \dostoptagged
288   \egroup}
289
290\permanent\protected\def\lomihi      {\typo_scripts_lowmidhigh[]}
291\permanent\protected\def\himilo#1#2#3{\typo_scripts_lowmidhigh[]{#3}{#2}{#1}}
292
293\protect \endinput
294