Skip to content

Commit

Permalink
Merge pull request #14 from dohyunkim/master
Browse files Browse the repository at this point in the history
v2.2
  • Loading branch information
dohyunkim committed Jan 2, 2014
2 parents 55b8656 + af45002 commit 796ff04
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 39 deletions.
5 changes: 3 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 45 additions & 27 deletions luamplib.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -576,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
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
Expand Down Expand Up @@ -638,8 +658,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)
Expand Down Expand Up @@ -668,7 +688,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
Expand All @@ -683,17 +703,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
Expand Down Expand Up @@ -745,8 +759,9 @@ end

luamplib.processwithTEXboxes = processwithTEXboxes

-- transparency / shading

% \end{macrocode}
% Transparency and Shading
% \begin{macrocode}
local pdf_objs = {}

-- objstr <string> => obj <number>, new <boolean>
Expand Down Expand Up @@ -910,8 +925,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")
Expand All @@ -921,7 +936,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
Expand All @@ -946,6 +961,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
Expand Down
14 changes: 9 additions & 5 deletions test-luamplib-latex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
14 changes: 9 additions & 5 deletions test-luamplib-plain.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

0 comments on commit 796ff04

Please sign in to comment.