texlive[71915] Master/texmf-dist: luamplib (27jul24)

commits+karl at tug.org commits+karl at tug.org
Sat Jul 27 22:48:49 CEST 2024


Revision: 71915
          https://tug.org/svn/texlive?view=revision&revision=71915
Author:   karl
Date:     2024-07-27 22:48:48 +0200 (Sat, 27 Jul 2024)
Log Message:
-----------
luamplib (27jul24)

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	2024-07-27 20:48:40 UTC (rev 71914)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS	2024-07-27 20:48:48 UTC (rev 71915)
@@ -1,5 +1,11 @@
                        History of the luamplib package
 
+2024/07/27 2.34.3
+   * in DVI mode, use LaTeX's shipout hooks to generate new XObjects
+   or to put resources to pageresources. (in plain, load atbegshi.sty)
+
+   * fix shading to allow the even-odd rule
+
 2024/07/24 2.34.2
    * With the newly introduced macros, \mplibgroup ... \endmplibgroup, users
    can define a transparency group or a normal form XObject from TeX side.

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	2024-07-27 20:48:40 UTC (rev 71914)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex	2024-07-27 20:48:48 UTC (rev 71915)
@@ -246,19 +246,19 @@
 \endmpfig
 \par\leavevmode
 \mppattern{mypatt}
-  \mpfig
-    picture q;
-    q := btex Q etex;
-    fill bbox q withcolor .8[red,white];
-    draw q withcolor .8red;
-  \endmpfig
+[
+  xstep = 5, ystep = 6,
+%  matrix = "rotated 30",
+]
+\mpfig
+draw (llcorner unitsquare--urcorner unitsquare) scaled 5 withcolor 1/3[blue,white] ;
+draw (ulcorner unitsquare--lrcorner unitsquare) scaled 5 withcolor 1/3[red,white] ;
+\endmpfig
 \endmppattern
 \mpfig
-  fill fullcircle scaled 100 withpostscript "collect";
-  draw unitsquare shifted - center unitsquare scaled 45
-    withpattern "mypatt"
-    withpostscript "evenodd"
-    ;
+draw unitsquare shifted -center unitsquare scaled 45 withpostscript "collect" ;
+draw fullcircle scaled 100 withpattern "mypatt" withpen pencircle scaled 1
+  withcolor \mpcolor{red!50!blue!50} withpostscript "evenodd" ;
 \endmpfig
 \begin{mppattern}{pattuncolored}
   [
@@ -323,7 +323,7 @@
   withgroupname "test:#1"
   withtransparency (1,.5)
   ;
-  currentpicture := currentpicture scaled 3/4;
+  currentpicture := currentpicture scaled 2/3;
   \endmpfig
 }%
 \hbox{\test{isolated,knockout}\,\test{isolated}\vbox to\MPheight{\vss\hbox{~isolated}\vss}}%

Modified: trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
===================================================================
--- trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx	2024-07-27 20:48:40 UTC (rev 71914)
+++ trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx	2024-07-27 20:48:48 UTC (rev 71915)
@@ -85,7 +85,7 @@
 %<*driver>
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesFile{luamplib.drv}%
-  [2024/07/24 v2.34.2 Interface for using the mplib library]%
+  [2024/07/27 v2.34.3 Interface for using the mplib library]%
 \documentclass{ltxdoc}
 \usepackage{metalogo,multicol,xspace}
 \usepackage[x11names]{xcolor}
