diff options
author | Marius <mariausol@gmail.com> | 2010-07-04 15:32:09 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2010-07-04 15:32:09 +0300 |
commit | 85b7bc695629926641c7cb752fd478adfdf374f3 (patch) | |
tree | 80293f5aaa7b95a500a78392c39688d8ee7a32fc /tex/context/base/m-graph.mkiv | |
download | context-85b7bc695629926641c7cb752fd478adfdf374f3.tar.gz |
stable 2010-05-24 13:10
Diffstat (limited to 'tex/context/base/m-graph.mkiv')
-rw-r--r-- | tex/context/base/m-graph.mkiv | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tex/context/base/m-graph.mkiv b/tex/context/base/m-graph.mkiv new file mode 100644 index 000000000..c92234884 --- /dev/null +++ b/tex/context/base/m-graph.mkiv @@ -0,0 +1,63 @@ +%D \module +%D [ file=m-graph, +%D version=2008.09.08, +%D title=\CONTEXT\ Extra Modules, +%D subtitle=\METAPOST\ graph module support, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +% We just assume lua specification instead of the graph ones that +% are limited by what mp can do. We support @ as replacement for +% the percent symbol. We also add a specifier when no one is given. + +\startluacode + local function strip(s) + return "\\times10^{"..(s:gsub("%+*0*","")).."}" + 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) + end + tex.sprint(str) + end +\stopluacode + +\unexpanded\long\def\MPgraphformat#1#2{\ctxlua{metapost.format_n("#1","#2")}} + +\startMPinclusions + input graph.mp ; + 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 + +\endinput |