diff options
author | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-05-14 17:38:55 +0000 |
---|---|---|
committer | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-05-14 17:38:55 +0000 |
commit | 15995e10bfc68edf79970c4ea4fbb6678566c46e (patch) | |
tree | 2de7ca2a83f2d37ef043ad7429a5cb945bb79ddb /Master/texmf-dist/tex/context/base/meta-ini.lua | |
parent | c9a39f716f1e5ec820ed3aab2c9aef25c5a9d730 (diff) |
ConTeXt 2012.05.14 16:00
git-svn-id: svn://tug.org/texlive/trunk@26371 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/meta-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/meta-ini.lua | 93 |
1 files changed, 83 insertions, 10 deletions
diff --git a/Master/texmf-dist/tex/context/base/meta-ini.lua b/Master/texmf-dist/tex/context/base/meta-ini.lua index 5150c38358f..bac1429ae1d 100644 --- a/Master/texmf-dist/tex/context/base/meta-ini.lua +++ b/Master/texmf-dist/tex/context/base/meta-ini.lua @@ -6,24 +6,97 @@ if not modules then modules = { } end modules ['meta-ini'] = { license = "see context related readme files" } -local format = string.format +local tonumber = tonumber +local format, gmatch, match, gsub = string.format, string.gmatch, string.match, string.gsub metapost = metapost or { } -- for the moment downward compatible -local report_metapost = logs.reporter ("metapost") +local report_metapost = logs.reporter ("metapost") local status_metapost = logs.messenger("metapost") local patterns = { "meta-imp-%s.mkiv", "meta-imp-%s.tex", "meta-%s.mkiv", "meta-%s.tex" } -- we are compatible -function metapost.uselibrary(name) - commands.uselibrary(name,patterns,function(name,foundname) - context.startreadingfile() - status_metapost("loaded: library '%s'",name) - context.input(foundname) - context.stopreadingfile() - end, function(name) - report_metapost("unknown: library '%s'",name) +local function action(name,foundname) + status_metapost("loaded: library '%s'",name) + context.startreadingfile() + context.input(foundname) + context.stopreadingfile() +end + +local function failure(name) + report_metapost("unknown: library '%s'",name) +end + +function commands.useMPlibrary(name) + commands.uselibrary { + name = name, + patterns = patterns, + action = action, + failure = failure, + onlyonce = true, + } +end + +-- experimental + +local colorhash = attributes.list[attributes.private('color')] + +local validdimen = lpeg.patterns.validdimen * lpeg.P(-1) + +local lpegmatch = lpeg.match +local textype = tex.type +local MPcolor = context.MPcolor + +function commands.prepareMPvariable(v) -- slow but ok + if v == "" then + MPcolor("black") + else + local typ, var = match(v,"(.):(.*)") + if not typ then + -- parse + if colorhash[v] then + MPcolor(v) + elseif tonumber(v) then + context(v) + elseif lpegmatch(validdimen,v) then + return context("\\the\\dimexpr %s",v) + else + for s in gmatch(v,"\\(.-)") do + local t = textype(s) + if t == "dimen" then + return context("\\the\\dimexpr %s",v) + elseif t == "count" then + return context("\\the\\numexpr %s",v) + end + end + return context("\\number %s",v) -- 0.4 ... + end + elseif typ == "d" then + -- dimension + context("\\the\\dimexpr %s",var) + elseif typ == "n" then + -- number + context("\\the\\numexpr %s",var) + elseif typ == "s" then + -- string + context(var) + elseif typ == "c" then + -- color + MPcolor(var) + else + context(var) + end + end +end + +function metapost.formatnumber(f,n) -- just lua format + f = gsub(f,"@(%d)","%%.%1") + f = gsub(f,"@","%%") + f = format(f,tonumber(n) or 0) + f = gsub(f,"e([%+%-%d]+)",function(s) + return format("\\times10^{%s}",tonumber(s) or s) -- strips leading zeros end) + context.mathematics(f) end |