diff options
Diffstat (limited to 'tex/context/base/meta-ini.lua')
-rw-r--r-- | tex/context/base/meta-ini.lua | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tex/context/base/meta-ini.lua b/tex/context/base/meta-ini.lua index 5b1f89463..bac1429ae 100644 --- a/tex/context/base/meta-ini.lua +++ b/tex/context/base/meta-ini.lua @@ -7,7 +7,7 @@ if not modules then modules = { } end modules ['meta-ini'] = { } local tonumber = tonumber -local format, gmatch, match = string.format, string.gmatch, string.match +local format, gmatch, match, gsub = string.format, string.gmatch, string.match, string.gsub metapost = metapost or { } @@ -90,3 +90,13 @@ function commands.prepareMPvariable(v) -- slow but ok 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 |