summaryrefslogtreecommitdiff
path: root/macros/luatex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex')
-rw-r--r--macros/luatex/generic/luamplib/NEWS6
-rw-r--r--macros/luatex/generic/luamplib/luamplib.dtx77
-rw-r--r--macros/luatex/generic/luamplib/luamplib.pdfbin153133 -> 153902 bytes
-rw-r--r--macros/luatex/generic/luamplib/test-luamplib-latex.tex7
4 files changed, 64 insertions, 26 deletions
diff --git a/macros/luatex/generic/luamplib/NEWS b/macros/luatex/generic/luamplib/NEWS
index 8f258c41f6..0a4d0ea068 100644
--- a/macros/luatex/generic/luamplib/NEWS
+++ b/macros/luatex/generic/luamplib/NEWS
@@ -1,5 +1,11 @@
History of the luamplib package
+2022/01/12 2.23.0
+ In parellel with the functionality introduced at previous version,
+ \everymplib (\everyendmplib as well, of course) supports
+ optional argument of named MetaPost instance, affecting only those
+ mplibcode environments of the same name.
+
2022/01/09 2.22.0
* Sergey Slyusarev (@jemmybutton) has suggested and contributed
a new feature for LaTeX mplibcode environment, which now supports
diff --git a/macros/luatex/generic/luamplib/luamplib.dtx b/macros/luatex/generic/luamplib/luamplib.dtx
index ae2f5d3a98..4e9eb71356 100644
--- a/macros/luatex/generic/luamplib/luamplib.dtx
+++ b/macros/luatex/generic/luamplib/luamplib.dtx
@@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information.
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luamplib.drv}%
- [2022/01/09 v2.22.0 Interface for using the mplib library]%
+ [2022/01/12 v2.23.0 Interface for using the mplib library]%
\documentclass{ltxdoc}
\usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace}
\usepackage[x11names]{xcolor}
@@ -153,7 +153,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{2022/01/09 v2.22.0}
+% \date{2022/01/12 v2.23.0}
%
% \maketitle
%
@@ -269,9 +269,9 @@ See source file '\inFileName' for licencing and contact information.
%
% \paragraph{\cs{everymplib}, \cs{everyendmplib}}
% Since v2.3, new macros \cs{everymplib} and \cs{everyendmplib} redefine
-% token lists \cs{everymplibtoks} and \cs{everyendmplibtoks} respectively,
+% the lua table containing MetaPost code
% which will
-% be automatically inserted at the beginning and ending of each mplib code.
+% be automatically inserted at the beginning and ending of each |mplibcode|.
% \begin{verbatim}
% \everymplib{ beginfig(0); }
% \everyendmplib{ endfig; }
@@ -374,6 +374,17 @@ See source file '\inFileName' for licencing and contact information.
% \item When an instance names is set,
% respective |\currentmpinstancename| is set.
% \end{itemize}
+% In parellel with this functionality, v2.23 and after supports
+% optional argument of instance name for \cs{everymplib} and
+% \cs{everyendmplib}, affecting only those |mplibcode| environments
+% of the same name.
+% Unnamed \cs{everymplib} affects not only those instances with no name,
+% but also those with name but with no corresponding \cs{everymplib}.
+% Syntax is:
+% \begin{verbatim}
+% \everymplib[instanceName]{...}
+% \everyendmplib[instanceName]{...}
+% \end{verbatim}
%
% \paragraph{\cs{mplibglobaltextext}}
% To inherit |btex ... etex| labels as well as metapost variables,
@@ -435,8 +446,8 @@ See source file '\inFileName' for licencing and contact information.
luatexbase.provides_module {
name = "luamplib",
- version = "2.22.0",
- date = "2022/01/09",
+ version = "2.23.0",
+ date = "2022/01/12",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}
@@ -1258,6 +1269,9 @@ local function unprotect_expansion (str)
end
end
+luamplib.everymplib = { [""] = "" }
+luamplib.everyendmplib = { [""] = "" }
+
local function process_mplibcode (data, instancename)
% \end{macrocode}
%
@@ -1265,8 +1279,10 @@ local function process_mplibcode (data, instancename)
% \begin{macrocode}
legacy_mplibcode_reset()
- local everymplib = texgettoks'everymplibtoks' or ''
- local everyendmplib = texgettoks'everyendmplibtoks' or ''
+ local everymplib = luamplib.everymplib[instancename] or
+ luamplib.everymplib[""]
+ local everyendmplib = luamplib.everyendmplib[instancename] or
+ luamplib.everyendmplib[""]
data = format("\n%s\n%s\n%s\n",everymplib, data, everyendmplib)
data = data:gsub("\r","\n")
@@ -2040,7 +2056,7 @@ luamplib.colorconverter = colorconverter
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2022/01/09 v2.22.0 mplib package for LuaTeX]
+ [2022/01/12 v2.23.0 mplib package for LuaTeX]
\ifx\newluafunction\@undefined
\input ltluatex
\fi
@@ -2124,7 +2140,7 @@ luamplib.colorconverter = colorconverter
}
\long\def\mplibdocode#1\endmplibcode{%
\endgroup
- \directlua{luamplib.process_mplibcode([===[\unexpanded{#1}]===])}%
+ \directlua{luamplib.process_mplibcode([===[\unexpanded{#1}]===],"")}%
\endgroup
}
\else
@@ -2186,30 +2202,47 @@ luamplib.colorconverter = colorconverter
\newtoks\mplibtmptoks
% \end{macrocode}
%
-% \cs{everymplib} \& \cs{everyendmplib}: macros redefining
-% \cs{everymplibtoks} \& \cs{everyendmplibtoks} respectively
+% \cs{everymplib} \& \cs{everyendmplib}: macros resetting
+% |luamplib.every(end)mplib| tables
%
% \begin{macrocode}
-\newtoks\everymplibtoks
-\newtoks\everyendmplibtoks
\protected\def\everymplib{%
\begingroup
\mplibsetupcatcodes
\mplibdoeverymplib
}
-\long\def\mplibdoeverymplib#1{%
- \endgroup
- \everymplibtoks{#1}%
-}
\protected\def\everyendmplib{%
\begingroup
\mplibsetupcatcodes
\mplibdoeveryendmplib
}
-\long\def\mplibdoeveryendmplib#1{%
- \endgroup
- \everyendmplibtoks{#1}%
-}
+\ifcsname ver@luamplib.sty\endcsname
+ \newcommand\mplibdoeverymplib[2][]{%
+ \endgroup
+ \directlua{
+ luamplib.everymplib["#1"] = [===[\unexpanded{#2}]===]
+ }%
+ }
+ \newcommand\mplibdoeveryendmplib[2][]{%
+ \endgroup
+ \directlua{
+ luamplib.everyendmplib["#1"] = [===[\unexpanded{#2}]===]
+ }%
+ }
+\else
+ \long\def\mplibdoeverymplib#1{%
+ \endgroup
+ \directlua{
+ luamplib.everymplib[""] = [===[\unexpanded{#1}]===]
+ }%
+ }
+ \long\def\mplibdoeveryendmplib#1{%
+ \endgroup
+ \directlua{
+ luamplib.everyendmplib[""] = [===[\unexpanded{#1}]===]
+ }%
+ }
+\fi
% \end{macrocode}
%
% Allow \TeX\ dimen/color macros. Now |runscript| does the job,
diff --git a/macros/luatex/generic/luamplib/luamplib.pdf b/macros/luatex/generic/luamplib/luamplib.pdf
index aeefe5ca28..58ee697d5f 100644
--- a/macros/luatex/generic/luamplib/luamplib.pdf
+++ b/macros/luatex/generic/luamplib/luamplib.pdf
Binary files differ
diff --git a/macros/luatex/generic/luamplib/test-luamplib-latex.tex b/macros/luatex/generic/luamplib/test-luamplib-latex.tex
index 632dae44e6..e3b0441336 100644
--- a/macros/luatex/generic/luamplib/test-luamplib-latex.tex
+++ b/macros/luatex/generic/luamplib/test-luamplib-latex.tex
@@ -169,12 +169,13 @@ diameter:\Dia bp.%
\vskip 2\baselineskip
\mplibcodeinherit{disable}%
+\everymplib[instanceOne]{beginfig(1);}
+\everyendmplib[instanceOne]{endfig;}
+
\begin{mplibcode}[instanceOne]
-beginfig(1);
a := 1cm;
draw fullcircle scaled a;
draw btex a circle with $d=a$ etex shifted (a,0);
-endfig;
\end{mplibcode}%
Current instance name is: \currentmpinstancename \vskip 2\baselineskip
@@ -213,10 +214,8 @@ endfig;
Current instance name is: \currentmpinstancename (should be empty) \vskip 2\baselineskip
\begin{mplibcode}[instanceOne]
-beginfig(1);
draw unitsquare scaled a;
draw btex a square with side $=a$, inherited from the same instance etex shifted (3/2a, 1/2a);
-endfig;
\end{mplibcode}%
Current instance name is: \currentmpinstancename \vskip 2\baselineskip