typo-scr.mkiv /size: 8222 b    last modification: 2020-07-01 14:35
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
=
.
4
8
\exheight
]
% historical
46
\setuphigh
[
\c!style
=
\tx
,
\c!distance
=
\zeropoint
,
\c!up
=
.
8
6
\exheight
]
% values
47 48
\appendtoks
\setuevalue
\currentlow
{
\typo_scripts_low
{
\currentlow
}}
\to
\everydefinelow
49
\appendtoks
\setuevalue
\currenthigh
{
\typo_scripts_high
{
\currenthigh
}}
\to
\everydefinehigh
50 51
\unexpanded
\def
\typo_scripts_low
#
1
#
2
%
52
{
\dontleavehmode
53
\begingroup
54
\edef
\currentlow
{
#
1
}
%
55
\kern
\lowparameter
\c!distance
\relax
56
\setbox
\scratchbox
\runninghbox
\bgroup
57
\lower
\lowparameter
\c!down
\hbox
\bgroup
58
\ifx
\fontsize
\empty
59
\ifmmode
60
\mr
% no color yet
61
\else
62
\uselowstyleandcolor
\c!style\c!color
63
\fi
64
\else
65
\uselowstyleandcolor
\c!style\c!color
66
\fi
67
\dostarttagged
\t!sub
\currentlow
68
#
2
%
69
\dostoptagged
70
\egroup
71
\egroup
72
\ht
\scratchbox\strutht
73
\dp
\scratchbox\strutdp
74
\box
\scratchbox
75
\endgroup
}
76 77
\unexpanded
\def
\typo_scripts_high
#
1
#
2
%
78
{
\dontleavehmode
79
\begingroup
80
\edef
\currenthigh
{
#
1
}
%
81
\kern
\highparameter
\c!distance
\relax
82
\setbox
\scratchbox
\runninghbox
\bgroup
83
\raise
\highparameter
\c!up
\hbox
\bgroup
84
\ifx
\fontsize
\empty
85
\ifmmode
86
\mr
% no color yet
87
\else
88
\usehighstyleandcolor
\c!style\c!color
89
\fi
90
\else
91
\usehighstyleandcolor
\c!style\c!color
92
\fi
93
\dostarttagged
\t!sup
\currenthigh
94
#
2
%
95
\dostoptagged
96
\egroup
97
\egroup
98
\ht
\scratchbox\strutht
99
\dp
\scratchbox\strutdp
100
\box
\scratchbox
101
\endgroup
}
102 103
\unexpanded
\def
\low
{
\typo_scripts_low
\empty
}
104
\unexpanded
\def
\high
{
\typo_scripts_high
\empty
}
105 106
%D \macros
107
%D {lohi, hilo, definelohi, setuplohi}
108
%D
109
%D You can provide an optional keyword \type {left}, in which case the super and
110
%D subscripts will be aligned in a way that permits placement at the left of a word
111
%D (which means that it will be right aligned).
112
%D
113
%D \startbuffer
114
%D \lohi {aha} {ah} test \lohi {aha} {ah} test
115
%D \lohi [left] {aha} {ah} test \lohi [left] {aha} {ah} test
116
%D \lohi {aha} {ah} test \lohi {aha} {ah} test
117
%D \lohi [left] {aha} {ah}test \lohi [left] {aha} {ah} test
118
%D \stopbuffer
119
%D
120
%D \typebuffer
121
%D \getbuffer
122 123
\installcorenamespace
{
lowhigh
}
124 125
\installcommandhandler
\??lowhigh
{
lowhigh
}
\??lowhigh
126 127
\setuplowhigh
128
[
\c!style
=
\tx
,
129
\c!distance
=
.
1
\exheight
,
% these are
130
\c!up
=
.
9
6
\exheight
,
% historical
131
\c!down
=
.
5
8
\exheight
]
% values
132 133
\appendtoks
134
\setuevalue
\currentlowhigh
{
\typo_scripts_lowhigh
{
\currentlowhigh
}
\typo_scripts_lowhigh_indeed
}
%
135
\to
\everydefinelowhigh
136 137
\unexpanded
\def
\typo_scripts_lowhigh
#
1
% #2
138
{
\dontleavehmode
139
\runninghbox
\bgroup
140
\edef
\currentlowhigh
{
#
1
}
%
141
\dosingleempty
}
% #2
142 143
\unexpanded
\def
\typo_scripts_lowhigh_indeed
[#
1
]#
2
#
3
% todo: align .. [#1] is compatible hack
144
{
\dostarttagged
\t!subsup
\currentlowhigh
145
\scratchdimen
\lowhighparameter
\c!distance
\relax
146
\setbox
\plusfour
\hpack
{
\typo_scripts_lowhigh_low_high
\lower
\c!down\t!sub
{
#
2
}}
%
147
\setbox
\plussix
\hpack
{
\typo_scripts_lowhigh_low_high
\raise
\c!up
\t!sup
{
#
3
}}
%
148
\edef
\p_align
{
#
1
}
%
149
\ifx
\p_align
\v!left
150
\ifdim
\wd
\plusfour
<
\wd
\plussix
151
\setbox
\plusfour
\hpack
to
\wd
\plussix
{
\hss\box
\plusfour
}
%
152
\else
153
\setbox
\plussix
\hpack
to
\wd
\plusfour
{
\hss\box
\plussix
}
%
154
\fi
155
\fi
156
\ifdim
\wd
\plusfour
<
\wd
\plussix
157
\wd
\plusfour\zeropoint
158
\box
\plusfour
159
\box
\plussix
160
\else
161
\wd
\plussix\zeropoint
162
\box
\plussix
163
\box
\plusfour
164
\fi
165
\dostoptagged
166
\egroup
}
167 168
\def
\typo_scripts_lowhigh_low_high
#
1
#
2
#
3
#
4
%
169
{
\kern
\scratchdimen
170
\setbox
\scratchbox
\hpack
\bgroup
171
#
1
\lowhighparameter
#
2
\hbox
\bgroup
172
\ifx
\fontsize
\empty
173
\ifmmode
174
\mr
% no color yet
175
\else
176
\uselowhighstyleandcolor
\c!style\c!color
177
\fi
178
\else
179
\uselowhighstyleandcolor
\c!style\c!color
180
\fi
181
\dostarttagged
#
3
\empty
182
#
4
%
183
\dostoptagged
184
\egroup
185
\egroup
186
\ht
\scratchbox\strutht
187
\dp
\scratchbox\strutdp
188
\box
\scratchbox
}
189 190
\unexpanded
\def
\typo_scripts_highlow_indeed
[#
1
]#
2
#
3
%
191
{
\typo_scripts_lowhigh_indeed
[#
1
]
{
#
3
}{
#
2
}}
192 193
\unexpanded
\def
\lohi
{
\typo_scripts_lowhigh
\empty
\typo_scripts_lowhigh_indeed
}
194
\unexpanded
\def
\hilo
{
\typo_scripts_lowhigh
\empty
\typo_scripts_highlow_indeed
}
195 196
%D \macros
197
%D {lowmidhigh, definelowmidhigh, setuplowmidhigh}
198
%D
199
%D The previous command originally didn't have definers. These were introduced when
200
%D the next showed up:
201
%D
202
%D \startbuffer
203
%D \definelow [MyLow] [style=\txx]
204
%D \definehigh [MyHigh] [style=\txx]
205
%D \definelowhigh [MyLoHi] [style=\txx]
206
%D \definelowmidhigh[MyLoMiHi][style=\txx]
207
%D
208
%D We have
209
%D \ruledhbox{\low {L}} and \ruledhbox{\MyLow {L}} and
210
%D \ruledhbox{\high {H}} and \ruledhbox{\MyHigh {H}} and
211
%D \ruledhbox{\lohi {L}{H}} and \ruledhbox{\MyLoHi {L}{H}} and
212
%D \ruledhbox{\lomihi{L}{M}{H}} and \ruledhbox{\MyLoMiHi{L}{M}{H}}.
213
%D \stopbuffer
214
%D
215
%D \typebuffer \getbuffer
216 217
\installcorenamespace
{
lowmidhigh
}
218 219
\installcommandhandler
\??lowmidhigh
{
lowmidhigh
}
\??lowmidhigh
220 221
\setuplowmidhigh
222
[
\c!style
=
\tx
,
223
\c!up
=
.
8
\struthtdp
,
224
\c!down
=
.
8
\struthtdp
]
225 226
\appendtoks
227
\setuevalue
\currentlowmidhigh
{
\typo_scripts_lowmidhigh
{
\currentlowmidhigh
}}
%
228
\to
\everydefinelowmidhigh
229 230
\unexpanded
\def
\typo_scripts_lowmidhigh
#
1
#
2
#
3
#
4
%
231
{
\dontleavehmode
232
\runninghbox
\bgroup
233
\edef
\currentlowmidhigh
{
#
1
}
%
234
\dostarttagged
\t!subsup
\currentlowmidhigh
235
\uselowmidhighstyleandcolor
\c!style\c!color
236
\setstrut
237
\setbox
\plustwo
\hbox
{
\strut
\dostarttagged
\t!sub
\empty
#
2
\dostoptagged
}
%
238
\setbox
\plusfour
\hbox
{
\strut
\dostarttagged
\t!mid
\empty
#
3
\dostoptagged
}
% inefficient
239
\setbox
\plussix
\hbox
{
\strut
\dostarttagged
\t!sup
\empty
#
4
\dostoptagged
}
%
240
\scratchdimen
\wd
241
\ifdim
\wd
\plustwo
>
\wd
\plusfour
242
\ifdim
\wd
\plustwo
>
\wd
\plussix
243
\plustwo
244
\else
245
\plussix
246
\fi
247
\else
248
\ifdim
\wd
\plusfour
>
\wd
\plussix
249
\plusfour
250
\else
251
\plussix
252
\fi
253
\fi
254
\relax
255
\setbox
\plustwo
\hpack
to
\scratchdimen
{
\hss\lower
\lowmidhighparameter
\c!down
\box
\plustwo
\hss
}
%
256
\setbox
\plusfour
\hpack
to
\scratchdimen
{
\hss
\box
\plusfour
\hss
}
%
257
\setbox
\plussix
\hpack
to
\scratchdimen
{
\hss\raise
\lowmidhighparameter
\c!up
\box
\plussix
\hss
}
%
258
\wd
\plustwo
\zeropoint
259
\wd
\plusfour\zeropoint
260
\box
\plusfour
261
\box
\plustwo
262
\box
\plussix
263
\dostoptagged
264
\egroup
}
265 266
\unexpanded
\def
\lomihi
{
\typo_scripts_lowmidhigh
\empty
}
267
\unexpanded
\def
\himilo
#
1
#
2
#
3
{
\typo_scripts_lowmidhigh
\empty
{
#
3
}{
#
2
}{
#
1
}}
268 269
\protect
\endinput
270