catc-sym.mkiv /size: 7641 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=catc-sym,
3
%D version=1997.01.03, % moved code
4
%D title=\CONTEXT\ Catcode Macros,
5
%D subtitle=Some Handy Constants,
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
%D We want to have access to the raw alternatives of the special characters. We
15
%D use a \type {\xdef} instead of \type {\let} because we need an expandable token
16
%D in a \type {\write}.
17 18
\bgroup
19 20
\catcode
`
B
=
\begingroupcatcode
21
\catcode
`
E
=
\endgroupcatcode
22
\catcode
`
.
=
\escapecatcode
23 24
.
catcode
`
.
{
1
2
.
xdef
.
letterleftbrace
B
.
string
{
E
25
.
catcode
`
.
}
1
2
.
xdef
.
letterrightbrace
B
.
string
}
E
26
.
catcode
`
.
&
1
2
.
xdef
.
letterampersand
B
.
string
&
E
27
.
catcode
`
.
<
1
2
.
xdef
.
letterless
B
.
string
<
E
28
.
catcode
`
.
>
1
2
.
xdef
.
lettermore
B
.
string
>
E
29
.
catcode
`
.
#
1
2
.
xdef
.
letterhash
B
.
string
#
E
30
.
catcode
`
.
"
1
2
.
xdef
.
letterdoublequote
B
.
string
"
E
31
.
catcode
`
.
'
1
2
.
xdef
.
lettersinglequote
B
.
string
'
E
32
.
catcode
`
.
$
1
2
.
xdef
.
letterdollar
B
.
string
$
E
33
.
catcode
`
.
% 12 .xdef .letterpercent B.string%E
34
.
catcode
`
.
^
1
2
.
xdef
.
letterhat
B
.
string
^
E
35
.
catcode
`
.
_
1
2
.
xdef
.
letterunderscore
B
.
string
_
E
36
.
catcode
`
.
|
1
2
.
xdef
.
letterbar
B
.
string
|
E
37
.
catcode
`
.
~
1
2
.
xdef
.
lettertilde
B
.
string
~
E
38
.
catcode
`
.
\
1
2
.
xdef
.
letterbackslash
B
.
string
\E
39
.
catcode
`
.
/
1
2
.
xdef
.
letterslash
B
.
string
/
E
40
.
catcode
`
.
?
1
2
.
xdef
.
letterquestionmark
B
.
string
?
E
41
.
catcode
`
.
!
1
2
.
xdef
.
letterexclamationmark
B
.
string
!
E
42
.
catcode
`
.
@
1
2
.
xdef
.
letterat
B
.
string
@
E
43
.
catcode
`
.
:
1
2
.
xdef
.
lettercolon
B
.
string
:
E
44 45
.
catcode
`
.
(
1
2
.
xdef
.
letterleftparenthesis
B
.
string
(
E
46
.
catcode
`
.
)
1
2
.
xdef
.
letterrightparenthesis
B
.
string
)
E
47
.
catcode
`
.
[
1
2
.
xdef
.
letterleftbracket
B
.
string
[
E
48
.
catcode
`
.
]
1
2
.
xdef
.
letterrightbracket
B
.
string
]
E
49 50
.
global
.
let
.
letterescape
.
letterbackslash
51
.
global
.
let
.
letterbgroup
.
letterleftbrace
52
.
global
.
let
.
letteregroup
.
letterrightbrace
53
.
global
.
let
.
letteropenbrace
.
letterleftbrace
54
.
global
.
let
.
letterclosebrace
.
letterrightbrace
55 56
.
egroup
57 58
\bgroup
59 60
\catcode
`_
=
\lettercatcode
61 62
%xdef\_n_u_l_{\expandafter\string\Uchar1} % nul(l)
63
%xdef\_s_o_h_{\expandafter\string\Uchar1} % start of header ^^^^0001
64
\xdef
\_s_t_x_
{
\expandafter\string\Uchar
2
}
% start of text ^^^^0002
65
\xdef
\_e_t_x_
{
\expandafter\string\Uchar
3
}
% end of text ^^^^0003
66
\xdef
\_e_o_t_
{
\expandafter\string\Uchar
4
}
% end of transmission ^^^^0004
67
%xdef\_e_n_q_{\expandafter\string\Uchar5} % enquiry
68
%xdef\_a_c_k_{\expandafter\string\Uchar6} % aknowledgement
69 70
\egroup
71 72
%D \macros
73
%D {uncatcodespecials,setnaturalcatcodes,setnormalcatcodes,
74
%D uncatcodecharacters,uncatcodeallcharacters,
75
%D uncatcodespacetokens}
76
%D
77
%D The following macros are more or less replaced by switching
78
%D to a catcode table (which we simulate in \MKII) but we keep
79
%D them for convenience and compatibility. Some old engine code
80
%D has been removed.
81 82
\normalprotected\def
\uncatcodespecials
{
\setcatcodetable
\nilcatcodes
\uncatcodespacetokens
}
83
\normalprotected\def
\setnaturalcatcodes
{
\setcatcodetable
\nilcatcodes
}
84
\normalprotected\def
\setnormalcatcodes
{
\setcatcodetable
\ctxcatcodes
}
% maybe \texcatcodes
85
\normalprotected\def
\uncatcodecharacters
{
\setcatcodetable
\nilcatcodes
}
% was fast version, gone now
86
\normalprotected\def
\uncatcodeallcharacters
{
\setcatcodetable
\nilcatcodes
}
% was slow one, with restore
87 88
\normalprotected\def
\uncatcodespacetokens
89
{
\catcode
\spaceasciicode
\spacecatcode
90
\catcode
\tabasciicode
\spacecatcode
91
\catcode
\formfeedasciicode
\endoflinecatcode
92
\catcode
\endoflineasciicode\endoflinecatcode
93
\catcode
\delasciicode
\ignorecatcode
}
94 95
%D \macros
96
%D {setverbosecharacter,setverbosecscharacters}
97
%D
98
%D Next follows a definition that lets some shortcuts expand to
99
%D themselves. This macro is meant for \POSTSCRIPT\ and \PDF\
100
%D code passed on to the backend.
101 102
\newtoks
\everyverbosechacters
103 104
\normalprotected\def
\setverbosecscharacter
#
1
%
105
{
\edef
#
1
{
\string
#
1
}}
106 107
\normalprotected\def
\setverbosecscharacters
108
{
\the
\everyverbosechacters
}
109 110
\bgroup
111 112
% if used often we can move the code inline
113 114
\catcode
\barasciicode
\activecatcode
115
\catcode
\tildeasciicode\activecatcode
116 117
\global
\everyverbosechacters
=
118
{
\setverbosecscharacter
|
\setverbosecscharacter
~%
context
specific
119
\setverbosecscharacter
\|
\setverbosecscharacter
\~
%
120
\setverbosecscharacter
\:
\setverbosecscharacter
\;
%
121
\setverbosecscharacter
\+
\setverbosecscharacter
\-
%
122
\setverbosecscharacter
\[
\setverbosecscharacter
\]
%
123
\setverbosecscharacter
\.
\setverbosecscharacter
\\
%
124
\setverbosecscharacter
\)
\setverbosecscharacter
\(
%
125
\setverbosecscharacter
\0
\setverbosecscharacter
\1
%
126
\setverbosecscharacter
\2
\setverbosecscharacter
\3
%
127
\setverbosecscharacter
\4
\setverbosecscharacter
\5
%
128
\setverbosecscharacter
\6
\setverbosecscharacter
\7
%
129
\setverbosecscharacter
\8
\setverbosecscharacter
\9
%
130
\setverbosecscharacter
\n
\setverbosecscharacter
\s
%
131
\setverbosecscharacter
\/
}
132 133
\egroup
134 135
%D (Inspired by a discussion on the \CONTEXT\ mailing list)
136
%D
137
%D In \TEX\ each character can have one of 16 catcodes. This way the
138
%D backslash, dollar, ampersand, hash and some more characters get
139
%D their special meaning. If you want to process tokens under a
140
%D certain catcode regime, passing arguments can interfere badly.
141
%D
142
%D \startbuffer[a]
143
%D \def\whatever#1{[#1]}
144
%D \whatever{whatever \type {\whatever{you want}} $or$ not!}
145
%D \stopbuffer
146
%D
147
%D \typebuffer[a]
148
%D
149
%D Here we pass an argument to \type {\whatever} but part of that
150
%D argument is to be processed under a different catcode regime, i.e.\
151
%D all characters that need to be typeset verbatim need to get
152
%D the catcode that makes it a letter. This is what we get when we typeset
153
%D the text verbatim:
154
%D
155
%D \starttyping
156
%D whatever \type {\whatever{you want}} $or$ not!
157
%D \stoptyping
158
%D
159
%D However, when passed to \type {\whatever} we get:
160
%D
161
%D \getbuffer[a]
162
%D
163
%D In \ETEX\ one can use \type {\scantokens} to circumvent this problem.
164
%D
165
%D \startbuffer[b]
166
%D \def\rescan#1{\scantokens{#1}}
167
%D \def\whatever#1{[\rescan{#1}]}
168
%D \whatever{whatever \type {\whatever{you want}} $or$ not!}
169
%D \stopbuffer
170
%D
171
%D \getbuffer[b] \typebuffer[b]
172
%D
173
%D This time the \type {\whatever} call gives:
174
%D
175
%D \getbuffer[b]
176
%D
177
%D In this example, two spaces have crept in. The first one, after the
178
%D macro name, is inserted by \TEX\ and cannot be avoided. The last space
179
%D is inserted by \type {\scantokens}, and is the consequence of the fact
180
%D that this macro mimics reading from a file. You can avoid the last
181
%D space by a slightly different definition:
182
%D
183
%D \startbuffer[c]
184
%D \def\rescan#1{\scantokens{#1\ignorespaces}}
185
%D \def\whatever#1{[\rescan{#1}]}
186
%D \whatever{whatever \type {\whatever{you want}} $or$ not!}
187
%D \stopbuffer
188
%D
189
%D \typebuffer[c]
190
%D
191
%D Unfortunately we still keep the first space, but at least it's better than
192
%D a failure:
193
%D
194
%D \getbuffer[c]
195 196
\def
\rescan
#
1
{
\scantokens
{
#
1
\ignorespaces
}}
197
\def
\rescanwithsetup
#
1
#
2
{
\begingroup
\directsetup
{
#
1
}
\scantokens
{
#
2
\ignorespaces
}
\endgroup
}
198 199
\ifx
\scantextokens
\undefined
\else
200
\def
\rescan
#
1
{
\scantextokens
{
#
1
}}
201
\def
\rescanwithsetup
#
1
#
2
{
\begingroup
\directsetup
{
#
1
}
\scantextokens
{
#
2
}
\endgroup
}
202
\fi
203 204
\endinput
205