summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkii/catc-sym.mkii
blob: 55782f11ed2111f2d42ac66d04ff3285abfa1294 (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
%D \module
%D   [       file=catc-sym,
%D        version=1997.01.03, % moved code
%D          title=\CONTEXT\ Catcode Macros,
%D       subtitle=Some Handy Constants,
%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.

% we now have loaded syst-* so we have all @@catcode constants

%D We want to have access to the raw alternatives of the
%D special characters. We use a \type {\xdef} instead of
%D \type {\let} because we need an expandable token in a
%D \type {\write}.

\bgroup

\catcode`B=\begingroupcatcode
\catcode`E=\endgroupcatcode
\catcode`.=\escapecatcode

.catcode `.{ 12 .xdef .letteropenbrace       B.string{E
.catcode `.} 12 .xdef .letterclosebrace      B.string}E
.catcode `.& 12 .xdef .letterampersand       B.string&E
.catcode `.< 12 .xdef .letterless            B.string<E
.catcode `.> 12 .xdef .lettermore            B.string>E
.catcode `.# 12 .xdef .letterhash            B.string#E
.catcode `." 12 .xdef .letterdoublequote     B.string"E
.catcode `.' 12 .xdef .lettersinglequote     B.string'E
.catcode `.$ 12 .xdef .letterdollar          B.string$E
.catcode `.% 12 .xdef .letterpercent         B.string%E
.catcode `.^ 12 .xdef .letterhat             B.string^E
.catcode `._ 12 .xdef .letterunderscore      B.string_E
.catcode `.| 12 .xdef .letterbar             B.string|E
.catcode `.~ 12 .xdef .lettertilde           B.string~E
.catcode `.\ 12 .xdef .letterbackslash       B.string\E
.catcode `./ 12 .xdef .letterslash           B.string/E
.catcode `.? 12 .xdef .letterquestionmark    B.string?E
.catcode `.! 12 .xdef .letterexclamationmark B.string!E
.catcode `.@ 12 .xdef .letterat              B.string@E
.catcode `.: 12 .xdef .lettercolon           B.string:E

         .global .let .letterescape     .letterbackslash
         .global .let .letterbgroup     .letteropenbrace
         .global .let .letteregroup     .letterclosebrace
         .global .let .letterleftbrace  .letteropenbrace
         .global .let .letterrightbrace .letterclosebrace

.egroup

%D \macros
%D   {uncatcodespecials,setnaturalcatcodes,setnormalcatcodes,
%D    uncatcodecharacters,uncatcodeallcharacters,
%D    uncatcodespacetokens}
%D
%D The following macros are more or less replaced by switching
%D to a catcode table (which we simulate in \MKII) but we keep
%D them for convenience and compatibility. Some old engine code
%D has been removed.

\def\uncatcodespecials     {\setcatcodetable\nilcatcodes \uncatcodespacetokens}
\def\setnaturalcatcodes    {\setcatcodetable\nilcatcodes}
\def\setnormalcatcodes     {\setcatcodetable\ctxcatcodes} % maybe \texcatcodes
\def\uncatcodecharacters   {\setcatcodetable\nilcatcodes} % was fast version, gone now
\def\uncatcodeallcharacters{\setcatcodetable\nilcatcodes} % was slow one, with restore

\def\uncatcodespacetokens
  {\catcode\spaceasciicode    \spacecatcode
   \catcode\formfeedasciicode \ignorecatcode
   \catcode\endoflineasciicode\endoflinecatcode
   \catcode\delasciicode      \ignorecatcode}

%D \macros
%D   {setverbosecharacter,setverbosecscharacters}
%D
%D Next follows a definition that lets some shortcuts expand to
%D themselves. This macro is meant for \POSTSCRIPT\ and \PDF\
%D code passed on to the backend.

\newtoks\everyverbosechacters

\def\setverbosecscharacter#1%
  {\edef#1{\string#1}}

\def\setverbosecscharacters
  {\the\everyverbosechacters}

\bgroup

    % if used often we can move the code inline

    \catcode\barasciicode  \activecatcode
    \catcode\tildeasciicode\activecatcode

    \global \everyverbosechacters =
      {\setverbosecscharacter |\setverbosecscharacter ~% context specific
       \setverbosecscharacter\|\setverbosecscharacter\~%
       \setverbosecscharacter\:\setverbosecscharacter\;%
       \setverbosecscharacter\+\setverbosecscharacter\-%
       \setverbosecscharacter\[\setverbosecscharacter\]%
       \setverbosecscharacter\.\setverbosecscharacter\\%
       \setverbosecscharacter\)\setverbosecscharacter\(%
       \setverbosecscharacter\0\setverbosecscharacter\1%
       \setverbosecscharacter\2\setverbosecscharacter\3%
       \setverbosecscharacter\4\setverbosecscharacter\5%
       \setverbosecscharacter\6\setverbosecscharacter\7%
       \setverbosecscharacter\8\setverbosecscharacter\9%
       \setverbosecscharacter\n\setverbosecscharacter\s%
       \setverbosecscharacter\/}

\egroup

%D (Inspired by a discussion on the \CONTEXT\ mailing list)
%D
%D In \TEX\ each character can have one of 16 catcodes. This way the
%D backslash, dollar, ampersand, hash and some more characters get
%D their  special meaning. If you want to process tokens under a
%D certain catcode  regime, passing arguments can interfere badly.
%D
%D \startbuffer[a]
%D \def\whatever#1{[#1]}
%D \whatever{whatever \type {\whatever{you want}} $or$ not!}
%D \stopbuffer
%D
%D \typebuffer[a]
%D
%D Here we pass an argument to \type {\whatever} but part of that
%D argument is to be processed under a different catcode regime, i.e.\
%D all characters that need to be typeset verbatim need to get
%D the catcode that makes it a letter. This is what we get when we typeset
%D the text verbatim:
%D
%D \starttyping
%D whatever \type {\whatever{you want}} $or$ not!
%D \stoptyping
%D
%D However, when passed to \type {\whatever} we get:
%D
%D \getbuffer[a]
%D
%D In \ETEX\ one can use  \type {\scantokens} to circumvent this problem.
%D
%D \startbuffer[b]
%D \def\rescan#1{\scantokens{#1}}
%D \def\whatever#1{[\rescan{#1}]}
%D \whatever{whatever \type {\whatever{you want}} $or$ not!}
%D \stopbuffer
%D
%D \getbuffer[b] \typebuffer[b]
%D
%D This time the \type {\whatever} call gives:
%D
%D \getbuffer[b]
%D
%D In this example, two spaces have crept in. The first one, after the
%D macro name, is inserted by \TEX\ and cannot be avoided. The last space
%D is inserted by \type {\scantokens}, and is the consequence of the fact
%D that this macro mimics reading from a file. You can avoid the last
%D space by a slightly different definition:
%D
%D \startbuffer[c]
%D \def\rescan#1{\scantokens{#1\ignorespaces}}
%D \def\whatever#1{[\rescan{#1}]}
%D \whatever{whatever \type {\whatever{you want}} $or$ not!}
%D \stopbuffer
%D
%D \typebuffer[c]
%D
%D Unfortunately we still keep the first space, but at least it's better than
%D a failure:
%D
%D \getbuffer[c]

\long\def\rescan#1{\scantokens{#1\ignorespaces}}
\long\def\rescanwithsetup#1#2{\begingroup\directsetup{#1}\scantokens{#2\ignorespaces}\endgroup}

\ifx\scantextokens\undefined \else
  \long\def\rescan#1{\scantextokens{#1}}
  \long\def\rescanwithsetup#1#2{\begingroup\directsetup{#1}\scantextokens{#2}\endgroup}
\fi

\endinput