summaryrefslogtreecommitdiff
path: root/tex/context/base/m-graph.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/m-graph.mkiv')
-rw-r--r--tex/context/base/m-graph.mkiv59
1 files changed, 46 insertions, 13 deletions
diff --git a/tex/context/base/m-graph.mkiv b/tex/context/base/m-graph.mkiv
index e99921c43..f8114561c 100644
--- a/tex/context/base/m-graph.mkiv
+++ b/tex/context/base/m-graph.mkiv
@@ -22,6 +22,37 @@
local simplify = true
+ -- local function strip(n,e)
+ -- -- get rid of e(0)
+ -- -- get rid of e(+*)
+ -- e = gsub(e,"^+","")
+ -- -- remove leading zeros
+ -- e = gsub(e,"^([+-]*)0+(%d)","%1%2")
+ -- if not simplify then
+ -- -- take it as it is
+ -- elseif n == "1" then
+ -- return format("10^{%s}",e)
+ -- end
+ -- return format("%s\\times10^{%s}",n,e)
+ -- end
+ --
+ -- function metapost.format_n(fmt,...)
+ -- fmt = gsub(fmt,"@","%%")
+ -- local initial, hasformat, final = match(fmt,"^(.-)(%%.-[%a])(.-)$")
+ -- if hasformat then
+ -- str = format(fmt,...)
+ -- str = gsub(str,"(.-)e(.-)$",strip)
+ -- str = format("%s\\mathematics{%s}%s",initial,str,final)
+ -- elseif not find(fmt,"%%") then
+ -- str = format("%"..fmt,...)
+ -- str = gsub(str,"(.-)e(.-)$",strip)
+ -- str = format("\\mathematics{%s}",str)
+ -- end
+ -- context(str)
+ -- end
+
+ -- todo: proper lpeg
+
local function strip(n,e)
-- get rid of e(0)
-- get rid of e(+*)
@@ -31,28 +62,28 @@
if not simplify then
-- take it as it is
elseif n == "1" then
- return format("10^{%s}",e)
+ return format("\\mathematics{10^{%s}}",e)
end
- return format("%s\\times10^{%s}",n,e)
+ return format("\\mathematics{%s\\times10^{%s}}",n,e)
end
- function metapost.format_n(fmt,str)
+ function metapost.format_n(fmt,...)
fmt = gsub(fmt,"@","%%")
- local initial, hasformat, final = match(fmt,"^(.-)(%%.-[%a])(.-)$")
- if hasformat then
- str = format(fmt,str)
- str = gsub(str,"(.-)e(.-)$",strip)
- str = format("%s\\mathematics{%s}%s",initial,str,final)
- elseif not find(fmt,"%%") then
- str = format("%"..fmt,str)
- str = gsub(str,"(.-)e(.-)$",strip)
- str = format("\\mathematics{%s}",str)
+ if find(fmt,"%%") then
+ str = format(fmt,...)
+ else -- yes or no
+ str = format("%"..fmt,...)
end
+ str = gsub(str,"([%-%+]-[%.%d]+)e([%-%+]-[%.%d]+)",strip)
context(str)
end
+
+ function metapost.format_v(fmt,str)
+ metapost.format_n(fmt,metapost.untagvariable(str,false))
+ end
\stopluacode
-\unexpanded\def\MPgraphformat#1#2{\ctxlua{metapost.format_n("#1","#2")}}
+\unexpanded\def\MPgraphformat#1#2{\ctxlua{metapost.format_v("#1","#2")}}
% We could also delegate parsing using lower level plugins.
@@ -86,6 +117,8 @@
label(format("@g","1"), (2cm,-2.0cm)) ;
label(format("@g","1e-102"),(0, -2.5cm)) ;
label(format("@g","1e+102"),(2cm,-2.5cm)) ;
+ label(format("@f,@f",(1.23,4.56)),(0cm,-3.0cm)) ;
+ label(format("@i,@f",(1.23,4.56)),(0cm,-3.5cm)) ;
\stopMPpage
% \startMPpage[instance=graph]