diff options
Diffstat (limited to 'tex/context/base/m-graph.mkiv')
-rw-r--r-- | tex/context/base/m-graph.mkiv | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/tex/context/base/m-graph.mkiv b/tex/context/base/m-graph.mkiv index db72927fb..45903e532 100644 --- a/tex/context/base/m-graph.mkiv +++ b/tex/context/base/m-graph.mkiv @@ -16,26 +16,30 @@ % the percent symbol. We also add a specifier when no one is given. \startluacode + local format, gsub, find, match = string.format, string.gsub, string.find, string.match + local function strip(s) - return "\\times10^{"..(s:gsub("%+*0*","")).."}" + s = gsub(s,"^([+-]*)0+(%d)","%1%2") + return format("\\times10^{%s}",s) end + function metapost.format_n(fmt,str) - fmt = fmt:gsub("@","%%") - local initial, format, final = fmt:match("^(.-)(%%.-[%a])(.-)$") - if format then - str = fmt:format(str) - str = str:gsub("e(.-)$",strip) - str = ("%s\\mathematics{%s}%s"):format(initial,str,final) - elseif not fmt:find("%%") then - str = ("%"..fmt):format(str) - str = str:gsub("e(.-)$",strip) - str = ("\\mathematics{%s}"):format(str) + 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) end context(str) end \stopluacode -\unexpanded\long\def\MPgraphformat#1#2{\ctxlua{metapost.format_n("#1","#2")}} +\unexpanded\def\MPgraphformat#1#2{\ctxlua{metapost.format_n("#1","#2")}} % We could also delegate parsing using lower level plugins. @@ -96,6 +100,23 @@ % format(f,x) % enddef; + % string Autoform_x ; Autoform_x := "@.0e" ; + % string Autoform_y ; Autoform_y := "@.0e" ; + + vardef autogrid(suffix tx, ty) text w = + Gneedgr_ := false ; + if str tx <> "" : + for x=auto.x : + tx(if known Autoform_x : Autoform_x else : Autoform fi,x) w ; + endfor + fi ; + if str ty <> "" : + for y=auto.y : + ty(if known Autoform_y : Autoform_y else : Autoform fi,y) w ; + endfor + fi ; + enddef ; + \stopMPinclusions \continueifinputfile{m-graph.mkiv} @@ -103,13 +124,26 @@ \starttext \startMPpage -draw begingraph(3in,2in); - gdraw "t:/metapost/grphdata/agepop91.d"; -endgraph; + label(format("@g","1e-10"), (0, 0)) ; + label(format("@g","1e+10"), (2cm, 0)) ; + label(format("@g","1e-12"), (0, -0.5cm)) ; + label(format("@g","1e+12"), (2cm,-0.5cm)) ; + label(format("@g","1e-0"), (0, -1.0cm)) ; + label(format("@g","1e+0"), (2cm,-1.0cm)) ; + label(format("@g","1"), (0, -1.5cm)) ; + label(format("@g","1"), (2cm,-1.5cm)) ; + label(format("@g","1e-102"),(0, -2.0cm)) ; + label(format("@g","1e+102"),(2cm,-2.0cm)) ; \stopMPpage % \startMPpage % draw begingraph(3in,2in); +% gdraw "t:/metapost/grphdata/agepop91.d"; +% endgraph; +% \stopMPpage + +% \startMPpage +% draw begingraph(3in,2in); % gdraw "agepop91.d" plot btex $\bullet$ etex; % endgraph; % \stopMPpage |