summaryrefslogtreecommitdiff
path: root/macros/luatex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-01-10 03:02:56 +0000
committerNorbert Preining <norbert@preining.info>2022-01-10 03:02:56 +0000
commitd50bfeb7feb32d585a89393c364ef5f9e1b915d0 (patch)
treee6d64ce9f2cb129a6c6d974ebd29251a13cba8d7 /macros/luatex
parentfbacb8167ccd172bb0b177974778f228ad41691d (diff)
CTAN sync 202201100302
Diffstat (limited to 'macros/luatex')
-rw-r--r--macros/luatex/generic/luamplib/NEWS8
-rw-r--r--macros/luatex/generic/luamplib/luamplib.dtx56
-rw-r--r--macros/luatex/generic/luamplib/luamplib.pdfbin151338 -> 153133 bytes
-rw-r--r--macros/luatex/generic/luamplib/test-luamplib-latex.tex56
4 files changed, 106 insertions, 14 deletions
diff --git a/macros/luatex/generic/luamplib/NEWS b/macros/luatex/generic/luamplib/NEWS
index 1fd97ca4f2..8f258c41f6 100644
--- a/macros/luatex/generic/luamplib/NEWS
+++ b/macros/luatex/generic/luamplib/NEWS
@@ -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)
diff --git a/macros/luatex/generic/luamplib/luamplib.dtx b/macros/luatex/generic/luamplib/luamplib.dtx
index 0966f32b98..ae2f5d3a98 100644
--- a/macros/luatex/generic/luamplib/luamplib.dtx
+++ b/macros/luatex/generic/luamplib/luamplib.dtx
@@ -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@tug.org>
@@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information.
%<*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 @@ 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{2021/11/23 v2.21.1}
+% \date{2022/01/09 v2.22.0}
%
% \maketitle
%
@@ -353,6 +353,28 @@ See source file '\inFileName' for licencing and contact information.
% 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 @@ See source file '\inFileName' for licencing and contact information.
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 @@ end
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 @@ local function process (data)
% 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 @@ local function unprotect_expansion (str)
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 @@ local function process_mplibcode (data)
end)
end
- process(data)
+ process(data, instancename)
end
luamplib.process_mplibcode = process_mplibcode
@@ -2011,7 +2040,7 @@ luamplib.colorconverter = colorconverter
\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 @@ luamplib.colorconverter = colorconverter
%
% 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 @@ luamplib.colorconverter = colorconverter
\mplibtmptoks\expandafter{\the\mplibtmptoks#1}%
\def\mplibtemp@a{#2}%
\ifx\mplib@mplibcode\mplibtemp@a
- \directlua{luamplib.process_mplibcode([===[\the\mplibtmptoks]===])}%
+ \directlua{luamplib.process_mplibcode([===[\the\mplibtmptoks]===],"\currentmpinstancename")}%
\end{mplibcode}%
\else
\mplibtmptoks\expandafter{\the\mplibtmptoks\end{#2}}%
diff --git a/macros/luatex/generic/luamplib/luamplib.pdf b/macros/luatex/generic/luamplib/luamplib.pdf
index a2685b2b09..aeefe5ca28 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 dc06a9bd8f..632dae44e6 100644
--- a/macros/luatex/generic/luamplib/test-luamplib-latex.tex
+++ b/macros/luatex/generic/luamplib/test-luamplib-latex.tex
@@ -164,6 +164,60 @@ diameter:\Dia bp.%
rotatedlabel.top(textext("Rotated!"), origin, 45);
endfig;
\end{mplibcode}%
-
\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}