typo-cap.mkiv /size: 10 Kb    last modification: 2021-10-28 13:50
1
%D \module
2
%D [ file=typo-cap,
3
%D version=2009.03.27, % code moved from core-spa.mkiv
4
%D title=\CONTEXT\ Typesetting Macros,
5
%D subtitle=Capping,
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
/
Caps
}
15 16
\unprotect
17 18
%D Maybe we need a more clever system: either command or style mode etc. so
19
%D that we can avoid the grouped mess in a simple style switch.
20 21
\registerctxluafile
{
typo
-
cap
}
{
optimize
}
22 23
% \definesystemattribute[case][public] % already predefined
24 25
%D \macros
26
%D {setupcapitals}
27
%D
28
%D By default we use pseudo small caps in titles. This can be
29
%D set up with:
30
%D
31
%D \showsetup{setupcapitals}
32 33
\installcorenamespace
{
capitals
}
34 35
\installcommandhandler
\??capitals
{
capitals
}
\??capitals
36 37
%D Beware, these are not really defines (yet).
38 39
\definecapitals
[
\v!WORD
]
% all upper
40
\definecapitals
[
\v!capital
]
% one upper + font
41
\definecapitals
[
\v!Capital
]
% some upper + font
42
\definecapitals
[
\v!mixed
]
% UpperCase
43
\definecapitals
[
\v!Word
]
% one upper + font
44
\definecapitals
[
\v!Words
]
% some upper
45
\definecapitals
[
\v!camel
]
% lowers first
46
\definecapitals
[
\v!word
]
[
\c!style
=
]
% nothing
47 48
%D \macros
49
%D {Word, Words, WORD, WORDS}
50
%D
51
%D This is probably not the right place to present the next set
52
%D of macros.
53
%D
54
%D \starttyping
55
%D \Word {far too many words}
56
%D \Words{far too many words}
57
%D \WORD {far too many words}
58
%D \WORDS{far too many words}
59
%D \stoptyping
60
%D
61
%D \typebuffer
62
%D
63
%D This calls result in:
64
%D
65
%D \startlines
66
%D \getbuffer
67
%D \stoplines
68
%D
69
%D \showsetup{Word}
70
%D \showsetup{Words}
71
%D \showsetup{WORD}
72
%D \showsetup{WORDS}
73 74
% test \WORD{test TEST \TeX} test
75
% test \word{test TEST \TeX} test
76
% test \Word{test TEST \TeX} test
77 78
\unexpanded
\def
\setcharactercasing
[
#
1
]
%
79
{
\clf_setcharactercasing
{
#
1
}
\fontid
\font
}
80 81
% todo: names casings
82 83
% \unexpanded\def\WORD {\groupedcommand{\setcharactercasing[\v!WORD ]}{}}
84
% \unexpanded\def\word {\groupedcommand{\setcharactercasing[\v!word ]}{}}
85
% \unexpanded\def\Word {\groupedcommand{\setcharactercasing[\v!Word ]}{}}
86
% \unexpanded\def\Words{\groupedcommand{\setcharactercasing[\v!Words]}{}}
87
% \unexpanded\def\camel{\groupedcommand{\setcharactercasing[\v!camel]}{}}
88 89
\unexpanded
\def
\typo_capitale_WORD
{
\clf_setcharactercasing
{
\v!WORD
}
\fontid
\font
}
90
\unexpanded
\def
\typo_capitale_word
{
\clf_setcharactercasing
{
\v!word
}
\fontid
\font
}
91
\unexpanded
\def
\typo_capitale_Word
{
\clf_setcharactercasing
{
\v!Word
}
\fontid
\font
}
92
\unexpanded
\def
\typo_capitale_Words
{
\clf_setcharactercasing
{
\v!Words
}
\fontid
\font
}
93
\unexpanded
\def
\typo_capitale_camel
{
\clf_setcharactercasing
{
\v!camel
}
\fontid
\font
}
94 95
\unexpanded
\def
\WORD
{
\triggergroupedcommandcs
\typo_capitale_WORD
}
96
\unexpanded
\def
\word
{
\triggergroupedcommandcs
\typo_capitale_word
}
97
\unexpanded
\def
\Word
{
\triggergroupedcommandcs
\typo_capitale_Word
}
98
\unexpanded
\def
\Words
{
\triggergroupedcommandcs
\typo_capitale_Words
}
99
\unexpanded
\def
\camel
{
\triggergroupedcommandcs
\typo_capitale_camel
}
100 101
\let
\WORDS
\WORD
102
\let
\words
\word
103 104
%D \macros
105
%D {kap,KAP,Kap,Kaps,nokap,userealcaps,usepseudocaps}
106
%D
107
%D We already introduced \type{\cap} as way to capitalize
108
%D words. This command comes in several versions:
109
%D
110
%D \startbuffer
111
%D \cap {let's put on a \cap{cap}}
112
%D \cap {let's put on a \nocap{cap}}
113
%D \CAP {let's put on a \\{cap}}
114
%D \Cap {let's put on a \\{cap}}
115
%D \Caps{let's put on a cap}
116
%D \stopbuffer
117
%D
118
%D \typebuffer
119
%D
120
%D Note the use of \type{\nocap}, \type{\\} and the nested
121
%D \type{\cap}.
122
%D
123
%D \startlines
124
%D \getbuffer
125
%D \stoplines
126
%D
127
%D These macros show te main reason why we introduced the
128
%D smaller \type{\tx} and \type{\txx}.
129
%D
130
%D \starttyping
131
%D \cap\romannumerals{1995}
132
%D \stoptyping
133
%D
134
%D This at first sight unusual capitilization is completely
135
%D legal.
136
%D
137
%D \showsetup{smallcapped}
138
%D \showsetup{notsmallcapped}
139
%D \showsetup{CAPPED}
140
%D \showsetup{SmallCapped}
141
%D \showsetup{SmallCaps}
142
%D
143
%D The difference between pseudo and real caps is demonstrated
144
%D below:
145
%D
146
%D \startbuffer
147
%D \usepseudocaps \cap{Hans Hagen}
148
%D \userealcaps \cap{Hans Hagen}
149
%D \stopbuffer
150
%D
151
%D \typebuffer
152
%D
153
%D \getbuffer
154
%D
155
%D The \type {\bgroup} trickery below is needed because of
156
%D \type {\groupedcommand}.
157 158
\let
\disablepseudocaps
\relax
% maybe used elsewhere
159 160
\newconditional
\c_typo_capitals_pseudo
161 162
\unexpanded
\def
\usepseudocaps
{
\settrue
\c_typo_capitals_pseudo
}
163
\unexpanded
\def
\userealcaps
{
\setfalse
\c_typo_capitals_pseudo
}
164 165
\usepseudocaps
166 167
% we use char0 as placeholder for the larger font
168
%
169
% here we keep the \groupedcommand
170 171
\def
\typo_capitals_set_fake
#
1
%
172
{
\edef
\currentcapitals
{
#
1
}
%
173
\clf_setcharactercasing
{
\currentcapitals
}
\fontid
\font
174
\usecapitalsstyleparameter
\c!style
}
175 176
\def
\typo_capitals_set_real
#
1
%
177
{
\edef
\currentcapitals
{
#
1
}
%
178
\sc
179
\clf_setcharactercasing
{
\currentcapitals
}
\fontid
\font
}
180 181
% \unexpanded\def\pseudosmallcapped{\groupedcommand{\typo_capitals_set_fake\v!WORD }\donothing} % all upper
182
% \unexpanded\def\pseudoSmallcapped{\groupedcommand{\typo_capitals_set_fake\v!capital}\donothing} % one upper + font
183
% \unexpanded\def\pseudoSmallCapped{\groupedcommand{\typo_capitals_set_fake\v!Capital}\donothing} % some upper + font
184
% \unexpanded\def\pseudoMixedCapped{\groupedcommand{\typo_capitals_set_fake\v!mixed }\donothing} % UpperCase
185
%
186
% \unexpanded\def\realsmallcapped {\groupedcommand{\typo_capitals_set_real\v!WORD }\donothing} % all lower
187
% \unexpanded\def\realSmallcapped {\groupedcommand{\typo_capitals_set_real\v!Word }\donothing} % one upper + font
188
% \unexpanded\def\realSmallCapped {\groupedcommand{\typo_capitals_set_real\v!Words }\donothing} % some upper
189
%
190
% \unexpanded\def\notsmallcapped {\groupedcommand{\typo_capitals_set_fake\v!word }\donothing}
191 192
\unexpanded
\def
\pseudosmallcapped
{
\triggergroupedcommandcs
\font_style_pseudosmallcapped
}
193
\unexpanded
\def
\pseudoSmallcapped
{
\triggergroupedcommandcs
\font_style_pseudoSmallcapped
}
194
\unexpanded
\def
\pseudoSmallCapped
{
\triggergroupedcommandcs
\font_style_pseudoSmallCapped
}
195
\unexpanded
\def
\pseudoMixedCapped
{
\triggergroupedcommandcs
\font_style_pseudoMixedCapped
}
196 197
\unexpanded
\def
\realsmallcapped
{
\triggergroupedcommandcs
\font_style_realsmallcapped
}
198
\unexpanded
\def
\realSmallcapped
{
\triggergroupedcommandcs
\font_style_realSmallcapped
}
199
\unexpanded
\def
\realSmallCapped
{
\triggergroupedcommandcs
\font_style_realSmallCapped
}
200 201
\unexpanded
\def
\notsmallcapped
{
\triggergroupedcommandcs
\font_style_notsmallcapped
}
202 203
\unexpanded
\def
\font_style_pseudosmallcapped
{
\typo_capitals_set_fake
\v!WORD
}
% all upper
204
\unexpanded
\def
\font_style_pseudoSmallcapped
{
\typo_capitals_set_fake
\v!capital
}
% one upper + font
205
\unexpanded
\def
\font_style_pseudoSmallCapped
{
\typo_capitals_set_fake
\v!Capital
}
% some upper + font
206
\unexpanded
\def
\font_style_pseudoMixedCapped
{
\typo_capitals_set_fake
\v!mixed
}
207 208
\unexpanded
\def
\font_style_realsmallcapped
{
\typo_capitals_set_real
\v!WORD
}
% all lower
209
\unexpanded
\def
\font_style_realSmallcapped
{
\typo_capitals_set_real
\v!Word
}
% one upper + font
210
\unexpanded
\def
\font_style_realSmallCapped
{
\typo_capitals_set_real
\v!Words
}
% some upper
211 212
\unexpanded
\def
\font_style_notsmallcapped
{
\typo_capitals_set_fake
\v!word
}
213 214
\unexpanded
\def
\typo_capitals_smallcaps
215
{
\ifconditional
\c_typo_capitals_pseudo
216
\expandafter
\firstoftwoarguments
217
\else
218
\expandafter
\secondoftwoarguments
219
\fi
}
220 221
\unexpanded
\def
\smallcapped
{
\typo_capitals_smallcaps
\pseudosmallcapped
\realsmallcapped
}
222
\unexpanded
\def
\Smallcapped
{
\typo_capitals_smallcaps
\pseudoSmallcapped
\realSmallcapped
}
223
\unexpanded
\def
\SmallCapped
{
\typo_capitals_smallcaps
\pseudoSmallCapped
\realSmallCapped
}
224 225
\unexpanded
\def
\font_style_smallcapped
{
\typo_capitals_smallcaps
\font_style_pseudosmallcapped
\font_style_realsmallcapped
}
226
\unexpanded
\def
\font_style_Smallcapped
{
\typo_capitals_smallcaps
\font_style_pseudoSmallcapped
\font_style_realSmallcapped
}
227
\unexpanded
\def
\font_style_SmallCapped
{
\typo_capitals_smallcaps
\font_style_pseudoSmallCapped
\font_style_realSmallCapped
}
228 229
\unexpanded
\def
\autocap
{
\ifmmode
\expandafter
\normalcap
\else
\expandafter
\smallcapped
\fi
}
230 231
\prependtoks
232
\let
\normalcap
\cap
% mathmode cap
233
\to
\everydump
234 235
\appendtoks
236
\let
\cap
\autocap
237
\to
\everydump
238 239
\let
\kap
\cap
% for old times sake
240
\let
\Caps
\SmallCapped
% for old times sake
241 242
\let
\mixedcaps
\pseudoMixedCapped
243 244
\let
\normalsmallcapped
\smallcapped
245
\let
\normalWORD
\WORD
246
\let
\normalword
\word
247 248
\let
\font_style_normalsmallcapped
\font_style_smallcapped
249
\let
\font_style_normalWORD
\WORD
250
\let
\font_style_normalword
\word
251 252
%D Further tweaks
253 254
\let
\normalsmallcapped
\smallcapped
255 256
\appendtoks
257
\ifx
\currentcapitals
\empty
258
\doifelse
{
\directcapitalsparameter
\c!title
}
\v!yes
259
{
\definealternativestyle
[
\v!capital
]
[
\font_style_normalsmallcapped
]
[
\font_style_normalsmallcapped
]
%
260
\definealternativestyle
[
\v!smallcaps
]
[
\setsmallcaps
]
[
\setsmallcaps
]
}
261
{
\definealternativestyle
[
\v!capital
]
[
\font_style_normalsmallcapped
]
[
\font_style_normalWORD
]
%
262
\definealternativestyle
[
\v!smallcaps
]
[
\setsmallcaps
]
[
\font_style_normalWORD
]
}
%
263
\doifelse
{
\directcapitalsparameter
\s!sc
}
\v!yes
264
\userealcaps
265
\usepseudocaps
266
\fi
267
\to
\everysetupcapitals
268 269
\let
\uppercased
\normalWORD
270
\let
\lowercased
\normalword
271 272
\setupcapitals
273
[
\c!title
=
\v!yes
,
274
\c!style
=
\tx
,
275
\s!sc
=
\v!no
]
% no \c!sc any longer
276 277
% \definefont
278
% [MixedCaps]
279
% [\v_font_string_a\v_font_string_c*default cp \the\exheight]
280
%
281
% \definefont
282
% [MixedCaps]
283
% [MixedCaps*default cp \the\exheight]
284 285
% \definefontfeature
286
% [mixeddefault]
287
% [default]
288
% [extend=1.2]
289 290
\definefont
291
[
MixedCaps
]
292
[
CurrentFont
*
default
cp
1
.
2
\exheight
]
293 294
\setupcapitals
295
[
\v!mixed
]
296
[
\c!style
=
MixedCaps
]
297 298
% \definestartstop is not yet in available at core-spa time
299
%
300
% \startrandomized \input tufte \stoprandomized
301
%
302
% \definestartstop[randomized][\c!before=\dosetattribute{case}{8},\c!after=]
303 304
% \unexpanded\def\randomizetext{\groupedcommand{\c_attr_case\pluseight}{}}
305 306
\unexpanded
\def
\randomizetext
{
\triggergroupedcommand
{
\c_attr_case
\pluseight
}
}
307 308
\definestartstop
[
randomized
]
[
\c!before
=
\dosetattribute
{
case
}
{
8
}
,
\c!after
=
]
309 310
\protect
\endinput
311