summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luamplib
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-02-21 00:20:55 +0000
committerKarl Berry <karl@freefriends.org>2014-02-21 00:20:55 +0000
commitaf161732d0da218229ae153646c74621e65a75a8 (patch)
tree92ce51ceda3892e0bde54fb71cf0ff2073bf03db /Master/texmf-dist/tex/luatex/luamplib
parent1994f6c1b400d3a70d26a4e3982d81af34ff31c9 (diff)
luamplib (20feb14)
git-svn-id: svn://tug.org/texlive/trunk@33013 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luamplib')
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.lua111
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.sty2
2 files changed, 104 insertions, 9 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
index 0cc7a65a92f..897dd456737 100644
--- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
+++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
@@ -18,8 +18,8 @@ luamplib.lastlog = ""
local err, warn, info, log = luatexbase.provides_module({
name = "luamplib",
- version = 2.4,
- date = "2014/02/02",
+ version = "2.5.1",
+ date = "2014/02/19",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
})
@@ -51,13 +51,97 @@ if not file then
end
end
+local mpreplacedabove = {}
+
+local function replaceinputmpfile (file)
+ local fh = io.open(file,"r")
+ if not fh then return file end
+ local data = fh:read("*all"); fh:close()
+ data = stringgsub(data, "\".-\"",
+ function(str)
+ str = stringgsub(str,"%%","*****PERCENT*****")
+ str = stringgsub(str,"([bm])tex%f[^A-Z_a-z]","%1***T***E***X***")
+ return str
+ end)
+ data = stringgsub(data,"%%.-\n","")
+ local count,cnt = 0,0
+ data,cnt = stringgsub(data,
+ "%f[A-Z_a-z]btex%f[^A-Z_a-z]%s*(.-)%s*%f[A-Z_a-z]etex%f[^A-Z_a-z]",
+ function(str)
+ str = stringgsub(str,"[\n\r]%s*"," ")
+ str = stringgsub(str,'"','"&ditto&"')
+ return format("rawtextext(\"%s\")",str)
+ end)
+ count = count + cnt
+ data,cnt = stringgsub(data,
+ "%f[A-Z_a-z]verbatimtex%f[^A-Z_a-z]%s*(.-)%s*%f[A-Z_a-z]etex%f[^A-Z_a-z]",
+ "")
+ count = count + cnt
+ if count == 0 then
+ mpreplacedabove[file] = file
+ return file
+ end
+ data = stringgsub(data,"([bm])***T***E***X***","%1tex")
+ data = stringgsub(data,"*****PERCENT*****","%%")
+ local newfile = stringgsub(file,".*/","luamplib_input_")
+ fh = io.open(newfile,"w")
+ if not fh then return file end
+ fh:write(data); fh:close()
+ mpreplacedabove[file] = newfile
+ return newfile
+end
+
+local noneedtoreplace = {
+ ["boxes.mp"] = true,
+ ["format.mp"] = true,
+ ["graph.mp"] = true,
+ ["marith.mp"] = true,
+ ["mfplain.mp"] = true,
+ ["mpost.mp"] = true,
+ ["plain.mp"] = true,
+ ["rboxes.mp"] = true,
+ ["sarith.mp"] = true,
+ ["string.mp"] = true,
+ ["TEX.mp"] = true,
+ ["metafun.mp"] = true,
+ ["metafun.mpiv"] = true,
+ ["mp-abck.mpiv"] = true,
+ ["mp-apos.mpiv"] = true,
+ ["mp-asnc.mpiv"] = true,
+ ["mp-base.mpiv"] = true,
+ ["mp-butt.mpiv"] = true,
+ ["mp-char.mpiv"] = true,
+ ["mp-chem.mpiv"] = true,
+ ["mp-core.mpiv"] = true,
+ ["mp-crop.mpiv"] = true,
+ ["mp-figs.mpiv"] = true,
+ ["mp-form.mpiv"] = true,
+ ["mp-func.mpiv"] = true,
+ ["mp-grap.mpiv"] = true,
+ ["mp-grid.mpiv"] = true,
+ ["mp-grph.mpiv"] = true,
+ ["mp-idea.mpiv"] = true,
+ ["mp-mlib.mpiv"] = true,
+ ["mp-page.mpiv"] = true,
+ ["mp-shap.mpiv"] = true,
+ ["mp-step.mpiv"] = true,
+ ["mp-text.mpiv"] = true,
+ ["mp-tool.mpiv"] = true,
+}
+
local mpkpse = kpse.new("luatex", "mpost")
local function finder(name, mode, ftype)
if mode == "w" then
return name
else
- return mpkpse:find_file(name,ftype)
+ local file = mpkpse:find_file(name,ftype)
+ if file then
+ if ftype ~= "mp" or noneedtoreplace[name] then return file end
+ if mpreplacedabove[file] then return mpreplacedabove[file] end
+ return replaceinputmpfile(file)
+ end
+ return mpkpse:find_file(name,stringmatch(name,"[a-zA-Z]+$"))
end
end
luamplib.finder = finder
@@ -121,6 +205,7 @@ else
end
function luamplib.load(name)
+ mpreplacedabove = {} -- reset
local mpx = mplib.new {
ini_version = true,
find_file = luamplib.finder,
@@ -372,6 +457,16 @@ if known context_mlib:
(1-mfun_labxf@#-mfun_labyf@#)*llcorner p))
fi
enddef;
+ def graphictext primary filename =
+ if (readfrom filename = EOF):
+ errmessage "Please prepare '"&filename&"' in advance with command"&
+ " 'pstoedit -ssp -dt -f mpost yourfile.ps "&filename&"'";
+ fi
+ closefrom filename;
+ def data_mpy_file = filename enddef;
+ mfun_do_graphic_text (filename)
+ enddef;
+ if unknown TEXBOX_: def mfun_do_graphic_text text t = enddef; fi
else:
vardef textext@# (text t) = rawtextext (t) enddef;
fi
@@ -392,13 +487,13 @@ local function protecttextext(data)
local everyendmplib = tex.toks['everyendmplibtoks'] or ''
data = " " .. everymplib .. data .. everyendmplib
data = stringgsub(data,
- "%f[A-Za-z]btex%f[^A-Za-z]%s*(.-)%s*%f[A-Za-z]etex%f[^A-Za-z]",
+ "%f[A-Z_a-z]btex%f[^A-Z_a-z]%s*(.-)%s*%f[A-Z_a-z]etex%f[^A-Z_a-z]",
function(str)
str = stringgsub(str,'"','"&ditto&"')
return format("rawtextext(\\unexpanded{\"%s\"})",str)
end)
data = stringgsub(data,
- "%f[A-Za-z]verbatimtex%f[^A-Za-z]%s*(.-)%s*%f[A-Za-z]etex%f[^A-Za-z]",
+ "%f[A-Z_a-z]verbatimtex%f[^A-Z_a-z]%s*(.-)%s*%f[A-Z_a-z]etex%f[^A-Z_a-z]",
function(str)
str = stringgsub(str,'"','"&ditto&"')
return format("VerbatimTeX(\\unexpanded{\"%s\"})",str)
@@ -409,9 +504,9 @@ local function protecttextext(data)
str = stringgsub(str,"%)","%%%%RGHTPAREN%%%%")
return str
end)
- data = stringgsub(data, "%f[A-Za-z]TEX%s*%b()", "\\unexpanded{%1}")
- data = stringgsub(data, "%f[A-Za-z]textext%s*%b()", "\\unexpanded{%1}")
- data = stringgsub(data, "%f[A-Za-z]textext%.[_a-z]+%s*%b()", "\\unexpanded{%1}")
+ data = stringgsub(data, "%f[A-Z_a-z]TEX%s*%b()", "\\unexpanded{%1}")
+ data = stringgsub(data, "%f[A-Z_a-z]textext%s*%b()", "\\unexpanded{%1}")
+ data = stringgsub(data, "%f[A-Z_a-z]textext%.[_a-z]+%s*%b()", "\\unexpanded{%1}")
data = stringgsub(data, "%%%%LEFTPAREN%%%%", "(") -- restore
data = stringgsub(data, "%%%%RGHTPAREN%%%%", ")") -- restore
texsprint(data)
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
index c1c75a46ad8..efa971be27f 100644
--- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
+++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
@@ -14,7 +14,7 @@
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2014/02/02 v2.4 mplib package for LuaTeX]
+ [2014/02/19 v2.5.1 mplib package for LuaTeX]
\RequirePackage{luatexbase-modutils}
\RequirePackage{pdftexcmds}
\fi