font-emp.mkvi /size: 8033 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=font-emp,
3
%D version=20120106, % (moved from font-ini)
4
%D title=\CONTEXT\ Font Macros,
5
%D subtitle=Emphasis,
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
Font
Macros
/
Emphasis
}
15 16
\unprotect
17 18
%D \macros
19
%D {em,emphasistypeface,emphasisboldface}
20
%D
21
%D The next macro started as a copy of Donald Arseneau's \type {\em} (\TUGNEWS\
22
%D Vol.~3, no.~1, 1994). His implementation was a bit more sophisticated version of
23
%D the standard \LATEX\ one. We further enhanced the macro, so now it also adapts
24
%D itself to boldface mode. Because we favor {\sl slanted} type over {\it italic},
25
%D we made the emphasis adaptable, for instance:
26
%D
27
%D \starttyping
28
%D \def\emphasistypeface {\it}
29
%D \def\emphasisboldface {\bi}
30
%D \stoptyping
31
%D
32
%D But we prefer:
33
%D
34
%D \starttyping
35
%D \unexpanded\def\emphasistypeface{\sl}
36
%D \unexpanded\def\emphasisboldface{\bs}
37
%D \stoptyping
38
%D
39
%D or even better:
40 41
\let
\m_font_emphasized_typeface
\empty
42 43
\def
\font_emphasis_checked_typeface
#
slanted
#
italic
%
44
{
\edef
\m_font_emphasized_typeface
{
\font_bodyfontvariable
\s!em
}
%
45
\ifx
\m_font_emphasized_typeface
\v!slanted
46
#
slanted
%
47
\else\ifx
\m_font_emphasized_typeface
\v!italic
48
#
italic
%
49
\else\ifx
\m_font_emphasized_typeface
\empty
50
#
slanted
%
51
\else
52
\csname
\m_font_emphasized_typeface
\endcsname
53
\fi\fi\fi
}
54 55
\unexpanded
\def
\emphasistypeface
{
\font_emphasis_checked_typeface
\sl
\it
}
56
\unexpanded
\def
\emphasisboldface
{
\font_emphasis_checked_typeface
\bs
\bi
}
57 58
\unexpanded
\def
\normalboldface
% public
59
{
\relax\ifx
\fontalternative
\s!it
\bi
60
\else
\ifx
\fontalternative
\s!sl
\bs
61
\else
\bf
\fi\fi
}
62 63
\unexpanded
\def
\normalitalicface
% public
64
{
\relax\ifx
\fontalternative
\s!tf
\it
65
\else
\ifx
\fontalternative
\s!bf
\bi
66
\else
\tf
\fi\fi
}
67 68
\unexpanded
\def
\normalslantedface
% public
69
{
\relax\ifx
\fontalternative
\s!tf
\sl
70
\else
\ifx
\fontalternative
\s!bf
\bs
71
\else
\tf
\fi\fi
}
72 73
\unexpanded
\def
\normaltypeface
% public
74
{
\relax
75
\ifx
\fontalternative
\s!bi
\it
\else
76
\ifx
\fontalternative
\s!bs
\sl
\else
77
\tf
\fi\fi
}
78 79
\unexpanded
\def
\swaptypeface
% public
80
{
\relax
81
\ifx
\fontalternative
\s!it
\tf
\else
82
\ifx
\fontalternative
\s!sl
\tf
\else
83
\ifx
\fontalternative
\s!bf
\emphasisboldface
\else
84
\ifx
\fontalternative
\s!bs
\bf
\else
85
\ifx
\fontalternative
\s!bi
\bf
\else
86
\emphasistypeface
\fi\fi\fi\fi\fi
}
87 88
\let
\typeface
\normaltypeface
% public
89
\let
\boldface
\normalboldface
% public
90
\let
\slantedface\normalslantedface
% public
91
\let
\italicface
\normalitalicface
% public
92
\let
\swapface
\swaptypeface
% public
93 94
%D To be set with the default body font environment: \type
95
%D {em} being \type {slanted} or \type {italic}.
96 97
% maybe a \csname...\fontalternative\endcsname
98 99
\newconditional
\c_font_emphasis_needed
100 101
\unexpanded
\def
\em
102
{
\relax
103
\ifdim
\slantperpoint
>
\zeropoint
104
\settrue
\c_font_emphasis_needed
105
\else
106
\setfalse
\c_font_emphasis_needed
107
\fi
108
\font_emphasis_set_emphasis_boldface
% new
109
\ifx
\fontalternative
\s!it
110
\unexpanded
\def
\emphasistypeface
{
\it
}
\tf
111
\else\ifx
\fontalternative
\s!sl
112
\unexpanded
\def
\emphasistypeface
{
\sl
}
\tf
113
\else\ifx
\fontalternative
\s!bf
114
\emphasisboldface
115
\else\ifx
\fontalternative
\s!bs
116
\unexpanded
\def
\emphasisboldface
{
\bs
}
\bf
117
\else\ifx
\fontalternative
\s!bi
118
\unexpanded
\def
\emphasisboldface
{
\bi
}
\bf
119
\else
120
\emphasistypeface
121
\fi\fi\fi\fi\fi
122
\ifconditional
\c_font_emphasis_needed
\else
123
\expandafter\aftergroup
124
\fi
125
\emphasiscorrection
}
126 127
%D The next feature was not present in previous versions. It
128
%D takes care of \type {\em \bf ...} situations.
129 130
\let
\font_emphasis_saved_emphasis_boldface
\relax
131 132
\def
\font_emphasis_set_emphasis_boldface
133
{
\let
\font_emphasis_saved_emphasis_boldface
\bf
134
\let
\font_emphasis_set_emphasis_boldface
\relax
135
\let
\bf
\font_emphasis_bold_bold
}
136 137
\unexpanded
\def
\font_emphasis_bold_bold
138
{
%\relax
139
\let
\bf
\relax
% new
140
\ifx
\fontalternative
\s!it
141
\bi
142
\else\ifx
\fontalternative
\s!sl
143
\bs
144
\else
145
\font_emphasis_saved_emphasis_boldface
146
\fi\fi
147
\let
\bf
\font_emphasis_saved_emphasis_boldface
}
148 149
%D Donald's (adapted) macros take the next character into account when placing
150
%D italic correction. As a bonus we also look for something that looks like a dash,
151
%D in which case we don't correct.
152 153
\let
\italiccorrection
=
\/
% tex primitive
154 155
\def
\emphasiscorrection
% public, not in raw alignment groups, else omit problem
156
{
\ifhmode\ifnum
\currentgrouptype
=
\aligngroupcode
\else
157
\expandafter\expandafter\expandafter
\font_emphasis_look
158
\fi\fi
}
159 160
\def
\font_emphasis_look
161
{
\begingroup
162
\futurelet
\nexttoken
\font_emphasis_test
}
163 164
\def
\font_emphasis_test
165
{
\ifcat
\noexpand
\nexttoken
,
% still ok?
166
\expandafter
\font_emphasis_a
167
\else
168
\expandafter
\font_emphasis_b
169
\fi
}
170 171
\def
\font_emphasis_a
172
{
\futurelet
\nexttoken
\font_emphasis_correction
}
173 174
\def
\font_emphasis_correction
175
{
\setbox
\scratchbox
\hbox
{
\nexttoken
}
% tricky as next can be a macro
176
\ifzeropt
\ht
\scratchbox
% probably a space
177
\expandafter
\font_emphasis_b
178
\else\ifdim\ht
\scratchbox
<
.
3
\exheight
179
\expandafter\expandafter\expandafter\endgroup
180
\else
181
\expandafter\expandafter\expandafter
\font_emphasis_b
182
\fi\fi
}
183 184
\def
\font_emphasis_b
185
{
\scratchskip
\lastskip
186
\ifzeropt
\scratchskip
187
\italiccorrection
\relax
188
\else
189
\unskip
\italiccorrection
\hskip
\scratchskip
190
\fi
191
\endgroup
}
192 193
%D We end with some examples which show the behavior when some punctuation is met.
194
%D We also show how the mechanism adapts itself to bold, italic and slanted typing.
195
%D
196
%D \startbuffer
197
%D test {test}test \par
198
%D test {\sl test}test \par
199
%D test {\em test}test \par
200
%D test {\em test}--test \par
201
%D
202
%D test {test}, test \par
203
%D test {\em test}, test \par
204
%D
205
%D test {\em test {\em test {\em test} test} test} test \par
206
%D test {\bf test {\em test {\em test} test} test} test \par
207
%D test {\sl test {\em test {\em test} test} test} test \par
208
%D test {\it test {\em test {\em test} test} test} test \par
209
%D \stopbuffer
210
%D
211
%D \typebuffer
212
%D
213
%D We get:
214
%D
215
%D \startpacked
216
%D \getbuffer
217
%D \stoppacked
218 219
%D \macros
220
%D {emphbf,emphit,emphsl,emphtf}
221
%D
222
%D The next emphasis alternatives are for \THANH. They adapt their style as good as
223
%D possible. These macros are obsolete in \MKIV.
224 225
% \unexpanded\def\emphbf{\groupedcommand{\bf\def\emphit{\bi}\def\emphsl{\bs}}{}}
226
% \unexpanded\def\emphit{\groupedcommand{\it\def\emphbf{\bi}\def\emphsl{\sl}}{}}
227
% \unexpanded\def\emphsl{\groupedcommand{\sl\def\emphbf{\bs}\def\emphit{\it}}{}}
228
% \unexpanded\def\emphtf{\groupedcommand{\tf\def\emphbf{\bf}\def\emphit{\it}\def\emphsl{\sl}}{}}
229
% \unexpanded\def\emph {\groupedcommand{\em}{}}
230 231
\unexpanded
\def
\font_emphasis_bf
{
\bf
\def
\emphit
{
\bi
}
\def
\emphsl
{
\bs
}}
232
\unexpanded
\def
\font_emphasis_it
{
\it
\def
\emphbf
{
\bi
}
\def
\emphsl
{
\sl
}}
233
\unexpanded
\def
\font_emphasis_sl
{
\sl
\def
\emphbf
{
\bs
}
\def
\emphit
{
\it
}}
234
\unexpanded
\def
\font_emphasis_tf
{
\tf
\def
\emphbf
{
\bf
}
\def
\emphit
{
\it
}
\def
\emphsl
{
\sl
}}
235 236
\unexpanded
\def
\emphbf
{
\triggergroupedcommandcs
\font_emphasis_bf
}
237
\unexpanded
\def
\emphit
{
\triggergroupedcommandcs
\font_emphasis_it
}
238
\unexpanded
\def
\emphsl
{
\triggergroupedcommandcs
\font_emphasis_sl
}
239
\unexpanded
\def
\emphtf
{
\triggergroupedcommandcs
\font_emphasis_tf
}
240
\unexpanded
\def
\emph
{
\triggergroupedcommandcs
\em
}
241 242
\unexpanded
\def
\emphasized
{
\bgroup
\em
\let
\nexttoken
}
243 244
%D \startbuffer
245
%D TEXT {\emphbf text \emphit text \emphtf text \emphsl text} TEXT
246
%D TEXT \emphbf{text \emphit{text} \emphtf{text} \emphsl{text}} TEXT
247
%D \stopbuffer
248
%D
249
%D \typebuffer
250
%D \startlines
251
%D \getbuffer
252
%D \stoplines
253 254
\protect
\endinput
255