From 1fea3cea85f378344550d9a6a73099c324ce366f Mon Sep 17 00:00:00 2001 From: Dohyun Kim Date: Mon, 30 Dec 2013 13:36:16 +0900 Subject: [PATCH 1/2] repect only one verbatimtex before beginfig --- NEWS | 5 ++-- luamplib.dtx | 55 ++++++++++++++++++++++++----------------- test-luamplib-latex.tex | 14 +++++++---- test-luamplib-plain.tex | 14 +++++++---- 4 files changed, 54 insertions(+), 34 deletions(-) diff --git a/NEWS b/NEWS index 2caff11..12deaf3 100644 --- a/NEWS +++ b/NEWS @@ -2,8 +2,9 @@ 2013/12/30 2.2 * start to support transparency/shading under metafun format. - * verbatimtex ... etex before beginfig() is not ignored. Using this - macro, each mplib box can be moved horizontally and/or vertically + * verbatimtex ... etex just before beginfig() is not ignored. + Using this macro, each mplib box can be moved horizontally and/or + vertically. 2013/12/23 2.11 * fix a bug wrt "withoutcolor" option diff --git a/luamplib.dtx b/luamplib.dtx index fc65e92..234ab98 100644 --- a/luamplib.dtx +++ b/luamplib.dtx @@ -189,15 +189,28 @@ See source file '\inFileName' for licencing and contact information. % |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 \verb|verbatimtex ... etex| before \verb|beginfig()| is not ignored, -% but \TeX\ code inbetween is inserted before the mplib hbox. Using this command, -% each mplib box can be freely moved horizontally and/or vertically.\\ -% \textsc{n.b.} \verb|\endgraf| should be used instead of \verb|\par| inside +% \item \verb|verbatimtex ... etex| that comes just before \verb|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. +% All other \verb|verbatimtex ... etex|'s are ignored. +% \textsc{e.g.}: +% \begin{verbatim} +% \mplibcode +% verbatimtex \moveright 3cm etex; beignfig(0); ... endfig; +% verbatimtex \leavevmode etex; beignfig(1); ... endfig; +% verbatimtex \leavevmode\lower 1ex etex; beignfig(2); ... endfig; +% verbatimtex \endgraf\moveright 1cm etex; beignfig(3); ... endfig; +% \endmplibcode +% \end{verbatim} +% \textsc{n.b.} \cs{endgraf} should be used instead of \cs{par} inside % \verb|verbatimtex ... etex|. +% \item Notice that, after each figure is processed, macro \cs{MPwidth} stores +% the width value of latest figure; \cs{MPheight}, the height value. % \end{itemize} % % Using this package is easy: in Plain, type your metapost code between the -% macros \texttt{mplibcode} and \texttt{endmplibcode}, and in \LaTeX\ in the +% macros \cs{mplibcode} and \cs{endmplibcode}, and in \LaTeX\ in the % \texttt{mplibcode} environment. % % There are (basically) two formats for metapost: \emph{plain} and @@ -580,7 +593,7 @@ end local function script2table(s) local t = {} for i in stringgmatch(s,"[^\13]+") do - k,v = stringmatch(i,"(.+)=(.+)") + local k,v = stringmatch(i,"(.+)=(.+)") if k and v then local vv = {} for j in stringgmatch(v,"[^:]+") do @@ -638,8 +651,8 @@ def fontmapfile primary filename = enddef; def specialVerbatimTeX (text t) = special "MPlibVerbTeX="&t; enddef; def ignoreVerbatimTeX (text t) = enddef; let VerbatimTeX = specialVerbatimTeX; -extra_beginfig := extra_beginfig & "let VerbatimTeX = ignoreVerbatimTeX;" ; -extra_endfig := extra_endfig & "let VerbatimTeX = specialVerbatimTeX;" ; +extra_beginfig := extra_beginfig & " let VerbatimTeX = ignoreVerbatimTeX;" ; +extra_endfig := extra_endfig & " let VerbatimTeX = specialVerbatimTeX;" ; ]] local factor = 65536*(7227/7200) @@ -668,7 +681,7 @@ local function domakeTEXboxes (data) if data and data.fig then local figures = data.fig for f=1, #figures do - TeX_code_t[f] = {} + TeX_code_t[f] = nil local figure = figures[f] local objects = getobjects(data,figure,f) if objects then @@ -683,17 +696,11 @@ local function domakeTEXboxes (data) end % \end{macrocode} % \verb|verbatimtex ... etex| before \verb|beginfig()| is not ignored, -% but the \TeX\ code inbetween is inserted before the mplib box. Examples: -% \verb|verbatimtex \moveright 3cm etex|; -% \verb|verbatimtex \leavevmode etex|; -% \verb|verbatimtex \leavevmode\lower 1ex etex|; -% \verb|verbatimtex \endgraf etex|. -% -% As shown, \verb|\endgraf| should be used instead of \verb|\par|. +% but the \TeX\ code inbetween is inserted before the mplib box. % \begin{macrocode} local texcode = prescript and prescript.MPlibVerbTeX if texcode and texcode ~= "" then - table.insert(TeX_code_t[f],texcode) + TeX_code_t[f] = texcode end end end @@ -745,8 +752,9 @@ end luamplib.processwithTEXboxes = processwithTEXboxes --- transparency / shading - +% \end{macrocode} +% Transparency and Shading +% \begin{macrocode} local pdf_objs = {} -- objstr => obj , new @@ -910,8 +918,8 @@ local function flush(result,flusher) % \end{macrocode} % Insert \verb|verbatimtex| code before mplib box. % \begin{macrocode} - if #TeX_code_t[f] > 0 then - texsprint(tableconcat(TeX_code_t[f])) + if TeX_code_t[f] then + texsprint(TeX_code_t[f]) end pdf_startfigure(fignum,llx,lly,urx,ury) pdf_literalcode("q") @@ -921,7 +929,7 @@ local function flush(result,flusher) local objecttype = object.type % \end{macrocode} % Change from \ConTeXt{} code: the following 5 lines are part of the -% |btex...etex| patch. +% |btex...etex| patch. Again, colors are processed at this stage. % % \begin{macrocode} local prescript = object.prescript @@ -946,6 +954,9 @@ local function flush(result,flusher) pdf_textfigure(object.font,object.dsize,object.text,object.width,object.height,object.depth) pdf_literalcode("Q") else +% \end{macrocode} +% Color stuffs are modified and moved to several lines above. +% \begin{macrocode} local ml = object.miterlimit if ml and ml ~= miterlimit then miterlimit = ml diff --git a/test-luamplib-latex.tex b/test-luamplib-latex.tex index 43b5b48..9df70dd 100644 --- a/test-luamplib-latex.tex +++ b/test-luamplib-latex.tex @@ -22,6 +22,7 @@ B\par A% \begin{mplibcode} +verbatimtex \lower.2em etex beginfig(0); draw origin--(1cm,0) withcolor red; draw btex g etex withcolor blue; @@ -54,20 +55,23 @@ B\par \mplibsetformat{metafun}% \begin{mplibcode} -verbatimtex \moveright 2cm etex +verbatimtex \moveright 0.4\hsize etex beginfig(0); path p; p:= fullcircle scaled 2cm yshifted .5cm; fill p withcolor transparent("normal", 0.5, red); fill p rotated 120 withcolor transparent("normal", 0.5, green); fill p rotated 240 withcolor transparent("normal", 0.5, blue); endfig; +verbatimtex \leavevmode etex +picture p; p := btex MetaPost etex scaled 2; beginfig(1); -picture p; -p := btex MetaPost etex scaled 2; linear_shade(bbox p,0,blue,.7white); -circular_shade(bbox p xshifted 4cm,0,blue,.7white); draw p withcolor white; -draw p xshifted 4cm withcolor white; +endfig; +verbatimtex \kern10pt etex +beginfig(2); +circular_shade(bbox p,0,blue,.7white); +draw p withcolor white; endfig; \end{mplibcode}% \end{document} diff --git a/test-luamplib-plain.tex b/test-luamplib-plain.tex index 3297f5a..52b300d 100644 --- a/test-luamplib-plain.tex +++ b/test-luamplib-plain.tex @@ -20,6 +20,7 @@ B\par A% \mplibcode +verbatimtex \lower.2em etex beginfig(0); draw origin--(1cm,0) withcolor red; draw btex g etex withcolor blue; @@ -52,20 +53,23 @@ B\par \mplibsetformat{metafun}% \mplibcode -verbatimtex \moveright 2cm etex +verbatimtex \moveright 0.4\hsize etex beginfig(0); path p; p:= fullcircle scaled 2cm yshifted .5cm; fill p withcolor transparent("normal", 0.5, red); fill p rotated 120 withcolor transparent("normal", 0.5, green); fill p rotated 240 withcolor transparent("normal", 0.5, blue); endfig; +verbatimtex \leavevmode etex +picture p; p := btex MetaPost etex scaled 2; beginfig(1); -picture p; -p := btex MetaPost etex scaled 2; linear_shade(bbox p,0,blue,.7white); -circular_shade(bbox p xshifted 4cm,0,blue,.7white); draw p withcolor white; -draw p xshifted 4cm withcolor white; +endfig; +verbatimtex \kern10pt etex +beginfig(2); +circular_shade(bbox p,0,blue,.7white); +draw p withcolor white; endfig; \endmplibcode \bye From af45002ed0101b6c90cea009befd3efb9bb9fd85 Mon Sep 17 00:00:00 2001 From: Dohyun Kim Date: Tue, 31 Dec 2013 10:06:58 +0900 Subject: [PATCH 2/2] fix bug of prescript parsing --- luamplib.dtx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/luamplib.dtx b/luamplib.dtx index 234ab98..2f673d7 100644 --- a/luamplib.dtx +++ b/luamplib.dtx @@ -589,20 +589,27 @@ end % % v2.2: Transparency and Shading % \begin{macrocode} +local further_split_keys = { + ["MPlibTEXboxID"] = true, + ["sh_color_a"] = true, + ["sh_color_b"] = true, +} local function script2table(s) local t = {} for i in stringgmatch(s,"[^\13]+") do - local k,v = stringmatch(i,"(.+)=(.+)") + local k,v = stringmatch(i,"(.-)=(.+)") -- v may contain =. if k and v then local vv = {} - for j in stringgmatch(v,"[^:]+") do - vv[#vv+1] = j + if further_split_keys[k] then + for j in stringgmatch(v,"[^:]+") do + vv[#vv+1] = j + end end - if #vv == 1 then - t[k] = v - else + if #vv > 0 then t[k] = vv + else + t[k] = v end end end