@@ -123,10 +123,9 @@
 
 \newcommand*\email [1] {<\href{mailto:#1}{#1}>}
 \newcommand \file       {\nolinkurl}
-\newcommand \pk         {\textsf}
 
 \newcommand*\metapost {\textsc{metapost}\xspace}
-\newcommand*\mplib {\textsf{mplib}\xspace}
+\newcommand*\mplib {\pkg{mplib}\xspace}
 
 \begin{document}
   \DocInput{luamplib.dtx}%
@@ -152,11 +151,11 @@
 %   Grave accent  \`     Left brace    \{     Vertical bar  \|
 %   Right brace   \}     Tilde         \~}
 %
-% \title{The \textsf{luamplib} package}
+% \title{The \pkg{luamplib} package}
 % \author{Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang and Kim Dohyun\\
 % Current Maintainer: Kim Dohyun\\
 % Support: \url{https://github.com/lualatex/luamplib}}
-% \date{2024/07/24 v2.34.2}
+% \date{2024/07/27 v2.34.3}
 %
 % \maketitle
 %
@@ -174,9 +173,9 @@
 %
 % 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.
+% |mplibcode| environment.
 %
-% The resulting \metapost figures are put in a \TeX\ \texttt{hbox} with dimensions
+% The resulting \metapost figures are put in a \TeX\ |hbox| with dimensions
 % adjusted to the \metapost code.
 %
 % The code of luamplib is basically from the |luatex-mplib.lua| and |luatex-mplib.tex| files
@@ -186,13 +185,13 @@
 %
 % \begin{itemize}
 % \item possibility to use |btex ... etex| to typeset \TeX\ code.
-%   |textext()| is a more versatile macro equivalent to |TEX()| from \textsf{TEX.mp}.
+%   |textext()| is a more versatile macro equivalent to |TEX()| from \pkg{TEX.mp}.
 %   |TEX()| is also allowed and is a synonym of |textext()|.
 %   The argument of
 %   \mplib's primitive |maketext| will also be processed by the same routine.
 %
 % \item possibility to use |verbatimtex ... etex|, though it's behavior cannot
-%   be the same as the stand-alone \textsf{mpost}.
+%   be the same as the stand-alone \pkg{mpost}.
 %   Of course you cannot include \cs{documentclass}, \cs{usepackage} etc.
 %   When these \TeX\ commands are found in |verbatimtex ... etex|, the entire code will be
 %   ignored.
@@ -231,7 +230,7 @@
 %     \end{mplibcode}
 %\end{verbatim}
 %
-% \paragraph{\cs{mplibsetformat\{plain\char"7C metafun\}}}
+% \paragraph{\cs{mplibsetformat\{plain\textbar metafun\}}}
 %   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
@@ -267,15 +266,15 @@
 %   it is regarded by luamplib as
 %   a color expression of \TeX\ side.
 %   For instance, when |withshadecolors("orange", 2/3red)| is given, the first color |"orange"| will be
-%   interpreted as an \textsf{xcolor}'s or \textsf{l3color}'s expression.
+%   interpreted as a \pkg{color}, \pkg{xcolor} or \pkg{l3color}'s expression.
 %
-% \paragraph{\cs{mplibnumbersystem\{scaled\char"7C double\char"7C decimal\}}}
+% \paragraph{\cs{mplibnumbersystem\{scaled\textbar double\textbar decimal\}}}
 %   Users can choose |numbersystem| option.
 %   The default value is |scaled|, which can be changed
 %   by declaring \cs{mplibnumbersystem\{double\}} or
 %   \cs{mplibnumbersystem\{decimal\}}.
 %
-% \paragraph{\cs{mplibshowlog\{enable\char"7C disable\}}}
+% \paragraph{\cs{mplibshowlog\{enable\textbar disable\}}}
 %   Default: |disable|.
 %   When \cs{mplibshowlog\{enable\}}\footnote{As for user's setting,
 %   |enable|, |true| and |yes| are identical;
@@ -283,7 +282,7 @@
 %   the \metapost process will be printed to the |.log| file.
 %   This is the \TeX{} side interface for |luamplib.showlog|.
 %
-% \paragraph{\cs{mpliblegacybehavior\{enable\char"7C disable\}}}
+% \paragraph{\cs{mpliblegacybehavior\{enable\textbar disable\}}}
 %   \hypertarget{mpliblegacybehavior}{}\relax
 %   By default, \cs{mpliblegacybehavior\{enable\}}
 %   is already declared for backward compatibility,
@@ -321,7 +320,7 @@
 %\end{verbatim}
 %
 %   By contrast,
-%   when \cs{mpliblegacybehavior\{disabled\}} is declared, any
+%   when \cs{mpliblegacybehavior\{disable\}} is declared, any
 %   |verbatimtex| |...| |etex| will be executed, along with |btex| |...| |etex|,
 %   sequentially one by one.
 %   So, some \TeX\ code in |verbatimtex ... etex| will have effects on
@@ -337,7 +336,7 @@
 %     \end{mplibcode}
 %\end{verbatim}
 %
-% \paragraph{\cs{mplibtextextlabel\{enable\char"7C disable\}}}
+% \paragraph{\cs{mplibtextextlabel\{enable\textbar disable\}}}
 %   Default: |disable|.
 %   \cs{mplibtextextlabel\{enable\}} enables
 %   the labels typeset via |textext| instead of |infont| operator.
@@ -351,7 +350,7 @@
 %   Also take care of |char| operator in the left side argument,
 %   as this might bring unpermitted characters into \TeX.
 %
-% \paragraph{\cs{mplibcodeinherit\{enable\char"7C disable\}}}
+% \paragraph{\cs{mplibcodeinherit\{enable\textbar disable\}}}
 %   Default: |disable|.
 %   \cs{mplibcodeinherit\{enable\}} enables the inheritance
 %   of variables, constants, and macros defined by previous \metapost code chunks.
@@ -393,7 +392,7 @@
 %     \everyendmplib[instanceName]{...}
 %\end{verbatim}
 %
-% \paragraph{\cs{mplibglobaltextext\{enable\char"7C disable\}}}
+% \paragraph{\cs{mplibglobaltextext\{enable\textbar disable\}}}
 %   Default: |disable|.
 %   Formerly, to inherit |btex| |...| |etex| boxes as well as other \metapost macros, variables and constants,
 %   it was necessary to declare \cs{mplibglobaltextext\{enable\}} in advance.
@@ -414,7 +413,7 @@
 %   \endmplibcode
 %\end{verbatim}
 %
-% \paragraph{\cs{mplibverbatim\{enable\char"7C disable\}}}
+% \paragraph{\cs{mplibverbatim\{enable\textbar disable\}}}
 %   Default: |disable|.
 %   Users can issue \cs{mplibverbatim\{enable\}}, after which
 %   the contents of mplibcode environment will be read verbatim. As a result,
@@ -426,8 +425,8 @@
 % \paragraph{\cs{mpdim\{...\}}}
 %   \hypertarget{mpdim}{}\relax
 %   Besides other \TeX\ commands, \cs{mpdim} is specially allowed
-%   in the mplibcode environment. This feature is inpired by \textsf{gmp} package authored by
-%   Enrico Gregorio. Please refer to the manual of \textsf{gmp} package for details.
+%   in the mplibcode environment. This feature is inpired by \pkg{gmp} package authored by
+%   Enrico Gregorio. Please refer to the manual of \pkg{gmp} package for details.
 %\begin{verbatim}
 %     \begin{mplibcode}
 %       beginfig(1)
@@ -439,13 +438,13 @@
 %
 % \paragraph{\cs{mpcolor[...]\{...\}}}
 %   With \cs{mpcolor} command, color names or expressions of
-%   \textsf{color}, \textsf{xcolor} and \textsf{l3color} module/packages can be used in the mplibcode
-%   enviroment (after |withcolor| operator).
+%   \pkg{color}, \pkg{xcolor} and \pkg{l3color} module/packages can be used in the mplibcode
+%   environment (after |withcolor| operator).
 %   See the example \hyperlink{mpdim}{above}.
-%   The optional |[...]| means the option of \textsf{xcolor}'s \cs{color} command.
-%   For spot colors, \textsf{l3color} (in PDF/DVI mode),
-%   \textsf{colorspace}, \textsf{spotcolor}
-%   (in PDF mode) and \textsf{xespotcolor} (in DVI mode) packages are supported
+%   The optional |[...]| denotes the option of \pkg{xcolor}'s \cs{color} command.
+%   For spot colors, \pkg{l3color} (in PDF/DVI mode),
+%   \pkg{colorspace}, \pkg{spotcolor}
+%   (in PDF mode) and \pkg{xespotcolor} (in DVI mode) packages are supported
 %   as well.
 %
 % \paragraph{\cs{mpfig} \ldots\ \cs{endmpfig}}
@@ -532,7 +531,7 @@
 %
 % \paragraph{\texttt{mplibdimen(...)}, \texttt{mplibcolor(...)}}
 %   These are \metapost interfaces for the \TeX\ commands
-%   \hyperlink{mpdim}{\cs{mpdim} \textcolor{black}{and} \cs{mpcolor}}. For example,
+%   \cs{mpdim} and \cs{mpcolor} (see \hyperlink{mpdim}{above}). For example,
 %   |mplibdimen("\linewidth")| is basically the same as \cs{mpdim\{\cs{linewidth}\}}, and
 %   |mplibcolor("red!50")| is basically the same as \cs{mpcolor\{red!50\}}.
 %   The difference is that these \metapost operators can also be used in external |.mp| files,
@@ -567,7 +566,7 @@
 %   |fakebold|, |drawcolor| and |fillcolor| are optional;
 %   default values are |2|, |"black"| and |"white"| respectively.
 %   When the color expressions are given in string type, they are regarded as
-%   \textsf{xcolor}'s or \textsf{l3color}'s expressions.
+%   \pkg{color}, \pkg{xcolor} or \pkg{l3color}'s expressions.
 %   All from |mplibgraphictext| to the end of sentence will compose an
 %   anonymous |picture|, which can be drawn or assigned to a variable.
 %   Incidentally, |withdrawcolor| and |withfillcolor| are synonyms of
@@ -581,7 +580,7 @@
 %   However, because the implementation is quite different from others,
 %   there are some limitations such that you can't
 %   apply shading (gradient colors) to the text. Again,
-%   in DVI mode, \textsf{unicode-math} package is needed for math formula,
+%   in DVI mode, \pkg{unicode-math} package is needed for math formula,
 %   as we cannot embolden type1 fonts in DVI mode.
 %
 %   \paragraph{\texttt{mplibglyph ... of ...}}
@@ -612,10 +611,10 @@
 %   will remain transparent.
 %
 %   \leavevmode\llap{\textcolor{red}{☞}\kern1.2\parindent}\relax
-%   To apply the nonzero winding number rule to a picture containg paths,
+%   To apply the nonzero winding number rule to a picture containing paths,
 %   luamplib appends |withpostscript| |"collect"|
 %   to the paths except the last one in the picture.
-%   If you want the even-odd rule instead, you can, even with \emph{plain} format,
+%   If you want the even-odd rule instead, you can, with \emph{plain} format as well,
 %   additionally declare |withpostscript| |"evenodd"| to the last path in the picture.
 %
 % \paragraph{\texttt{mpliboutlinetext (...)}}
@@ -637,7 +636,7 @@
 %   \textsc{n.b.} As Unicode grapheme cluster is not considered in the array, a unit that must be
 %   a single cluster might be separated apart.
 %
-% \paragraph{\cs{mppattern\{...\}} \texttt{...} \cs{endmppattern}, \texttt{... withpattern ...}}
+% \paragraph{\cs{mppattern\{...\} ...} \cs{endmppattern}, \texttt{... withpattern ...}}
 %   \hypertarget{mppattern}{}\relax
 %   \TeX\ macros
 %   \cs{mppattern\{<name>\}} |...| \cs{endmppattern} define a tiling pattern
@@ -648,26 +647,34 @@
 %   by replicating it horizontally and vertically.
 %   An example:
 %\begin{verbatim}
-%     \mppattern{mypatt}           % or \begin{mppattern}{mypatt}
-%       [                          % options: see below
-%         xstep = 10, ystep = 12,
-%         matrix = {0,1,-1,0},     % or "0 1 -1 0"
-%       ]
-%       \mpfig                     % or any other TeX code,
-%         picture q;
-%         q := btex Q etex;
-%         fill bbox q withcolor .8[red,white];
-%         draw q withcolor .8red;
-%       \endmpfig
-%     \endmppattern                % or \end{mppattern}
+%    \mppattern{mypatt}               % or \begin{mppattern}{mypatt}
+%      [                              % options: see below
+%        xstep = 10, ystep = 12,
+%        matrix = {0, 1, -1, 0},      % or "0 1 -1 0"
+%      ]
+%      \mpfig                         % or any other TeX code,
+%        draw (llcorner unitsquare--urcorner unitsquare)
+%          scaled 10
+%          withcolor 1/3[blue,white]
+%          ;
+%        draw (ulcorner unitsquare--lrcorner unitsquare)
+%          scaled 10
+%          withcolor 1/3[red,white]
+%          ;
+%      \endmpfig
+%    \endmppattern                    % or \end{mppattern}
 %
-%     \mpfig
-%       fill fullcircle scaled 100
-%         withpostscript "collect" ;
-%       draw unitsquare shifted - center unitsquare scaled 45
-%         withpattern "mypatt"
-%         withpostscript "evenodd" ;
-%     \endmpfig
+%    \mpfig
+%      draw fullcircle scaled 90
+%        withpostscript "collect"
+%        ;
+%      draw fullcircle scaled 200
+%        withpattern "mypatt"
+%        withpen pencircle scaled 1
+%        withcolor \mpcolor{red!50!blue!50}
+%        withpostscript "evenodd"
+%        ;
+%    \endmpfig
 %\end{verbatim}
 %
 %   The available options are listed in Table~\ref{tab:mppatternoptions}.
@@ -705,7 +712,7 @@
 %   Uncolored pattern will be painted later by the color of a \metapost object.
 %   An example:
 %\begin{verbatim}
-%      \begin{mppattern}{pattuncolored}
+%      \begin{mppattern}{pattnocolor}
 %        [
 %          colored = false,
 %          matrix = "slanted .3 rotated 30",
@@ -725,7 +732,7 @@
 %            if j < length mpliboutlinepic[i]:
 %                withpostscript "collect"
 %            else:
-%                withpattern "pattuncolored"
+%                withpattern "pattnocolor"
 %                withpen pencircle scaled 1/2
 %                withcolor (i/4)[red,blue]          % paints the pattern
 %            fi;
@@ -737,7 +744,7 @@
 %
 % \paragraph{\texttt{... withfademethod ...}}
 %   This is a \metapost operator which makes the color of an object gradiently transparent.
-%   The syntax is \emph{<path>}\texttt{\char"7C}\emph{<picture>} |withfademethod| \emph{<string>},
+%   The syntax is \emph{<path>}\texttt{\textbar}\emph{<picture>} |withfademethod| \emph{<string>},
 %   the latter being either |"linear"| or |"circular"|.
 %   Though it is similar to the |withshademethod| from \emph{metafun},
 %   the differences are: (1) the operand of |withfademethod| can be a picture as well as a path;
@@ -784,8 +791,8 @@
 % As said \hyperlink{metafunformat}{before},
 % transparency group is available with \emph{plain} as well as \emph{metafun} format.
 % The syntax is exactly the same:
-% \emph{<picture>} \char"7C\ \emph{<path>} |asgroup|
-% |""| \char"7C\ |"isolated"| \char"7C\ |"knockout"| \char"7C\ |"isolated,knockout"|,
+% \emph{<picture>} \textbar\ \emph{<path>} |asgroup|
+% |""| \textbar\ |"isolated"| \textbar\ |"knockout"| \textbar\ |"isolated,knockout"|,
 % which will return a \metapost picture.
 % It is called \emph{Transparency Group} because the objects contained in the group are composited
 % to produce a single object, so that outer transparency effect, if any,
@@ -981,8 +988,8 @@
 
 luatexbase.provides_module {
   name          = "luamplib",
-  version       = "2.34.2",
-  date          = "2024/07/24",
+  version       = "2.34.3",
+  date          = "2024/07/27",
   description   = "Lua package to typeset Metapost with LuaTeX's MPLib.",
 }
 
@@ -1039,7 +1046,7 @@
 %    \end{macrocode}
 %
 %    This module is a stripped down version of libraries that are used by
-%    \ConTeXt. Provide a few ``shortcuts'' expected by the imported code.
+%    \ConTeXt. Provide a few ``shortcuts'' expected by the code.
 %    \begin{macrocode}
 local tableconcat = table.concat
 local tableinsert = table.insert
@@ -1228,7 +1235,7 @@
 %    \end{macrocode}
 %
 %    As the finder function for \mplib, use the |kpse| library and
-%    make it behave like as if \metapost was used. And replace it with
+%    make it behave like as if \metapost was used. And replace |.mp| files with
 %    cache files if needed.
 %    See also \#74, \#97.
 %    \begin{macrocode}
@@ -1349,10 +1356,8 @@
     find_file   = luamplib.finder,
 %    \end{macrocode}
 %    Make use of |make_text| and |run_script|, which will co-operate
-%    with \LuaTeX's |tex.runtoks|. And we
-%    provide |numbersystem| option since v2.4. Default value ``|scaled|''
-%    can be changed by declaring |\mplibnumbersystem{double}|
-%    or |\mplibnumbersystem{decimal}|.
+%    with \LuaTeX's |tex.runtoks| or other Lua functions. And we
+%    provide |numbersystem| option since v2.4.
 %    See \url{https://github.com/lualatex/luamplib/issues/21}.
 %    \begin{macrocode}
     make_text   = luamplib.maketext,
@@ -1862,7 +1867,6 @@
 %
 %    luamplib's mplibgraphictext operator
 %    \begin{macrocode}
-local running = -1073741824
 local emboldenfonts = { }
 local function getemboldenwidth (curr, fakebold)
   local width = emboldenfonts.width
@@ -1902,6 +1906,7 @@
   return pl
 end
 local function getrulemetric (box, curr, bp)
+  local running = -1073741824
   local wd,ht,dp = curr.width, curr.height, curr.depth
   wd = wd == running and box.width  or wd
   ht = ht == running and box.height or ht
@@ -2970,12 +2975,20 @@
   end
 else
   texsprint {
+    "\\luamplibatfirstshipout{",
     "\\special{pdf:obj @MPlibTr<<>>}",
     "\\special{pdf:obj @MPlibSh<<>>}",
     "\\special{pdf:obj @MPlibCS<<>>}",
-    "\\special{pdf:obj @MPlibPt<<>>}",
+    "\\special{pdf:obj @MPlibPt<<>>}}",
   }
   pdfetcs.resadded = { }
+  pdfetcs.fallback_update_resources = function (name,obj,res)
+    texsprint{"\\special{pdf:put ", obj, " <<", res, ">>}"}
+    if not pdfetcs.resadded[name] then
+      texsprint{"\\luamplibateveryshipout{\\special{pdf:put @resources <</", name, " ", obj, ">>}}"}
+      pdfetcs.resadded[name] = obj
+    end
+  end
 end
 
 %    \end{macrocode}
@@ -3016,14 +3029,10 @@
           pdfetcs.fallback_update_resources("ExtGState", tr)
         end
       else
-        texsprint { "\\special{pdf:put @MPlibTr<<", tr, ">>}" }
+        pdfetcs.fallback_update_resources("ExtGState","@MPlibTr",tr)
       end
     end
   end
-  if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfextgs) then
-    texsprint"\\special{pdf:put @resources <</ExtGState @MPlibTr>>}"
-    pdfetcs.resadded.ExtGState = "@MPlibTr"
-  end
   return key
 end
 local function do_preobj_TR(object,prescript)
@@ -3094,14 +3103,10 @@
       if pdfmode then
         pdfetcs.fallback_update_resources("Shading", res)
       else
-        texsprint { "\\special{pdf:put @MPlibSh<<", res, ">>}" }
+        pdfetcs.fallback_update_resources("Shading","@MPlibSh",res)
       end
     end
   end
-  if not pdfmode and not pdfmanagement then
-    texsprint"\\special{pdf:put @resources <</Shading @MPlibSh>>}"
-    pdfetcs.resadded.Shading = "@MPlibSh"
-  end
   return on
 end
 local function color_normalize(ca,cb)
@@ -3247,7 +3252,6 @@
 %    Patterns
 %    \begin{macrocode}
 pdfetcs.patterns = { }
-local patterns = pdfetcs.patterns
 local function gather_resources (optres)
   local t, do_pattern = { }, not optres
   local names = {"ExtGState","ColorSpace","Shading"}
@@ -3297,7 +3301,7 @@
         "}}",
       }, catat11)
       t[#t+1] = texgettoks'mplibtmptoks'
-    elseif do_pattern then
+    else
       for _,v in ipairs(names) do
         local vv = pdfetcs.resadded[v]
         if vv then
@@ -3342,6 +3346,7 @@
   }
   local optres = opts.resources or ""
   optres = optres .. gather_resources(optres)
+  local patterns = pdfetcs.patterns
   if pdfmode then
     if opts.bbox then
       attr[#attr+1] = format("/BBox[%s]", opts.bbox)
@@ -3349,20 +3354,23 @@
     local index = tex.saveboxresource(boxid, tableconcat(attr), optres, true, opts.bbox and 4 or 1)
     patterns[name] = { id = index, colored = opts.colored }
   else
-    local objname = "@mplibpattern"..name
+    local cnt = #patterns + 1
+    local objname = "@mplibpattern" .. cnt
     local metric = format("bbox %s", opts.bbox or format("0 0 %s %s",wd,hd))
     texsprint {
-      "\\ifvmode\\nointerlineskip\\fi\\vbox to0pt{\\vss\\hbox to0pt{",
+      "\\expandafter\\newbox\\csname luamplib.patternbox.", cnt, "\\endcsname",
+      "\\global\\setbox\\csname luamplib.patternbox.", cnt, "\\endcsname",
+      "\\hbox{\\unhbox ", boxid, "}\\luamplibatnextshipout{",
       "\\special{pdf:bcontent}",
       "\\special{pdf:bxobj ", objname, " ", metric, "}",
-      "\\raise\\dp ", boxid, "\\box ", boxid,
+      "\\raise\\dp\\csname luamplib.patternbox.", cnt, "\\endcsname",
+      "\\box\\csname luamplib.patternbox.", cnt, "\\endcsname",
       "\\special{pdf:put @resources <<", optres, ">>}",
       "\\special{pdf:exobj <<", tableconcat(attr), ">>}",
-      "\\special{pdf:econtent}",
-      "\\hss}}",
+      "\\special{pdf:econtent}}",
     }
-    patterns[#patterns+1] = objname
-    patterns[name] = { id = #patterns, colored = opts.colored }
+    patterns[cnt] = objname
+    patterns[name] = { id = cnt, colored = opts.colored }
   end
 end
 local function pattern_colorspace (cs)
@@ -3380,19 +3388,16 @@
       elseif pdfmode then
         pdfetcs.fallback_update_resources("ColorSpace", res)
       else
-        texsprint { "\\special{pdf:put @MPlibCS<<", res, ">>}" }
+        pdfetcs.fallback_update_resources("ColorSpace","@MPlibCS",res)
       end
     end
   end
-  if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfcolorspace) then
-    texsprint"\\special{pdf:put @resources <</ColorSpace @MPlibCS>>}"
-    pdfetcs.resadded.ColorSpace = "@MPlibCS"
-  end
   return on
 end
 local function do_preobj_PAT(object, prescript)
   local name = prescript and prescript.mplibpattern
   if not name then return end
+  local patterns = pdfetcs.patterns
   local patt = patterns[name]
   local index = patt and patt.id or err("cannot get pattern object '%s'", name)
   local key = format("MPlibPt%s",index)
@@ -3435,14 +3440,10 @@
       elseif pdfmode then
         pdfetcs.fallback_update_resources("Pattern", res)
       else
-        texsprint { "\\special{pdf:put @MPlibPt<<", res, ">>}" }
+        pdfetcs.fallback_update_resources("Pattern","@MPlibPt",res)
       end
     end
   end
-  if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfpattern) then
-    texsprint"\\special{pdf:put @resources <</Pattern @MPlibPt>>}"
-    pdfetcs.resadded.Pattern = "@MPlibPt"
-  end
   patt.done = true
 end
 
@@ -3564,10 +3565,11 @@
         "\\special{pdf:put @resources <<", res, ">>}",
         "\\special{pdf:exobj <<", grattr, ">>}",
         "\\special{pdf:uxobj ", objname, "}\\endgroup",
-        "\\expandafter\\gdef\\csname luamplib.group.", trgroup.name, "\\endcsname{",
+      })
+      token.set_macro("luamplib.group."..trgroup.name, tableconcat{
         "\\mplibstarttoPDF{",llx,"}{",lly,"}{",urx,"}{",ury,"}",
-        "\\special{pdf:uxobj ", objname, "}\\mplibstoptoPDF}",
-      })
+        "\\special{pdf:uxobj ", objname, "}\\mplibstoptoPDF",
+      }, "global")
     end
     trgroup.shifts[trgroup.name] = { llx, lly }
   end
@@ -3602,30 +3604,29 @@
   trgroup.shifts[name] = { get_macro'MPllx', get_macro'MPlly' }
   if pdfmode then
     local index = tex.saveboxresource(boxid, tableconcat(attr), res, true, grtype)
-    texsprint{
-      "\\expandafter\\gdef\\csname luamplib.group.", name,
-      "\\endcsname{\\useboxresource ", index, "}",
-    }
+    token.set_macro("luamplib.group."..name, "\\useboxresource "..index, "global")
   else
     trgroup.cnt = (trgroup.cnt or 0) + 1
     local objname = format("@mplibtrgr%s", trgroup.cnt)
     local wd, ht, dp = node.getwhd(box)
     texsprint {
-      "\\ifvmode\\nointerlineskip\\fi\\vbox to0pt{\\vss\\hbox to0pt{",
+      "\\expandafter\\newbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
+      "\\global\\setbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
+      "\\hbox{\\unhbox ", boxid, "}\\luamplibatnextshipout{",
       "\\special{pdf:bcontent}",
       "\\special{pdf:bxobj ", objname, " width ", wd, "sp height ", ht, "sp depth ", dp, "sp}",
-      "\\unhbox ", boxid,
+      "\\unhbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
       "\\special{pdf:put @resources <<", res, ">>}",
       "\\special{pdf:exobj <<", tableconcat(attr), ">>}",
-      "\\special{pdf:econtent}",
-      "\\hss}}",
-      "\\expandafter\\gdef\\csname luamplib.group.", name, "\\endcsname{",
+      "\\special{pdf:econtent}}",
+    }
+    token.set_macro("luamplib.group."..name, tableconcat{
       "\\begingroup\\setbox\\mplibscratchbox\\hbox{\\special{pdf:uxobj ", objname, "}}",
       "\\wd\\mplibscratchbox ", wd, "sp",
       "\\ht\\mplibscratchbox ", ht, "sp",
       "\\dp\\mplibscratchbox ", dp, "sp",
-      "\\box\\mplibscratchbox\\endgroup}",
-    }
+      "\\box\\mplibscratchbox\\endgroup",
+    }, "global")
   end
 end
 
@@ -3936,6 +3937,9 @@
                     stop_pdf_code()
                   end
                   local path = object.htap
+%    \end{macrocode}
+%    How can we generate an |htap| object? Please let us know if you have succeeded.
+%    \begin{macrocode}
                   if path then
                     if transformed then
                       start_pdf_code()
@@ -3973,7 +3977,7 @@
 %    We should beware the |q ... Q| scope.
 %    \begin{macrocode}
                   if shade_no then -- shading
-                    pdf_literalcode("W n /MPlibSh%s sh Q",shade_no)
+                    pdf_literalcode("W%s n /MPlibSh%s sh Q",evenodd and "*" or "",shade_no)
                   end
                 end
               end
@@ -4044,15 +4048,34 @@
 %    First we need to load some packages.
 %
 %    \begin{macrocode}
-\bgroup\expandafter\expandafter\expandafter\egroup
-\expandafter\ifx\csname selectfont\endcsname\relax
-  \input ltluatex
-\else
+\ifcsname ProvidesPackage\endcsname
+%    \end{macrocode}
+% We need \LaTeX\ 2024-06-01 as we use |ltx.pdf.object_id| when pdfmanagement is loaded.
+% But as \pkg{fp} package does not accept an option, we do not append the date option.
+%    \begin{macrocode}
   \NeedsTeXFormat{LaTeX2e}
   \ProvidesPackage{luamplib}
-    [2024/07/24 v2.34.2 mplib package for LuaTeX]
-  \ifx\newluafunction\@undefined
+    [2024/07/27 v2.34.3 mplib package for LuaTeX]
+\fi
+\ifdefined\newluafunction\else
   \input ltluatex
+\fi
+%    \end{macrocode}
+%
+% In DVI mode, a new XObject (mppattern, mplibgroup) must be encapsulated in an \cs{hbox}.
+% But this should not affect typesetting. So we use Hook mechanism provided by \LaTeX\ kernel.
+% In Plain, \pkg{atbegshi.sty} is loaded.
+%    \begin{macrocode}
+\ifnum\outputmode=0
+  \ifdefined\AddToHookNext
+    \def\luamplibatnextshipout{\AddToHookNext{shipout/background}}
+    \def\luamplibatfirstshipout{\AddToHook{shipout/firstpage}}
+    \def\luamplibateveryshipout{\AddToHook{shipout/background}}
+  \else
+    \input atbegshi.sty
+    \def\luamplibatnextshipout#1{\AtBeginShipoutNext{\AtBeginShipoutAddToBox{#1}}}
+    \let\luamplibatfirstshipout\AtBeginShipoutFirst
+    \def\luamplibateveryshipout#1{\AtBeginShipout{\AtBeginShipoutAddToBox{#1}}}
   \fi
 \fi
 %    \end{macrocode}

Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua	2024-07-27 20:48:40 UTC (rev 71914)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua	2024-07-27 20:48:48 UTC (rev 71915)
@@ -11,8 +11,8 @@
 
 luatexbase.provides_module {
   name          = "luamplib",
-  version       = "2.34.2",
-  date          = "2024/07/24",
+  version       = "2.34.3",
+  date          = "2024/07/27",
   description   = "Lua package to typeset Metapost with LuaTeX's MPLib.",
 }
 
@@ -639,7 +639,6 @@
 
 local function rmzeros(str) return str:gsub("%.?0+$","") end
 
-local running = -1073741824
 local emboldenfonts = { }
 local function getemboldenwidth (curr, fakebold)
   local width = emboldenfonts.width
@@ -679,6 +678,7 @@
   return pl
 end
 local function getrulemetric (box, curr, bp)
+  local running = -1073741824
   local wd,ht,dp = curr.width, curr.height, curr.depth
   wd = wd == running and box.width  or wd
   ht = ht == running and box.height or ht
@@ -1684,12 +1684,20 @@
   end
 else
   texsprint {
+    "\\luamplibatfirstshipout{",
     "\\special{pdf:obj @MPlibTr<<>>}",
     "\\special{pdf:obj @MPlibSh<<>>}",
     "\\special{pdf:obj @MPlibCS<<>>}",
-    "\\special{pdf:obj @MPlibPt<<>>}",
+    "\\special{pdf:obj @MPlibPt<<>>}}",
   }
   pdfetcs.resadded = { }
+  pdfetcs.fallback_update_resources = function (name,obj,res)
+    texsprint{"\\special{pdf:put ", obj, " <<", res, ">>}"}
+    if not pdfetcs.resadded[name] then
+      texsprint{"\\luamplibateveryshipout{\\special{pdf:put @resources <</", name, " ", obj, ">>}}"}
+      pdfetcs.resadded[name] = obj
+    end
+  end
 end
 
 local transparancy_modes = { [0] = "Normal",
@@ -1726,14 +1734,10 @@
           pdfetcs.fallback_update_resources("ExtGState", tr)
         end
       else
-        texsprint { "\\special{pdf:put @MPlibTr<<", tr, ">>}" }
+        pdfetcs.fallback_update_resources("ExtGState","@MPlibTr",tr)
       end
     end
   end
-  if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfextgs) then
-    texsprint"\\special{pdf:put @resources <</ExtGState @MPlibTr>>}"
-    pdfetcs.resadded.ExtGState = "@MPlibTr"
-  end
   return key
 end
 local function do_preobj_TR(object,prescript)
@@ -1800,14 +1804,10 @@
       if pdfmode then
         pdfetcs.fallback_update_resources("Shading", res)
       else
-        texsprint { "\\special{pdf:put @MPlibSh<<", res, ">>}" }
+        pdfetcs.fallback_update_resources("Shading","@MPlibSh",res)
       end
     end
   end
-  if not pdfmode and not pdfmanagement then
-    texsprint"\\special{pdf:put @resources <</Shading @MPlibSh>>}"
-    pdfetcs.resadded.Shading = "@MPlibSh"
-  end
   return on
 end
 local function color_normalize(ca,cb)
@@ -1949,7 +1949,6 @@
 end
 
 pdfetcs.patterns = { }
-local patterns = pdfetcs.patterns
 local function gather_resources (optres)
   local t, do_pattern = { }, not optres
   local names = {"ExtGState","ColorSpace","Shading"}
@@ -1999,7 +1998,7 @@
         "}}",
       }, catat11)
       t[#t+1] = texgettoks'mplibtmptoks'
-    elseif do_pattern then
+    else
       for _,v in ipairs(names) do
         local vv = pdfetcs.resadded[v]
         if vv then
@@ -2044,6 +2043,7 @@
   }
   local optres = opts.resources or ""
   optres = optres .. gather_resources(optres)
+  local patterns = pdfetcs.patterns
   if pdfmode then
     if opts.bbox then
       attr[#attr+1] = format("/BBox[%s]", opts.bbox)
@@ -2051,20 +2051,23 @@
     local index = tex.saveboxresource(boxid, tableconcat(attr), optres, true, opts.bbox and 4 or 1)
     patterns[name] = { id = index, colored = opts.colored }
   else
-    local objname = "@mplibpattern"..name
+    local cnt = #patterns + 1
+    local objname = "@mplibpattern" .. cnt
     local metric = format("bbox %s", opts.bbox or format("0 0 %s %s",wd,hd))
     texsprint {
-      "\\ifvmode\\nointerlineskip\\fi\\vbox to0pt{\\vss\\hbox to0pt{",
+      "\\expandafter\\newbox\\csname luamplib.patternbox.", cnt, "\\endcsname",
+      "\\global\\setbox\\csname luamplib.patternbox.", cnt, "\\endcsname",
+      "\\hbox{\\unhbox ", boxid, "}\\luamplibatnextshipout{",
       "\\special{pdf:bcontent}",
       "\\special{pdf:bxobj ", objname, " ", metric, "}",
-      "\\raise\\dp ", boxid, "\\box ", boxid,
+      "\\raise\\dp\\csname luamplib.patternbox.", cnt, "\\endcsname",
+      "\\box\\csname luamplib.patternbox.", cnt, "\\endcsname",
       "\\special{pdf:put @resources <<", optres, ">>}",
       "\\special{pdf:exobj <<", tableconcat(attr), ">>}",
-      "\\special{pdf:econtent}",
-      "\\hss}}",
+      "\\special{pdf:econtent}}",
     }
-    patterns[#patterns+1] = objname
-    patterns[name] = { id = #patterns, colored = opts.colored }
+    patterns[cnt] = objname
+    patterns[name] = { id = cnt, colored = opts.colored }
   end
 end
 local function pattern_colorspace (cs)
@@ -2082,19 +2085,16 @@
       elseif pdfmode then
         pdfetcs.fallback_update_resources("ColorSpace", res)
       else
-        texsprint { "\\special{pdf:put @MPlibCS<<", res, ">>}" }
+        pdfetcs.fallback_update_resources("ColorSpace","@MPlibCS",res)
       end
     end
   end
-  if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfcolorspace) then
-    texsprint"\\special{pdf:put @resources <</ColorSpace @MPlibCS>>}"
-    pdfetcs.resadded.ColorSpace = "@MPlibCS"
-  end
   return on
 end
 local function do_preobj_PAT(object, prescript)
   local name = prescript and prescript.mplibpattern
   if not name then return end
+  local patterns = pdfetcs.patterns
   local patt = patterns[name]
   local index = patt and patt.id or err("cannot get pattern object '%s'", name)
   local key = format("MPlibPt%s",index)
@@ -2137,14 +2137,10 @@
       elseif pdfmode then
         pdfetcs.fallback_update_resources("Pattern", res)
       else
-        texsprint { "\\special{pdf:put @MPlibPt<<", res, ">>}" }
+        pdfetcs.fallback_update_resources("Pattern","@MPlibPt",res)
       end
     end
   end
-  if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfpattern) then
-    texsprint"\\special{pdf:put @resources <</Pattern @MPlibPt>>}"
-    pdfetcs.resadded.Pattern = "@MPlibPt"
-  end
   patt.done = true
 end
 
@@ -2258,10 +2254,11 @@
         "\\special{pdf:put @resources <<", res, ">>}",
         "\\special{pdf:exobj <<", grattr, ">>}",
         "\\special{pdf:uxobj ", objname, "}\\endgroup",
-        "\\expandafter\\gdef\\csname luamplib.group.", trgroup.name, "\\endcsname{",
+      })
+      token.set_macro("luamplib.group."..trgroup.name, tableconcat{
         "\\mplibstarttoPDF{",llx,"}{",lly,"}{",urx,"}{",ury,"}",
-        "\\special{pdf:uxobj ", objname, "}\\mplibstoptoPDF}",
-      })
+        "\\special{pdf:uxobj ", objname, "}\\mplibstoptoPDF",
+      }, "global")
     end
     trgroup.shifts[trgroup.name] = { llx, lly }
   end
@@ -2296,30 +2293,29 @@
   trgroup.shifts[name] = { get_macro'MPllx', get_macro'MPlly' }
   if pdfmode then
     local index = tex.saveboxresource(boxid, tableconcat(attr), res, true, grtype)
-    texsprint{
-      "\\expandafter\\gdef\\csname luamplib.group.", name,
-      "\\endcsname{\\useboxresource ", index, "}",
-    }
+    token.set_macro("luamplib.group."..name, "\\useboxresource "..index, "global")
   else
     trgroup.cnt = (trgroup.cnt or 0) + 1
     local objname = format("@mplibtrgr%s", trgroup.cnt)
     local wd, ht, dp = node.getwhd(box)
     texsprint {
-      "\\ifvmode\\nointerlineskip\\fi\\vbox to0pt{\\vss\\hbox to0pt{",
+      "\\expandafter\\newbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
+      "\\global\\setbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
+      "\\hbox{\\unhbox ", boxid, "}\\luamplibatnextshipout{",
       "\\special{pdf:bcontent}",
       "\\special{pdf:bxobj ", objname, " width ", wd, "sp height ", ht, "sp depth ", dp, "sp}",
-      "\\unhbox ", boxid,
+      "\\unhbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
       "\\special{pdf:put @resources <<", res, ">>}",
       "\\special{pdf:exobj <<", tableconcat(attr), ">>}",
-      "\\special{pdf:econtent}",
-      "\\hss}}",
-      "\\expandafter\\gdef\\csname luamplib.group.", name, "\\endcsname{",
+      "\\special{pdf:econtent}}",
+    }
+    token.set_macro("luamplib.group."..name, tableconcat{
       "\\begingroup\\setbox\\mplibscratchbox\\hbox{\\special{pdf:uxobj ", objname, "}}",
       "\\wd\\mplibscratchbox ", wd, "sp",
       "\\ht\\mplibscratchbox ", ht, "sp",
       "\\dp\\mplibscratchbox ", dp, "sp",
-      "\\box\\mplibscratchbox\\endgroup}",
-    }
+      "\\box\\mplibscratchbox\\endgroup",
+    }, "global")
   end
 end
 
@@ -2624,7 +2620,7 @@
                     end
                   end
                   if shade_no then -- shading
-                    pdf_literalcode("W n /MPlibSh%s sh Q",shade_no)
+                    pdf_literalcode("W%s n /MPlibSh%s sh Q",evenodd and "*" or "",shade_no)
                   end
                 end
               end

Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty	2024-07-27 20:48:40 UTC (rev 71914)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty	2024-07-27 20:48:48 UTC (rev 71915)
@@ -8,15 +8,24 @@
 %% 
 %% See source file 'luamplib.dtx' for licencing and contact information.
 %% 
-\bgroup\expandafter\expandafter\expandafter\egroup
-\expandafter\ifx\csname selectfont\endcsname\relax
-  \input ltluatex
-\else
+\ifcsname ProvidesPackage\endcsname
   \NeedsTeXFormat{LaTeX2e}
   \ProvidesPackage{luamplib}
-    [2024/07/24 v2.34.2 mplib package for LuaTeX]
-  \ifx\newluafunction\@undefined
+    [2024/07/27 v2.34.3 mplib package for LuaTeX]
+\fi
+\ifdefined\newluafunction\else
   \input ltluatex
+\fi
+\ifnum\outputmode=0
+  \ifdefined\AddToHookNext
+    \def\luamplibatnextshipout{\AddToHookNext{shipout/background}}
+    \def\luamplibatfirstshipout{\AddToHook{shipout/firstpage}}
+    \def\luamplibateveryshipout{\AddToHook{shipout/background}}
+  \else
+    \input atbegshi.sty
+    \def\luamplibatnextshipout#1{\AtBeginShipoutNext{\AtBeginShipoutAddToBox{#1}}}
+    \let\luamplibatfirstshipout\AtBeginShipoutFirst
+    \def\luamplibateveryshipout#1{\AtBeginShipout{\AtBeginShipoutAddToBox{#1}}}
   \fi
 \fi
 \directlua{require("luamplib")}



More information about the tex-live-commits mailing list.