char-act.mkiv /size: 4960 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=char-act,
3
%D version=2006.12.05,
4
%D title=\CONTEXT\ Character Support,
5
%D subtitle=Active,
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
Character
Support
/
Active
}
15 16
\unprotect
17 18
\ifdefined
\page_otr_fill_and_eject_page
\else
\let
\page_otr_fill_and_eject_page
\relax
\fi
% forward reference
19 20
%D \macros
21
%D {obeyedspace, obeyedtab, obeyedline, obeyedpage}
22
%D
23
%D We have followed Knuth in naming macros that make \SPACE,
24
%D \NEWLINE\ and \NEWPAGE\ active and assigning them
25
%D \type{\obeysomething}, but first we set some default values.
26 27
% These are expandable!
28 29
\def
\obeyedspace
{
\space
}
30
\def
\obeyedtab
{
\obeyedspace
}
31
\def
\obeyedline
{
\par
}
32
\def
\obeyedpage
{
\page_otr_fill_and_eject_page
}
33 34
%D \macros
35
%D {controlspace,setcontrolspaces}
36
%D
37
%D First we define \type{\obeyspaces}. When we want visible
38
%D spaces (control spaces) we only have to adapt the definition
39
%D of \type{\obeyedspace} to:
40 41
\chardef
\asciispacechar\spaceasciicode
% a real space character
42 43
\unexpanded
\def
\naturalspace
{
\asciispacechar
}
44
\unexpanded
\def
\controlspace
{
\hbox
{
\asciispacechar
}}
% rather tex, we need the unicode value
45
\unexpanded
\def
\normalspaces
{
\catcode
\spaceasciicode\spacecatcode
}
46 47
% \bgroup
48
% \catcode\spaceasciicode\activecatcode
49
% \unexpanded\gdef\obeyspaces {\catcode\spaceasciicode\activecatcode\def {\obeyedspace }}
50
% \unexpanded\gdef\setcontrolspaces{\catcode\spaceasciicode\activecatcode\def {\controlspace}}
51
% \egroup
52 53
%unexpanded\def\obeyspaces {\catcode\spaceasciicode\activecatcode\letcharcode\spaceasciicode\obeyedspace }
54
\unexpanded
\def
\setcontrolspaces
{
\catcode
\spaceasciicode\activecatcode
\letcharcode
\spaceasciicode
\controlspace
}
55 56
%D \macros
57
%D {obeytabs, obeylines, obeypages,ignoretabs, ignorelines, ignorepages}
58
%D
59
%D Next we take care of \NEWLINE\ and \NEWPAGE\ and because we
60
%D want to be able to typeset listings that contain \TAB, we
61
%D have to handle those too. Because we have to redefine the
62
%D \NEWPAGE\ character locally, we redefine the meaning of
63
%D this (often already) active character.
64 65
% \expandafter\def\activeformfeedtoken{\par}
66 67
\letcharcode
\formfeedasciicode
\par
68 69
%D The following indirect definitions enable us to implement
70
%D all kind of \type{\obeyed} handlers.
71 72
% \unexpanded\def\obeytabs {\catcode\tabasciicode \activecatcode\expandafter\def\activetabtoken {\obeyedtab }}
73
% \unexpanded\def\obeylines {\catcode\endoflineasciicode\activecatcode\expandafter\def\activeendoflinetoken{\obeyedline}}
74
% \unexpanded\def\obeypages {\catcode\formfeedasciicode \activecatcode\expandafter\def\activeformfeedtoken {\obeyedpage}}
75 76
% \unexpanded\def\ignoretabs {\catcode\tabasciicode \activecatcode\expandafter\def\activetabtoken {\obeyedspace}}
77
% \unexpanded\def\ignorelines{\catcode\endoflineasciicode\activecatcode\expandafter\def\activeendoflinetoken{\obeyedspace}}
78
% \unexpanded\def\ignorepages{\catcode\formfeedasciicode \ignorecatcode}
79
% \unexpanded\def\ignoreeofs {\catcode\endoffileasciicode\ignorecatcode}
80 81
% but ... as we don't want to freeze to \obeyedspace etc which can be set after \obeyspaces, we
82
% use an idirectness
83 84
\def
\_obeyed_space_
{
\obeyedspace
}
85
\def
\_obeyed_tab_
{
\obeyedtab
}
86
\def
\_obeyed_line_
{
\obeyedline
}
87
\def
\_obeyed_page_
{
\obeyedpage
}
88 89
\unexpanded
\def
\obeyspaces
{
\catcode
\spaceasciicode
\activecatcode
\letcharcode
\spaceasciicode
\_obeyed_space_
}
90
\unexpanded
\def
\obeytabs
{
\catcode
\tabasciicode
\activecatcode
\letcharcode
\tabasciicode
\_obeyed_tab_
}
91
\unexpanded
\def
\obeylines
{
\catcode
\endoflineasciicode\activecatcode
\letcharcode
\endoflineasciicode
\_obeyed_line_
}
92
\unexpanded
\def
\obeypages
{
\catcode
\formfeedasciicode
\activecatcode
\letcharcode
\formfeedasciicode
\_obeyed_page_
}
93 94
\unexpanded
\def
\ignoretabs
{
\catcode
\tabasciicode
\activecatcode
\letcharcode
\tabasciicode
\_obeyed_space_
}
95
\unexpanded
\def
\ignorelines
{
\catcode
\endoflineasciicode\activecatcode
\letcharcode
\endoflineasciicode
\_obeyed_space_
}
96
\unexpanded
\def
\ignorepages
{
\catcode
\formfeedasciicode
\ignorecatcode
}
97
\unexpanded
\def
\ignoreeofs
{
\catcode
\endoffileasciicode\ignorecatcode
}
98 99
\unexpanded
\def
\setcontrolspaces
{
\catcode
\spaceasciicode\activecatcode
\letcharcode
\spaceasciicode
\_control_space_
}
100 101
%D \macros
102
%D {naturaltextext}
103
%D
104
%D When one uses \ETEX, switching to normal \TEX\ is possible
105
%D too. We also introduce a switch that can be used in the
106
%D drivers and set in higher level shell macros.
107 108
\unexpanded
\def
\naturaltextext
#
1
\relax
% this command will become obsolete
109
{
\begingroup
110
\def
\ascii
{
#
1
}
%
111
\setcatcodetable
\ctxcatcodes
112
\prettynaturalfont
{
\scantextokens\expandafter
{
\ascii
}
\ifhmode
\unskip\fi
}
%
113
\endgroup
}
114 115
\endinput
\protect
116