summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/typo-cap.mkiv
blob: 890b081867542210757bc5ce4c800a16b07239d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
%D \module
%D   [       file=typo-cap,
%D        version=2009.03.27, % code moved from core-spa.mkiv
%D          title=\CONTEXT\ Typesetting Macros,
%D       subtitle=Capping,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Typesetting Macros / Caps}

\unprotect

%D Maybe we need a more clever system: either command or style mode etc. so
%D that we can avoid the grouped mess in a simple style switch.

\registerctxluafile{typo-cap}{optimize}

% \definesystemattribute[case][public] % already predefined

%D \macros
%D   {setupcapitals}
%D
%D By default we use pseudo small caps in titles. This can be
%D set up with:
%D
%D \showsetup{setupcapitals}

\installcorenamespace{capitals}

\installcommandhandler \??capitals {capitals} \??capitals

%D Beware, these are not really defines (yet).

\definecapitals[\v!WORD]            % all upper
\definecapitals[\v!capital]         % one upper + font
\definecapitals[\v!Capital]         % some upper + font
\definecapitals[\v!mixed]           % UpperCase
\definecapitals[\v!WORD]            % all lower
\definecapitals[\v!Word]            % one upper + font
\definecapitals[\v!Words]           % some upper
\definecapitals[\v!camel]           % lowers first
\definecapitals[\v!word][\c!style=] % nothing

%D \macros
%D   {Word, Words, WORD, WORDS}
%D
%D This is probably not the right place to present the next set
%D of macros.
%D
%D \starttyping
%D \Word {far too many words}
%D \Words{far too many words}
%D \WORD {far too many words}
%D \WORDS{far too many words}
%D \stoptyping
%D
%D \typebuffer
%D
%D This calls result in:
%D
%D \startlines
%D \getbuffer
%D \stoplines
%D
%D \showsetup{Word}
%D \showsetup{Words}
%D \showsetup{WORD}
%D \showsetup{WORDS}

% test \WORD{test TEST \TeX} test
% test \word{test TEST \TeX} test
% test \Word{test TEST \TeX} test

