Skip to content

Commit

Permalink
Merge pull request #48 from dohyunkim/master
Browse files Browse the repository at this point in the history
v2.8.1
  • Loading branch information
dohyunkim committed Jul 8, 2014
2 parents a0a071c + f038aeb commit d29da12
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
History of the luamplib package

2014/07/04 2.8.1
* support color package on plain tex.
* fix a failure at `btex \% etex'.

2014/06/17 2.8.0
* support color/xcolor/spotcolor packages.
On LaTeX, color names or expressions of color/xcolor packages
Expand Down
54 changes: 33 additions & 21 deletions luamplib.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information.
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luamplib.drv}%
[2014/06/17 v2.8.0 Interface for using the mplib library]%
[2014/07/04 v2.8.1 Interface for using the mplib library]%
\documentclass{ltxdoc}
\usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace}
\usepackage[x11names]{xcolor}
Expand Down Expand Up @@ -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{[email protected]}}
% \date{2014/06/17 v2.8.0}
% \date{2014/07/04 v2.8.1}
%
% \maketitle
%
Expand Down Expand Up @@ -252,11 +252,10 @@ See source file '\inFileName' for licencing and contact information.
% automatically protects \TeX\ code inbetween, \cs{btex} is not supported
% here.
% \item With \cs{mpcolor} command, color names or expressions of
% \textsf{color} or \textsf{xcolor} package can be used inside mplibcode
% enviroment. In PDF mode, \textsf{spotcolor} package is supported
% as well. This is a \LaTeX-only functionality and \textsf{color} or
% \textsf{xcolor} package should be loaded by users.
% See the example code of the previous item.
% \textsf{color}/\textsf{xcolor} packages can be used inside mplibcode
% enviroment, though \textsf{luamplib} does not automatically load these
% packages. See the example code above. In PDF mode, \textsf{(x)spotcolor}
% package is supported as well.
% \item Users can choose |numbersystem| option since v2.4.
% The default value |scaled| can be changed to |double| by declaring
% |\mplibnumbersystem{double}|. For details see
Expand Down Expand Up @@ -328,8 +327,8 @@ luamplib.lastlog = ""

local err, warn, info, log = luatexbase.provides_module({
name = "luamplib",
version = "2.8.0",
date = "2014/06/17",
version = "2.8.1",
date = "2014/07/04",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
})

Expand Down Expand Up @@ -529,15 +528,17 @@ local function replaceinputmpfile (name,file)
local data = fh:read("*all"); fh:close()
data = stringgsub(data, "\"[^\n]-\"",
function(str)
str = stringgsub(str,"%%","!!!!!PERCENT!!!!!")
str = stringgsub(str,"([bem])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,"\\%%","\\!!!!!PERCENT!!!!!")
str = stringgsub(str,"%%.-\n", "")
str = stringgsub(str,"%%.-$", "")
str = stringgsub(str,"\\!!!!!PERCENT!!!!!","\\%%")
str = stringgsub(str,"[\n\r]%s*"," ")
str = stringgsub(str,'"','"&ditto&"')
return format("rawtextext(\"%s\")",str)
Expand All @@ -557,7 +558,6 @@ local function replaceinputmpfile (name,file)
return file
end
data = stringgsub(data,"([bem])!!!T!!!E!!!X!!!","%1tex")
data = stringgsub(data,"!!!!!PERCENT!!!!!","%%")
fh = ioopen(newfile,"w")
if not fh then return file end
fh:write(data); fh:close()
Expand Down Expand Up @@ -989,17 +989,22 @@ local function protecttextext(data)
str = stringgsub(str,"([bem])tex%f[^A-Z_a-z]","%1!!!T!!!E!!!X!!!")
return str
end)
data = stringgsub(data,"%%.-\n","")
data = 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,"\\%%","\\!!!!!PERCENT!!!!!")
str = stringgsub(str,"%%.-\n", "")
str = stringgsub(str,"%%.-$", "")
str = stringgsub(str,'"','"&ditto&"')
str = stringgsub(str,"\n%s*"," ")
return format("rawtextext(\"%s\")",str)
end)
data = 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]",
function(str)
str = stringgsub(str,"\\%%","\\!!!!!PERCENT!!!!!")
str = stringgsub(str,"%%.-\n", "")
str = stringgsub(str,"%%.-$", "")
str = stringgsub(str,'"','"&ditto&"')
str = stringgsub(str,"\n%s*"," ")
return format("VerbatimTeX(\"%s\")",str)
Expand All @@ -1012,6 +1017,7 @@ local function protecttextext(data)
str = stringgsub(str,"#", "!!!!!SHARPE!!!!!")
return format("\\detokenize{%s}",str)
end)
data = stringgsub(data,"%%.-\n", "")
luamplib.mpxcolors = {}
data = stringgsub(data, "\\mpcolor%s*{(.-)}",
function(str)
Expand Down Expand Up @@ -1572,7 +1578,7 @@ luamplib.colorconverter = colorconverter
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
[2014/06/17 v2.8.0 mplib package for LuaTeX]
[2014/07/04 v2.8.1 mplib package for LuaTeX]
\RequirePackage{luatexbase-modutils}
\fi
% \end{macrocode}
Expand Down Expand Up @@ -1631,7 +1637,7 @@ luamplib.colorconverter = colorconverter
%
% \begin{macrocode}
\bgroup\expandafter\expandafter\expandafter\egroup
\expandafter\ifx\csname ProvidesPackage\endcsname\relax
\expandafter\ifx\csname selectfont\endcsname\relax
\def\mplibreplacenewlinecs{%
\begingroup \mplibpostmpcatcodes \mplibdoreplacenewlinecs}
\begingroup\lccode`\~=`\^^M \lowercase{\endgroup
Expand All @@ -1645,7 +1651,8 @@ luamplib.colorconverter = colorconverter
}
\long\def\mplibdocode#1\endmplibcode{%
\endgroup
\def\mplibtemp{\directlua{luamplib.protecttextext([===[\unexpanded{#1}]===])}}%
\edef\mplibtemp{\directlua{luamplib.protecttextext([===[\unexpanded{#1}]===])}}%
\directlua{ tex.sprint(table.concat(luamplib.mpxcolors)) }%
\directlua{luamplib.tempdata = luamplib.makeTEXboxes([===[\mplibtemp]===])}%
\directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\endgroup
Expand Down Expand Up @@ -1683,21 +1690,26 @@ luamplib.colorconverter = colorconverter
\toks@\expandafter{\the\toks@\end{#2}}\expandafter\ltxdomplibcode
\fi
}
\fi
% \end{macrocode}
% Support color/xcolor package on \LaTeX.
%
% Support color/xcolor packages.
% User interface is: \verb|\mpcolor{teal}|, for example.
% \begin{macrocode}
\def\mplibcolor#1#2{%
\ifcsname\string\color @#2\endcsname
\edef#1{1 withprescript
"MPlibOverrideColor=\csname\string\color @#2\endcsname"}%
\else
\extractcolorspecs{#2}\mplibtemp@a\mplibtemp@b
\convertcolorspec\mplibtemp@a\mplibtemp@b{cmyk}\mplibtemp@c
\edef#1{(\mplibtemp@c)}%
\ifdefined\extractcolorspecs
\extractcolorspecs{#2}\mplibtemp@a\mplibtemp@b
\convertcolorspec\mplibtemp@a\mplibtemp@b{cmyk}\mplibtemp@c
\edef#1{(\mplibtemp@c)}%
\else
\errmessage{Undefined color `#2'}%
\fi
\fi
}
\fi
% \end{macrocode}
%
% \cs{everymplib} \& \cs{everyendmplib}: macros redefining
Expand Down
8 changes: 7 additions & 1 deletion test-luamplib-latex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
verbatimtex \lower.2em etex
beginfig(0);
draw origin--(1cm,0) withcolor \mpcolor{teal};
draw btex g\begin{huge}g\end{huge}etex withcolor \mpcolor{orange};
draw btex g etex withcolor \mpcolor{orange};
draw btex\tracingcommands0
multi%
\begin{huge}line\end{huge}%
texcode
with \%
etex shifted (10,0);
draw bbox currentpicture;
endfig;

Expand Down
6 changes: 5 additions & 1 deletion test-luamplib-plain.tex
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
\input miniltx
\input color
\definecolor{orange}{rgb}{1,0.5,0}
\input luamplib.sty
\everymplib{ beginfig(0); }\everyendmplib{ endfig; }
\tracingcommands1
Expand Down Expand Up @@ -27,6 +30,7 @@
draw btex\tracingcommands0 multi
line
tex code
100 \% color
etex shifted (20,0);
draw textext("\tracingcommands0 textext 50\% color") shifted (10,-10) withcolor .5white;
draw bbox currentpicture;
Expand All @@ -52,7 +56,7 @@
z1=-z2=(-u,0);
for i = 1 upto 3:
draw z1..(0, i*u)..z2;
label.top(TEX("$e_{" & decimal(i) & "}$"), (0, i*u)) withcolor blue;
label.top(TEX("$e_{" & decimal(i) & "}$"), (0, i*u)) withcolor \mpcolor{orange};
endfor;
endfig;
\endmplibcode
Expand Down

0 comments on commit d29da12

Please sign in to comment.