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