summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2014-06-05 23:04:00 +0200
committerHans Hagen <pragma@wxs.nl>2014-06-05 23:04:00 +0200
commit1b8d827a6d33b746d004ac5cfab16de8840054e9 (patch)
tree9f9c49a37d2d1eb913d17dac51247cdfc296b2e7 /scripts
parentca16b82275f15170ca269f77b9dd9b0e29bbd7f6 (diff)
downloadcontext-1b8d827a6d33b746d004ac5cfab16de8840054e9.tar.gz
beta 2014.06.05 23:04
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtx-check.lua2
-rw-r--r--scripts/context/lua/mtx-metapost.lua60
-rw-r--r--scripts/context/lua/mtxrun.lua37
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua37
-rwxr-xr-xscripts/context/stubs/unix/mtxrun37
-rw-r--r--scripts/context/stubs/win64/mtxrun.lua37
6 files changed, 131 insertions, 79 deletions
diff --git a/scripts/context/lua/mtx-check.lua b/scripts/context/lua/mtx-check.lua
index 9f52509ec..1d6b48096 100644
--- a/scripts/context/lua/mtx-check.lua
+++ b/scripts/context/lua/mtx-check.lua
@@ -21,7 +21,7 @@ local helpinfo = [[
<flags>
<category name="basic">
<subcategory>
- <flag name="convert"><short>check tex file for errors</short></flag>
+ <flag name="check"><short>check tex file for errors</short></flag>
</subcategory>
</category>
</flags>
diff --git a/scripts/context/lua/mtx-metapost.lua b/scripts/context/lua/mtx-metapost.lua
index 08daec978..6306125d4 100644
--- a/scripts/context/lua/mtx-metapost.lua
+++ b/scripts/context/lua/mtx-metapost.lua
@@ -6,6 +6,8 @@ if not modules then modules = { } end modules ['mtx-metapost'] = { -- this was m
license = "see context related readme files"
}
+-- todo: load map files
+
local helpinfo = [[
<?xml version="1.0"?>
<application>
@@ -60,24 +62,42 @@ local function assumes_latex(filename)
return find(d,"\\documentstyle") or find(d,"\\documentclass") or find(d,"\\begin{document}")
end
+local basemaps = "original-base.map,original-ams-base.map,original-ams-euler.map,original-public-lm.map"
+
+local wrapper = "\\starttext\n%s\n%s\\stoptext"
+local loadmap = "\\loadmapfile[%s]\n"
local template = "\\startTEXpage\n\\convertMPtoPDF{%s}{1}{1}\n\\stopTEXpage"
local texified = "\\starttext\n%s\n\\stoptext"
local splitter = "\\startTEXpage\\externalfigure[%s][page=%s]\\stopTEXpage"
local tempname = "mptopdf-temp.tex"
-local function do_convert(filename)
+local function do_mapfiles(mapfiles)
+ local maps = { }
+ for i=1,#mapfiles do
+ local mapfile = mapfiles[i]
+ application.report("using map file %a",mapfile)
+ maps[i] = format(loadmap,mapfile)
+ end
+ return table.concat(maps)
+end
+
+local function do_convert(filename,mapfiles)
if find(filename,".%d+$") or find(filename,"%.mps$") then
- io.savedata(tempname,format(template,filename))
+ local body = format(template,filename)
+ local maps = do_mapfiles(mapfiles)
+ io.savedata(tempname,format(wrapper,maps,body))
local resultname = format("%s-%s.pdf",file.nameonly(filename),file.suffix(filename))
local result = os.execute(format([[context --once --batch --purge --result=%s "%s"]],resultname,tempname))
return lfs.isfile(resultname) and resultname
end
end
-local function do_split(filename,numbers)
+local function do_split(filename,numbers,mapfiles)
local name = file.nameonly(filename)
+ local maps = do_mapfiles(mapfiles)
for i=1,#numbers do
- io.savedata(tempname,format(splitter,file.addsuffix(name,"pdf"),i))
+ local body = format(splitter,file.addsuffix(name,"pdf"),i)
+ io.savedata(tempname,format(wrapper,maps,body))
local resultname = format("%s-%s.pdf",name,numbers[i])
local result = os.execute(format([[context --once --batch --purge --result=%s "%s"]],resultname,tempname))
end
@@ -99,12 +119,12 @@ local function do_texify(str)
return format(texified,str), numbers
end
-local function do_convert_all(filename)
+local function do_convert_all(filename,mapfiles)
local results = dir.glob(file.nameonly(filename) .. ".*") -- reset
local report = { }
for i=1,#results do
local filename = results[i]
- local resultname = do_convert(filename)
+ local resultname = do_convert(filename,mapfiles)
if resultname then
report[#report+1] = { filename, resultname }
end
@@ -121,8 +141,8 @@ local function do_convert_all(filename)
end
end
-local function do_convert_one(filename)
- local resultname = do_convert(filename)
+local function do_convert_one(filename,mapfiles)
+ local resultname = do_convert(filename,mapfiles)
if resultname then
report("%s => %s", filename,resultname)
else
@@ -131,17 +151,13 @@ local function do_convert_one(filename)
end
function scripts.mptopdf.convertall()
- local rawmp = environment.arguments.rawmp or false
- local metafun = environment.arguments.metafun or false
- local latex = environment.arguments.latex or false
- local pattern = environment.arguments.pattern or false
- local split = environment.arguments.split or false
- local files
- if pattern then
- files = dir.glob(file.nameonly(filename))
- else
- files = environment.files
- end
+ local rawmp = environment.arguments.rawmp or false
+ local metafun = environment.arguments.metafun or false
+ local latex = environment.arguments.latex or false
+ local pattern = environment.arguments.pattern or false
+ local split = environment.arguments.split or false
+ local files = pattern and dir.glob(file.nameonly(filename)) or environment.files
+ local mapfiles = utilities.parsers.settings_to_array(environment.arguments.mapfiles or basemaps)
if #files > 0 then
for i=1,#files do
local filename = files[i]
@@ -168,16 +184,16 @@ function scripts.mptopdf.convertall()
local done = os.execute(command)
if done then
if convert then
- do_convert_all(filename)
+ do_convert_all(filename,mapfiles)
elseif split then
- do_split(filename,numbers)
+ do_split(filename,numbers,mapfiles)
-- already pdf, maybe optionally split
end
else
report("error while processing mp file '%s'", filename)
end
else
- do_convert_one(filename)
+ do_convert_one(filename,mapfiles)
end
end
else
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index c31468122..8d49438a3 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -437,7 +437,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true
--- original size: 29983, stripped down to: 16202
+-- original size: 31588, stripped down to: 16483
if not modules then modules={} end modules ['l-lpeg']={
version=1.001,
@@ -566,9 +566,12 @@ patterns.integer=sign^-1*digit^1
patterns.unsigned=digit^0*period*digit^1
patterns.float=sign^-1*patterns.unsigned
patterns.cunsigned=digit^0*comma*digit^1
+patterns.cpunsigned=digit^0*(period+comma)*digit^1
patterns.cfloat=sign^-1*patterns.cunsigned
+patterns.cpfloat=sign^-1*patterns.cpunsigned
patterns.number=patterns.float+patterns.integer
patterns.cnumber=patterns.cfloat+patterns.integer
+patterns.cpnumber=patterns.cpfloat+patterns.integer
patterns.oct=zero*octdigit^1
patterns.octal=patterns.oct
patterns.HEX=zero*P("X")*(digit+uppercase)^1
@@ -985,21 +988,22 @@ function lpeg.append(list,pp,delayed,checked)
end
return p
end
-local function make(t)
- local p
+local function make(t,hash)
+ local p=P(false)
local keys=sortedkeys(t)
for i=1,#keys do
local k=keys[i]
local v=t[k]
- if not p then
+ local h=hash[v]
+ if h then
if next(v) then
- p=P(k)*make(v)
+ p=p+P(k)*(make(v,hash)+P(true))
else
- p=P(k)
+ p=p+P(k)*P(true)
end
else
if next(v) then
- p=p+P(k)*make(v)
+ p=p+P(k)*make(v,hash)
else
p=p+P(k)
end
@@ -1009,16 +1013,20 @@ local function make(t)
end
function lpeg.utfchartabletopattern(list)
local tree={}
+ local hash={}
for i=1,#list do
local t=tree
for c in gmatch(list[i],".") do
- if not t[c] then
- t[c]={}
+ local tc=t[c]
+ if not tc then
+ tc={}
+ t[c]=tc
end
- t=t[c]
+ t=tc
end
+ hash[t]=list[i]
end
- return make(tree)
+ return make(tree,hash)
end
patterns.containseol=lpeg.finder(eol)
local function nextstep(n,step,result)
@@ -4871,7 +4879,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-str"] = package.loaded["util-str"] or true
--- original size: 33334, stripped down to: 18384
+-- original size: 33456, stripped down to: 18419
if not modules then modules={} end modules ['util-str']={
version=1.001,
@@ -5001,6 +5009,7 @@ local striplinepatterns={
["retain"]=p_retain_normal,
["retain and collapse"]=p_retain_collapse,
["retain and no empty"]=p_retain_noempty,
+ ["collapse"]=patterns.collapser,
}
strings.striplinepatterns=striplinepatterns
function strings.striplines(str,how)
@@ -16893,8 +16902,8 @@ end -- of closure
-- used libraries : l-lua.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-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-mrg.lua util-tpl.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
-- skipped libraries : -
--- original bytes : 696010
--- stripped bytes : 247335
+-- original bytes : 697737
+-- stripped bytes : 248746
-- end library merge
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index c31468122..8d49438a3 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -437,7 +437,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true
--- original size: 29983, stripped down to: 16202
+-- original size: 31588, stripped down to: 16483
if not modules then modules={} end modules ['l-lpeg']={
version=1.001,
@@ -566,9 +566,12 @@ patterns.integer=sign^-1*digit^1
patterns.unsigned=digit^0*period*digit^1
patterns.float=sign^-1*patterns.unsigned
patterns.cunsigned=digit^0*comma*digit^1
+patterns.cpunsigned=digit^0*(period+comma)*digit^1
patterns.cfloat=sign^-1*patterns.cunsigned
+patterns.cpfloat=sign^-1*patterns.cpunsigned
patterns.number=patterns.float+patterns.integer
patterns.cnumber=patterns.cfloat+patterns.integer
+patterns.cpnumber=patterns.cpfloat+patterns.integer
patterns.oct=zero*octdigit^1
patterns.octal=patterns.oct
patterns.HEX=zero*P("X")*(digit+uppercase)^1
@@ -985,21 +988,22 @@ function lpeg.append(list,pp,delayed,checked)
end
return p
end
-local function make(t)
- local p
+local function make(t,hash)
+ local p=P(false)
local keys=sortedkeys(t)
for i=1,#keys do
local k=keys[i]
local v=t[k]
- if not p then
+ local h=hash[v]
+ if h then
if next(v) then
- p=P(k)*make(v)
+ p=p+P(k)*(make(v,hash)+P(true))
else
- p=P(k)
+ p=p+P(k)*P(true)
end
else
if next(v) then
- p=p+P(k)*make(v)
+ p=p+P(k)*make(v,hash)
else
p=p+P(k)
end
@@ -1009,16 +1013,20 @@ local function make(t)
end
function lpeg.utfchartabletopattern(list)
local tree={}
+ local hash={}
for i=1,#list do
local t=tree
for c in gmatch(list[i],".") do
- if not t[c] then
- t[c]={}
+ local tc=t[c]
+ if not tc then
+ tc={}
+ t[c]=tc
end
- t=t[c]
+ t=tc
end
+ hash[t]=list[i]
end
- return make(tree)
+ return make(tree,hash)
end
patterns.containseol=lpeg.finder(eol)
local function nextstep(n,step,result)
@@ -4871,7 +4879,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-str"] = package.loaded["util-str"] or true
--- original size: 33334, stripped down to: 18384
+-- original size: 33456, stripped down to: 18419
if not modules then modules={} end modules ['util-str']={
version=1.001,
@@ -5001,6 +5009,7 @@ local striplinepatterns={
["retain"]=p_retain_normal,
["retain and collapse"]=p_retain_collapse,
["retain and no empty"]=p_retain_noempty,
+ ["collapse"]=patterns.collapser,
}
strings.striplinepatterns=striplinepatterns
function strings.striplines(str,how)
@@ -16893,8 +16902,8 @@ end -- of closure
-- used libraries : l-lua.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-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-mrg.lua util-tpl.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
-- skipped libraries : -
--- original bytes : 696010
--- stripped bytes : 247335
+-- original bytes : 697737
+-- stripped bytes : 248746
-- end library merge
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index c31468122..8d49438a3 100755
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -437,7 +437,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true
--- original size: 29983, stripped down to: 16202
+-- original size: 31588, stripped down to: 16483
if not modules then modules={} end modules ['l-lpeg']={
version=1.001,
@@ -566,9 +566,12 @@ patterns.integer=sign^-1*digit^1
patterns.unsigned=digit^0*period*digit^1
patterns.float=sign^-1*patterns.unsigned
patterns.cunsigned=digit^0*comma*digit^1
+patterns.cpunsigned=digit^0*(period+comma)*digit^1
patterns.cfloat=sign^-1*patterns.cunsigned
+patterns.cpfloat=sign^-1*patterns.cpunsigned
patterns.number=patterns.float+patterns.integer
patterns.cnumber=patterns.cfloat+patterns.integer
+patterns.cpnumber=patterns.cpfloat+patterns.integer
patterns.oct=zero*octdigit^1
patterns.octal=patterns.oct
patterns.HEX=zero*P("X")*(digit+uppercase)^1
@@ -985,21 +988,22 @@ function lpeg.append(list,pp,delayed,checked)
end
return p
end
-local function make(t)
- local p
+local function make(t,hash)
+ local p=P(false)
local keys=sortedkeys(t)
for i=1,#keys do
local k=keys[i]
local v=t[k]
- if not p then
+ local h=hash[v]
+ if h then
if next(v) then
- p=P(k)*make(v)
+ p=p+P(k)*(make(v,hash)+P(true))
else
- p=P(k)
+ p=p+P(k)*P(true)
end
else
if next(v) then
- p=p+P(k)*make(v)
+ p=p+P(k)*make(v,hash)
else
p=p+P(k)
end
@@ -1009,16 +1013,20 @@ local function make(t)
end
function lpeg.utfchartabletopattern(list)
local tree={}
+ local hash={}
for i=1,#list do
local t=tree
for c in gmatch(list[i],".") do
- if not t[c] then
- t[c]={}
+ local tc=t[c]
+ if not tc then
+ tc={}
+ t[c]=tc
end
- t=t[c]
+ t=tc
end
+ hash[t]=list[i]
end
- return make(tree)
+ return make(tree,hash)
end
patterns.containseol=lpeg.finder(eol)
local function nextstep(n,step,result)
@@ -4871,7 +4879,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-str"] = package.loaded["util-str"] or true
--- original size: 33334, stripped down to: 18384
+-- original size: 33456, stripped down to: 18419
if not modules then modules={} end modules ['util-str']={
version=1.001,
@@ -5001,6 +5009,7 @@ local striplinepatterns={
["retain"]=p_retain_normal,
["retain and collapse"]=p_retain_collapse,
["retain and no empty"]=p_retain_noempty,
+ ["collapse"]=patterns.collapser,
}
strings.striplinepatterns=striplinepatterns
function strings.striplines(str,how)
@@ -16893,8 +16902,8 @@ end -- of closure
-- used libraries : l-lua.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-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-mrg.lua util-tpl.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
-- skipped libraries : -
--- original bytes : 696010
--- stripped bytes : 247335
+-- original bytes : 697737
+-- stripped bytes : 248746
-- end library merge
diff --git a/scripts/context/stubs/win64/mtxrun.lua b/scripts/context/stubs/win64/mtxrun.lua
index c31468122..8d49438a3 100644
--- a/scripts/context/stubs/win64/mtxrun.lua
+++ b/scripts/context/stubs/win64/mtxrun.lua
@@ -437,7 +437,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true
--- original size: 29983, stripped down to: 16202
+-- original size: 31588, stripped down to: 16483
if not modules then modules={} end modules ['l-lpeg']={
version=1.001,
@@ -566,9 +566,12 @@ patterns.integer=sign^-1*digit^1
patterns.unsigned=digit^0*period*digit^1
patterns.float=sign^-1*patterns.unsigned
patterns.cunsigned=digit^0*comma*digit^1
+patterns.cpunsigned=digit^0*(period+comma)*digit^1
patterns.cfloat=sign^-1*patterns.cunsigned
+patterns.cpfloat=sign^-1*patterns.cpunsigned
patterns.number=patterns.float+patterns.integer
patterns.cnumber=patterns.cfloat+patterns.integer
+patterns.cpnumber=patterns.cpfloat+patterns.integer
patterns.oct=zero*octdigit^1
patterns.octal=patterns.oct
patterns.HEX=zero*P("X")*(digit+uppercase)^1
@@ -985,21 +988,22 @@ function lpeg.append(list,pp,delayed,checked)
end
return p
end
-local function make(t)
- local p
+local function make(t,hash)
+ local p=P(false)
local keys=sortedkeys(t)
for i=1,#keys do
local k=keys[i]
local v=t[k]
- if not p then
+ local h=hash[v]
+ if h then
if next(v) then
- p=P(k)*make(v)
+ p=p+P(k)*(make(v,hash)+P(true))
else
- p=P(k)
+ p=p+P(k)*P(true)
end
else
if next(v) then
- p=p+P(k)*make(v)
+ p=p+P(k)*make(v,hash)
else
p=p+P(k)
end
@@ -1009,16 +1013,20 @@ local function make(t)
end
function lpeg.utfchartabletopattern(list)
local tree={}
+ local hash={}
for i=1,#list do
local t=tree
for c in gmatch(list[i],".") do
- if not t[c] then
- t[c]={}
+ local tc=t[c]
+ if not tc then
+ tc={}
+ t[c]=tc
end
- t=t[c]
+ t=tc
end
+ hash[t]=list[i]
end
- return make(tree)
+ return make(tree,hash)
end
patterns.containseol=lpeg.finder(eol)
local function nextstep(n,step,result)
@@ -4871,7 +4879,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-str"] = package.loaded["util-str"] or true
--- original size: 33334, stripped down to: 18384
+-- original size: 33456, stripped down to: 18419
if not modules then modules={} end modules ['util-str']={
version=1.001,
@@ -5001,6 +5009,7 @@ local striplinepatterns={
["retain"]=p_retain_normal,
["retain and collapse"]=p_retain_collapse,
["retain and no empty"]=p_retain_noempty,
+ ["collapse"]=patterns.collapser,
}
strings.striplinepatterns=striplinepatterns
function strings.striplines(str,how)
@@ -16893,8 +16902,8 @@ end -- of closure
-- used libraries : l-lua.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-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-mrg.lua util-tpl.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
-- skipped libraries : -
--- original bytes : 696010
--- stripped bytes : 247335
+-- original bytes : 697737
+-- stripped bytes : 248746
-- end library merge