summaryrefslogtreecommitdiff
path: root/tex/context/base/cont-new.mkiv
blob: 107215e66657e7c4926b814b4682c294c0e17aa0 (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
%D \module
%D   [       file=cont-new,
%D        version=2006.10.04,
%D          title=\CONTEXT\ Miscellaneous Macros,
%D       subtitle=New Macros,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% \appendtoks
%     \writestatus\m!lua{tfm over afm, wide fonts not yet supported}
% \to \everystoptext

% \ctxlua { fonts.define.method = 2 }  % normally 3

\enablemode[mkiv] \setsystemmode{mkiv}

% potential new defaults:

% \setbreakpoints[compound]

\unprotect

% \appendtoks
%     \ctxlua{
%         table.insert(input.stop_actions, function()
%             tex.sprint(tex.ctxcatcodes,"\\immediatewriteutilitytua{end}")
%             tex.sprint(tex.ctxcatcodes,"\\immediatewriteutilitytua{}")
%             tex.sprint(tex.ctxcatcodes,"\\immediatewriteutilitytua{end of utility file}")
%         end)
%     }%
% \to \everyopenutilities

\def\writestatus#1#2{\ctxlua{ctx.writestatus(\!!bs#1\!!es,\!!bs#2\!!es)}}

\ifx\clearmarks\undefined
    \def\clearmarks  {\begingroup\afterassignment\doclearmarks\scratchcounter}
    \def\doclearmarks{\normalmarks\scratchcounter{}\endgroup}
\fi

\def\resetmark#1% we cannot use \normalmarks#1{}
  {\global\@EA\chardef\csname\@@mrk\string#1\endcsname\zerocount
   \@EA\clearmarks\csname\@@prk\string#1\endcsname
   \global\@EA\let\csname\@@trk\string#1\endcsname\empty
   \global\@EA\let\csname\@@frk\string#1\endcsname\empty
   \global\@EA\let\csname\@@brk\string#1\endcsname\empty
   \global\@EA\let\csname\@@crk\string#1\endcsname\empty}

% \appendtoks
%     \ctxlua{garbagecollector.update()}%
% \to \everyshipout

%D Since this can be a showstopper, we report the path at the beginning
%D as well as at the end of a run.

\writestatus\m!lua{used config path - \ctxlua{tex.print(caches.configpath())}}
\writestatus\m!lua{used cache path  - \ctxlua{tex.print(caches.path)}}

%D For the moment we report some statistics. Later this will become an option,
%D but for now we need this information.

% \appendtoks
%     \ctxlua{ctx.show_statistics()}%
% \to \everygoodbye

\def\nomkivstatistics{\ctxlua{function ctx.show_statistics() end}} % for taco

\def\resettimer    {\ctxlua{environment.starttime = os.clock()}}
\def\elapsedtime   {\ctxlua{tex.sprint(os.clock()-environment.starttime)}}
\let\elapsedseconds \elapsedtime

\resettimer

% \appendtoks
%     \resettimer
% \to \everyjob

%D For me.

\def\traceluausage
  {\dosingleempty\dotraceluausage}

\def\dotraceluausage[#1]%
  {\ctxlua{debugger.enable()}%
   \appendtoks\ctxlua{debugger.disable() debugger.showstats(print,\doifnumberelse{#1}{#1}{5000})}\to\everybye}

%D Fonts (experimental AFM loading}

% \ctxlua {
%     remapper.define('encoding','^lm' ,'^(.*)$','lm-\letterpercent1')
%     remapper.define('encoding','^qbk','^(.*)$','q-\letterpercent1')
%     remapper.define('encoding','^qcs','^(.*)$','q-\letterpercent1')
%     remapper.define('encoding','^qpl','^(.*)$','q-\letterpercent1')
%     remapper.define('encoding','^qtm','^(.*)$','q-\letterpercent1')
% }

\appendtoksonce \loadallXfontmapfiles \to \everyPDFxform
\appendtoksonce \loadallXfontmapfiles \to \everyPDFximage
\appendtoksonce \loadallXfontmapfiles \to \everystarttext
\appendtoksonce \loadallXfontmapfiles \to \everybeforepagebody

\def\loadallXfontmapfiles{\ctxlua{fonts.map.flush("pdftex")}}

% \ctxlua{
%     do
%         local pth = "." .. io.fileseparator .. "tmp" .. io.fileseparator .. "\jobname"
%         texio.write_nl("CREATING "..pth)
%         os.execute("mkdir " .. pth)
%     end
%     input.output_files = { }
%     callback.register('find_write_file', function(id,name)
%         input.output_files[name] = file.join(".","tmp","\jobname",name)
%         texio.write_nl("REDIRECTING OUTPUT "..name.. " TO " .. input.output_files[name])
%         return input.output_files[name]
%     end)
%     callback.register('find_read_file', function(id,name)
%         local sname = string.gsub(name,"^\letterpercent./","")
%         if input.output_files[sname] then
%             return input.output_files[name]
%         elseif string.find(sname,"^\jobname[\letterpercent.\letterpercent-]") then
%             local n = file.join(".","tmp","\jobname",sname)
%             local f = io.open(n)
%             if f then
%                 input.output_files[name] = n
%                 texio.write_nl("REDIRECTING INPUT "..sname.. " TO " .. n)
%                 f:close()
%                 return n
%             else
%                 return input.findtexfile(name)
%             end
%         else
%             return input.findtexfile(name)
%         end
%     end)
% }

% The following commands need to be taken care of, e.g. because there is not yet
% a mkiv module for them. (Currently they're overloaded so we need to redefine them.)

\def\WORD {\groupedcommand{\setcharactercasing[\plusone  ]}{}}
\def\word {\groupedcommand{\setcharactercasing[\plustwo  ]}{}}
\def\Word {\groupedcommand{\setcharactercasing[\plusthree]}{}}
\def\Words{\groupedcommand{\setcharactercasing[\plusfour]}{}}

\let\WORDS\WORD
\let\words\word

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

\protect \endinput

% \expanded{\defineactivecharacter \number"2000E} {\textdir TRT\relax}
% \expanded{\defineactivecharacter \number"2000F} {\textdir TLT\relax}