diff options
author | Karl Berry <karl@freefriends.org> | 2014-02-21 00:20:55 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-02-21 00:20:55 +0000 |
commit | af161732d0da218229ae153646c74621e65a75a8 (patch) | |
tree | 92ce51ceda3892e0bde54fb71cf0ff2073bf03db | |
parent | 1994f6c1b400d3a70d26a4e3982d81af34ff31c9 (diff) |
luamplib (20feb14)
git-svn-id: svn://tug.org/texlive/trunk@33013 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/doc/luatex/luamplib/NEWS | 5 | ||||
-rw-r--r-- | Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf | bin | 115536 -> 119768 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/luatex/luamplib/luamplib.dtx | 136 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.lua | 111 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.sty | 2 |
5 files changed, 231 insertions, 23 deletions
diff --git a/Master/texmf-dist/doc/luatex/luamplib/NEWS b/Master/texmf-dist/doc/luatex/luamplib/NEWS index 48a48ec90e3..43da66abb30 100644 --- a/Master/texmf-dist/doc/luatex/luamplib/NEWS +++ b/Master/texmf-dist/doc/luatex/luamplib/NEWS @@ -1,5 +1,10 @@ History of the luamplib package +2014/02/19 2.5 + * btex ... etex input from external *.mp files will also be processed + by luamplib. However, verbatimtex ... etex will be entirely ignored + in this case. + 2014/02/02 2.4 * implemented "numbersystem" option. Default value "scaled" can be changed by declaring \mplibnumbersystem{double}. For details, see diff --git a/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf b/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf Binary files differindex c01d04c5b60..c9b1df7af42 100644 --- a/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf +++ b/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf diff --git a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx index 0cbae2e6ad3..ff71bb6fbd9 100644 --- a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx +++ b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx @@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information. %<*driver> \NeedsTeXFormat{LaTeX2e} \ProvidesFile{luamplib.drv}% - [2014/02/02 v2.4 Interface for using the mplib library]% + [2014/02/19 v2.5.1 Interface for using the mplib library]% \documentclass{ltxdoc} \usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace} \usepackage[x11names]{xcolor} @@ -154,7 +154,7 @@ See source file '\inFileName' for licencing and contact information. % \author{Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang and Kim Dohyun\\ % Maintainer: LuaLaTeX Maintainers --- % Support: \email{lualatex-dev@tug.org}} -% \date{2014/02/02 v2.4} +% \date{2014/02/19 v2.5.1} % % \maketitle % @@ -192,11 +192,16 @@ See source file '\inFileName' for licencing and contact information. % \item possibility to use |btex ... etex| to typeset \TeX\ code. % |textext()| is a more versatile macro equivalent to |TEX()| from TEX.mp. % |TEX()| is also allowed unless TEX.mp is loaded, which should be always -% avoided. -% \item |verbatimtex ... etex| that comes just before |beginfig()| +% avoided.\par +% \textsc{n.b.} Since v2.5, |btex ... etex| input from external |mp| files +% will also be processed by \textsf{luamplib}. However, +% |verbatimtex ... etex| will be entirely ignored in this case. +% \item |verbatimtex ... etex| (in \TeX\ file) that comes just before |beginfig()| % is not ignored, but the \TeX\ code inbetween will be inserted before the % following mplib hbox. Using this command, % each mplib box can be freely moved horizontally and/or vertically. +% Also, a box number might be assigned to mplib box, allowing it to be +% reused later (see test files). % All other |verbatimtex ... etex|'s are ignored. % \textsc{e.g.} % \begin{verbatim} @@ -223,6 +228,11 @@ See source file '\inFileName' for licencing and contact information. % draw fullcircle scaled 1cm; % \endmplibcode % \end{verbatim} +% \textsc{n.b.} Many users have complained that mplib figures do not +% respect alignment commands such as \cs{centering} or \cs{raggedleft}. +% That's because \textsf{luamplib} does not force horizontal or vertical mode. +% If you want all mplib figures center- (or right-) aligned, please use +% \cs{everymplib} command with \cs{leavevmode} as shown above. % \item Since v2.3, \cs{mpdim} and other raw \TeX\ commands are allowed % inside mplib code. This feature is inpired by gmp.sty authored by % Enrico Gregorio. Please refer the manual of gmp package for details. @@ -273,8 +283,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.", }) @@ -319,6 +329,87 @@ if not file then return (stringgsub(filename,"%.[%a%d]+$","")) end end + +% \end{macrocode} +% |btex ... etex| in input .mp files will be replaced in finder. +% \begin{macrocode} +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, +} % \end{macrocode} % As the finder function for |mplib|, use the |kpse| library and % make it behave like as if MetaPost was used (or almost, since the engine @@ -332,7 +423,13 @@ 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 @@ -411,6 +508,7 @@ else end function luamplib.load(name) + mpreplacedabove = {} -- reset local mpx = mplib.new { ini_version = true, find_file = luamplib.finder, @@ -625,7 +723,7 @@ end % % v2.2: Transparency and Shading % -% v2.2: \cs{everymplib}, \cs{everyendmplib}, +% v2.3: \cs{everymplib}, \cs{everyendmplib}, % and allows naked \TeX\ commands. % \begin{macrocode} local further_split_keys = { @@ -686,6 +784,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 @@ -706,13 +814,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) @@ -723,9 +831,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) @@ -1165,7 +1273,7 @@ luamplib.colorconverter = colorconverter \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 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 |