texlive[61554] Master/texmf-dist: luamplib (9jan22)
commits+karl at tug.org
commits+karl at tug.org
Sun Jan 9 22:20:32 CET 2022
Revision: 61554
http://tug.org/svn/texlive?view=revision&revision=61554
Author: karl
Date: 2022-01-09 22:20:32 +0100 (Sun, 09 Jan 2022)
Log Message:
-----------
luamplib (9jan22)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS
trunk/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex
trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
Modified: trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS 2022-01-09 21:20:14 UTC (rev 61553)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS 2022-01-09 21:20:32 UTC (rev 61554)
@@ -1,5 +1,13 @@
History of the luamplib package
+2022/01/09 2.22.0
+ * Sergey Slyusarev (@jemmybutton) has suggested and contributed
+ a new feature for LaTeX mplibcode environment, which now supports
+ separately named MetaPost instances. Using this feature,
+ all the variables and functions are shared only among
+ all the environments belonging to the same instance.
+ (#99 and #100)
+
2021/11/23 2.21.1
* address #97 (typesetting fails with "--lua" option)
Modified: trunk/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex 2022-01-09 21:20:14 UTC (rev 61553)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex 2022-01-09 21:20:32 UTC (rev 61554)
@@ -164,6 +164,60 @@
rotatedlabel.top(textext("Rotated!"), origin, 45);
endfig;
\end{mplibcode}%
+\tracingcommands0
-\tracingcommands0
+\vskip 2\baselineskip
+\mplibcodeinherit{disable}%
+
+\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
+
+\begin{mplibcode}[instanceTwo]
+beginfig(1);
+if not known a:
+ draw btex code is not inherited from an instance with a different name etex;
+else:
+ errmessage("Variable was inherited from a different instance");
+fi;
+endfig;
+\end{mplibcode}%
+Current instance name is: \currentmpinstancename \vskip 2\baselineskip
+
+\begin{mplibcode}
+beginfig(1);
+if not known a:
+ draw btex code is not inherited if instance name is not listed etex;
+else:
+ errmessage("Variable was inherited from a different instance");
+fi;
+a := 1cm;
+endfig;
+\end{mplibcode}%
+Current instance name is: \currentmpinstancename (should be empty) \vskip 2\baselineskip
+
+\begin{mplibcode}
+beginfig(1);
+if not known a:
+ draw btex code is not inherited if mplibcodeinherit is disabled and instance name is not explicitly set etex;
+else:
+ errmessage("Variable was inherited when code inheritance is turned off and instance name is not set");
+fi;
+endfig;
+\end{mplibcode}%
+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
+
\end{document}
Modified: trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
===================================================================
--- trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx 2022-01-09 21:20:14 UTC (rev 61553)
+++ trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx 2022-01-09 21:20:32 UTC (rev 61554)
@@ -1,6 +1,6 @@
% \iffalse meta-comment -- by the way, this file contains UTF-8
%
-% Copyright (C) 2008-2021 by Hans Hagen, Taco Hoekwater, Elie Roux,
+% Copyright (C) 2008-2022 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 at tug.org>
@@ -85,7 +85,7 @@
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luamplib.drv}%
- [2021/11/23 v2.21.1 Interface for using the mplib library]%
+ [2022/01/09 v2.22.0 Interface for using the mplib library]%
\documentclass{ltxdoc}
\usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace}
\usepackage[x11names]{xcolor}
@@ -153,7 +153,7 @@
% \author{Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang and Kim Dohyun\\
% Maintainer: LuaLaTeX Maintainers ---
% Support: \email{lualatex-dev at tug.org}}
-% \date{2021/11/23 v2.21.1}
+% \date{2022/01/09 v2.22.0}
%
% \maketitle
%
@@ -353,6 +353,28 @@
% each code chunks being treated as an independent instance, and never
% affected by previous code chunks.
%
+% \paragraph{Separate instances for \LaTeX{} environment}
+% v2.22 has added the support for several named MetaPost instances
+% in \LaTeX{} |mplibcode| environment.
+% Syntax is like so:
+% \begin{verbatim}
+% \begin{mplibcode}[instanceName]
+% % some mp code
+% \end{mplibcode}
+% \end{verbatim}
+% Behaviour is as follows.
+% \begin{itemize}
+% \item All the variables and functions are shared
+% only among all the environments belonging to the same instance.
+% \item |\mplibcodeinherit| only affects environments
+% with no instance name set (since if a name is set,
+% the code is intended to be reused at some point).
+% \item |btex ... etex| labels still exist separately and
+% require |\mplibglobaltextext|.
+% \item When an instance names is set,
+% respective |\currentmpinstancename| is set.
+% \end{itemize}
+%
% \paragraph{\cs{mplibglobaltextext}}
% To inherit |btex ... etex| labels as well as metapost variables,
% it is necessary to declare \cs{mplibglobaltextext\{enable\}} in advance.
@@ -413,8 +435,8 @@
luatexbase.provides_module {
name = "luamplib",
- version = "2.21.1",
- date = "2021/11/23",
+ version = "2.22.0",
+ date = "2022/01/09",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}
@@ -846,7 +868,7 @@
luamplib.codeinherit = false
local mplibinstances = {}
-local function process (data)
+local function process (data, instancename)
% \end{macrocode}
%
% The workaround of issue \#70 seems to be unnecessary, as we use
@@ -857,10 +879,17 @@
% end
% \end{verbatim}
% \begin{macrocode}
- local standalone = not luamplib.codeinherit
- local currfmt = currentformat .. (luamplib.numbersystem or "scaled")
+ local defaultinstancename = currentformat .. (luamplib.numbersystem or "scaled")
.. tostring(luamplib.textextlabel) .. tostring(luamplib.legacy_verbatimtex)
+ local currfmt = instancename or defaultinstancename
+ if #currfmt == 0 then
+ currfmt = defaultinstancename
+ end
local mpx = mplibinstances[currfmt]
+ local standalone = false
+ if currfmt == defaultinstancename then
+ standalone = not luamplib.codeinherit
+ end
if mpx and standalone then
mpx:finish()
end
@@ -1229,7 +1258,7 @@
end
end
-local function process_mplibcode (data)
+local function process_mplibcode (data, instancename)
% \end{macrocode}
%
% This is needed for legacy behavior regarding |verbatimtex|
@@ -1283,7 +1312,7 @@
end)
end
- process(data)
+ process(data, instancename)
end
luamplib.process_mplibcode = process_mplibcode
@@ -2011,7 +2040,7 @@
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2021/11/23 v2.21.1 mplib package for LuaTeX]
+ [2022/01/09 v2.22.0 mplib package for LuaTeX]
\ifx\newluafunction\@undefined
\input ltluatex
\fi
@@ -2103,7 +2132,8 @@
%
% The \LaTeX-specific part: a new environment.
% \begin{macrocode}
-\newenvironment{mplibcode}{%
+\newenvironment{mplibcode}[1][]{%
+ \global\def\currentmpinstancename{#1}%
\mplibtmptoks{}\ltxdomplibcode
}{}
\def\ltxdomplibcode{%
@@ -2117,7 +2147,7 @@
\mplibtmptoks\expandafter{\the\mplibtmptoks#1}%
\def\mplibtemp at a{#2}%
\ifx\mplib at mplibcode\mplibtemp at a
- \directlua{luamplib.process_mplibcode([===[\the\mplibtmptoks]===])}%
+ \directlua{luamplib.process_mplibcode([===[\the\mplibtmptoks]===],"\currentmpinstancename")}%
\end{mplibcode}%
\else
\mplibtmptoks\expandafter{\the\mplibtmptoks\end{#2}}%
Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua 2022-01-09 21:20:14 UTC (rev 61553)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua 2022-01-09 21:20:32 UTC (rev 61554)
@@ -11,8 +11,8 @@
luatexbase.provides_module {
name = "luamplib",
- version = "2.21.1",
- date = "2021/11/23",
+ version = "2.22.0",
+ date = "2022/01/09",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}
@@ -346,11 +346,18 @@
luamplib.codeinherit = false
local mplibinstances = {}
-local function process (data)
- local standalone = not luamplib.codeinherit
- local currfmt = currentformat .. (luamplib.numbersystem or "scaled")
+local function process (data, instancename)
+ local defaultinstancename = currentformat .. (luamplib.numbersystem or "scaled")
.. tostring(luamplib.textextlabel) .. tostring(luamplib.legacy_verbatimtex)
+ local currfmt = instancename or defaultinstancename
+ if #currfmt == 0 then
+ currfmt = defaultinstancename
+ end
local mpx = mplibinstances[currfmt]
+ local standalone = false
+ if currfmt == defaultinstancename then
+ standalone = not luamplib.codeinherit
+ end
if mpx and standalone then
mpx:finish()
end
@@ -635,7 +642,7 @@
end
end
-local function process_mplibcode (data)
+local function process_mplibcode (data, instancename)
legacy_mplibcode_reset()
local everymplib = texgettoks'everymplibtoks' or ''
@@ -675,7 +682,7 @@
end)
end
- process(data)
+ process(data, instancename)
end
luamplib.process_mplibcode = process_mplibcode
Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty 2022-01-09 21:20:14 UTC (rev 61553)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty 2022-01-09 21:20:32 UTC (rev 61554)
@@ -14,7 +14,7 @@
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2021/11/23 v2.21.1 mplib package for LuaTeX]
+ [2022/01/09 v2.22.0 mplib package for LuaTeX]
\ifx\newluafunction\@undefined
\input ltluatex
\fi
@@ -62,7 +62,8 @@
\endgroup
}
\else
-\newenvironment{mplibcode}{%
+\newenvironment{mplibcode}[1][]{%
+ \global\def\currentmpinstancename{#1}%
\mplibtmptoks{}\ltxdomplibcode
}{}
\def\ltxdomplibcode{%
@@ -76,7 +77,7 @@
\mplibtmptoks\expandafter{\the\mplibtmptoks#1}%
\def\mplibtemp at a{#2}%
\ifx\mplib at mplibcode\mplibtemp at a
- \directlua{luamplib.process_mplibcode([===[\the\mplibtmptoks]===])}%
+ \directlua{luamplib.process_mplibcode([===[\the\mplibtmptoks]===],"\currentmpinstancename")}%
\end{mplibcode}%
\else
\mplibtmptoks\expandafter{\the\mplibtmptoks\end{#2}}%
More information about the tex-live-commits
mailing list.