summaryrefslogtreecommitdiff
path: root/metapost/context/base/mp-mlib.mpiv
diff options
context:
space:
mode:
Diffstat (limited to 'metapost/context/base/mp-mlib.mpiv')
-rw-r--r--metapost/context/base/mp-mlib.mpiv23
1 files changed, 23 insertions, 0 deletions
diff --git a/metapost/context/base/mp-mlib.mpiv b/metapost/context/base/mp-mlib.mpiv
index 6139a63c2..dfb3f7102 100644
--- a/metapost/context/base/mp-mlib.mpiv
+++ b/metapost/context/base/mp-mlib.mpiv
@@ -865,3 +865,26 @@ vardef mfun_tagged_string(expr value) =
else : "2:" & value
fi
enddef ;
+
+% moved here from mp-grap.mpiv
+
+vardef escaped_format(expr s) =
+ "" for n=0 upto length(s) : &
+ if ASCII substring (n,n+1) of s = 37 :
+ "@"
+ else :
+ substring (n,n+1) of s
+ fi
+ endfor
+enddef ;
+
+vardef strfmt(expr f, x) = % maybe use mfun_ namespace
+ "\MPgraphformat{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}"
+enddef ;
+
+vardef varfmt(expr f, x) = % maybe use mfun_ namespace
+ "\MPformatted{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}"
+enddef ;
+
+vardef format (expr f, x) = textext(strfmt(f, x)) enddef ;
+vardef formatted(expr f, x) = textext(varfmt(f, x)) enddef ;