summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/typo-cap.mkiv
blob: 28ced7c42cf5774927daa3cb81274e9ef322b947 (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
%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

\registerctxluafile{typo-cap}{1.001}

\definesystemattribute[case][public]

%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]%
  {\ctxcommand{setcharactercasing("#1")}}

% 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]}{}}

% This might become:
%
% \unexpanded\def\WORD {\bgroup\def\g_word{\setcharactercasing[\v!WORD ]}\afterassignment\g_word\let\nexttoken}
% \unexpanded\def\word {\bgroup\def\g_word{\setcharactercasing[\v!word ]}\afterassignment\g_word\let\nexttoken}
% \unexpanded\def\Word {\bgroup\def\g_word{\setcharactercasing[\v!Word ]}\afterassignment\g_word\let\nexttoken}
% \unexpanded\def\Words{\bgroup\def\g_word{\setcharactercasing[\v!Words]}\afterassignment\g_word\let\nexttoken}
%
% so no longer {\Word test} and { } mandate (also later \groupedcommands will go)

\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

\unexpanded\def\pseudosmallcapped{\groupedcommand{\setcharactercasing   [\v!WORD   ]\signalcharacter\tx}{}} % all upper
\unexpanded\def\pseudoSmallcapped{\groupedcommand{\setcharactercasing   [\v!capital]\signalcharacter\tx}{}} % one upper + font
\unexpanded\def\pseudoSmallCapped{\groupedcommand{\setcharactercasing   [\v!Capital]\signalcharacter\tx}{}} % some upper + font

\unexpanded\def\realsmallcapped  {\groupedcommand{\sc\setcharactercasing[\v!WORD   ]}{}} % all lower
\unexpanded\def\realSmallcapped  {\groupedcommand{\sc\setcharactercasing[\v!Word   ]}{}} % one upper + font
\unexpanded\def\realSmallCapped  {\groupedcommand{\sc\setcharactercasing[\v!Words  ]}{}} % some upper

\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\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\normalsmallcapped\smallcapped
\let\normalWORD       \WORD
\let\normalword       \word

%D As suggested by WS:

\unexpanded\def\notsmallcapped{\groupedcommand{\setcharactercasing[\v!word]\signalcharacter}{}}

%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}

\let\normalsmallcapped\smallcapped

\definesystemvariable{kk}

\unexpanded\def\setupcapitals
  {\dosingleempty\typo_capitals_setup}

\def\typo_capitals_setup[#1]% todo: don't use grouping just a switch
  {\getparameters[\??kk][#1]%
   \doifelse\@@kktitle\v!yes
     {\definealternativestyle[\v!capital  ][\normalsmallcapped][\normalsmallcapped]%
      \definealternativestyle[\v!smallcaps][\sc               ][\sc               ]}
     {\definealternativestyle[\v!capital  ][\normalsmallcapped][\normalWORD       ]%
      \definealternativestyle[\v!smallcaps][\sc               ][\normalWORD       ]}%
   \doifelse\@@kksc\v!yes\userealcaps\usepseudocaps}

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

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

% \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}{}}

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

\protect \endinput