typo-cap.mkxl /size: 10 Kb    last modification: 2025-02-21 11:03
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}{autosuffix}
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 set up with:
29%D
30%D \showsetup{setupcapitals}
31
32\installcorenamespace{capitals}
33
34\installcommandhandler \??capitals {capitals} \??capitals
35
36%D Beware, these are not really defines (yet).
37
38% 1=upper 2=lower 3=mixed
39
40\setupcapitals
41  [\c!category=\zerocount,
42   \c!xscale=\plusthousand,
43   \c!yscale=\plusthousand]
44
45\definecapitals[\v!WORD]    [\c!category=\plusone]   % all upper
46\definecapitals[\v!capital] [\c!category=\plusthree] % one upper + font
47\definecapitals[\v!Capital] [\c!category=\plusthree] % some upper + font
48\definecapitals[\v!mixed]   [\c!category=\plusthree] % UpperCase
49\definecapitals[\v!Word]    [\c!category=\plusthree] % one upper + font
50\definecapitals[\v!Words]   [\c!category=\plusthree] % some upper
51\definecapitals[\v!camel]   [\c!category=\plusthree] % lowers first
52
53\definecapitals[\v!cap]     [\v!capital] % adapts to mathmode
54\definecapitals[\v!Cap]     [\v!Capital]
55
56\definecapitals % nothing
57  [\v!word]
58  [\c!category=\plustwo,
59   \c!style=]
60
61\definecapitals % scale upper
62  [\v!Camel]
63  [\c!xscale=900,
64   \c!yscale=900,
65   \c!category=\plusthree]
66
67\permanent\protected\def\resetcharactercasing{\c_attr_case\attributeunsetvalue}
68
69\definecapitals % nothing
70  [randomvariant]
71  [\c!category=\zerocount]
72
73
74%D \macros
75%D   {Word, Words, WORD, WORDS}
76%D
77%D This is probably not the right place to present the next set of macros.
78%D
79%D \starttyping
80%D \Word {far too many words}
81%D \Words{far too many words}
82%D \WORD {far too many words}
83%D \WORDS{far too many words}
84%D \stoptyping
85%D
86%D \typebuffer
87%D
88%D This calls result in:
89%D
90%D \startlines
91%D \getbuffer
92%D \stoplines
93%D
94%D \showsetup{Word}
95%D \showsetup{Words}
96%D \showsetup{WORD}
97%D \showsetup{WORDS}
98
99% test \WORD{test TEST \TeX} test
100% test \word{test TEST \TeX} test
101% test \Word{test TEST \TeX} test
102
103\permanent\tolerant\protected\def\setcharactercasing[#1]%
104  {\clf_setcharactercasing
105     {#1}%
106     {\namedcapitalsparameter{#1}\c!category}%
107     {\namedcapitalsparameter{#1}\c!xscale}%
108     {\namedcapitalsparameter{#1}\c!yscale}}
109
110\protected\def\casing[#1]{\groupedcommand{\setcharactercasing[#1]}{}}
111\protected\def\nocasing  {\groupedcommand{\resetcharactercasing}{}}
112
113\protected\def\typo_capital_WORD {\setcharactercasing[\v!WORD ]}
114\protected\def\typo_capital_word {\setcharactercasing[\v!word ]}
115\protected\def\typo_capital_Word {\setcharactercasing[\v!Word ]}
116\protected\def\typo_capital_Words{\setcharactercasing[\v!Words]}
117\protected\def\typo_capital_camel{\setcharactercasing[\v!camel]}
118\protected\def\typo_capital_Camel{\setcharactercasing[\v!Camel]}
119
120\pushoverloadmode
121
122\permanent\protected\def\WORD {\triggergroupedcommandcs\typo_capital_WORD }
123\permanent\protected\def\word {\triggergroupedcommandcs\typo_capital_word }
124\permanent\protected\def\Word {\triggergroupedcommandcs\typo_capital_Word }
125\permanent\protected\def\Words{\triggergroupedcommandcs\typo_capital_Words}
126\permanent\protected\def\camel{\triggergroupedcommandcs\typo_capital_camel}
127\permanent\protected\def\Camel{\triggergroupedcommandcs\typo_capital_Camel}
128
129\aliased\let\WORDS\WORD
130\aliased\let\words\word
131
132\popoverloadmode
133
134%D \macros
135%D   {kap,KAP,Kap,Kaps,nokap,userealcaps,usepseudocaps}
136%D
137%D We already introduced \type {\cap} as way to capitalize words. This command comes
138%D in several versions:
139%D
140%D \startbuffer
141%D \cap {let's put on a \cap{cap}}
142%D \cap {let's put on a \nocap{cap}}
143%D \CAP {let's put on a \\{cap}}
144%D \Cap {let's put on a \\{cap}}
145%D \Caps{let's put on a cap}
146%D \stopbuffer
147%D
148%D \typebuffer
149%D
150%D Note the use of \type {\nocap}, \type {\\} and the nested \type {\cap}.
151%D
152%D \startlines
153%D \getbuffer
154%D \stoplines
155%D
156%D These macros show te main reason why we introduced the smaller \type {\tx} and
157%D \type {\txx}.
158%D
159%D \starttyping
160%D \cap\romannumerals{1995}
161%D \stoptyping
162%D
163%D This at first sight unusual capitilization is completely legal.
164%D
165%D \showsetup{smallcapped}
166%D \showsetup{notsmallcapped}
167%D \showsetup{CAPPED}
168%D \showsetup{SmallCapped}
169%D \showsetup{SmallCaps}
170%D
171%D The difference between pseudo and real caps is demonstrated below:
172%D
173%D \startbuffer
174%D \usepseudocaps \cap{Hans Hagen}
175%D \userealcaps   \cap{Hans Hagen}
176%D \stopbuffer
177%D
178%D \typebuffer
179%D
180%D \getbuffer
181%D
182%D The \type {\bgroup} trickery below is needed because of \type {\groupedcommand}.
183
184\newconditional\c_typo_capitals_pseudo
185
186\permanent\protected\def\usepseudocaps{\c_typo_capitals_pseudo\conditionaltrue}
187\permanent\protected\def\userealcaps  {\c_typo_capitals_pseudo\conditionalfalse}
188
189\usepseudocaps
190
191% we use char0 as placeholder for the larger font
192%
193% here we keep the \groupedcommand
194
195\def\typo_capitals_set_fake#1%
196  {\cdef\currentcapitals{#1}%
197   \setcharactercasing[\currentcapitals]%
198   \usecapitalsstyleparameter\c!style}
199
200\def\typo_capitals_set_real#1#2%
201  {\cdef\currentcapitals{#1}%
202   \sc % \smallcaps
203   \setcharactercasing[\currentcapitals]}
204
205\permanent\protected\def\pseudosmallcapped{\triggergroupedcommandcs\font_style_pseudosmallcapped}
206\permanent\protected\def\pseudoSmallcapped{\triggergroupedcommandcs\font_style_pseudoSmallcapped}
207\permanent\protected\def\pseudoSmallCapped{\triggergroupedcommandcs\font_style_pseudoSmallCapped}
208\permanent\protected\def\pseudoMixedCapped{\triggergroupedcommandcs\font_style_pseudoMixedCapped}
209
210\permanent\protected\def\realsmallcapped  {\triggergroupedcommandcs\font_style_realsmallcapped}
211\permanent\protected\def\realSmallcapped  {\triggergroupedcommandcs\font_style_realSmallcapped}
212\permanent\protected\def\realSmallCapped  {\triggergroupedcommandcs\font_style_realSmallCapped}
213
214\permanent\protected\def\notsmallcapped   {\triggergroupedcommandcs\font_style_notsmallcapped}
215
216\protected\def\font_style_pseudosmallcapped{\typo_capitals_set_fake\v!WORD}    % all upper
217\protected\def\font_style_pseudoSmallcapped{\typo_capitals_set_fake\v!capital} % one upper + font
218\protected\def\font_style_pseudoSmallCapped{\typo_capitals_set_fake\v!Capital} % some upper + font
219\protected\def\font_style_pseudoMixedCapped{\typo_capitals_set_fake\v!mixed  }
220
221\protected\def\font_style_realsmallcapped  {\typo_capitals_set_real\v!WORD}    % all lower
222\protected\def\font_style_realSmallcapped  {\typo_capitals_set_real\v!Word}    % one upper + font
223\protected\def\font_style_realSmallCapped  {\typo_capitals_set_real\v!Words}   % some upper
224
225\protected\def\font_style_notsmallcapped   {\typo_capitals_set_fake\v!word}
226
227\protected\def\typo_capitals_smallcaps
228  {\ifconditional\c_typo_capitals_pseudo
229     \expandafter\firstoftwoarguments
230   \else
231     \expandafter\secondoftwoarguments
232   \fi}
233
234\permanent\protected\def\smallcapped{\typo_capitals_smallcaps\pseudosmallcapped\realsmallcapped}
235\permanent\protected\def\Smallcapped{\typo_capitals_smallcaps\pseudoSmallcapped\realSmallcapped}
236\permanent\protected\def\SmallCapped{\typo_capitals_smallcaps\pseudoSmallCapped\realSmallCapped}
237
238\permanent\protected\def\font_style_smallcapped{\typo_capitals_smallcaps\font_style_pseudosmallcapped\font_style_realsmallcapped}
239\permanent\protected\def\font_style_Smallcapped{\typo_capitals_smallcaps\font_style_pseudoSmallcapped\font_style_realSmallcapped}
240\permanent\protected\def\font_style_SmallCapped{\typo_capitals_smallcaps\font_style_pseudoSmallCapped\font_style_realSmallCapped}
241
242\permanent\protected\def\autocap{\ifmmode\expandafter\normalcap\else\expandafter\smallcapped\fi}
243
244\prependtoks
245    \enforced\let\normalcap\cap % mathmode cap
246\to \everydump
247
248\appendtoks
249    \enforced\let\cap\autocap
250\to \everydump
251
252\ifdefined\kap\else \aliased\let\kap\cap \fi % for old times sake
253
254\aliased\let\Caps\SmallCapped % for old times sake
255
256\aliased\let\mixedcaps\pseudoMixedCapped
257
258\aliased\let\normalsmallcapped\smallcapped
259\aliased\let\normalWORD       \WORD
260\aliased\let\normalword       \word
261
262\aliased\let\font_style_normalsmallcapped\font_style_smallcapped
263\aliased\let\font_style_normalWORD       \WORD
264\aliased\let\font_style_normalword       \word
265
266\appendtoks
267    \ifempty\currentcapitals
268      \ifcstok{\directcapitalsparameter\c!title}\v!yes
269        \definealternativestyle[\v!capital  ][\font_style_normalsmallcapped][\font_style_normalsmallcapped]%
270        \definealternativestyle[\v!smallcaps][\setsmallcaps][\setsmallcaps]%
271      \else
272        \definealternativestyle[\v!capital  ][\font_style_normalsmallcapped][\font_style_normalWORD]%
273        \definealternativestyle[\v!smallcaps][\setsmallcaps][\font_style_normalWORD]%
274      \fi
275      \ifcstok{\directcapitalsparameter\s!sc}\v!yes
276        \userealcaps
277      \else
278        \usepseudocaps
279      \fi
280    \fi
281\to \everysetupcapitals
282
283\aliased\let\uppercased\normalWORD
284\aliased\let\lowercased\normalword
285
286\setupcapitals
287  [\c!title=\v!yes,
288   \c!style=\tx,
289   \s!sc=\v!no] % no \c!sc any longer
290
291\definefont
292  [MixedCaps]
293  [CurrentFont*default cp 1.2\exheight]
294% [CurrentFont*default at 1.5\exheight] % better adaptation to slanted but still not nice
295% [CurrentFont*default ht 1.2\exheight] % maybe this is better indeed
296
297\setupcapitals
298  [\v!mixed]
299  [\c!style=MixedCaps]
300
301% \definestartstop is not yet in available at core-spa time
302%
303% \startrandomized \input tufte \stoprandomized
304%
305% \definestartstop[randomized][\c!before=\dosetattribute{case}{8},\c!after=]
306
307% \protected\def\randomizetext{\groupedcommand{\c_attr_case\pluseight}{}}
308
309\permanent\protected\def\randomizetext{\triggergroupedcommand{\c_attr_case\pluseight}}
310
311\definestartstop[randomized][\c!before=\dosetattribute{case}{8},\c!after=]
312
313\protect \endinput
314