diff options
author | Marius <mariausol@gmail.com> | 2011-06-08 20:40:24 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2011-06-08 20:40:24 +0300 |
commit | e5fe861660d5cf60cfeb67f7e57f659b309e9613 (patch) | |
tree | f5bc4ea0cd61f18c096f0fd5df8cf439700ba71e /tex/context/base/meta-ini.lua | |
parent | b17f22aa285224dcf5b1dbccd795bc73b9a16426 (diff) | |
download | context-e5fe861660d5cf60cfeb67f7e57f659b309e9613.tar.gz |
beta 2011.06.08 19:06
Diffstat (limited to 'tex/context/base/meta-ini.lua')
-rw-r--r-- | tex/context/base/meta-ini.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tex/context/base/meta-ini.lua b/tex/context/base/meta-ini.lua index 5150c3835..872c628aa 100644 --- a/tex/context/base/meta-ini.lua +++ b/tex/context/base/meta-ini.lua @@ -27,3 +27,56 @@ function metapost.uselibrary(name) report_metapost("unknown: library '%s'",name) end) end + +-- experimental + +local colorhash = attributes.list[attributes.private('color')] + +local validdimen = lpeg.patterns.validdimen * lpeg.P(-1) + +local lpegmatch = lpeg.match +local gmatch = string.gmatch +local textype = tex.type +local MPcolor = context.MPcolor + +function commands.prepareMPvariable(v) -- slow but ok + if v == "" then + MPcolor("black") + else + local typ, var = string.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 |