summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/tools/tools-mkiv.tex
blob: cd5214b3fd6ab71cdc8ba8b37271715957b17b9e (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
% language=uk

% author    : Hans Hagen
% copyright : PRAGMA ADE & ConTeXt Development Team
% license   : Creative Commons Attribution ShareAlike 4.0 International
% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
% origin    : the ConTeXt distribution
%
% comment   : Because this manual is distributed with TeX distributions it comes with a rather
%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
%             that they describe. Using parts of the content otherwise can therefore conflict
%             with existing functionality and we cannot be held responsible for that. Many of
%             the manuals contain characteristic graphics and personal notes or examples that
%             make no sense when used out-of-context.
%
% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
%             to users for testing, feedback and corrections.

\usemodule[abr-02]

\setuplayout
  [width=middle,
   height=middle,
   backspace=2cm,
   topspace=1cm,
   footer=0pt,
   bottomspace=2cm]

\definecolor
  [DocumentColor]
  [r=.5]

\setuptype
  [color=DocumentColor]

\setuptyping
  [color=DocumentColor]

\setupalign
  [tolerant,stretch]

% \usetypescript
%   [iwona]
%
% \setupbodyfont
%   [iwona]

\setupbodyfont
  [ibmplex,rm]

\setuphead
  [chapter]
  [style=\bfc,
   color=DocumentColor]

\setuphead
  [section]
  [style=\bfb,
   color=DocumentColor]

\setuphead
  [sub  section]
  [style=\bfa,
   color=DocumentColor]

\setupinteraction
  [hidden]

\setupwhitespace
  [big]

\setupheadertexts
  []

\setupheadertexts
  []
  [{\DocumentColor \type {luatools mtxrun context}\quad\pagenumber}]

\usesymbols[cc]

\def\sTEXMFSTART{\type{texmfstart}}
\def\sLUATOOLS  {\type{luatools}}
\def\sMTXRUN    {\type{mtxrun}}
\def\sCONTEXT   {\type{context}}
\def\sKPSEWHICH {\type{kpsewhich}}
\def\sMKTEXLSR  {\type{mktexlsr}}
\def\sXSLTPROC  {\type{xsltproc}}

\usemodule[narrowtt]

\startdocument
  [metadata:author=Hans Hagen,
   metadata:title={Tools: luatools, mtxrun, context},
   author=Hans Hagen,
   affiliation=PRAGMA ADE,
   location=Hasselt NL,
   title=Tools,
   extra-1=luatools,
   extra-2=mtxrun,
   extra-3=context,
   support=www.contextgarden.net,
   website=www.pragma-ade.nl]

\startMPpage
    StartPage ;
        picture p ; p := image (
            for i=1 upto 21 :
                for j=1 upto 30 :
                    drawarrow (fullcircle rotated uniformdeviate 360) scaled 10 shifted (i*15,j*15) ;
                endfor ;
            endfor ;
        ) ;
        p := p ysized (bbheight(Page)-4mm) ;
        fill Page enlarged 2mm withcolor \MPcolor{DocumentColor} ;
        draw p shifted (center Page - center p) withpen pencircle scaled 2 withcolor .5white ;
        numeric dx ; dx := bbwidth(Page)/21 ;
        numeric dy ; dy := bbheight(Page)/30 ;
        p := textext("\tt\bf\white\getvariable{document}{extra-1}") xsized(14*dx) ;
        p := p shifted (-lrcorner p) shifted lrcorner Page shifted (-1dx,8dy) ;
        draw p ;
        p := textext("\tt\bf\white\getvariable{document}{extra-2}") xsized(14*dx) ;
        p := p shifted (-lrcorner p) shifted lrcorner Page shifted (-1dx,5dy) ;
        draw p ;
        p := textext("\tt\bf\white\getvariable{document}{extra-3}") xsized(14*dx) ;
        p := p shifted (-lrcorner p) shifted lrcorner Page shifted (-1dx,2dy) ;
        draw p ;
        setbounds currentpicture to Page ;
    StopPage
\stopMPpage

\startsubject[title=Contents]

\placelist[section][alternative=a]

\stopsubject

\startsection[title={Remark}]

This manual is work in progress. Feel free to submit additions or corrections.
Before you start reading, it is good to know that in order to get starting with
\CONTEXT, the easiest way to do that is to download the standalone distribution
from \type {contextgarden.net}. After that you only need to make sure that \type
{luatex} is in your path. The main command you use is then \sCONTEXT\ and
normally it does all the magic it needs itself.

\stopsection

\startsection[title={Introduction}]

Right from the start \CONTEXT\ came with programs that managed the process of
\TEX-ing. Although you can perfectly well run \TEX\ directly, it is a fact that
often multiple runs are needed as well as that registers need to be sorted.
Therefore managing a job makes sense.

First we had \TEXEXEC\ and \TEXUTIL, and both were written in \MODULA, and as
this language was not supported on all platforms the programs were rewritten in
\PERL. Following that a few more tools were shipped with \CONTEXT.

When we moved on to \RUBY\ all the \PERL\ scripts were rewritten and when
\CONTEXT\ \MKIV\ showed up, \LUA\ replaced \RUBY. As we use \LUATEX\ this means
that currently the tools and the main program share the same language. For \MKII\
scripts like \TEXEXEC\ will stay around but the idea is that there will be \LUA\
alternatives for them as well.

Because we shipped many scripts, and because the de facto standard \TEX\
directory structure expects scripts to be in certain locations we not only ship
tools but also some more generic scripts that locate and run these tools.

\stopsection

\startsection[title={The location}]

Normally you don't need to know so many details about where the scripts
are located but here they are:

\starttyping
<texroot>/scripts/context/perl
<texroot>/scripts/context/ruby
<texroot>/scripts/context/lua
<texroot>/scripts/context/stubs
\stoptyping

This hierarchy was actually introduced because \CONTEXT\ was shipped with a bunch
of tools. As mentioned, we nowadays focus on \LUA\ but we keep a few of the older
scripts around in the \PERL\ and \RUBY\ paths.Now, if you're only using \CONTEXT\
\MKIV, and this is highly recommended, you can forget about all but the \LUA\
scripts.

\stopsection

\startsection[title={The traditional finder}]

When you run scripts multiple times, and in the case of \CONTEXT\ they are even
run inside other scripts, you want to minimize the startup time. Unfortunately
the traditional way to locate a script, using \sKPSEWHICH, is not that fast,
especially in a setup with many large trees Also, because not all tasks can be
done with the traditional scripts (take format generation) we provided a runner
that could deal with this: \sTEXMFSTART. As this script was also used in more
complex workflows, it had several tasks:

\startitemize[packed]
\item locate scripts in the distribution and run them using the right
      interpreter
\item do this selectively, for instance identify the need for a run using
      checksums for potentially changed files (handy for image conversion)
\item pass information to child processes so that lookups are avoided
\item choose a distribution among several installed versions (set the root
      of the \TEX\ tree)
\item change the working directory before running the script
\item resolve paths and names on demand and launch programs with arguments
      where names are expanded controlled by prefixes (handy for
      \TEX-unware programs)
\item locate and open documentation, mostly as part the help systems in
      editors, but also handy for seeing what configuration file is used
\item act as a \KPSEWHICH\ server cq.\ client (only used in special cases,
      and using its own database)
\stopitemize

Of course there were the usual more obscure and undocumented features as
well. The idea was to use this runner as follows:

\starttyping
texmfstart texexec <further arguments>
texmfstart --tree <rootoftree> texexec <further arguments>
\stoptyping

These are just two ways of calling this program. As \sTEXMFSTART\ can initialize
the environment as well, it is basically the only script that has to be present
in the binary path. This is quite comfortable as this avoids conflicts in names
between the called scripts and other installed programs.

Of course calls like above can be wrapped in a shell script or batch file without
penalty as long as \sTEXMFSTART\ itself is not wrapped in a caller script that
applies other inefficient lookups. If you use the \CONTEXT\ minimals you can be
sure that the most efficient method is chosen, but we've seen quite inefficient
call chains elsewhere.

In the \CONTEXT\ minimals this script has been replaced by the one we will
discuss in the next section: \sMTXRUN\ but a stub is still provided.

\stopsection

\startsection[title={The current finder}]

In \MKIV\ we went a step further and completely abandoned the traditional lookup
methods and do everything in \LUA. As we want a clear separation between
functionality we have two main controlling scripts: \sMTXRUN\ and \sLUATOOLS. The
last name may look somewhat confusing but the name is just one on in a series.
\footnote {We have \type {ctxtools}, \type {exatools}, \type {mpstools}, \type
{mtxtools}, \type {pdftools}, \type {rlxtools}, \type {runtools}, \type
{textools}, \type {tmftools} and \type {xmltools}. Most if their funtionality is
already reimplemented.}

In \MKIV\ the \sLUATOOLS\ program is nowadays seldom used. It's just a drop in
for \sKPSEWHICH\ plus a bit more. In that respect it's rather dumb in that it
does not use the database, but clever at the same time because it can make one
based on the little information available when it runs. It can also be used to
generate format files either or not using \LUA\ stubs but in practice this is not
needed at all.

For \CONTEXT\ users, the main invocation of this tool is when the \TEX\ tree is
updated. For instance, after adding a font to the tree or after updating
\CONTEXT, you need to run:

\starttyping
mtxrun --generate
\stoptyping

After that all tools will know where to find stuff and how to behave well within
the tree. This is because they share the same code, mostly because they are
started using \sMTXRUN. For instance, you process a file with:

\starttyping
mtxrun --script context <somefile>
\stoptyping

Because this happens often, there's also a shortcut:

\starttyping
context <somefile>
\stoptyping

But this does use \sMTXRUN\ as well. The help information of \sMTXRUN\ is rather
minimalistic and if you have no clue what an option does, you probably never
needed it anyway. Here we discuss a few options. We already saw that we can
explicitly ask for a script:

\starttyping
mtxrun --script context <somefile>
\stoptyping

but

\starttyping
mtxrun context <somefile>
\stoptyping

also works. However, by using \type {--script} you limit te lookup to the valid
\CONTEXT\ \MKIV\ scripts. In the \TEX\ tree these have names prefixed by \type
{mtx-} and a lookup look for a plural as well. So, the next two lookups are
equivalent:

\starttyping
mtxrun --script font
mtxrun --script fonts
\stoptyping

Both will run \type {mtx-fonts.lua}. Actually, this is one of the scripts that
you might need when your font database is somehow outdated and not updated
automatically:

\starttyping
mtxrun --script fonts --reload --force
\stoptyping

Normally \sMTXRUN\ is all you need in order to run a script. However, there are a
few more options:

\ctxlua{os.execute("mtxrun > tools-mkiv-help.tmp")}

\typefile[ntyping]{tools-mkiv-help.tmp}

Don't worry,you only need those obscure features when you integrate \CONTEXT\ in
for instance a web service or when you run large projects where runs and paths
take special care.

\stopsection

\startsection[title={Updating}]

There are two ways to update \CONTEXT\ \MKIV. When you manage your
trees yourself or when you use for instance \TEXLIVE, you act as
follows:

\startitemize[packed]
\item download the file cont-tmf.zip from \type {www.pragma-ade.com} or elsewhere
\item unzip this file in a subtree, for instance \type {tex/texmf-local}
\item run \type {mtxrun --generate}
\item run \type {mtxrun --script font --reload}
\item run \type {mtxrun --script context --make}
\stopitemize

Or shorter:

\startitemize[packed]
\item run \type {mtxrun --generate}
\item run \type {mtxrun font --reload}
\item run \type {context --make}
\stopitemize

Normally these commands are not even needed, but they are a nice test if your
tree is still okay. To some extend \sCONTEXT\ is clever enough to decide if the
databases need to be regenerated and|/|or a format needs to be remade and|/|or if
a new font database is needed.

Now, if you also want to run \MKII, you need to add:

\startitemize[packed]
\item run \type {mktexlsr}
\item run \type {texexec --make}
\stopitemize

The question is, how to act when \sLUATOOLS\ and \sMTXRUN\ have been updated
themselves? In that case, after unzipping the archive, you need to do the
following:

\startitemize[packed]
\item run \type {luatools --selfupdate}
\item run \type {mtxrun --selfupdate}
\stopitemize

For quite a while we shipped so called \CONTEXT\ minimals. These zip files
contained only the resources and programs that made sense for running \CONTEXT.
Nowadays the minimals are installed and synchronized via internet. \footnote
{This project was triggered by Mojca Miklavec who is also in charge of this bit
of the \CONTEXT\ infrastructure. More information can be found at \type
{contextgarden.net}.} You can just run the installer again and no additional
commands are needed. In the console you will see several calls to \sMTXRUN\ and
\sLUATOOLS\ fly by.

\stopsection

\startsection[title={The tools}]

We only mention the tools here. The most important ones are \sCONTEXT\ and \type
{fonts}. You can ask for a list of installed scripts with:

\starttyping
mtxrun --script
\stoptyping

On my machine this gives:

\ctxlua{os.execute("mtxrun --script > tools-mkiv-help.tmp")}

\typefile[ntyping]{tools-mkiv-help.tmp}

The most important scripts are \type {mtx-fonts} and \type {mtx-context}. By
default fonts are looked up by filename (the \type {file:} prefix before font
names in \CONTEXT\ is default). But you can also lookup fonts by name (\type
{name:}) or by specification (\type {spec:}). If you want to use these two
methods, you need to generate a font database as mentioned in the previous
section. You can also use the font tool to get information about the fonts
installed on your system.

\stopsection

\startsection[title={Running \CONTEXT}]

The \sCONTEXT\ tool is what you will use most as it manages your
run.

\ctxlua{os.execute("context > tools-mkiv-help.tmp")}

\typefile[ntyping]{tools-mkiv-help.tmp}

There are few expert options too:

\ctxlua{os.execute("context --expert > tools-mkiv-help.tmp")}

\typefile[ntyping]{tools-mkiv-help.tmp}

You might as well forget about these unless you are one of the
\CONTEXT\ developers.

\stopsection

\startsection[title={Prefixes}]

A handy feature of \sMTXRUN\ (and as most features an inheritance of
\sTEXMFSTART) is that it will resolve prefixed arguments. This can be of help
when you run programs that are unaware of the \TEX\ tree but nevertheless need to
locate files in it.

\ctxlua{os.execute("mtxrun --prefixes > tools-mkiv-help.tmp")}

\typefile[ntyping]{tools-mkiv-help.tmp}

An example is:

\starttyping
mtxrun --execute xsltproc file:whatever.xsl file:whatever.xml
\stoptyping

The call to \sXSLTPROC\ will get two arguments, being the complete path to the
files (given that it can be resolved). This permits you to organize the files in
a similar was as \TEX\ files.

\stopsection

\startsection[title={Stubs}]

As the tools are written in the \LUA\ language we need a \LUA\ interpreter and of
course we use \LUATEX\ itself. On \UNIX\ we can copy \sLUATOOLS\ and \sMTXRUN\ to
files in the binary path with the same name but without suffix. Starting them in
another way is a waste of time, especially when \sKPSEWHICH\ is used to find
then, something which is useless in \MKIV\ anyway. Just use these scripts
directly as they are self contained.

For \sCONTEXT\ and other scripts that we want convenient access to, stubs are
needed, like:

\starttyping
#!/bin/sh
mtxrun --script context "$@"
\stoptyping

This is also quite efficient as the \sCONTEXT\ script \type {mtx-context} is
loaded in \sMTXRUN\ and uses the same database.

On \WINDOWS\ you can copy the scripts as|-|is and associate the suffix with
\LUATEX\ (or more precisely: \type {texlua}) but then all \LUA\ script will be
run that way which is not what you might want.

In \TEXLIVE\ stubs for starting scripts were introduced by Fabrice Popineau. Such
a stub would start for instance \sTEXMFSTART, that is: it located the script
(\PERL\ or \RUBY) in the \TEX\ tree and launched it with the right interpreter.
Later we shipped pseudo binaries of \sTEXMFSTART: a \RUBY\ interpreter plus
scripts wrapped into a self contained binary.

For \MKIV\ we don't need such methods and started with simple batch files,
similar to the \UNIX\ startup scripts. However, these have the disadvantage that
they cannot be used in other batch files without using the \type {start} command.
In \TEXLIVE\ this is taken care of by a small binary written bij T.M.\ Trzeciak
so on \TEXLIVE\ 2009 we saw a call chain from \type {exe} to \type {cmd} to \type
{lua} which is somewhat messy.

This is why we now use an adapted and stripped down version of that program that
is tuned for \sMTXRUN, \sLUATOOLS\ and \sCONTEXT. So, we moved from the original
\type {cmd} based approach to an \type {exe} one.

\starttyping
mtxrun.dll
mtxrun.exe
\stoptyping

You can copy \type {mtxrun.exe} to for instance \type {context.exe} and it will
still use \sMTXRUN\ for locating the right script. It also takes care of mapping
\sTEXMFSTART\ to \sMTXRUN. So we've removed the intermediate \type {cmd} step,
can run the script as any program, and most of all, we're as efficient as can be.
Of course this program is only meaningful for the \CONTEXT\ approach to tools.

It may all sound more complex than it is but once it works users will not notice
those details. Also, in practice not that much has changed in running the tools
between \MKII\ and \MKIV\ as we've seen no reason to change the methods.

\stopsection

\startsection[title={A detailed look at \sMTXRUN}]

This section is derived from Taco Hoekwaters presentation and article for the
2018 \CONTEXT\ meeting. You might want to read this is you want to benefit from
even the most obscure features. There is a bit of repetition with the previous
sections but so be it.

% macros specific to this section

\def\highlighted#1#2#3%
  {\testpage[4]
   \dontleavehmode
   \backgroundline[gray]{\tt\strut #1}
   \nowhitespace
   \startnarrower[left]
   \veryraggedright
   #2\par
   \doifsomething{#3}{{\it #3}}
   \stopnarrower}

\definestartstop
  [options]
  [before=\blank,
   after=\blank]

\def\option#1#2%
  {\highlighted{--#1}{#2}{}}

\definestartstop
  [mtxrunscripts]
  [before=\blank,after=\blank]

\def\mtxrunscriptv#1#2#3#4%
  {\highlighted{#1}{#3}{#4}}

\def\mtxrunscript#1#2#3%
  {\highlighted{#1}{#3}{}}

\definestartstop
  [mtxrunenvironment]
  [before=\blank,
   after=\blank]

\def\mtxrunenv#1#2%
  {\highlighted{#1}{#2}{}}

\startsubsection[title=Common flags]

Much of the code inside \MKIV\ can alter its behaviour based on either \quote
{trackers} (which add debugging information to the terminal and log output) or
\quote {directives} or \quote {experiments} (for getting code to perform some
alternate behaviour). Since this also affects the \LUA\ code within \sMTXRUN\
itself, it makes sense to list these options first.

Trackers enable more extensive status messages on the console or in \CONTEXT\
additional visual clues. Directives change behaviour that is not part of the
official interface and have no corresponding commands. Experiments are like
directives but not official (yet).

\startoptions
    \option
        {trackers}
        {show (known) trackers}
    \option
        {directives}
        {show (known) directives}
    \option
        {experiments}
        {show (known) experiments}
\stopoptions

Enabling directives, trackers and experiments:

\startoptions
    \option
        {trackers=list}
        {enable given trackers}
    \option
        {directives=list}
        {enable given directives}
    \option
        {experiments=list}
        {enable given experiments}
\stopoptions

The next tree (hidden) options are converted into \quote {directives} entries,
that are then enabled. These are just syntactic sugar for the relevant directive.

\startoptions
    \option
        {silent[=...]}
        {sets \type {logs.blocked={\%s}}}
    \option
        {errors[=...]}
        {sets \type {logs.errors={\%s}}}
    \option
        {noconsole}
        {sets \type {logs.target=file}}
\stopoptions

As you can see here, various directives (and even some trackers) have optional
arguments, which can make specifying such directives on the command line a bit of
a challenge. Explaining the details of all the directives is outside of the scope
of this article, but you can look them up in the \CONTEXT\ source by searching
for \typ {directives.register} and \typ {trackers.register}.

In verbose mode, \sMTXRUN\ itself gives more messages, and it also enables \typ
{resolvers.locating}, which is a tracker itself:

\startoptions
    \option
        {verbose}
        {give a bit more info}
\stopoptions

The \type {--timedlog} (hidden) option starts the \sMTXRUN\ output with a
timestamp line:

\startoptions
    \option
        {timedlog}
        {prepend output with a timestamp}
\stopoptions

\stopsubsection

\startsubsection[title=Setup for finding files and configurations]

The next block of options deals with the setup of \sMTXRUN\ itself. You do not
need to deal with these options unless you are messing with the \CONTEXT\
distribution yourself instead of relying on a prepackaged solution, or you need
to use kpathsea for some reason (typically in a \MKII\ environment). In
particular, \type {--progname} and \type {--tree} are often needed as well when
using the \type {kpse} options.

\startoptions
    \option
        {configurations}
        {show configuration order, alias \type {--show-configurations}}
    \option
        {resolve}
        {resolve prefixed arguments, see \type {--prefixes}, below}
\stopoptions

and:

\startoptions
    \option
        {usekpse}
        {use kpse as fallback (when no \MKIV\ and cache installed, often slower)}
    \option
        {forcekpse}
        {force using kpse (handy when no \MKIV\ and cache installed but less
         functionality)}
    \option
        {progname=str}
        {format or backend}
    \option
        {tree=pathtotree}
        {use given texmf tree (default file: \type {setuptex.tmf})}
\stopoptions

We don't provide such a \type {.tmf} file in the distribution.

\stopsubsection

\startsubsection[title=Options for finding files and reporting configurations]

Once the configuration setup is done, it makes sense to have a bunch of options
to use and|/|or query the configuration.

\startoptions
    \option
        {locate}
        {locate given filename in database (default) or system (uses the
         sub||options \type {--first}, \type {--all} and \type {--detail})}
    \option
        {autogenerate}
        {regenerate databases if needed (handy when used to run context in an
         editor)}
    \option
        {generate}
        {generate file database}
    \option
        {prefixes}
        {show supported prefixes for file searches}
    \option
        {variables}
        {show configuration variables (uses the sub||option \type {--pattern},
         and an alias is \type {--show-variables})}
    \option
        {expansions}
        {show configuration variable expansion (uses the sub||options
         \type{--pattern}, alias \type {--show-expansions})}
    \option
        {expand-braces}
        {expand complex variable}
    \option
        {resolve-path}
        {expand variable (completely resolve paths)}
    \option
        {expand-path}
        {expand variable (resolve paths)}
    \option
        {expand-var}
        {expand variable (resolves references inside variables, alias
         \type{--expand-variable})}
    \option
        {show-path}
        {show path expansion of \type {...} (alias \type {--path-value})}
    \option
        {var-value}
        {report value of variable (alias \type {--show-value})}
    \option
        {find-file}
        {report file location; it uses the sub||options \type {--all}, \type
         {--pattern}, and \type {--format}}
    \option
        {find-path}
        {report path of file}
\stopoptions

Hidden option:

\startoptions
    \option
        {format-path}
        {report format path}
\stopoptions

\stopsubsection

\startsubsection[title=Running code]

Here we come to the core functionality of \sMTXRUN: running scripts. First
there are few options that trigger how the running takes place:

\startoptions
    \option
        {path=runpath}
        {go to given path before execution}
    \option
        {ifchanged=filename}
        {only execute when given file has changed (this loads and saves an md5
         checksum from \type {filename.md5})}
    \option
        {iftouched=old,new}
        {only execute when given file has changed (time stamp)}
    \option
        {timedrun}
        {run a script or program and time its run (external)}
\stopoptions

Specifying both \type {--iftouched} and \type {--ifchanged} means both are
tested, and when either one is false, nothing will happen. These options have to
come before one of the next options:

\startoptions
    \option
        {script}
        {run an mtx script (where \LUA\ is the preferred method); it has the
         sub||options \typ {--nofiledatabase}, \typ {--autogenerate}, \type
         {--load}, and \type {--save}. The latter two are currently no|-|ops}
    \option
        {execute}
        {run a script or program externally (\type {texmfstart} method); it has
         sub||option \type {--noquotes}}
    \option
        {internal}
        {run a script using built|-|in libraries (alias is \type {--ctxlua})}
    \option
        {direct}
        {run an external program; it has the sub||option \type {--noquotes}}
\stopoptions

Since scripts potentially have their own options, any options intended for
\sMTXRUN\ itself have to come {\it before} the option that specifies the script
to run, and options for the script itself have to come {\it after} the option
that gives the script name. This is especially true when using \type {--script},
so it is important to check the order of your options.

Of the four above options, \type {--script} is the most important one, since that
is the one that finds and executes the \LUA\ \sMTXRUN\ scripts provided by the
distribution. With \typ {--nofiledatabase}, it will not attempt to resolve any
file names (which means you need either a local script or a full path name). On
the opposite side, when you also provide \typ {--autogenerate}, it will not only
attempt to resolve the file name, it will also regenerate the database if it
cannot find the script on the first try. In a future version of \CONTEXT, the
\type {--load} and \type {--save} will allow you to save|/|restore the current
command line in a file for reuse.

The shell return value of \sMTXRUN\ indicates whether the script was found. When
you specify something like \type {--script base}, \sMTXRUN\ actually searches
for \type {mtx-base.lua}, \type {mtx-bases.lua}, \type {mtx-t-base.lua}, \type
{mtx-t-bases.lua}, and \type {base.lua}, in that order. The
distribution||supplied scripts normally use \type {mtx-<name>.lua} as template.
The template names with \type {mtx-t-} prefix is reserved for third||party
scripts, and \type {<name>.lua} is just a last-ditch effort if nothing else
works. Scripts are looked for in the local path, and in whatever directories the
configuration variable \type {LUAINPUTS} points to.

The \type {--execute} option exists mostly for the non||\LUA\ {\MKII} scripts
that still exist in the distribution. It will try to find a matching interpreter
for non||\LUA\ scripts, and it is aware of a number of distribution||supplied
scripts so that if you specify \type {--execute texexec}, it knows that what you
really want to execute is \type {ruby texexec.rb}. Support is present for \RUBY\
(\type {.rb}, \LUA\ (\type {.lua}), python (\type {.py}) and \PERL\ (\type {.pl})
scripts (tested in that order). File resolving uses \type {TEXMFSCRIPTS} from the
configuration. The shell return value of \sMTXRUN\ indicates whether the script
was found and executed.

The \type {--internal} option uses the file search method of \type {--execute},
but then assumes this is a \LUA\ script and executes it internally like \type
{--script}. This is useful if you have a \LUA\ script in an odd location.

The last of the four options, \type {--direct}, directly executes an external
program. You need to give the full path for binaries not in the current shell
\type {PATH}, because no searching is done at all. The shell return value of
\sMTXRUN\ in this case is a boolean based on the return value of
\type {os.exec()}.

It is also possible to execute bare \LUA\ code directly:

\startoptions
    \option
        {evaluate}
        {run code passed on the command-line (between quotes)}
\stopoptions

\stopsubsection

\startsubsection[title=Options for maintenance of \sMTXRUN\ itself]

None of these are advertised. Normally developers should be the only ones needing
them, but if you made a change to one of the distributed libraries (maybe because
of a beta bug), you may need to run \type {--selfmerge} and \type {--selfupdate}.

\startoptions
    \option
        {selfclean}
        {remove embedded libraries}
    \option
        {selfmerge}
        {update embedded libraries in \type {mtxrun.lua}}
    \option
        {selfupdate}
        {copy \type {mtxlua.lua} to the executable directory, renamed \type
         {mtxrun}}
\stopoptions

\stopsubsection

\startsubsection[title=Creating stubs]

Stubs are little shortcuts that live in some binaries directory. For example, the
content of the \UNIX||style \sCONTEXT\ shell command is:

\starttyping
#!/bin/sh
mtxrun --script context "$@"
\stoptyping

Apart from the \sCONTEXT\ command itself (which is provided by the distribution),
use of stubs is discouraged. Still, the \sMTXRUN\ options are there because
sometimes existing workflows depend on executable tool names like \type
{ctxtools}.

\startoptions
    \option
        {makestubs}
        {create stubs for (context related) scripts}
    \option
        {removestubs}
        {remove stubs (context related) scripts}
    \option
        {stubpath=binpath}
        {paths where stubs will be written}
    \option
        {windows}
        {create windows (mswin) stubs (alias \type {--mswin})}
    \option
        {unix}
        {create unix (linux) stubs (alias \type {--linux})}
\stopoptions

\stopsubsection

\startsubsection[title=Remaining options]

The remaining options are hard to group into a subcategory. These are the
advertised options:

\startoptions
    \option
        {systeminfo}
        {show current operating system, processor, et cetera}
    \option
        {edit}
        {launch editor with found file; the editor is taken from the environment
         variable \type {MTXRUN_EDITOR}, or \type {TEXMFSTART_EDITOR}, or
         \type {EDITOR}, or as a last resort: \type {gvim}}
    \option
        {launch}
        {launch files like manuals, assumes os support (uses the sub||options
         \type {--all}, \type {--pattern} and \type {--list})}
\stopoptions

While these are sort of hidden options:

\startoptions
    \option
        {ansi}
        {colorize output to terminal using \ANSI\ escapes}
    \option
        {associate}
        {launch files like manuals, assumes os support. this function does not do
         any file searching, so you have to use either a local file or a full
         path name}
    \option
        {exporthelp}
        {output the \sMTXRUN\ \XML\ help blob (useful for creating man and \HTML\
         help pages)}
    \option
        {fmt}
        {shortcut for \type {--script base --fmt}}
    \option
        {gethelp}
        {attempt to look up remote \sCONTEXT\ command help (uses the sub||options
         \type{--command} and \type {--url})}
    \option
        {help}
        {print the \sMTXRUN\ help screen}
    \option
        {locale}
        {force setup of locale; unless you are certain you need this option, stay
         away from it, because it can interfere massively with \CONTEXT's \LUA\
         code}
    \option
        {make}
        {(re)create format files (aliases are \type {--ini} and \type {--compile})}
    \option
        {platform}
        {(alias is \type {--show-platform})}
    \option
        {run}
        {shortcut for \type {--script base --run}}
    \option
        {version}
        {print \sMTXRUN\ version}
\stopoptions

\stopsubsection

\startsubsection[title=Known scripts]

When you run \type {mtxrun --scripts}, it will output a list of \quote {known}
scripts. The definition of \quote {known} is important here: the list comprises
the scripts that are present in the same directory as \type {mtx-context.lua}
that do not have an extra hyphen in the name (like \type {mtx-t-...}scripts would
have). In a normal installation, this means it \quote {knows} almost all the
scripts that are distributed with \CONTEXT. Note: it skips over any files from
the distribution that do have an extra hyphen, like the \type {mtx-server}
support scripts.

Since this section is about \sMTXRUN, I'll just present the list of the scripts
that are \quote {known} in the current \CONTEXT\ beta as output by \sMTXRUN\
itself, and not get into detail about all of the script functionality (they all
have \type {--help} options if you want to find out more). Where we still felt the
need to explain something, there is an extra bit of text in italics.

\startmtxrunscripts
\mtxrunscript
    {babel}
    {1.20}
    {Babel Input To UTF Conversion}
\mtxrunscript
    {base}
    {1.35}
    {ConTeXt TDS Management Tool (aka luatools)}
\mtxrunscript
    {bibtex}
    {}
    {bibtex helpers (obsolete)}
\mtxrunscript
    {cache}
    {0.10}
    {ConTeXt & MetaTeX Cache Management}
\mtxrunscript
    {chars}
    {0.10}
    {MkII Character Table Generators}
\mtxrunscriptv
    {check}
    {0.10}
    {Basic ConTeXt Syntax Checking}
    {Occasionally useful on big projects, but be warned that it does not actually
     run any \TEX\ engine, so it is not 100\% reliable.}
\mtxrunscriptv
    {colors}
    {0.10}
    {ConTeXt Color Management}
    {This displays icc color tables by name}
\mtxrunscriptv
    {convert}
    {0.10}
    {ConTeXT Graphic Conversion Helpers}
    {A wrapper around ghostscript and imagemagick that offers some extra (batch
     processing) functionality.}
\mtxrunscript
    {dvi}
    {0.10}
    {ConTeXt DVI Helpers}
\mtxrunscriptv
    {epub}
    {1.10}
    {ConTeXt EPUB Helpers}
    {The EPUB manual (\type {epub-mkiv.pdf}) explains how to use this script.}
\mtxrunscriptv
    {evohome}
    {1.00}
    {Evohome Fetcher}
    {Evohome is a domotica system that controls your central heating}
\mtxrunscript
    {fcd}
    {1.00}
    {Fast Directory Change}
\mtxrunscriptv
    {flac}
    {0.10}
    {ConTeXt Flac Helpers}
    {Extracts information from \type{.flac} audio files into an \XML\ index.}
\mtxrunscript
    {fonts}
    {0.21}
    {ConTeXt Font Database Management}
\mtxrunscript
    {grep}
    {0.10}
    {Simple Grepper}
\mtxrunscript
    {interface}
    {0.13}
    {ConTeXt Interface Related Goodies}
\mtxrunscript
    {metapost}
    {0.10}
    {MetaPost to PDF processor}
\mtxrunscript
    {metatex}
    {0.10}
    {MetaTeX Process Management (obsolete)}
\mtxrunscript
    {modules}
    {1.00}
    {ConTeXt Module Documentation Generators}
\mtxrunscriptv
    {package}
    {0.10}
    {Distribution Related Goodies}
    {This script is used to create the generic \CONTEXT\ code used in
     \LUA\LATEX~c.s.}
\mtxrunscriptv
    {patterns}
    {0.20}
    {ConTeXt Pattern File Management}
    {Hyphenation patterns, that is \unknown}
\mtxrunscript
    {pdf}
    {0.10}
    {ConTeXt PDF Helpers}
\mtxrunscript
    {plain}
    {1.00}
    {Plain TeX Runner}
\mtxrunscript
    {profile}
    {1.00}
    {ConTeXt MkIV LuaTeX Profiler}
\mtxrunscript
    {rsync}
    {0.10}
    {Rsync Helpers}
\mtxrunscript
    {scite}
    {1.00}
    {Scite Helper Script}
\mtxrunscriptv
    {server}
    {0.10}
    {Simple Webserver For Helpers}
    {There are some subscripts associated with this.}
\mtxrunscript
    {synctex}
    {1.00}
    {ConTeXt SyncTeX Checker}
\mtxrunscript
    {texworks}
    {1.00}
    {TeXworks Startup Script}
\mtxrunscript
    {timing}
    {0.10}
    {ConTeXt Timing Tools}
\mtxrunscript
    {tools}
    {1.01}
    {Some File Related Goodies}
\mtxrunscript
    {unicode}
    {1.02}
    {Checker for \type{char-def.lua}}
\mtxrunscript
    {unzip}
    {0.10}
    {Simple Unzipper}
\mtxrunscript
    {update}
    {1.03}
    {ConTeXt Minimals Updater}
\mtxrunscript
    {watch}
    {1.00}
    {ConTeXt Request Watchdog}
\mtxrunscriptv
    {youless}
    {1.10}
    {YouLess Fetcher}
    {YouLess is a domotica system that tracks your home energy use.}
\stopmtxrunscripts

\stopsubsection

\startsubsection[title=Writing your own]

A well|-|written script has some required internal structure. It should start with
a module definition block. This gives some information about the module, but more
importantly, it prevents double|-|loading.

Here is an example:

\starttyping
if not modules then modules = { } end

modules ['mtx-envtest'] = {
    version   = 0.100,
    comment   = "companion to mtxrun.lua",
    author    = "Taco Hoekwater",
    copyright = "Taco Hoekwater",
    license   = "bsd"
}
\stoptyping

Next up is a variable containing the help information. The help information is actually
a bit of \XML\ stored in \LUA\ string. In the full example listing at the end of this
article, you can see what the internal structure is supposed to be like.

\starttyping
local helpinfo = [[
<?xml version="1.0"?>
<application>
  ....
</application>
]]
\stoptyping

And this help information is then used to create an instance of an \type
{application} table.

\starttyping
local application = logs.application {
    name     = "envtest",
    banner   = "Mtxrun environment demo",
    helpinfo = helpinfo,
}
\stoptyping

After this call, the \type {application} table contains (amongst some other
things) three functions that are very useful:

\startmtxrunenvironment
\mtxrunenv
    {identify()}
    {Prints out a banner identifying the current script to the user.}
\mtxrunenv
    {report(str)}
    {For printing information to the terminal with the script name as prefix.}
\mtxrunenv
    {export()}
    {Prints the \type {helpinfo} to the terminal, so it can easily be used for
     documentation purposes.}
\stopmtxrunenvironment

Next up, it is good to define your scripts' functionality in functions in a
private table. This prevents namespace pollution, and looks like this:

\starttyping
scripts          = scripts         or { }
scripts.envtest  = scripts.envtest or { }

function scripts.envtest.runtest()
    application.report("script name is " .. environment.ownname)
end
\stoptyping

And finally, identify the current script, followed by handling the provided
options (usually with an \type {if}||\type {else} statement).

\starttyping
if environment.argument("exporthelp") then
   application.export()
elseif environment.argument('test') then
   scripts.envtest.runtest()
else
    application.help()
end
\stoptyping

\stopsubsection

\startsubsection[title=Script environment]

\sMTXRUN\ includes lots of the internal \LUA\ helper libraries from \CONTEXT. We
actually maintain a version of the script without all those libraries included,
and before every (beta) \CONTEXT\ release, an amalgamated version of \sMTXRUN\ is
added to the distribution. In the merging process, all comments are stripped from
the embedded libraries, so if you want to know details, it is better to look in
the original \LUA\ source file.

Inside \sMTXRUN, the full list of embedded libraries can be queried via the array
\type {own.libs}:

\startalign[flushleft]
l-lua.lua l-macro.lua l-sandbox.lua l-package.lua l-lpeg.lua
l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua
l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua
l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua
util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua
util-lua.lua util-deb.lua util-tpl.lua util-sbx.lua util-mrg.lua util-env.lua
luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua
trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua
data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua
data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua
data-tmf.lua data -lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
\stopalign

In fact, the \LUA\ table \type {own} contains some other useful stuff like the
script's actual disk name and location (\type {own.name} and \type {own.path})
and some internal variables like a list of all the locations it searches for its
embedded libraries (\type {own.list}), which is used by the \type {--selfmerge}
option and also allows the non||amalgamated version to run (since otherwise \type
{--selfmerge} could not be bootstrapped).

\sMTXRUN\ offers a programming environment that makes it easy to write \LUA\
script. The most important element of that environment is a \LUA\ table that is
conveniently called \type {environment} (\type {util-env} does the actual work of
setting that up).

The bulk of \type {environment} consists of functions and variables that deal
with the command||line given by the user as \sMTXRUN\ does quite a bit of work on
the given command||line. The goal is to safely tuck all the given options into
the \type {arguments} and \type {files} tables. This work is done by two
functions called \type {initializearguments()} and \type {splitarguments()}.
These functions are part of the \type{environment} table, but you should not need
them as they have been called already once control is passed on to your script.

\startmtxrunenvironment
\mtxrunenv
    {arguments}
    {These are the processed options to the current script. The keys are option
     names (without the leading dashes) and the value is either \type {true} or a
     string with one level of shell quotes removed.}
\mtxrunenv
    {files}
    {This array holds all the non||option arguments to the current script.
     Typically, those are supposed to be files, but they could be any text,
     really.}
\mtxrunenv
    {getargument(name,partial)}
    {Queries the \type {arguments} table using a function. Its main reason for
     existence is the \type {partial} argument, which allows scripts to accept
     shortened command||line options (alias: \type {argument()}).}
\mtxrunenv
    {setargument(name,value)}
    {Sets a value in the \type {arguments} table. This can be useful in
     complicated scripts with default options.}
\stopmtxrunenvironment

In case you need access to the full command||line, there are some possibilities:

\startmtxrunenvironment
\mtxrunenv
    {arguments_after}
    {These are the unquoted but otherwise unprocessed arguments to your script as
     an array.}
\mtxrunenv
    {arguments_before}
    {These are the unquoted but otherwise unprocessed arguments to \sMTXRUN\
     before your scripts' name (so the last entry is usually \type {--script}).}
\mtxrunenv
    {rawarguments}
    {This is the whole unprocessed command||line as an array.}
\mtxrunenv
    {originalarguments}
    {Like \type{rawarguments}, but with some top||level quotes removed.}
\mtxrunenv
    {reconstructcommandline(arg,noquote)}
    {Tries to reconstruct a command||line from its arguments. It uses \type
     {originalarguments} if no \type {arg} is given. Take care: due to the
     vagaries of shell command||line processing, this may or may not work when
     quoting is involved.}
\stopmtxrunenvironment

\type{environment} also stores various bits of information you may find useful:

\startmtxrunenvironment
\mtxrunenv
    {validengines}
    {This table contains keys for \type {luatex} and \type {luajittex}. This is
     only relevant when \sMTXRUN\ itself is called via \LUATEX's \type {luaonly}
     option.}
\mtxrunenv
    {basicengines}
    {This table maps executable names to \type{validengines} entries.}
\mtxrunenv
    {default_texmfcnf}
    {This is the \type {texmfcnf} value from \type {kpathsea}, processed for use
     with \MKIV\ in the unlikely event this is needed.}
\mtxrunenv
    {homedir}
    {The user's home directory.}
\mtxrunenv
    {ownbin}
    {The name of the binary used to call \sMTXRUN.}
\mtxrunenv
    {ownmain}
    {The mapped version of \type {ownbin}.}
\mtxrunenv
    {ownname}
    {Full name of this instance of \sMTXRUN.}
\mtxrunenv
    {ownpath}
    {The path this  instance of \sMTXRUN\ resides in.}
\mtxrunenv
    {texmfos}
    {Operating system root directory path.}
\mtxrunenv
    {texos}
    {Operating system root directory name.}
\mtxrunenv
    {texroot}
    {\CONTEXT\ root directory path.}
\stopmtxrunenvironment

As well as some functions:

\startmtxrunenvironment
\mtxrunenv
    {texfile(filename)}
    {Locates a {\TEX} file.}
\mtxrunenv
    {luafile(filename)}
    {Locates a \LUA\ file.}
\mtxrunenv
    {loadluafile(filename,version)}
    {Locates, compiles and loads a \LUA\ file, possibly in compressed \type {.luc}
     format. In the compressed case, it uses the \type {version} to make sure the
     compressed form is up||to||date.}
\mtxrunenv
    {luafilechunk(filename,silent,macros)}
    {Locates and compiles a \LUA\ file, returning its contents as data.}
\mtxrunenv
    {make_format(name,arguments)}
    {Creates a format file and stores it in the \CONTEXT\ cache, used by \type
     {mtxrun --make}.}
\mtxrunenv
    {relativepath(path,root)}
    {Returns a modified version of \type {root} based on the relative path in
     \type {path}.}
\mtxrunenv
    {run_format(name,data,more)}
    {Run a \TEX\ format file.}
\stopmtxrunenvironment

\stopsubsection

\startsubsection[title=Shell return values]

As explained earlier, the shell return value of \sMTXRUN\ normally indicates
whether the script was found. If you are running a \CONTEXT\ release newer than
September 2018 and want to modify the shell return value from within your script,
you can use \type {os.exitcode}. Whatever value you assign to that variable will
be the shell return value of your script.

\stopsubsection

\stopsection

\startsubject[title={Colofon}]

\starttabulate[|B|p|]
    \NC author    \NC \documentvariable{author},
                      \documentvariable{affiliation},
                      \documentvariable{location} \NC \NR
    \NC           \NC Taco Hoekwater, extra \sMTXRUN\ section \NC \NR
    \NC version   \NC \currentdate \NC \NR
    \NC website   \NC \documentvariable{website} \endash\
                      \documentvariable{support} \NC \NR
    \NC copyright \NC \symbol[cc][cc-by-sa-nc] \NC \NR
\stoptabulate

\stopsubject

\stopdocument