summaryrefslogtreecommitdiff
path: root/tex/context/base/file-mod.mkvi
blob: 6259a04d819cd7fae9fcbe4a4a3195909abfb4b0 (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
188
189
190
191
192
193
194
%D \module
%D   [       file=file-mod, % was core-fil,
%D        version=20110701, % 1997.11.15,
%D          title=\CONTEXT\ File Macros,
%D       subtitle=Module Support,
%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.

\writestatus{loading}{ConTeXt File Macros / Modules}

\unprotect

\registerctxluafile{file-mod}{1.001}

%D \macros
%D   {usemodule}
%D
%D Most of \CONTEXT is preloaded in the format file. Some very
%D domain specific typesetting topics are however dealt with in
%D separate modules, e.g. typesetting of chemical structure
%D formulas. These modules are loaded by:
%D
%D \showsetup{usemodule}
%D
%D More information on the specific modules can be found in
%D their dedicated manuals. We use \type {\next} so that we
%D can \type {\end} in modules.

\def\dodousemodules#category#name%
  {\ctxcommand{usemodules("#category","#name","\truefilename{#name}")}}

\def\usemodules
  {\dotripleempty\dousemodules}

\let\usemodule\usemodules

\def\dousemodules[#category][#name][#parameters]%
  {\pushmacro\currentmodule
   \pushmacro\currentmoduleparameters
   \let\currentmoduleparameters\empty
   \ifthirdargument
     \doifelsenothing{#name}
       {\let\next\relax}
       {\def\currentmoduleparameters{#parameters}%
        \def\next{\processcommalist[#name]{\dodousemodules{#category}}}}%
   \else\ifsecondargument
     \doifelsenothing{#name}
       {\let\next\relax}
       {\doifassignmentelse{#name}
          {\def\currentmoduleparameters{#name}%
           \def\next{\processcommalist[#category]{\dodousemodules{}}}}
          {\def\next{\processcommalist[#name]{\dodousemodules{#category}}}}}%
   \else
     \def\next{\processcommalist[#category]{\dodousemodules{}}}%
   \fi\fi
   \next
   \popmacro\currentmoduleparameters
   \popmacro\currentmodule}

\let\currentmoduleparameters\empty
\let\currentmodule          \s!unknown

\unexpanded\def\startmodule
  {\doifnextoptionalelse\dostartmodule\nostartmodule}

\def\nostartmodule #name %
  {\dostartmodule[#name]}

\def\dostartmodule[#name]%
  {\pushmacro\currentmodule
   \pushmacro\currentmoduleparameters
   \def\currentmodule{#name}}

\unexpanded\def\stopmodule
  {\popmacro\currentmoduleparameters
   \popmacro\currentmodule}

\unexpanded\def\setupmodule
  {\dodoubleempty\dosetupmodule}

\def\dosetupmodule[#name][#parameters]%
  {\scratchtoks\expandafter{\currentmoduleparameters}%
   \ifsecondargument
     \getparameters[\??md:#name:][#parameters]%
     \expanded{\getparameters[\??md:#name:][\the\scratchtoks]}%
   \else
     \getparameters[\??md:\currentmodule:][#name]%
     \expanded{\getparameters[\??md:\currentmodule:][\the\scratchtoks]}%
   \fi
   \let\currentmoduleparameters\empty}

\def\moduleparameter    #name#parameter{\executeifdefined{\??md:#name:#parameter}{}}
\def\currentmoduleparameter  #parameter{\executeifdefined{\??md:\currentmodule:#parameter}{}}

\def\useluamodule  [#name]{\ctxlua{dofile(resolvers.findctxfile("#name"))}}
\def\luaenvironment #name {\ctxlua{dofile(resolvers.findctxfile("#name"))}}

% \usemodule[newmml]
% \usemodule[newmml][a=b]
% \usemodule[x][newmml]
% \usemodule[x][newmml][a=b]
%
% \startmodule [mathml]
%   \setupmodule[a=c] \relax [\currentmoduleparameter{a}] % user vars will be set afterwards
%   \setupmodule[a=c] \relax [\currentmoduleparameter{a}] % user vars are now forgotten
% \stopmodule

% one can introduce test sections with:
%
% \enablemode[newmml:test:\currentmoduleparameter{test}]
% \startmode[newmml:test:yes} ... \stopmode
%
% these will be ignored unless test=yes
%
% however, a better way is:

\let\stopmoduletestsection\donothing

\unexpanded\def\startmoduletestsection
  {\bgroup
   \setupmodule % we need to make sure that the vars are set
   \doifelse{\currentmoduleparameter\v!test}\v!yes
     {\egroup
      \writestatus{\currentmodule}{loading experimental code}}
     {\egroup
      \writestatus{\currentmodule}{skipping experimental code}%
      \gobbleuntil\stopmoduletestsection}}

% will become file-run

%D To save memory, we implement some seldomly used commands
%D in a lazy way. Nota bene: such runtime definitions are
%D global.
%D
%D \starttyping
%D \fetchruntimecommand\showaccents{\f!encodingprefix ...}
%D \stoptyping

\def\fetchruntimecommand#1#2%
  {\def#1{\dofetchruntimecommand#1{#2}}}

\def\dofetchruntimecommand#1#2%
  {\doifnotflagged{#2}
     {\let#1\undefined
      \startreadingfile
      \startnointerference % \bgroup
      \cleanupfeatures % better \setnormalcatcodes / test first
      \readfile{#2.\mksuffix}\donothing\donothing
      \stopnointerference  % \egroup
      \stopreadingfile
      \doglobal\setflag{#2}}%
   \ifx#1\undefined
     \writestatus\m!system{command \string#1 not found in file #2}%
     \gdef#1{{\infofont[unknown command \string#1]}}%
   \fi
   #1}

%D \macros
%D   {doifolderversionelse}
%D
%D We start with a macro specially for Aditya who wants to be able
%D to use development versions of \MKIV\ for real documents.
%D
%D \starttyping
%D \doifolderversionelse\contextversion{1010.10.10} {OLDER} {OKAY} => OLDER
%D \doifolderversionelse\contextversion{2020.20.20} {OLDER} {OKAY} => OKAY
%D \doifolderversionelse\contextversion{2020}       {OLDER} {OKAY} => OKAY
%D \stoptyping
%D
%D The version pattern is \type {yyyy.mm.dd} (with mm and dd being optional).

\def\doifolderversionelse#parent#child{\ctxcommand{doifolderversionelse("#parent","#child")}}
\def\doifoldercontextelse       #child{\ctxcommand{doifolderversionelse("#child")}}

%D Experimental:

\let\checkpreprocessor\relax

%D To be documented and probably moved

\def\documentresources{\@@erurl}

\unexpanded\def\setupexternalresources
  {\dodoubleargument\getparameters[\??er]}

\setupexternalresources
  [url=]

\protect \endinput