diff options
Diffstat (limited to 'tex')
27 files changed, 535 insertions, 226 deletions
diff --git a/tex/context/base/chem-str.lua b/tex/context/base/chem-str.lua index 9fa5494fd..c76583fed 100644 --- a/tex/context/base/chem-str.lua +++ b/tex/context/base/chem-str.lua @@ -52,6 +52,7 @@ local v_big = variables.big local v_normal = variables.normal local v_fit = variables.fit local v_on = variables.on +local v_none = variables.none local mpnamedcolor = attributes.colors.mpnamedcolor local topoints = number.topoints @@ -602,20 +603,92 @@ end -- -- rulethickness in points +local function checked(d,factor,unit,scale) + if d == v_none then + return 0 + end + local n = tonumber(d) + if not n then + -- assume dimen + elseif n >= 10 or n <= -10 then + return factor * unit * n / 1000 + else + return factor * unit * n + end + local n = todimen(d) + if n then + return scale * n + else + return v_fit + end +end + +local function calculated(height,bottom,top,factor,unit,scale) + if height == v_none then + -- this always wins + height = "0pt" + bottom = "0pt" + top = "0pt" + elseif height == v_fit then + height = "true" + bottom = bottom == v_fit and "true" or topoints(checked(bottom,factor,unit,scale)) + top = top == v_fit and "true" or topoints(checked(top, factor,unit,scale)) + else + height = checked(height,factor,unit,scale) + if bottom == v_fit then + if top == v_fit then + bottom = height / 2 + top = bottom + else + top = checked(top,factor,unit,scale) + bottom = height - top + end + elseif top == v_fit then + bottom = checked(bottom,factor,unit,scale) + top = height - bottom + else + bottom = checked(bottom,factor,unit,scale) + top = checked(top, factor,unit,scale) + local ratio = height / (bottom+top) + bottom = bottom * ratio + top = top * ratio + end + top = topoints(top) + bottom = topoints(bottom) + height = topoints(height) + end + return height, bottom, top +end + function chemistry.start(settings) chemistry.structures = chemistry.structures + 1 - local emwidth, rulethickness, rulecolor, axiscolor = settings.emwidth, settings.rulethickness, settings.rulecolor, settings.framecolor - local width, height, scale, rotation, offset = settings.width or v_fit, settings.height or v_fit, settings.scale or "normal", settings.rotation or 0, settings.offset or 0 - local l, r, t, b = settings.left or v_fit, settings.right or v_fit, settings.top or v_fit, settings.bottom or v_fit + local unit = settings.unit or 655360 + local factor = settings.factor or 3 + local rulethickness = settings.rulethickness or 65536 + local rulecolor = settings.rulecolor or "" + local axiscolor = settings.framecolor or "" + local width = settings.width or v_fit + local height = settings.height or v_fit + local scale = settings.scale or "normal" + local rotation = settings.rotation or 0 + local offset = settings.offset or 0 + local left = settings.left or v_fit + local right = settings.right or v_fit + local top = settings.top or v_fit + local bottom = settings.bottom or v_fit -- metacode = { } -- align = settings.symalign or "auto" if trace_structure then - report_chemistry("%s scale %a, rotation %a, width %a, height %a, left %a, right %a, top %a, bottom %a","asked",scale,rotation,width,height,l,r,t,b) - report_chemistry("symalign: %s", align) + report_chemistry("unit %p, factor %s, symalign %s",unit,factor,align) + end + if align ~= "" then + align = "." .. align + end + if trace_structure then + report_chemistry("%s scale %a, rotation %a, width %s, height %s, left %s, right %s, top %s, bottom %s","asked",scale,rotation,width,height,left,right,top,bottom) end - if align ~= "" then align = "." .. align end if scale == v_small then scale = 1/1.2 elseif scale == v_normal or scale == v_medium or scale == 0 then @@ -633,107 +706,21 @@ function chemistry.start(settings) end end -- - -- -- shorter: - -- - -- local width = tonumber(width) or v_fit - -- if width ~= v_fit and (width >= 10 or width <= -10) then - -- width = width / 1000 - -- end + unit = scale * unit -- - if width ~= v_fit then - if tonumber(width) then - width = tonumber(width) - if width >= 10 or width <= -10 then - width = width / 1000 - end - else - width = v_fit - end - end - if r ~= v_fit then - if tonumber(r) then - r = tonumber(r) - if r >= 10 or r <= -10 then - r = r / 1000 - end - else - r = v_fit - end - end - if l ~= v_fit then - if tonumber(l) then - l = tonumber(l) - if l >= 10 or l <= -10 then - l = l / 1000 - end - else - l = v_fit - end - end - if width ~= v_fit and r == v_fit and l == v_fit then - l = width/2 - r = width/2 - elseif r == v_fit and l ~= v_fit and width ~= v_fit then - r = width - l -- left and width are specified, but not right - elseif l == v_fit and r ~= v_fit and width ~= v_fit then - l = width - r -- right and width are specified, but not left - end - -- setting both left and right overrides width (width is no longer needed) - if l == v_fit then l = "true" end - if r == v_fit then r = "true" end - -- - if height ~= v_fit then - if tonumber(height) then - height = tonumber(height) - if height >= 10 or height <= -10 then - height = height / 1000 - end - else - height = v_fit - end - end - if b ~= v_fit then - if tonumber(b) then - b = tonumber(b) - if b >= 10 or b <= -10 then - b = b / 1000 - end - else - b = v_fit - end - end - if t ~= v_fit then - if tonumber(t) then - t = tonumber(t) - if t >= 10 or t <= -10 then - t = t / 1000 - end - else - t = v_fit - end - end - if height ~= v_fit and b == v_fit and t == v_fit then - b = height/2 - t = height/2 - elseif b == v_fit and t ~= v_fit and height ~= v_fit then - b = height - t -- top and height are specified, but not bottom - elseif t == v_fit and b ~= v_fit and height ~= v_fit then - t = height - b -- bottom and height are specified, but not top - end - -- setting both top and bottom overrides height (height is no longer needed) - if b == v_fit then b = "true" end - if t == v_fit then t = "true" end + width, left, right = calculated(width, left, right,factor,unit,scale) + height, bottom, top = calculated(height,bottom,top, factor,unit,scale) -- rotation = tonumber(rotation) or 0 -- if trace_structure then - report_chemistry("%s scale %a, rotation %a, width %a, height %a, left %a, right %a, top %a, bottom %a","used",scale,rotation,width,height,l,r,t,b) + report_chemistry("%s scale %a, rotation %a, width %s, height %s, left %s, right %s, top %s, bottom %s","used",scale,rotation,width,height,left,right,top,bottom) end metacode[#metacode+1] = f_start_structure( chemistry.structures, - l, r, t, b, scale, rotation, - tostring(emwidth), tostring(offset), - tostring(settings.axis == v_on), tostring(rulethickness), tostring(axiscolor) + left, right, top, bottom, + rotation, topoints(unit), factor, topoints(offset), + tostring(settings.axis == v_on), topoints(rulethickness), tostring(axiscolor) ) metacode[#metacode+1] = f_set_tracing(trace_metapost) ; -- diff --git a/tex/context/base/chem-str.mkiv b/tex/context/base/chem-str.mkiv index a43b756b8..c28ea21d9 100644 --- a/tex/context/base/chem-str.mkiv +++ b/tex/context/base/chem-str.mkiv @@ -163,18 +163,19 @@ \ctxcommand{startchemical { width = "\chemicalparameter\c!width", height = "\chemicalparameter\c!height", - left = \chemicalparameter\c!left, - right = \chemicalparameter\c!right, - top = \chemicalparameter\c!top, - bottom = \chemicalparameter\c!bottom, + left = "\chemicalparameter\c!left", + right = "\chemicalparameter\c!right", + top = "\chemicalparameter\c!top", + bottom = "\chemicalparameter\c!bottom", scale = "\chemicalparameter\c!scale", rotation = "\chemicalparameter\c!rotation", symalign = "\chemicalparameter\c!symalign", axis = "\chemicalparameter\c!axis", framecolor = "\MPcolor{\chemicalparameter\c!framecolor}", - rulethickness = "\the\dimexpr\chemicalparameter\c!rulethickness\relax", - offset = "\the\dimexpr\chemicalparameter\c!offset\relax", - emwidth = "\the\emwidth", % EmWidth (\the\emwidth) does not work in MP... + rulethickness = \number\dimexpr\chemicalparameter\c!rulethickness\relax, + offset = \number\dimexpr\chemicalparameter\c!offset\relax, + unit = \number\dimexpr\chemicalparameter\c!unit\relax, + factor = \number\chemicalparameter\c!factor, } }% \startnointerference} @@ -689,12 +690,13 @@ \c!symalign=\v!auto, \c!location=, % not yet used (was interaction related in mkii) \c!offset=.25em, + \c!unit=\emwidth, + \c!factor=3, \c!color=, \c!strut=\v!yes, \c!framecolor=chemicalframecolor, \c!rulethickness=0.6pt, %1.5\linewidth, - \c!rulecolor=, - \c!factor=1] % how is factor used?? + \c!rulecolor=] %D Compatibility: diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex 2d4af29ec..b01bf0369 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png Binary files differindex da8d14758..e274ca41e 100644 --- a/tex/context/base/context-version.png +++ b/tex/context/base/context-version.png diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index bc697a9a6..dd9e85779 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -25,7 +25,8 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2013.03.29 01:03} +\edef\contextversion{2013.04.01 14:16} +\edef\contextkind {beta} %D For those who want to use this: @@ -64,10 +65,11 @@ \expandafter\end \fi -%D There is only this way to pass the version info -%D to \LUA\ (currently). +%D There is only this way to pass the version info to \LUA\ (currently). Hm, we could +%D now put it into the environment. \newtoks\contextversiontoks \contextversiontoks\expandafter{\contextversion} +\newtoks\contextkindtoks \contextkindtoks \expandafter{\contextkind} % \normaleverypar{\wait} % uncomment for test of funny injections @@ -89,8 +91,8 @@ \loadmarkfile{cldf-ini} -% From here on we have \unexpanded being \normalprotected, as we -% already had \unexpanded long before etex came around. +% From here on we have \unexpanded being \normalprotected, as we already had +% \unexpanded long before etex came around. \loadmarkfile{syst-aux} \loadmarkfile{syst-lua} @@ -501,7 +503,7 @@ \to \everyjob \appendtoks - \ctxlua{statistics.savefmtstatus("\jobname","\contextversion","context.mkiv")}% can become automatic + \ctxlua{statistics.savefmtstatus("\jobname","\contextversion","context.mkiv","\contextkind")}% can become automatic \to \everydump \errorstopmode \dump \endinput diff --git a/tex/context/base/data-lua.lua b/tex/context/base/data-lua.lua index 2725c149f..fde79d464 100644 --- a/tex/context/base/data-lua.lua +++ b/tex/context/base/data-lua.lua @@ -90,9 +90,9 @@ local function loadedbyformat(name,rawname,suffixes,islib) report("! lib %a located on %a",name,resolved) end if islib then - return loadedaslib(resolved,rawname) + return true, loadedaslib(resolved,rawname) else - return loadfile(resolved) + return true, loadfile(resolved) end end end @@ -100,19 +100,43 @@ end helpers.loadedbyformat = loadedbyformat +-- alternatively we could set the package.searchers + function helpers.loaded(name) local thename = gsub(name,"%.","/") local luaname = addsuffix(thename,"lua") local libname = addsuffix(thename,os.libsuffix) local libpaths = getlibpaths() local clibpaths = getclibpaths() - return loadedbyformat(luaname,name,libsuffixes,false) - or loadedbyformat(libname,name,clibsuffixes,true) - or loadedbypath(luaname,name,libpaths,false,"lua") - or loadedbypath(luaname,name,clibpaths,false,"lua") - or loadedbypath(libname,name,clibpaths,true,"lib") - or loadedbylua(name) - or notloaded(name) + local done, result = loadedbyformat(luaname,name,libsuffixes,false) + if done then + return result + end + local done, result = loadedbyformat(libname,name,clibsuffixes,true) + if done then + return result + end + local done, result = loadedbypath(luaname,name,libpaths,false,"lua") + if done then + return result + end + local done, result = loadedbypath(luaname,name,clibpaths,false,"lua") + if done then + return result + end + local done, result = loadedbypath(libname,name,clibpaths,true,"lib") + if done then + return result + end + local done, result = loadedbylua(name) + if done then + return result + end + return notloaded(name) end +package.searchers[3] = nil -- get rid of the built in one + +-- package.extraclibpath(environment.ownpath) + resolvers.loadlualib = require diff --git a/tex/context/base/data-res.lua b/tex/context/base/data-res.lua index f0b7a96cb..c69ee4ce3 100644 --- a/tex/context/base/data-res.lua +++ b/tex/context/base/data-res.lua @@ -12,6 +12,9 @@ if not modules then modules = { } end modules ['data-res'] = { -- instance but for practical purposes we now avoid this and use a -- instance variable. We always have one instance active (sort of global). +-- I will reimplement this module ... way too fuzzy now and we can work +-- with some sensible constraints as it is only is used for context. + -- todo: cache:/// home:/// selfautoparent:/// (sometime end 2012) local gsub, find, lower, upper, match, gmatch = string.gsub, string.find, string.lower, string.upper, string.match, string.gmatch @@ -870,7 +873,7 @@ local function collect_files(names) local files = blobpath and instance.files[blobpath] if files then if trace_detail then - report_resolving("deep checking %a (%s)",blobpath,bname) + report_resolving("deep checking %a, base %a, pattern %a",blobpath,bname,dname) end local blobfile = files[bname] if not blobfile then @@ -1022,7 +1025,7 @@ local function find_wildcard(filename,allresults) end end -local function find_qualified(filename,allresults) -- this one will be split too +local function find_qualified(filename,allresults,askedformat,alsostripped) -- this one will be split too if not file.is_qualified_path(filename) then return end @@ -1054,7 +1057,7 @@ local function find_qualified(filename,allresults) -- this one will be split too end end end - if suffix and suffix ~= "" then + if alsostripped and suffix and suffix ~= "" then -- try to find in tree (no suffix manipulation), here we search for the -- matching last part of the name local basename = filebasename(filename) @@ -1069,6 +1072,8 @@ local function find_qualified(filename,allresults) -- this one will be split too askedformat = "othertextfiles" -- kind of everything, maybe all end -- + -- is this really what we want? basename if we have an explicit path? + -- if basename ~= filename then local resolved = collect_instance_files(basename,askedformat,allresults) if #resolved == 0 then @@ -1291,7 +1296,7 @@ collect_instance_files = function(filename,askedformat,allresults) -- uses neste local results = { { find_direct (filename,true) }, { find_wildcard (filename,true) }, - { find_qualified(filename,true) }, + { find_qualified(filename,true,askedformat) }, -- we can add ,true if we want to find dups { find_intree (filename,filetype,wantedfiles,true) }, { find_onpath (filename,filetype,wantedfiles,true) }, { find_otherwise(filename,filetype,wantedfiles,true) }, @@ -1330,7 +1335,7 @@ collect_instance_files = function(filename,askedformat,allresults) -- uses neste if not result then method, result = find_wildcard(filename) if not result then - method, result = find_qualified(filename) + method, result = find_qualified(filename,false,askedformat) if not result then filetype, wantedfiles = find_analyze(filename,askedformat) method, result = find_intree(filename,filetype,wantedfiles) diff --git a/tex/context/base/font-def.lua b/tex/context/base/font-def.lua index 5dbd1f0fd..74073227a 100644 --- a/tex/context/base/font-def.lua +++ b/tex/context/base/font-def.lua @@ -437,6 +437,10 @@ function definers.read(specification,size,id) -- id can be optional, name can al return tfmdata end +function font.getfont(id) + return fontdata[id] -- otherwise issues +end + --[[ldx-- <p>We overload the <l n='tfm'/> reader.</p> --ldx]]-- diff --git a/tex/context/base/font-hsh.lua b/tex/context/base/font-hsh.lua index 42c4be950..d6c226b7c 100644 --- a/tex/context/base/font-hsh.lua +++ b/tex/context/base/font-hsh.lua @@ -176,3 +176,7 @@ setmetatableindex(dynamics, function(t,k) return dynamics end end) + +function font.getfont(id) + return identifiers[id] +end diff --git a/tex/context/base/l-dir.lua b/tex/context/base/l-dir.lua index 0568bcfb5..00cda3899 100644 --- a/tex/context/base/l-dir.lua +++ b/tex/context/base/l-dir.lua @@ -24,6 +24,7 @@ local walkdir = lfs.dir local isdir = lfs.isdir local isfile = lfs.isfile local currentdir = lfs.currentdir +local chdir = lfs.chdir -- in case we load outside luatex @@ -385,7 +386,7 @@ if onwindows then function dir.expandname(str) -- will be merged with cleanpath and collapsepath local first, nothing, last = match(str,"^(//)(//*)(.*)$") if first then - first = dir.current() .. "/" + first = dir.current() .. "/" -- dir.current sanitizes end if not first then first, last = match(str,"^(//)/*(.*)$") @@ -394,10 +395,10 @@ if onwindows then first, last = match(str,"^([a-zA-Z]:)(.*)$") if first and not find(last,"^/") then local d = currentdir() - if lfs.chdir(first) then + if chdir(first) then first = dir.current() end - lfs.chdir(d) + chdir(d) end end if not first then @@ -433,13 +434,16 @@ file.expandname = dir.expandname -- for convenience local stack = { } function dir.push(newdir) - insert(stack,lfs.currentdir()) + insert(stack,currentdir()) + if newdir and newdir ~= "" then + chdir(newdir) + end end function dir.pop() local d = remove(stack) if d then - lfs.chdir(d) + chdir(d) end return d end diff --git a/tex/context/base/l-lua.lua b/tex/context/base/l-lua.lua index 39f15cd65..555d5d746 100644 --- a/tex/context/base/l-lua.lua +++ b/tex/context/base/l-lua.lua @@ -159,9 +159,10 @@ end -- -- local mylib = require("libtest") -- -- local mysql = require("luasql.mysql") +local type = type local gsub, format = string.gsub, string.format -local package = package +local package = package local searchers = package.searchers or package.loaders local libpaths = nil @@ -203,48 +204,104 @@ end package.libpaths = getlibpaths package.clibpaths = getclibpaths -function package.extralibpath(...) - libpaths = getlibpaths() +local function addpath(what,paths,extras,hash,...) local pathlist = { ... } local cleanpath = helpers.cleanpath local trace = helpers.trace local report = helpers.report - for p=1,#pathlist do - local paths = pathlist[p] - for i=1,#paths do - local path = cleanpath(paths[i]) - if not libhash[path] then - if trace then - report("! extra lua path: %s",path) - end - libextras[#libextras+1] = path - libpaths [#libpaths +1] = path + -- + local function add(path) + local path = cleanpath(path) + if not hash[path] then + if trace then + report("! extra %s path: %s",what,path) end + paths [#paths +1] = path + extras[#extras+1] = path end end -end - -function package.extraclibpath(...) - clibpaths = getclibpaths() - local pathlist = { ... } - local cleanpath = helpers.cleanpath - local trace = helpers.trace - local report = helpers.report + -- for p=1,#pathlist do - local paths = pathlist[p] - for i=1,#paths do - local path = cleanpath(paths[i]) - if not clibhash[path] then - if trace then - report("! extra lib path: %s",path) - end - clibextras[#clibextras+1] = path - clibpaths [#clibpaths +1] = path + local path = pathlist[p] + if type(path) == "table" then + for i=1,#path do + add(path[i]) end + else + add(path) end end + return paths, extras +end + +function package.extralibpath(...) + libpaths, libextras = addpath("lua", getlibpaths(), libextras, libhash,...) +end + +function package.extraclibpath(...) + clibpaths, clibextras = addpath("lib",getclibpaths(),clibextras,clibhash,...) end +-- function package.extralibpath(...) +-- libpaths = getlibpaths() +-- local pathlist = { ... } +-- local cleanpath = helpers.cleanpath +-- local trace = helpers.trace +-- local report = helpers.report +-- -- +-- local function add(path) +-- local path = cleanpath(path) +-- if not libhash[path] then +-- if trace then +-- report("! extra lua path: %s",path) +-- end +-- libextras[#libextras+1] = path +-- libpaths [#libpaths +1] = path +-- end +-- end +-- -- +-- for p=1,#pathlist do +-- local path = pathlist[p] +-- if type(path) == "table" then +-- for i=1,#path do +-- add(path[i]) +-- end +-- else +-- add(path) +-- end +-- end +-- end + +-- function package.extraclibpath(...) +-- clibpaths = getclibpaths() +-- local pathlist = { ... } +-- local cleanpath = helpers.cleanpath +-- local trace = helpers.trace +-- local report = helpers.report +-- -- +-- local function add(path) +-- local path = cleanpath(path) +-- if not clibhash[path] then +-- if trace then +-- report("! extra lib path: %s",path) +-- end +-- clibextras[#clibextras+1] = path +-- clibpaths [#clibpaths +1] = path +-- end +-- end +-- -- +-- for p=1,#pathlist do +-- local path = pathlist[p] +-- if type(path) == "table" then +-- for i=1,#path do +-- add(path[i]) +-- end +-- else +-- add(path) +-- end +-- end +-- end + if not searchers[-2] then -- use package-path and package-cpath searchers[-2] = searchers[2] @@ -254,15 +311,22 @@ searchers[2] = function(name) return helpers.loaded(name) end +searchers[3] = nil -- get rid of the built in one + local function loadedaslib(resolved,rawname) - return package.loadlib(resolved,"luaopen_" .. gsub(rawname,"%.","_")) + -- local init = "luaopen_" .. string.match(rawname,".-([^%.]+)$") + local init = "luaopen_"..gsub(rawname,"%.","_") + if helpers.trace then + helpers.report("! calling loadlib with '%s' with init '%s'",resolved,init) + end + return package.loadlib(resolved,init) end local function loadedbylua(name) if helpers.trace then helpers.report("! locating '%s' using normal loader",name) end - return searchers[-2](name) + return true, searchers[-2](name) -- the original end local function loadedbypath(name,rawname,paths,islib,what) @@ -282,9 +346,9 @@ local function loadedbypath(name,rawname,paths,islib,what) report("! lib '%s' located on '%s'",name,resolved) end if islib then - return loadedaslib(resolved,rawname) + return true, loadedaslib(resolved,rawname) else - return loadfile(resolved) + return true, loadfile(resolved) end end end @@ -301,15 +365,29 @@ helpers.loadedbylua = loadedbylua helpers.loadedbypath = loadedbypath helpers.notloaded = notloaded +-- alternatively we could set the package.searchers + function helpers.loaded(name) local thename = gsub(name,"%.","/") local luaname = addsuffix(thename,"lua") local libname = addsuffix(thename,os.libsuffix or "so") -- brrr local libpaths = getlibpaths() local clibpaths = getclibpaths() - return loadedbypath(luaname,name,libpaths,false,"lua") - or loadedbypath(luaname,name,clibpaths,false,"lua") - or loadedbypath(libname,name,clibpaths,true,"lib") - or loadedbylua(name) - or notloaded(name) + local done, result = loadedbypath(luaname,name,libpaths,false,"lua") + if done then + return result + end + local done, result = loadedbypath(luaname,name,clibpaths,false,"lua") + if done then + return result + end + local done, result = loadedbypath(libname,name,clibpaths,true,"lib") + if done then + return result + end + local done, result = loadedbylua(name) + if done then + return result + end + return notloaded(name) end diff --git a/tex/context/base/luat-env.lua b/tex/context/base/luat-env.lua index e741bca6a..8753972c6 100644 --- a/tex/context/base/luat-env.lua +++ b/tex/context/base/luat-env.lua @@ -35,6 +35,14 @@ local mt = { else return "unknown" end + elseif k == "kind" then + local kind = tex.toks and tex.toks.contextkindtoks + if kind and kind ~= "" then + rawset(environment,"kind",kind) + return kind + else + return "unknown" + end elseif k == "jobname" or k == "formatname" then local name = tex and tex[k] if name or name== "" then diff --git a/tex/context/base/luat-lib.mkiv b/tex/context/base/luat-lib.mkiv index 26596c157..a2ad4cac4 100644 --- a/tex/context/base/luat-lib.mkiv +++ b/tex/context/base/luat-lib.mkiv @@ -30,6 +30,7 @@ \registerctxluafile{trac-inf}{1.001} %registerctxluafile{trac-pro}{1.001} \registerctxluafile{util-lua}{1.001} +\registerctxluafile{util-lib}{1.001} \registerctxluafile{util-deb}{1.001} % could also be done in trac-deb.mkiv \registerctxluafile{util-tpl}{1.001} % needs tracker diff --git a/tex/context/base/math-map.lua b/tex/context/base/math-map.lua index 7772a981c..9a8c8a69c 100644 --- a/tex/context/base/math-map.lua +++ b/tex/context/base/math-map.lua @@ -105,8 +105,8 @@ registerotffeature { -- fallbacks; symbols is currently mostly greek local function todigit(n) local t = { } for i=0, 9 do t[0x00030+i] = n+i end return t end -local function toupper(n) local t = { } for i=0,26 do t[0x00041+i] = n+i end return t end -local function tolower(n) local t = { } for i=0,26 do t[0x00061+i] = n+i end return t end +local function toupper(n) local t = { } for i=0,25 do t[0x00041+i] = n+i end return t end +local function tolower(n) local t = { } for i=0,25 do t[0x00061+i] = n+i end return t end local regular_tf = { digits = todigit(0x00030), diff --git a/tex/context/base/mult-ini.mkiv b/tex/context/base/mult-ini.mkiv index 79b94f202..52f9255c8 100644 --- a/tex/context/base/mult-ini.mkiv +++ b/tex/context/base/mult-ini.mkiv @@ -819,7 +819,7 @@ \def\contextbanner {ConTeXt \space - ver: \contextversion \space \contextmark \space \space + ver: \contextversion \space \contextmark \space \contextkind \space \space fmt: \formatversion \space \space int: \currentinterface/\currentresponses} diff --git a/tex/context/base/s-inf-01.mkvi b/tex/context/base/s-inf-01.mkvi index 9d624c168..8263413ac 100644 --- a/tex/context/base/s-inf-01.mkvi +++ b/tex/context/base/s-inf-01.mkvi @@ -78,13 +78,18 @@ end end local data = io.loaddata(name) - if suffix == "lua" then - data = gsub(data,"%-%-%[%[.-%]%]%-%-","") - data = gsub(data,"%-%-.-[\n\r]","") + if data then + if suffix == "lua" then + data = gsub(data,"%-%-%[%[.-%]%]%-%-","") + data = gsub(data,"%-%-.-[\n\r]","") + else + data = gsub(data,"%%.-[\n\r]","") + end + data = gsub(data,"%s","") else - data = gsub(data,"%%.-[\n\r]","") + logs.report("error","unknown file %a",name) + data = "" end - data = gsub(data,"%s","") sm[n+5] = sm[n+5] + #data if done then sm[n] = sm[n] + #data diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex 17e374e90..303deffba 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex ca5714750..ce82487af 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/status-mkiv.lua b/tex/context/base/status-mkiv.lua index 5f101e7d6..f08b2ec63 100644 --- a/tex/context/base/status-mkiv.lua +++ b/tex/context/base/status-mkiv.lua @@ -4724,6 +4724,12 @@ return { }, { category = "lua", + filename = "util-lib", + loading = "luat-lib", + status = "okay", + }, + { + category = "lua", filename = "util-mrg", loading = "luat-lib", status = "todo", diff --git a/tex/context/base/strc-con.mkvi b/tex/context/base/strc-con.mkvi index 13de171dc..0f5b202b9 100644 --- a/tex/context/base/strc-con.mkvi +++ b/tex/context/base/strc-con.mkvi @@ -248,11 +248,19 @@ \constructionparameter\c!before \begingroup \edef\currentconstructionalternative{\constructionparameter\c!alternative}% - % \checkconstructionalternativeparent % this catches an unknown alternative \edef\p_strc_constructions_renderingsetup{\constructionalternativeparameter\c!renderingsetup}% - \doifnotsetups\p_strc_constructions_renderingsetup - {\letconstructionparameter\c!alternative\v!left - \let\currentconstructionalternative\v!left}% + % catch fuzzyness + \ifx\p_strc_constructions_renderingsetup\empty + \letconstructionparameter\c!alternative\v!left + \let\currentconstructionalternative\v!left + \edef\p_strc_constructions_renderingsetup{\constructionalternativeparameter\c!renderingsetup}% + \else + \doifnotsetups\p_strc_constructions_renderingsetup + {\letconstructionparameter\c!alternative\v!left + \let\currentconstructionalternative\v!left + \edef\p_strc_constructions_renderingsetup{\constructionalternativeparameter\c!renderingsetup}}% + \fi + % \doadaptleftskip{\constructionparameter\c!margin}% \setlocalhsize % so we can use \localhsize in width assignments \edef\p_strc_constructions_distance{\constructionalternativeparameter\c!distance}% diff --git a/tex/context/base/strc-not.mkvi b/tex/context/base/strc-not.mkvi index a7cad42aa..324499b4e 100644 --- a/tex/context/base/strc-not.mkvi +++ b/tex/context/base/strc-not.mkvi @@ -1584,7 +1584,7 @@ \fi \begingroup \strc_notes_set_bodyfont - \getvalue{\??notealternative\noteparameter\c!alternative}% + \csname\??notealternative\noteparameter\c!alternative\endcsname \endgroup \ifvmode \noteparameter\c!after diff --git a/tex/context/base/trac-deb.lua b/tex/context/base/trac-deb.lua index 9e724f9fa..ba37447a6 100644 --- a/tex/context/base/trac-deb.lua +++ b/tex/context/base/trac-deb.lua @@ -6,7 +6,8 @@ if not modules then modules = { } end modules ['trac-deb'] = { license = "see context related readme files" } -local lpeg = lpeg +local lpeg, status = lpeg, status + local lpegmatch = lpeg.match local format, concat, match = string.format, table.concat, string.match local tonumber, tostring = tonumber, tostring diff --git a/tex/context/base/trac-tex.lua b/tex/context/base/trac-tex.lua index 362a1dd67..7e3406073 100644 --- a/tex/context/base/trac-tex.lua +++ b/tex/context/base/trac-tex.lua @@ -58,6 +58,7 @@ local function saveusedfilesintrees(format) local data = { jobname = environment.jobname or "?", version = environment.version or "?", + kind = environment.kind or "?", files = resolvers.instance.foundintrees } local filename = file.replacesuffix(environment.jobname or "context-job",'jlg') diff --git a/tex/context/base/util-lib.lua b/tex/context/base/util-lib.lua new file mode 100644 index 000000000..c987bdde3 --- /dev/null +++ b/tex/context/base/util-lib.lua @@ -0,0 +1,146 @@ +if not modules then modules = { } end modules ['util-lib'] = { + version = 1.001, + comment = "companion to luat-lib.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files", +} + +-- This is experimental code for Hans and Luigi. Don't depend on it! There +-- will be a plain variant. + +--[[ + +The problem with library bindings is manyfold. They are of course platform +dependent and while a binary with its directly related libraries are often +easy to maintain and load, additional libraries can each have their demands. + +One important aspect is that loading additional libraries from within the +loaded one is also operating system dependent. There can be shared libraries +elsewhere on the system and as there can be multiple libraries with the same +name but different usage and versioning there can be clashes. So there has to +be some logic in where to look for these sublibraries. + +We found out that for instance on windows libraries are by default sought on +the parents path and then on the binary paths and these of course can be in +an out of our control, thereby enlarging the changes on a clash. A rather +safe solution for that to load the library on the path where it sits. + +Another aspect is initialization. When you ask for a library t.e.x it will +try to initialize luaopen_t_e_x no matter if such an inializer is present. +However, because loading is configurable and in the case of luatex is already +partly under out control, this is easy to deal with. We only have to make +sure that we inform the loader that the library has been loaded so that +it won't load it twice. + +In swiglib we have chosen for a clear organization and although one can use +variants normally in the tex directory structure predictability is more or +less the standard. For instance: + +..../tex/texmf-mswin/bin/swiglib/gmwand + +]]-- + +local savedrequire = require +local loaded = package.loaded +local gsub, find = string.gsub, string.find + +--[[ + +A request for t.e.x is converted to t/e/x.dll or t/e/x.so depending on the +platform. Then we use the regular finder to locate the file in the tex +directory structure. Once located we goto the path where it sits, load the +file and return to the original path. We register as t.e.x in order to +prevent reloading and also because the base name is seldom unique. + +]]-- + +local function requireswiglib(required) + local library = loaded[required] + if not library then + local name = gsub(required,"%.","/") .. "." .. os.libsuffix + local full = resolvers.findfile(name,"lib") + -- local full = resolvers.findfile(name) + if not full or full == "" then + -- We can consider alternatives but we cannot load yet ... I + -- need to extent l-lua with a helper if we really want that. + -- + -- package.helpers.trace = true + -- package.extraclibpath(environment.ownpath) + end + local path = file.pathpart(full) + local base = file.nameonly(full) + dir.push(path) + -- if false then + -- local savedlibrary = loaded[base] + -- library = savedrequire(base) + -- loaded[base] = savedlibrary + -- else + library = package.loadlib(full,"luaopen_" .. base) + if type(library) == "function" then + library = library() + else + -- some error + end + -- end + dir.pop() + loaded[required] = library + end + return library +end + +--[[ + +For convenience we make the require loader function swiglib aware. Alternatively +we could put the specific loader in the global namespace. + +]]-- + +function require(name,...) -- this might disappear or change + if find(name,"^swiglib%.") then + return requireswiglib(name,...) + else + return savedrequire(name,...) + end +end + +--[[ + +At the cost of some overhead we provide a specific loader so that we can keep +track of swiglib usage which is handy for development. + +]]-- + +local report_swiglib = logs.reporter("swiglib") + +local swiglibs = { } + +function swiglib(name) + local library = swiglibs[name] + if not library then + statistics.starttiming(swiglibs) + report_swiglib("loading %a",name) + library = requireswiglib("swiglib." .. name) + swiglibs[name] = library + statistics.stoptiming(swiglibs) + end + return library +end + +statistics.register("used swiglibs", function() + if next(swiglibs) then + return string.format("%s, initial load time %s seconds",table.concat(table.sortedkeys(swiglibs)," "),statistics.elapsedtime(swiglibs)) + end +end) + +--[[ + +So, we now have: + +----- gm = requireswiglib("swiglib.gmwand.core") -- most bare method (not public in context) +local gm = require("swiglib.gmwand.core") -- nicer integrated (maybe not in context) +local gm = swiglib("gmwand.core") -- the context way + +Watch out, the last one is less explicit and lacks the swiglib prefix. + +]]-- diff --git a/tex/context/base/util-sto.lua b/tex/context/base/util-sto.lua index ddf699bca..191d6cd73 100644 --- a/tex/context/base/util-sto.lua +++ b/tex/context/base/util-sto.lua @@ -6,7 +6,7 @@ if not modules then modules = { } end modules ['util-sto'] = { license = "see context related readme files" } -local setmetatable, getmetatable = setmetatable, getmetatable +local setmetatable, getmetatable, type = setmetatable, getmetatable, type utilities = utilities or { } utilities.storage = utilities.storage or { } @@ -111,6 +111,9 @@ local t_table = { __index = f_table } local t_ignore = { __newindex = f_ignore } function table.setmetatableindex(t,f) + if type(t) ~= "table" then + f, t = t, { } + end local m = getmetatable(t) if m then if f == "empty" then @@ -137,6 +140,9 @@ function table.setmetatableindex(t,f) end function table.setmetatablenewindex(t,f) + if type(t) ~= "table" then + f, t = t, { } + end local m = getmetatable(t) if m then if f == "ignore" then @@ -155,6 +161,9 @@ function table.setmetatablenewindex(t,f) end function table.setmetatablecall(t,f) + if type(t) ~= "table" then + f, t = t, { } + end local m = getmetatable(t) if m then m.__call = f diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index a6a0a2e87..a7b4d64ee 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 03/29/13 01:03:45 +-- merge date : 04/01/13 14:16:57 do -- begin closure to overcome local limits and interference @@ -82,6 +82,7 @@ function optionalrequire(...) return result end end +local type=type local gsub,format=string.gsub,string.format local package=package local searchers=package.searchers or package.loaders @@ -113,45 +114,38 @@ local function getclibpaths() end package.libpaths=getlibpaths package.clibpaths=getclibpaths -function package.extralibpath(...) - libpaths=getlibpaths() +local function addpath(what,paths,extras,hash,...) local pathlist={... } local cleanpath=helpers.cleanpath local trace=helpers.trace local report=helpers.report - for p=1,#pathlist do - local paths=pathlist[p] - for i=1,#paths do - local path=cleanpath(paths[i]) - if not libhash[path] then - if trace then - report("! extra lua path: %s",path) - end - libextras[#libextras+1]=path - libpaths [#libpaths+1]=path + local function add(path) + local path=cleanpath(path) + if not hash[path] then + if trace then + report("! extra %s path: %s",what,path) end + paths [#paths+1]=path + extras[#extras+1]=path end end -end -function package.extraclibpath(...) - clibpaths=getclibpaths() - local pathlist={... } - local cleanpath=helpers.cleanpath - local trace=helpers.trace - local report=helpers.report for p=1,#pathlist do - local paths=pathlist[p] - for i=1,#paths do - local path=cleanpath(paths[i]) - if not clibhash[path] then - if trace then - report("! extra lib path: %s",path) - end - clibextras[#clibextras+1]=path - clibpaths [#clibpaths+1]=path + local path=pathlist[p] + if type(path)=="table" then + for i=1,#path do + add(path[i]) end + else + add(path) end end + return paths,extras +end +function package.extralibpath(...) + libpaths,libextras=addpath("lua",getlibpaths(),libextras,libhash,...) +end +function package.extraclibpath(...) + clibpaths,clibextras=addpath("lib",getclibpaths(),clibextras,clibhash,...) end if not searchers[-2] then searchers[-2]=searchers[2] @@ -159,14 +153,19 @@ end searchers[2]=function(name) return helpers.loaded(name) end +searchers[3]=nil local function loadedaslib(resolved,rawname) - return package.loadlib(resolved,"luaopen_"..gsub(rawname,"%.","_")) + local init="luaopen_"..gsub(rawname,"%.","_") + if helpers.trace then + helpers.report("! calling loadlib with '%s' with init '%s'",resolved,init) + end + return package.loadlib(resolved,init) end local function loadedbylua(name) if helpers.trace then helpers.report("! locating '%s' using normal loader",name) end - return searchers[-2](name) + return true,searchers[-2](name) end local function loadedbypath(name,rawname,paths,islib,what) local trace=helpers.trace @@ -185,9 +184,9 @@ local function loadedbypath(name,rawname,paths,islib,what) report("! lib '%s' located on '%s'",name,resolved) end if islib then - return loadedaslib(resolved,rawname) + return true,loadedaslib(resolved,rawname) else - return loadfile(resolved) + return true,loadfile(resolved) end end end @@ -207,11 +206,23 @@ function helpers.loaded(name) local libname=addsuffix(thename,os.libsuffix or "so") local libpaths=getlibpaths() local clibpaths=getclibpaths() - return loadedbypath(luaname,name,libpaths,false,"lua") - or loadedbypath(luaname,name,clibpaths,false,"lua") - or loadedbypath(libname,name,clibpaths,true,"lib") - or loadedbylua(name) - or notloaded(name) + local done,result=loadedbypath(luaname,name,libpaths,false,"lua") + if done then + return result + end + local done,result=loadedbypath(luaname,name,clibpaths,false,"lua") + if done then + return result + end + local done,result=loadedbypath(libname,name,clibpaths,true,"lib") + if done then + return result + end + local done,result=loadedbylua(name) + if done then + return result + end + return notloaded(name) end end -- closure @@ -10780,6 +10791,9 @@ function definers.read(specification,size,id) statistics.stoptiming(fonts) return tfmdata end +function font.getfont(id) + return fontdata[id] +end callbacks.register('define_font',definers.read,"definition of fonts (tfmdata preparation)") end -- closure diff --git a/tex/generic/context/luatex/luatex-languages.lua b/tex/generic/context/luatex/luatex-languages.lua index 712118dbc..1ea8c1fd1 100644 --- a/tex/generic/context/luatex/luatex-languages.lua +++ b/tex/generic/context/luatex/luatex-languages.lua @@ -6,7 +6,7 @@ if not modules then modules = { } end modules ['luatex-languages'] = { license = "see context related readme files" } --- We borrow fron ConTeXt. +-- We borrow from ConTeXt. languages = languages or { } |