summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-01-20 23:18:15 +0000
committerKarl Berry <karl@freefriends.org>2014-01-20 23:18:15 +0000
commit70a9a637489e651f4aee19179e792b79d7ab79f6 (patch)
tree7a576526987016eb599cf323acfb83e252cfac16 /Master/texmf-dist
parent2b5c60ccb1ed42479efd6b30e140b111770e7114 (diff)
luamplib (20jan14)
git-svn-id: svn://tug.org/texlive/trunk@32739 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/luatex/luamplib/NEWS9
-rw-r--r--Master/texmf-dist/doc/luatex/luamplib/luamplib.pdfbin111854 -> 114244 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex22
-rw-r--r--Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex21
-rw-r--r--Master/texmf-dist/source/luatex/luamplib/luamplib.dtx166
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.lua52
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.sty56
7 files changed, 228 insertions, 98 deletions
diff --git a/Master/texmf-dist/doc/luatex/luamplib/NEWS b/Master/texmf-dist/doc/luatex/luamplib/NEWS
index 12deaf389a5..fb51e6062cc 100644
--- a/Master/texmf-dist/doc/luatex/luamplib/NEWS
+++ b/Master/texmf-dist/doc/luatex/luamplib/NEWS
@@ -1,5 +1,14 @@
History of the luamplib package
+2014/01/20 2.3
+ * \everymplib, \everyendmplib: macros that redefine token lists
+ \everymplibtoks and \everyendmplibtoks. These will be
+ automatically inserted at the beginning and ending (respectively)
+ of each and every mplib code.
+ * naked TeX codes, includig \mpdim{...}, are allowed inside
+ mplibcode environment. Refer the manual of gmp package for
+ details.
+
2013/12/30 2.2
* start to support transparency/shading under metafun format.
* verbatimtex ... etex just before beginfig() is not ignored.
diff --git a/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf b/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
index 7f914758345..0ef953f2d82 100644
--- a/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
+++ b/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
Binary files 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 9df70dd7869..211667504bb 100644
--- a/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex
+++ b/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex
@@ -1,5 +1,7 @@
\documentclass{article}
\usepackage{luamplib}
+\everymplib{ beginfig(0); }
+\everyendmplib{ endfig; }
\begin{document}
\tracingcommands1
A%
@@ -15,11 +17,10 @@ A%
%% % / 9 C M W a k u DEL
%% & 0 : D N X b l v
%% ´ 1 ; E O Y c m w
-beginfig(1);
fill fullcircle scaled 20; %% actual <tab> to make sure it works
-endfig;
\end{mplibcode}%
B\par
+\everymplib{}\everyendmplib{}% reset toks
A%
\begin{mplibcode}
verbatimtex \lower.2em etex
@@ -74,4 +75,21 @@ circular_shade(bbox p,0,blue,.7white);
draw p withcolor white;
endfig;
\end{mplibcode}%
+
+\newbox\mympbox
+\begin{mplibcode}
+verbatimtex \global\setbox\mympbox etex
+beginfig(0);
+breadth=.667\mpdim\linewidth;
+height=2pt;
+x1=0; x2=x6=.333x4; x5=x3=.667x4;
+x4=breadth;
+y1=y4=height/2; y2=y3=height; y5=y6=0;
+fill z1--z2--z3--z4--z5--z6--cycle;
+endfig;
+\end{mplibcode}%
+\copy\mympbox
+\copy\mympbox
+\copy\mympbox
+\copy\mympbox
\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 52b300dce95..f2262d91e39 100644
--- a/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex
+++ b/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex
@@ -1,4 +1,5 @@
\input luamplib.sty
+\everymplib{ beginfig(0); }\everyendmplib{ endfig; }
\tracingcommands1
A%
\mplibcode
@@ -13,11 +14,10 @@ A%
%% % / 9 C M W a k u DEL
%% & 0 : D N X b l v
%% ´ 1 ; E O Y c m w
-beginfig(1);
fill fullcircle scaled 20;
-endfig;
\endmplibcode
B\par
+\everymplib{}\everyendmplib{}% reset toks
A%
\mplibcode
verbatimtex \lower.2em etex
@@ -72,4 +72,21 @@ circular_shade(bbox p,0,blue,.7white);
draw p withcolor white;
endfig;
\endmplibcode
+
+\newbox\mympbox
+\mplibcode
+verbatimtex \global\setbox\mympbox etex
+beginfig(0);
+breadth=.667\mpdim\hsize;
+height=2pt;
+x1=0; x2=x6=.333x4; x5=x3=.667x4;
+x4=breadth;
+y1=y4=height/2; y2=y3=height; y5=y6=0;
+fill z1--z2--z3--z4--z5--z6--cycle;
+endfig;
+\endmplibcode
+\copy\mympbox
+\copy\mympbox
+\copy\mympbox
+\copy\mympbox
\bye
diff --git a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
index 2f673d7f773..f6c95a77d21 100644
--- a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
+++ b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment -- by the way, this file contains UTF-8
%
-% Copyright (C) 2008-2010 by Hans Hagen, Taco Hoekwater, Elie Roux,
+% Copyright (C) 2008-2014 by Hans Hagen, Taco Hoekwater, Elie Roux,
% Manuel Pégourié-Gonnard, Philipp Gesang and Kim Dohyun.
% Currently maintained by the LuaLaTeX development team.
% Support: <lualatex-dev@tug.org>
@@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information.
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luamplib.drv}%
- [2013/12/29 v2.2 Interface for using the mplib library]%
+ [2014/01/20 v2.3 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{2013/12/29 v2.2}
+% \date{2014/01/20 v2.3}
%
% \maketitle
%
@@ -176,6 +176,10 @@ See source file '\inFileName' for licencing and contact information.
% The metapost figures are put in a \TeX\ \texttt{hbox} with dimensions
% adjusted to the metapost code.
%
+% Using this package is easy: in Plain, type your metapost code between the
+% macros \cs{mplibcode} and \cs{endmplibcode}, and in \LaTeX\ in the
+% \texttt{mplibcode} environment.
+%
% The code is from the \texttt{luatex-mplib.lua} and \texttt{luatex-mplib.tex} files
% from \ConTeXt, they have been adapted to \LaTeX\ and Plain by Elie Roux and
% Philipp Gesang, new functionalities have been added by Kim Dohyun.
@@ -189,12 +193,12 @@ 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| that comes just before \verb|beginfig()|
+% \item |verbatimtex ... etex| 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.
-% All other \verb|verbatimtex ... etex|'s are ignored.
-% \textsc{e.g.}:
+% All other |verbatimtex ... etex|'s are ignored.
+% \textsc{e.g.}
% \begin{verbatim}
% \mplibcode
% verbatimtex \moveright 3cm etex; beignfig(0); ... endfig;
@@ -204,15 +208,37 @@ See source file '\inFileName' for licencing and contact information.
% \endmplibcode
% \end{verbatim}
% \textsc{n.b.} \cs{endgraf} should be used instead of \cs{par} inside
-% \verb|verbatimtex ... etex|.
+% |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.
+% \item Since v2.3, new macros \cs{everymplib} and \cs{everyendmplib} redefine
+% token lists \cs{everymplibtoks} and \cs{everyendmplibtoks} respectively,
+% which will
+% be automatically inserted at the beginning and ending of each mplib code.
+% \textsc{e.g.}
+% \begin{verbatim}
+% \everymplib{ verbatimtex \leavevmode etex; beginfig(0); }
+% \everyendmplib{ endfig; }
+% \mplibcode % befinfig/endfig not needed; always in horizontal mode
+% draw fullcircle scaled 1cm;
+% \endmplibcode
+% \end{verbatim}
+% \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.
+% \textsc{e.g.}
+% \begin{verbatim}
+% \begin{mplibcode}
+% draw origin--(\mpdim{\linewidth},0) withpen pencircle scaled 4
+% dashed evenly scaled 4 withcolor \myrulecolor;
+% \end{mplibcode}
+% \end{verbatim}
+% \textsc{n.b.} Users should not use the protected variant of
+% |btex ... etex| as provided by gmp package. As \textsf{luamplib}
+% automatically protects \TeX\ code inbetween, \cs{btex} is not supported
+% here.
% \end{itemize}
%
-% Using this package is easy: in Plain, type your metapost code between 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
% \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
@@ -243,8 +269,8 @@ luamplib.lastlog = ""
local err, warn, info, log = luatexbase.provides_module({
name = "luamplib",
- version = 2.2,
- date = "2013/12/29",
+ version = 2.3,
+ date = "2014/01/20",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
})
@@ -588,6 +614,9 @@ end
% \verb|TEX()| is synonym of \verb|textext()| unless TEX.mp is loaded.
%
% v2.2: Transparency and Shading
+%
+% v2.2: \cs{everymplib}, \cs{everyendmplib},
+% and allows naked \TeX\ commands.
% \begin{macrocode}
local further_split_keys = {
["MPlibTEXboxID"] = true,
@@ -662,6 +691,38 @@ extra_beginfig := extra_beginfig & " let VerbatimTeX = ignoreVerbatimTeX;" ;
extra_endfig := extra_endfig & " let VerbatimTeX = specialVerbatimTeX;" ;
]]
+local function protecttextext(data)
+ local everymplib = tex.toks['everymplibtoks'] or ''
+ 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]",
+ 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]",
+ function(str)
+ str = stringgsub(str,'"','"&ditto&"')
+ return format("VerbatimTeX(\\unexpanded{\"%s\"})",str)
+ end)
+ data = stringgsub(data, "\".-\"", -- hack for parentheses inside quotes
+ function(str)
+ str = stringgsub(str,"%(","%%%%LEFTPAREN%%%%")
+ 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, "%%%%LEFTPAREN%%%%", "(") -- restore
+ data = stringgsub(data, "%%%%RGHTPAREN%%%%", ")") -- restore
+ texsprint(data)
+end
+
+luamplib.protecttextext = protecttextext
+
local factor = 65536*(7227/7200)
local function putTEXboxes (object,prescript)
@@ -716,22 +777,6 @@ local function domakeTEXboxes (data)
end
local function makeTEXboxes (data)
- data = "relax " .. data
- data = stringgsub(data, "([^A-Z_a-z])btex([^A-Z_a-z])",
- function(pre,post)
- post = stringgsub(post,"%s","")
- return pre .. 'rawtextext("' .. 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
local result = mpx:execute(mplibcodepreamble .. data)
@@ -1109,7 +1154,7 @@ luamplib.colorconverter = colorconverter
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2013/12/29 v2.2 mplib package for LuaTeX]
+ [2014/01/20 v2.3 mplib package for LuaTeX]
\RequirePackage{luatexbase-modutils}
\RequirePackage{pdftexcmds}
\fi
@@ -1146,7 +1191,8 @@ luamplib.colorconverter = colorconverter
\fi
\fi
\def\mplibsetupcatcodes{%
- \catcode`\{=12 \catcode`\}=12 \catcode`\#=12
+ %catcode`\{=12 %catcode`\}=12
+ \catcode`\#=12
\catcode`\^=12 \catcode`\~=12 \catcode`\_=12
%catcode`\%=12 %% don’t in Plain!
\catcode`\&=12 \catcode`\$=12
@@ -1172,12 +1218,10 @@ luamplib.colorconverter = colorconverter
}
\long\def\mplibdocode#1\endmplibcode{%
\egroup
- \directlua{
- luamplib.tempdata = luamplib.makeTEXboxes([===[\unexpanded{#1}]===])
- }%
- \directlua{
- luamplib.processwithTEXboxes(luamplib.tempdata)
- }%
+ \expandafter\def\expandafter\mplibtmp\expandafter
+ {\directlua{luamplib.protecttextext([===[\unexpanded{#1}]===])}}%
+ \directlua{luamplib.tempdata = luamplib.makeTEXboxes([===[\mplibtmp]===])}%
+ \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\endgroup
}
\else
@@ -1188,32 +1232,48 @@ luamplib.colorconverter = colorconverter
% \begin{macrocode}
\newenvironment{mplibcode}{\toks@{}\ltxdomplibcode}{}
\def\ltxdomplibcode{%
- \bgroup
+ \begingroup
\mplibsetupcatcodes
\ltxdomplibcodeindeed %
}
%
-\long\def\ltxdomplibcodeindeed#1\end{%
- \egroup
- \toks@\expandafter{\the\toks@#1}\ltxdomplibcodefinally%
-}%
-%
-\def\ltxdomplibcodefinally#1{%
- \ifnum\pdf@strcmp{#1}{mplibcode}=\z@
- \directlua{
- luamplib.tempdata = luamplib.makeTEXboxes([===[\the\toks@]===])
- }%
- \directlua{
- luamplib.processwithTEXboxes(luamplib.tempdata)
- }%
+\long\def\ltxdomplibcodeindeed#1\end#2{%
+ \endgroup
+ \toks@\expandafter{\the\toks@#1}%
+ \ifnum\pdf@strcmp{#2}{mplibcode}=\z@
+ \expandafter\def\expandafter\reserved@a\expandafter
+ {\directlua{luamplib.protecttextext([===[\the\toks@]===])}}%
+ \directlua{luamplib.tempdata=luamplib.makeTEXboxes([===[\reserved@a]===])}%
+ \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\end{mplibcode}%
\else
- \toks@\expandafter{\the\toks@\end{#1}}\expandafter\ltxdomplibcode
- \fi%
+ \toks@\expandafter{\the\toks@\end{#2}}\expandafter\ltxdomplibcode
+ \fi
}
\fi
% \end{macrocode}
%
+% \cs{everymplib} \& \cs{everyendmplib}: macros redefining
+% \cs{everymplibtoks} \& \cs{everyendmplibtoks} respectively
+%
+% \begin{macrocode}
+\newtoks\everymplibtoks
+\newtoks\everyendmplibtoks
+\protected\def\everymplib{%
+ \begingroup
+ \mplibsetupcatcodes
+ \expandafter\endgroup
+ \everymplibtoks
+}
+\protected\def\everyendmplib{%
+ \begingroup
+ \mplibsetupcatcodes
+ \expandafter\endgroup
+ \everyendmplibtoks
+}
+\def\mpdim#1{ begingroup \the\dimexpr #1\relax\space endgroup } % gmp.sty
+% \end{macrocode}
+%
% We use a dedicated scratchbox.
%
% \begin{macrocode}
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
index 8fb71d6fe64..e0db6e0c767 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.2,
- date = "2013/12/29",
+ version = 2.3,
+ date = "2014/01/20",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
})
@@ -386,6 +386,38 @@ extra_beginfig := extra_beginfig & " let VerbatimTeX = ignoreVerbatimTeX;" ;
extra_endfig := extra_endfig & " let VerbatimTeX = specialVerbatimTeX;" ;
]]
+local function protecttextext(data)
+ local everymplib = tex.toks['everymplibtoks'] or ''
+ 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]",
+ 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]",
+ function(str)
+ str = stringgsub(str,'"','"&ditto&"')
+ return format("VerbatimTeX(\\unexpanded{\"%s\"})",str)
+ end)
+ data = stringgsub(data, "\".-\"", -- hack for parentheses inside quotes
+ function(str)
+ str = stringgsub(str,"%(","%%%%LEFTPAREN%%%%")
+ 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, "%%%%LEFTPAREN%%%%", "(") -- restore
+ data = stringgsub(data, "%%%%RGHTPAREN%%%%", ")") -- restore
+ texsprint(data)
+end
+
+luamplib.protecttextext = protecttextext
+
local factor = 65536*(7227/7200)
local function putTEXboxes (object,prescript)
@@ -436,22 +468,6 @@ local function domakeTEXboxes (data)
end
local function makeTEXboxes (data)
- data = "relax " .. data
- data = stringgsub(data, "([^A-Z_a-z])btex([^A-Z_a-z])",
- function(pre,post)
- post = stringgsub(post,"%s","")
- return pre .. 'rawtextext("' .. 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
local result = mpx:execute(mplibcodepreamble .. data)
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
index 89d55e9a8e1..548bf58dda4 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/29 v2.2 mplib package for LuaTeX]
+ [2014/01/20 v2.3 mplib package for LuaTeX]
\RequirePackage{luatexbase-modutils}
\RequirePackage{pdftexcmds}
\fi
@@ -35,7 +35,8 @@
\fi
\fi
\def\mplibsetupcatcodes{%
- \catcode`\{=12 \catcode`\}=12 \catcode`\#=12
+ %catcode`\{=12 %catcode`\}=12
+ \catcode`\#=12
\catcode`\^=12 \catcode`\~=12 \catcode`\_=12
%catcode`\%=12 %% don^^e2^^80^^99t in Plain!
\catcode`\&=12 \catcode`\$=12
@@ -51,39 +52,48 @@
}
\long\def\mplibdocode#1\endmplibcode{%
\egroup
- \directlua{
- luamplib.tempdata = luamplib.makeTEXboxes([===[\unexpanded{#1}]===])
- }%
- \directlua{
- luamplib.processwithTEXboxes(luamplib.tempdata)
- }%
+ \expandafter\def\expandafter\mplibtmp\expandafter
+ {\directlua{luamplib.protecttextext([===[\unexpanded{#1}]===])}}%
+ \directlua{luamplib.tempdata = luamplib.makeTEXboxes([===[\mplibtmp]===])}%
+ \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\endgroup
}
\else
\newenvironment{mplibcode}{\toks@{}\ltxdomplibcode}{}
\def\ltxdomplibcode{%
- \bgroup
+ \begingroup
\mplibsetupcatcodes
\ltxdomplibcodeindeed %
}
-\long\def\ltxdomplibcodeindeed#1\end{%
- \egroup
- \toks@\expandafter{\the\toks@#1}\ltxdomplibcodefinally%
-}%
-\def\ltxdomplibcodefinally#1{%
- \ifnum\pdf@strcmp{#1}{mplibcode}=\z@
- \directlua{
- luamplib.tempdata = luamplib.makeTEXboxes([===[\the\toks@]===])
- }%
- \directlua{
- luamplib.processwithTEXboxes(luamplib.tempdata)
- }%
+\long\def\ltxdomplibcodeindeed#1\end#2{%
+ \endgroup
+ \toks@\expandafter{\the\toks@#1}%
+ \ifnum\pdf@strcmp{#2}{mplibcode}=\z@
+ \expandafter\def\expandafter\reserved@a\expandafter
+ {\directlua{luamplib.protecttextext([===[\the\toks@]===])}}%
+ \directlua{luamplib.tempdata=luamplib.makeTEXboxes([===[\reserved@a]===])}%
+ \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\end{mplibcode}%
\else
- \toks@\expandafter{\the\toks@\end{#1}}\expandafter\ltxdomplibcode
- \fi%
+ \toks@\expandafter{\the\toks@\end{#2}}\expandafter\ltxdomplibcode
+ \fi
}
\fi
+\newtoks\everymplibtoks
+\newtoks\everyendmplibtoks
+\protected\def\everymplib{%
+ \begingroup
+ \mplibsetupcatcodes
+ \expandafter\endgroup
+ \everymplibtoks
+}
+\protected\def\everyendmplib{%
+ \begingroup
+ \mplibsetupcatcodes
+ \expandafter\endgroup
+ \everyendmplibtoks
+}
+\def\mpdim#1{ begingroup \the\dimexpr #1\relax\space endgroup } % gmp.sty
\ifx\mplibscratchbox\undefined \newbox\mplibscratchbox \fi
\def\mplibstarttoPDF#1#2#3#4{%
\hbox\bgroup