From e79024c0c4b136036ad806dc3f848b5e388fdbf3 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 19 Dec 2013 22:50:05 +0000 Subject: luamplib (19dec13) git-svn-id: svn://tug.org/texlive/trunk@32451 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/luatex/luamplib/NEWS | 4 + Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf | Bin 101829 -> 102765 bytes .../doc/luatex/luamplib/test-luamplib-latex.tex | 19 ++++ .../doc/luatex/luamplib/test-luamplib-plain.tex | 17 ++++ .../texmf-dist/source/luatex/luamplib/luamplib.dtx | 108 +++++++++++++-------- Master/texmf-dist/tex/luatex/luamplib/luamplib.lua | 81 ++++++++++------ Master/texmf-dist/tex/luatex/luamplib/luamplib.sty | 4 +- 7 files changed, 160 insertions(+), 73 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/luatex/luamplib/NEWS b/Master/texmf-dist/doc/luatex/luamplib/NEWS index cd1398a0d22..66c93c46e1e 100644 --- a/Master/texmf-dist/doc/luatex/luamplib/NEWS +++ b/Master/texmf-dist/doc/luatex/luamplib/NEWS @@ -1,5 +1,9 @@ History of the luamplib package +2013/12/19 2.1 + * Do not ignore "withcolor" option during textext process + * verbatimtex ... etex is now just ignored, not raising error + 2013/12/11 2.03 * implemented textext() macro which is identical to TEX() from TEX.mp. TEX() is a synonym of textext(). diff --git a/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf b/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf index b8a91225742..6a725dea35c 100644 Binary files a/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf and b/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf differ diff --git a/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex b/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex index a6c696e6262..57fbafd26ed 100644 --- a/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex +++ b/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex @@ -20,7 +20,13 @@ beginfig(1); endfig; \end{mplibcode}% B\par +A% \begin{mplibcode} +beginfig(0); +draw origin--(1cm,0) withcolor red; +draw btex g etex withcolor blue; +endfig; + beginfig(18); numeric u; u = 1cm; @@ -33,4 +39,17 @@ label.bot(btex $x$ etex, (2u,0)); label.lft(btex $y$ etex, (0,u)); endfig; \end{mplibcode}% +B\par +A% +\begin{mplibcode} +beginfig(2); +numeric u; u=1cm; +z1=-z2=origin-(u,0); +for i = 1 upto 3: + draw z1..(0, i*u)..z2; + label.top(TEX("$e_{" & decimal(i) & "}$"), (0, i*u)) withcolor blue; +endfor; +endfig; +\end{mplibcode}% +B\par \end{document} diff --git a/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex b/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex index 96b1ea73553..f708013717a 100644 --- a/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex +++ b/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex @@ -20,6 +20,11 @@ endfig; B\par A% \mplibcode +beginfig(0); +draw origin--(1cm,0) withcolor red; +draw btex g etex withcolor blue; +endfig; + beginfig(18); numeric u; u = 1cm; @@ -33,4 +38,16 @@ label.lft(btex $y$ etex, (0,u)); endfig; \endmplibcode B\par +A% +\mplibcode +beginfig(2); +numeric u; u=1cm; +z1=-z2=origin-(u,0); +for i = 1 upto 3: + draw z1..(0, i*u)..z2; + label.top(TEX("$e_{" & decimal(i) & "}$"), (0, i*u)) withcolor blue; +endfor; +endfig; +\endmplibcode +B\par \bye diff --git a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx index f56d8b19e1d..b2d02e46601 100644 --- a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx +++ b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx @@ -15,7 +15,7 @@ % tex luamplib.dtx % % Documentation: -% pdflatex luamplib.dtx +% lualatex luamplib.dtx % %<*ignore> \begingroup @@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information. %<*driver> \NeedsTeXFormat{LaTeX2e} \ProvidesFile{luamplib.drv}% - [2013/12/11 v2.03 Interface for using the mplib library]% + [2013/12/19 v2.1 Interface for using the mplib library]% \documentclass{ltxdoc} \usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace} \usepackage[x11names]{xcolor} @@ -101,7 +101,7 @@ See source file '\inFileName' for licencing and contact information. citecolor=\primarycolor, pdftitle={The luamplib package}, pdfsubject={Interface for using the mplib library}, - pdfauthor={Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang & Kin Dohyun}, + pdfauthor={Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang & Kim Dohyun}, pdfkeywords={luatex, lualatex, mplib, metapost} ]{hyperref} \usepackage{fontspec} @@ -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{2013/12/11 v2.03} +% \date{2013/12/19 v2.1} % % \maketitle % @@ -185,7 +185,7 @@ See source file '\inFileName' for licencing and contact information. % \item a \LaTeX\ environment % \item all \TeX\ macros start by \texttt{mplib} % \item use of luatexbase for errors, warnings and declaration -% \item possibility to use |btex ... etex| to typeset \TeX . +% \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. @@ -196,7 +196,7 @@ See source file '\inFileName' for licencing and contact information. % \texttt{mplibcode} environment. % % There are (basically) two formats for metapost: \emph{plain} and -% \emph{mpfun}. By default, the \emph{plain} format is used, but you can set +% \emph{metafun}. By default, the \emph{plain} format is used, but you can set % the format to be used by future figures at any time using % \cs{mplibsetformat}\marg{format name}. % @@ -225,8 +225,8 @@ luamplib.lastlog = "" local err, warn, info, log = luatexbase.provides_module({ name = "luamplib", - version = 2.03, - date = "2013/12/11", + version = 2.1, + date = "2013/12/19", description = "Lua package to typeset Metapost with LuaTeX's MPLib.", }) @@ -562,7 +562,7 @@ end % Below code has been contributed by Dohyun Kim. % It implements \verb|btex| / \verb|etex| functions. % -% v2.2: \verb|textext()| is now available, which is equivalent to \verb|TEX()| macro from TEX.mp. +% v2.1: \verb|textext()| is now available, which is equivalent to \verb|TEX()| macro from TEX.mp. % \verb|TEX()| is synonym of \verb|textext()| unless TEX.mp is loaded. % % \begin{macrocode} @@ -572,23 +572,27 @@ def textext (expr t) = image( special "%%mkTEXbox:"&t; ) enddef; let TEX = textext; +def VerbatimTeX (text t) = enddef; ]] local mplibcodepreamblesecond = [[ -vardef textext (expr t) = - TEXBOX := TEXBOX + 1; +vardef textext (text t) = + TEXBOX_ := TEXBOX_ + 1; image ( addto currentpicture doublepath unitsquare - xscaled TEXBOXwd[TEXBOX] - yscaled (TEXBOXht[TEXBOX] + TEXBOXdp[TEXBOX]) - shifted (0, -TEXBOXdp[TEXBOX]) + xscaled TEXBOX_wd[TEXBOX_] + yscaled (TEXBOX_ht[TEXBOX_] + TEXBOX_dp[TEXBOX_]) + shifted (0, -TEXBOX_dp[TEXBOX_]) withprescript "%%TEXtxtbox:" & - decimal TEXBOX & ":" & - decimal TEXBOXwd[TEXBOX] & ":" & - decimal(TEXBOXht[TEXBOX]+TEXBOXdp[TEXBOX]); -) + decimal TEXBOX_ & ":" & + decimal TEXBOX_wd[TEXBOX_] & ":" & + decimal(TEXBOX_ht[TEXBOX_]+TEXBOX_dp[TEXBOX_]); + ) +enddef; +def TEX (text t) = textext (t) enddef; +def VerbatimTeX (text t) = + message "verbatimtex '"& t &"' is ignored"; enddef; -def TEX (expr t) = textext (t) enddef; ]] local factor = 65536*(7227/7200) @@ -604,7 +608,12 @@ local function putTEXboxes (object) local rx, ry = (second.y_coord - ty)/tw, (fourth.x_coord - tx)/th if sx == 0 then sx = 0.00001 end if sy == 0 then sy = 0.00001 end + local cs = object.color + if cs and #cs > 0 then + cs = luamplib.colorconverter(cs) + end pdf_literalcode("q %f %f %f %f %f %f cm",sx,rx,ry,sy,tx,ty) + if cs then pdf_literalcode(cs) end texsprint(format("\\mplibputtextbox{%i}",n)) pdf_literalcode("Q") end @@ -621,12 +630,10 @@ local function domakeTEXboxes (data) for o=1,#objects do local object = objects[o] local prescript = object.prescript - if prescript and stringfind(prescript,"%%%%mkTEXbox:") then + local str = prescript and stringmatch(prescript, "%%%%mkTEXbox:(.*)") + if str then num = num + 1 - stringgsub(prescript, "%%%%mkTEXbox:(.+)", - function(str) - texsprint(format("\\setbox%i\\hbox{%s}",num,str)) - end) + texsprint(format("\\setbox%i\\hbox{%s}",num,str)) end end end @@ -635,10 +642,20 @@ local function domakeTEXboxes (data) end local function makeTEXboxes (data) - data = stringgsub(data,"(%A)btex(%A.-%A)etex(%A)", - function(pre,texcode,post) - texcode = stringgsub(texcode,"^%s*(.-)%s*$","%1") - return pre .. "textext(\"" .. texcode .. "\")" .. post + data = stringgsub(data, "([^A-Z_a-z])btex([^A-Z_a-z])", + function(pre,post) + post = stringgsub(post,"%s","") + return pre .. 'textext("' .. post + end) + data = stringgsub(data, "([^A-Z_a-z])verbatimtex([^A-Z_a-z])", + function(pre,post) + post = stringgsub(post,"%s","") + return pre .. 'VerbatimTeX("' .. post + end) + data = stringgsub(data, "([^A-Z_a-z])etex([^A-Z_a-z])", + function(pre,post) + pre = stringgsub(pre,"%s","") + return pre .. '")' .. post end) local mpx = luamplib.load(currentformat) if mpx and data then @@ -652,16 +669,15 @@ luamplib.makeTEXboxes = makeTEXboxes local function processwithTEXboxes (data) local num = tex.count[14] -- the same newbox register - local prepreamble = "numeric TEXBOX, TEXBOXwd[], TEXBOXht[], TEXBOXdp[];\n".. - "TEXBOX := "..num..";\n" + local prepreamble = "TEXBOX_ := "..num..";\n" while true do num = num + 1 local box = tex.box[num] if not box then break end prepreamble = prepreamble .. - "TEXBOXwd["..num.."] := "..box.width/factor ..";\n".. - "TEXBOXht["..num.."] := "..box.height/factor..";\n".. - "TEXBOXdp["..num.."] := "..box.depth /factor..";\n" + "TEXBOX_wd["..num.."] := "..box.width /factor..";\n".. + "TEXBOX_ht["..num.."] := "..box.height/factor..";\n".. + "TEXBOX_dp["..num.."] := "..box.depth /factor..";\n" end process(prepreamble .. mplibcodepreamblesecond .. data) end @@ -717,21 +733,29 @@ local function flush(result,flusher) -- not supported elseif objecttype == "text" then local ot = object.transform -- 3,4,5,6,1,2 +% \end{macrocode} +% +% Change from \ConTeXt{} code: the `cs' stuffs are for supporting `withcolor' option +% +% \begin{macrocode} + local cs = object.color + if cs and #cs > 0 then + cs = luamplib.colorconverter(cs) + end pdf_literalcode("q %f %f %f %f %f %f cm",ot[3],ot[4],ot[5],ot[6],ot[1],ot[2]) + if cs then pdf_literalcode(cs) end pdf_textfigure(object.font,object.dsize,object.text,object.width,object.height,object.depth) pdf_literalcode("Q") else - local cs = object.color % \end{macrocode} -% Change from \ConTeXt{} code: the following 5 lines are part of the -% |btex...etex| patch. +% +% Change from \ConTeXt{} code: the following 5 lines are for properly supporting `withcolor' option % % \begin{macrocode} - local cr = nil + local cs, cr = object.color, nil if cs and #cs > 0 then - local start,stop = luamplib.colorconverter(cs) - pdf_literalcode(start) - cr = stop + cs, cr = luamplib.colorconverter(cs) + pdf_literalcode(cs) end local ml = object.miterlimit if ml and ml ~= miterlimit then @@ -865,7 +889,7 @@ luamplib.colorconverter = colorconverter \else \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{luamplib} - [2013/12/11 v2.03 mplib package for LuaTeX] + [2013/12/19 v2.1 mplib package for LuaTeX] \RequirePackage{luatexbase-modutils} \RequirePackage{pdftexcmds} \fi @@ -921,6 +945,7 @@ luamplib.colorconverter = colorconverter \bgroup\expandafter\expandafter\expandafter\egroup \expandafter\ifx\csname ProvidesPackage\endcsname\relax \def\mplibcode{% + \begingroup \bgroup \mplibsetupcatcodes \mplibdocode % @@ -933,6 +958,7 @@ luamplib.colorconverter = colorconverter \directlua{ luamplib.processwithTEXboxes(luamplib.tempdata) }% + \endgroup } \else % \end{macrocode} diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua index 4969538ec15..fe8c03cc1a9 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.03, - date = "2013/12/11", + version = 2.1, + date = "2013/12/19", description = "Lua package to typeset Metapost with LuaTeX's MPLib.", }) @@ -315,23 +315,27 @@ def textext (expr t) = image( special "%%mkTEXbox:"&t; ) enddef; let TEX = textext; +def VerbatimTeX (text t) = enddef; ]] local mplibcodepreamblesecond = [[ -vardef textext (expr t) = - TEXBOX := TEXBOX + 1; +vardef textext (text t) = + TEXBOX_ := TEXBOX_ + 1; image ( addto currentpicture doublepath unitsquare - xscaled TEXBOXwd[TEXBOX] - yscaled (TEXBOXht[TEXBOX] + TEXBOXdp[TEXBOX]) - shifted (0, -TEXBOXdp[TEXBOX]) + xscaled TEXBOX_wd[TEXBOX_] + yscaled (TEXBOX_ht[TEXBOX_] + TEXBOX_dp[TEXBOX_]) + shifted (0, -TEXBOX_dp[TEXBOX_]) withprescript "%%TEXtxtbox:" & - decimal TEXBOX & ":" & - decimal TEXBOXwd[TEXBOX] & ":" & - decimal(TEXBOXht[TEXBOX]+TEXBOXdp[TEXBOX]); -) + decimal TEXBOX_ & ":" & + decimal TEXBOX_wd[TEXBOX_] & ":" & + decimal(TEXBOX_ht[TEXBOX_]+TEXBOX_dp[TEXBOX_]); + ) +enddef; +def TEX (text t) = textext (t) enddef; +def VerbatimTeX (text t) = + message "verbatimtex '"& t &"' is ignored"; enddef; -def TEX (expr t) = textext (t) enddef; ]] local factor = 65536*(7227/7200) @@ -347,7 +351,12 @@ local function putTEXboxes (object) local rx, ry = (second.y_coord - ty)/tw, (fourth.x_coord - tx)/th if sx == 0 then sx = 0.00001 end if sy == 0 then sy = 0.00001 end + local cs = object.color + if cs and #cs > 0 then + cs = luamplib.colorconverter(cs) + end pdf_literalcode("q %f %f %f %f %f %f cm",sx,rx,ry,sy,tx,ty) + if cs then pdf_literalcode(cs) end texsprint(format("\\mplibputtextbox{%i}",n)) pdf_literalcode("Q") end @@ -364,12 +373,10 @@ local function domakeTEXboxes (data) for o=1,#objects do local object = objects[o] local prescript = object.prescript - if prescript and stringfind(prescript,"%%%%mkTEXbox:") then + local str = prescript and stringmatch(prescript, "%%%%mkTEXbox:(.*)") + if str then num = num + 1 - stringgsub(prescript, "%%%%mkTEXbox:(.+)", - function(str) - texsprint(format("\\setbox%i\\hbox{%s}",num,str)) - end) + texsprint(format("\\setbox%i\\hbox{%s}",num,str)) end end end @@ -378,10 +385,20 @@ local function domakeTEXboxes (data) end local function makeTEXboxes (data) - data = stringgsub(data,"(%A)btex(%A.-%A)etex(%A)", - function(pre,texcode,post) - texcode = stringgsub(texcode,"^%s*(.-)%s*$","%1") - return pre .. "textext(\"" .. texcode .. "\")" .. post + data = stringgsub(data, "([^A-Z_a-z])btex([^A-Z_a-z])", + function(pre,post) + post = stringgsub(post,"%s","") + return pre .. 'textext("' .. post + end) + data = stringgsub(data, "([^A-Z_a-z])verbatimtex([^A-Z_a-z])", + function(pre,post) + post = stringgsub(post,"%s","") + return pre .. 'VerbatimTeX("' .. post + end) + data = stringgsub(data, "([^A-Z_a-z])etex([^A-Z_a-z])", + function(pre,post) + pre = stringgsub(pre,"%s","") + return pre .. '")' .. post end) local mpx = luamplib.load(currentformat) if mpx and data then @@ -395,16 +412,15 @@ luamplib.makeTEXboxes = makeTEXboxes local function processwithTEXboxes (data) local num = tex.count[14] -- the same newbox register - local prepreamble = "numeric TEXBOX, TEXBOXwd[], TEXBOXht[], TEXBOXdp[];\n".. - "TEXBOX := "..num..";\n" + local prepreamble = "TEXBOX_ := "..num..";\n" while true do num = num + 1 local box = tex.box[num] if not box then break end prepreamble = prepreamble .. - "TEXBOXwd["..num.."] := "..box.width/factor ..";\n".. - "TEXBOXht["..num.."] := "..box.height/factor..";\n".. - "TEXBOXdp["..num.."] := "..box.depth /factor..";\n" + "TEXBOX_wd["..num.."] := "..box.width /factor..";\n".. + "TEXBOX_ht["..num.."] := "..box.height/factor..";\n".. + "TEXBOX_dp["..num.."] := "..box.depth /factor..";\n" end process(prepreamble .. mplibcodepreamblesecond .. data) end @@ -451,16 +467,19 @@ local function flush(result,flusher) -- not supported elseif objecttype == "text" then local ot = object.transform -- 3,4,5,6,1,2 + local cs = object.color + if cs and #cs > 0 then + cs = luamplib.colorconverter(cs) + end pdf_literalcode("q %f %f %f %f %f %f cm",ot[3],ot[4],ot[5],ot[6],ot[1],ot[2]) + if cs then pdf_literalcode(cs) end pdf_textfigure(object.font,object.dsize,object.text,object.width,object.height,object.depth) pdf_literalcode("Q") else - local cs = object.color - local cr = nil + local cs, cr = object.color, nil if cs and #cs > 0 then - local start,stop = luamplib.colorconverter(cs) - pdf_literalcode(start) - cr = stop + cs, cr = luamplib.colorconverter(cs) + pdf_literalcode(cs) end local ml = object.miterlimit if ml and ml ~= miterlimit then diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty index ea377e7e895..ceff5edcddb 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} - [2013/12/11 v2.03 mplib package for LuaTeX] + [2013/12/19 v2.1 mplib package for LuaTeX] \RequirePackage{luatexbase-modutils} \RequirePackage{pdftexcmds} \fi @@ -44,6 +44,7 @@ \bgroup\expandafter\expandafter\expandafter\egroup \expandafter\ifx\csname ProvidesPackage\endcsname\relax \def\mplibcode{% + \begingroup \bgroup \mplibsetupcatcodes \mplibdocode % @@ -56,6 +57,7 @@ \directlua{ luamplib.processwithTEXboxes(luamplib.tempdata) }% + \endgroup } \else \newenvironment{mplibcode}{\toks@{}\ltxdomplibcode}{} -- cgit v1.2.3