diff options
Diffstat (limited to 'tex/context/base/m-graph.mkiv')
-rw-r--r-- | tex/context/base/m-graph.mkiv | 124 |
1 files changed, 74 insertions, 50 deletions
diff --git a/tex/context/base/m-graph.mkiv b/tex/context/base/m-graph.mkiv index 8acbe1f8d..db72927fb 100644 --- a/tex/context/base/m-graph.mkiv +++ b/tex/context/base/m-graph.mkiv @@ -16,76 +16,100 @@ % 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 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) + local function strip(s) + return "\\times10^{"..(s:gsub("%+*0*","")).."}" end - function metapost.format_n(fmt,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) + 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) end context(str) end \stopluacode -\unexpanded\def\MPgraphformat#1#2{\ctxlua{metapost.format_n("#1","#2")}} +\unexpanded\long\def\MPgraphformat#1#2{\ctxlua{metapost.format_n("#1","#2")}} % We could also delegate parsing using lower level plugins. -\startMPextensions - if unknown Fe_plus : picture Fe_plus ; Fe_plus := textext("+") ; fi ; - if unknown context_grap: input "mp-grap.mpiv" ; fi ; -\stopMPextensions +\startMPinclusions + % input string ; + % input marith ; + input graph.mp ; + + vardef roundd(expr x, d) = + if abs d > 4 : + if d > 0 : + x + else : + 0 + fi + elseif d > 0 : + save i ; i = floor x ; + i + round(Ten_to[d]*(x-i))/Ten_to[d] + else : + round(x/Ten_to[-d])*Ten_to[-d] + fi + enddef ; + + Ten_to0 = 1 ; + Ten_to1 = 10 ; + Ten_to2 = 100 ; + Ten_to3 = 1000 ; + Ten_to4 = 10000 ; + + def sFe_base = + enddef ; + + picture Fe_plus ; Fe_plus := btex + etex ; + + vardef format (expr f,x) = dofmt_.Feform_(f,x) enddef ; + vardef Mformat (expr f,x) = dofmt_.Meform (f,x) enddef ; + vardef formatstr (expr f,x) = dofmt_.Feform_(f,x) enddef ; + vardef Mformatstr(expr f,x) = dofmt_.Meform(f,x) enddef ; + + vardef escaped_format(expr s) = + "" for n=1 upto length(s) : & + if ASCII substring (n,n+1) of s = 37 : + "@" + else : + substring (n,n+1) of s + fi + endfor + enddef ; + + vardef dofmt_@\#(expr f, x) = + textext("\MPgraphformat{" & escaped_format(f) & "}{" & (if string x : x else: decimal x fi) & "}") + enddef ; + + % vardef format(expr f, x) = + % textext("\MPgraphformatN{"&escaped_format(f)&"}{"&(if string x : x else: decimal x fi)&"}") + % enddef; + % vardef Mformat(expr f, x) = + % format(f,x) + % enddef; + +\stopMPinclusions \continueifinputfile{m-graph.mkiv} \starttext \startMPpage - label(format("@g","1e-8"), (0, 0)) ; - label(format("@g","1e+8"), (2cm, 0)) ; - label(format("@g","1e-10"), (0, -0.5cm)) ; - label(format("@g","1e+10"), (2cm,-0.5cm)) ; - label(format("@g","1e-12"), (0, -1.0cm)) ; - label(format("@g","1e+12"), (2cm,-1.0cm)) ; - label(format("@g","1e-0"), (0, -1.5cm)) ; - label(format("@g","1e+0"), (2cm,-1.5cm)) ; - label(format("@g","1"), (0, -2.0cm)) ; - label(format("@g","1"), (2cm,-2.0cm)) ; - label(format("@g","1e-102"),(0, -2.5cm)) ; - label(format("@g","1e+102"),(2cm,-2.5cm)) ; +draw begingraph(3in,2in); + gdraw "t:/metapost/grphdata/agepop91.d"; +endgraph; \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 |