\unexpanded\def\setcharactercasing[#1]%
  {\clf_setcharactercasing{#1}\fontid\font}

% todo: names casings

% \unexpanded\def\WORD {\groupedcommand{\setcharactercasing[\v!WORD ]}{}}
% \unexpanded\def\word {\groupedcommand{\setcharactercasing[\v!word ]}{}}
% \unexpanded\def\Word {\groupedcommand{\setcharactercasing[\v!Word ]}{}}
% \unexpanded\def\Words{\groupedcommand{\setcharactercasing[\v!Words]}{}}
% \unexpanded\def\camel{\groupedcommand{\setcharactercasing[\v!camel]}{}}

\unexpanded\def\typo_capitale_WORD {\clf_setcharactercasing{\v!WORD }\fontid\font}
\unexpanded\def\typo_capitale_word {\clf_setcharactercasing{\v!word }\fontid\font}
\unexpanded\def\typo_capitale_Word {\clf_setcharactercasing{\v!Word }\fontid\font}
\unexpanded\def\typo_capitale_Words{\clf_setcharactercasing{\v!Words}\fontid\font}
\unexpanded\def\typo_capitale_camel{\clf_setcharactercasing{\v!camel}\fontid\font}

\unexpanded\def\WORD {\triggergroupedcommandcs\typo_capitale_WORD }
\unexpanded\def\word {\triggergroupedcommandcs\typo_capitale_word }
\unexpanded\def\Word {\triggergroupedcommandcs\typo_capitale_Word }
\unexpanded\def\Words{\triggergroupedcommandcs\typo_capitale_Words}
\unexpanded\def\camel{\triggergroupedcommandcs\typo_capitale_camel}

\let\WORDS\WORD
\let\words\word

%D \macros
%D   {kap,KAP,Kap,Kaps,nokap,userealcaps,usepseudocaps}
%D
%D We already introduced \type{\cap} as way to capitalize
%D words. This command comes in several versions:
%D
%D \startbuffer
%D \cap {let's put on a \cap{cap}}
%D \cap {let's put on a \nocap{cap}}
%D \CAP {let's put on a \\{cap}}
%D \Cap {let's put on a \\{cap}}
%D \Caps{let's put on a cap}
%D \stopbuffer
%D
%D \typebuffer
%D
%D Note the use of \type{\nocap}, \type{\\} and the nested
%D \type{\cap}.
%D
%D \startlines
%D \getbuffer
%D \stoplines
%D
%D These macros show te main reason why we introduced the
%D smaller \type{\tx} and \type{\txx}.
%D
%D \starttyping
%D \cap\romannumerals{1995}
%D \stoptyping
%D
%D This at first sight unusual capitilization is completely
%D legal.
%D
%D \showsetup{smallcapped}
%D \showsetup{notsmallcapped}
%D \showsetup{CAPPED}
%D \showsetup{SmallCapped}
%D \showsetup{SmallCaps}
%D
%D The difference between pseudo and real caps is demonstrated
%D below:
%D
%D \startbuffer
%D \usepseudocaps \cap{Hans Hagen}
%D \userealcaps   \cap{Hans Hagen}
%D \stopbuffer
%D
%D \typebuffer
%D
%D \getbuffer
%D
%D The \type {\bgroup} trickery below is needed because of
%D \type {\groupedcommand}.

\let\disablepseudocaps\relax % maybe used elsewhere

\newconditional\c_typo_capitals_pseudo

\unexpanded\def\usepseudocaps{\settrue \c_typo_capitals_pseudo}
\unexpanded\def\userealcaps  {\setfalse\c_typo_capitals_pseudo}

\usepseudocaps

% we use char0 as placeholder for the larger font
%
% here we keep the \groupedcommand

\def\typo_capitals_set_fake#1%
  {\edef\currentcapitals{#1}%
   \clf_setcharactercasing{\currentcapitals}\fontid\font
   \usecapitalsstyleparameter\c!style}

\def\typo_capitals_set_real#1%
  {\edef\currentcapitals{#1}%
   \sc
   \clf_setcharactercasing{\currentcapitals}\fontid\font}

% \unexpanded\def\pseudosmallcapped{\groupedcommand{\typo_capitals_set_fake\v!WORD   }\donothing} % all upper
% \unexpanded\def\pseudoSmallcapped{\groupedcommand{\typo_capitals_set_fake\v!capital}\donothing} % one upper + font
% \unexpanded\def\pseudoSmallCapped{\groupedcommand{\typo_capitals_set_fake\v!Capital}\donothing} % some upper + font
% \unexpanded\def\pseudoMixedCapped{\groupedcommand{\typo_capitals_set_fake\v!mixed  }\donothing} % UpperCase
%
% \unexpanded\def\realsmallcapped  {\groupedcommand{\typo_capitals_set_real\v!WORD   }\donothing} % all lower
% \unexpanded\def\realSmallcapped  {\groupedcommand{\typo_capitals_set_real\v!Word   }\donothing} % one upper + font
% \unexpanded\def\realSmallCapped  {\groupedcommand{\typo_capitals_set_real\v!Words  }\donothing} % some upper
%
% \unexpanded\def\notsmallcapped   {\groupedcommand{\typo_capitals_set_fake\v!word   }\donothing}

\unexpanded\def\pseudosmallcapped{\triggergroupedcommandcs\font_style_pseudosmallcapped}
\unexpanded\def\pseudoSmallcapped{\triggergroupedcommandcs\font_style_pseudoSmallcapped}
\unexpanded\def\pseudoSmallCapped{\triggergroupedcommandcs\font_style_pseudoSmallCapped}
\unexpanded\def\pseudoMixedCapped{\triggergroupedcommandcs\font_style_pseudoMixedCapped}

\unexpanded\def\realsmallcapped  {\triggergroupedcommandcs\font_style_realsmallcapped}
\unexpanded\def\realSmallcapped  {\triggergroupedcommandcs\font_style_realSmallcapped}
\unexpanded\def\realSmallCapped  {\triggergroupedcommandcs\font_style_realSmallCapped}

\unexpanded\def\notsmallcapped   {\triggergroupedcommandcs\font_style_notsmallcapped}

\unexpanded\def\font_style_pseudosmallcapped{\typo_capitals_set_fake\v!WORD   } % all upper
\unexpanded\def\font_style_pseudoSmallcapped{\typo_capitals_set_fake\v!capital} % one upper + font
\unexpanded\def\font_style_pseudoSmallCapped{\typo_capitals_set_fake\v!Capital} % some upper + font
\unexpanded\def\font_style_pseudoMixedCapped{\typo_capitals_set_fake\v!mixed  }

\unexpanded\def\font_style_realsmallcapped  {\typo_capitals_set_real\v!WORD   } % all lower
\unexpanded\def\font_style_realSmallcapped  {\typo_capitals_set_real\v!Word   } % one upper + font
\unexpanded\def\font_style_realSmallCapped  {\typo_capitals_set_real\v!Words  } % some upper

\unexpanded\def\font_style_notsmallcapped   {\typo_capitals_set_fake\v!word   }

\unexpanded\def\typo_capitals_smallcaps
  {\ifconditional\c_typo_capitals_pseudo
     \expandafter\firstoftwoarguments
   \else
     \expandafter\secondoftwoarguments
   \fi}

\unexpanded\def\smallcapped{\typo_capitals_smallcaps\pseudosmallcapped\realsmallcapped}
\unexpanded\def\Smallcapped{\typo_capitals_smallcaps\pseudoSmallcapped\realSmallcapped}
\unexpanded\def\SmallCapped{\typo_capitals_smallcaps\pseudoSmallCapped\realSmallCapped}

\unexpanded\def\font_style_smallcapped{\typo_capitals_smallcaps\font_style_pseudosmallcapped\font_style_realsmallcapped}
\unexpanded\def\font_style_Smallcapped{\typo_capitals_smallcaps\font_style_pseudoSmallcapped\font_style_realSmallcapped}
\unexpanded\def\font_style_SmallCapped{\typo_capitals_smallcaps\font_style_pseudoSmallCapped\font_style_realSmallCapped}

\unexpanded\def\autocap{\ifmmode\expandafter\normalcap\else\expandafter\smallcapped\fi}

\appendtoks
    \let\normalcap\cap % mathmode cap
    \let\cap\autocap
\to \everydump

\let\kap\cap          % for old times sake
\let\Caps\SmallCapped % for old times sake

\let\mixedcaps\pseudoMixedCapped

\let\normalsmallcapped\smallcapped
\let\normalWORD       \WORD
\let\normalword       \word

\let\font_style_normalsmallcapped\font_style_smallcapped
\let\font_style_normalWORD       \WORD
\let\font_style_normalword       \word

%D Further tweaks

\let\normalsmallcapped\smallcapped

\appendtoks
    \ifx\currentcapitals\empty
      \doifelse{\directcapitalsparameter\c!title}\v!yes
        {\definealternativestyle[\v!capital  ][\font_style_normalsmallcapped][\font_style_normalsmallcapped]%
         \definealternativestyle[\v!smallcaps][\setsmallcaps][\setsmallcaps]}
        {\definealternativestyle[\v!capital  ][\font_style_normalsmallcapped][\font_style_normalWORD]%
         \definealternativestyle[\v!smallcaps][\setsmallcaps][\font_style_normalWORD]}%
      \doifelse{\directcapitalsparameter\s!sc}\v!yes
        \userealcaps
        \usepseudocaps
    \fi
\to \everysetupcapitals

\let\uppercased\normalWORD
\let\lowercased\normalword

\setupcapitals
  [\c!title=\v!yes,
   \c!style=\tx,
   \s!sc=\v!no] % no \c!sc any longer

% \definefont
%   [MixedCaps]
%   [\v_font_string_a\v_font_string_c*default cp \the\exheight]
%
% \definefont
%   [MixedCaps]
%   [MixedCaps*default cp \the\exheight]

% \definefontfeature
%   [mixeddefault]
%   [default]
%   [extend=1.2]

\definefont
  [MixedCaps]
  [CurrentFont*default cp 1.2\exheight]

\setupcapitals
  [\v!mixed]
  [\c!style=MixedCaps]

% \definestartstop is not yet in available at core-spa time
%
% \startrandomized \input tufte \stoprandomized
%
% \definestartstop[randomized][\c!before=\dosetattribute{case}{8},\c!after=]

% \unexpanded\def\randomizetext{\groupedcommand{\attribute\caseattribute\pluseight}{}}

\unexpanded\def\randomizetext{\triggergroupedcommand{\attribute\caseattribute\pluseight}}

\definestartstop[randomized][\c!before=\dosetattribute{case}{8},\c!after=]

\protect \endinput