summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/lua/mtx-context.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-context.lua')
-rw-r--r--Master/texmf-dist/scripts/context/lua/mtx-context.lua53
1 files changed, 31 insertions, 22 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-context.lua b/Master/texmf-dist/scripts/context/lua/mtx-context.lua
index 5645e476050..3052365092a 100644
--- a/Master/texmf-dist/scripts/context/lua/mtx-context.lua
+++ b/Master/texmf-dist/scripts/context/lua/mtx-context.lua
@@ -66,7 +66,6 @@ expert options:
--update update context from website (not to be confused with contextgarden)
--profile profile job (use: mtxrun --script profile --analyze)
--timing generate timing and statistics overview
---tracefiles show some extra info when locating files (at the tex end)
--extra=name process extra (mtx-context-<name> in distribution)
--extras show extras
@@ -453,6 +452,7 @@ scripts.context.multipass = {
-- suffixes = { ".tuo", ".tuc" },
suffixes = { ".tuc" },
nofruns = 8,
+-- nofruns = 7, -- test oscillation
}
function scripts.context.multipass.hashfiles(jobname)
@@ -475,7 +475,7 @@ function scripts.context.multipass.changed(oldhash, newhash)
return false
end
-function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,currentrun,finalrun)
+function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,currentrun,finalrun,once)
-- take jobname from ctx
jobname = file.removesuffix(jobname)
local f = io.open(jobname..".top","w")
@@ -526,14 +526,15 @@ function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,curr
--
setalways("%% feedback and basic job control")
--
- -- Option file, we can pass more on the commandline some day soon.
+ -- Option file, we can pass more on the commandline some day soon. Actually we
+ -- should use directives and trackers.
--
setfixed ("timing" , "\\usemodule[timing]")
setfixed ("batchmode" , "\\batchmode")
setfixed ("batch" , "\\batchmode")
setfixed ("nonstopmode" , "\\nonstopmode")
setfixed ("nonstop" , "\\nonstopmode")
- setfixed ("tracefiles" , "\\tracefilestrue")
+ -- setfixed ("tracefiles" , "\\tracefilestrue")
setfixed ("nostats" , "\\nomkivstatistics")
setfixed ("paranoid" , "\\def\\maxreadlevel{1}")
--
@@ -554,6 +555,9 @@ function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,curr
setvalue ("setuppath" , "\\setupsystem[\\c!directory={%s}]")
setvalue ("randomseed" , "\\setupsystem[\\c!random=%s]")
setvalue ("arguments" , "\\setupenv[%s]")
+ if once then
+ setalways("\\enabledirectives[system.runonce]")
+ end
setalways("%% modes")
setvalues("modefile" , "\\readlocfile{%s}{}{}")
setvalues("mode" , "\\enablemode[%s]", true)
@@ -590,7 +594,7 @@ function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,curr
end
end
-function scripts.context.multipass.copyluafile(jobname)
+function scripts.context.multipass.copyluafile(jobname) -- obsolete
local tuaname, tucname = jobname..".tua", jobname..".tuc"
if lfs.isfile(tuaname) then
os.remove(tucname)
@@ -623,7 +627,7 @@ scripts.context.interfaces = {
de = "cont-de",
fr = "cont-fr",
nl = "cont-nl",
- cz = "cont-cz",
+ cs = "cont-cs",
it = "cont-it",
ro = "cont-ro",
pe = "cont-pe",
@@ -638,14 +642,18 @@ scripts.context.defaultformats = {
-- "plain"
}
+local lpegpatterns, Cs, P = lpeg.patterns, lpeg.Cs, lpeg.P
+
+local pattern = lpegpatterns.utfbom^-1 * (P("%% ") + P("% ")) * Cs((1-lpegpatterns.newline)^1)
+
local function analyze(filename) -- only files on current path
local f = io.open(file.addsuffix(filename,"tex"))
if f then
local t = { }
local line = f:read("*line") or ""
- local preamble = match(line,"[\254\255]*%%%s+(.+)$") -- there can be an utf bomb in front
+ local preamble = lpeg.match(pattern,line)
if preamble then
- for key, value in gmatch(preamble,"(%S+)=(%S+)") do
+ for key, value in gmatch(preamble,"(%S+)%s*=%s*(%S+)") do
t[key] = value
end
t.type = "tex"
@@ -661,7 +669,6 @@ local function analyze(filename) -- only files on current path
f:close()
return t
end
- return nil
end
local function makestub(wrap,template,filename,prepname)
@@ -898,7 +905,7 @@ function scripts.context.run(ctxdata,filename)
end
flags[#flags+1] = format('--backend="%s"',backend)
--
- local command = format("luatex %s %s", concat(flags," "), quote(filename))
+ local command = format("luatex %s %s \\stoptext", concat(flags," "), quote(filename))
local oldhash, newhash = scripts.context.multipass.hashfiles(jobname), { }
local once = environment.argument("once")
local maxnofruns = (once and 1) or scripts.context.multipass.nofruns
@@ -906,7 +913,7 @@ function scripts.context.run(ctxdata,filename)
for i=1,maxnofruns do
-- 1:first run, 2:successive run, 3:once, 4:last of maxruns
local kindofrun = (once and 3) or (i==1 and 1) or (i==maxnofruns and 4) or 2
- scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,i,false) -- kindofrun, currentrun, final
+ scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,i,false,once) -- kindofrun, currentrun, final
report("run %s: %s",i,command)
--~ print("\n") -- cleaner, else continuation on same line
print("") -- cleaner, else continuation on same line
@@ -1133,14 +1140,10 @@ function scripts.context.autoctx()
scripts.context.run(ctxdata)
end
--- todo: quite after first image
-
local template = [[
- \starttext
- \startMPpage %% %s
- input "%s" ;
- \stopMPpage
- \stoptext
+\starttext
+ \directMPgraphic{%s}{input "%s"}
+\stoptext
]]
local loaded = false
@@ -1211,7 +1214,8 @@ local temporary_runfiles = {
"tui", "tua", "tup", "ted", "tes", "top",
"log", "tmp", "run", "bck", "rlg",
"mpt", "mpx", "mpd", "mpo", "mpb", "ctl",
- "synctex.gz", "pgf"
+ "synctex.gz", "pgf",
+ "prep",
}
local persistent_runfiles = {
@@ -1219,7 +1223,8 @@ local persistent_runfiles = {
}
local special_runfiles = {
- "-mpgraph*", "-mprun*", "-temp-*"
+--~ "-mpgraph*", "-mprun*", "-temp-*" -- hm, wasn't this escaped?
+ "-mpgraph", "-mprun", "-temp-"
}
local function purge_file(dfile,cfile)
@@ -1393,6 +1398,9 @@ end
function scripts.context.extras(pattern)
-- only in base path, i.e. only official ones
+ if type(pattern) ~= "string" then
+ pattern = "*"
+ end
local found = resolvers.findfile("context.mkiv")
if found ~= "" then
pattern = file.join(dir.expandname(file.dirname(found)),format("mtx-context-%s.tex",pattern or "*"))
@@ -1638,6 +1646,7 @@ elseif environment.argument("ctx") then
elseif environment.argument("mp") or environment.argument("metapost") then
scripts.context.timed(scripts.context.metapost)
elseif environment.argument("version") then
+ application.identify()
scripts.context.version()
elseif environment.argument("touch") then
scripts.context.touch()
@@ -1648,7 +1657,7 @@ elseif environment.argument("expert") then
elseif environment.argument("modules") then
scripts.context.modules()
elseif environment.argument("extras") then
- scripts.context.extras()
+ scripts.context.extras(environment.files[1] or environment.argument("extras"))
elseif environment.argument("extra") then
scripts.context.extra()
elseif environment.argument("help") then
@@ -1675,7 +1684,7 @@ elseif environment.argument("purge") then
scripts.context.purge()
elseif environment.argument("purgeall") then
-- only when no filename given, supports --pattern
- scripts.context.purge(true)
+ scripts.context.purge(true,nil,true)
else
application.help("basic")
end