texlive[74709] Master/texmf-dist: luamplib (20mar25)

commits+karl at tug.org commits+karl at tug.org
Thu Mar 20 20:59:11 CET 2025


Revision: 74709
          https://tug.org/svn/texlive?view=revision&revision=74709
Author:   karl
Date:     2025-03-20 20:59:11 +0100 (Thu, 20 Mar 2025)
Log Message:
-----------
luamplib (20mar25)

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/doc/luatex/luamplib/test-luamplib-plain.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	2025-03-20 10:47:33 UTC (rev 74708)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS	2025-03-20 19:59:11 UTC (rev 74709)
@@ -1,5 +1,19 @@
                        History of the luamplib package
 
+2025/03/20 2.37.2
+   * Formerly, it was not possible to give shading effect to a textual picture
+   inside a tiling pattern. This limitation is now lifted.
+   As a side effect, a tiling pattern inside a tiling pattern is also allowed.
+
+   * 'withmppattern <string>' is a newly introduced command virtually the same
+   as 'withpattern <string>', but the former does not force the result of MP
+   picture. So users can use any drawing command suitable, such as 'fill' or
+   'filldraw' as well as 'draw'.
+
+   * 'textext', 'TEX', 'mplibcolor', 'mplibdimen', or 'VerbatimTeX' can accept
+   a string argument without parentheses. For instance, 'textext "\TeX"' is now
+   allowed as well as 'textext("\TeX")'.
+
 2025/02/18 2.37.1
    * A new operator 'mplibuclength <string>' returns the number of unicode
    grapheme clusters in the string.

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	2025-03-20 10:47:33 UTC (rev 74708)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex	2025-03-20 19:59:11 UTC (rev 74709)
@@ -170,7 +170,7 @@
   enddef;
 
   beginfig(1);
-    rotatedlabel.top(textext("Rotated!"), origin, 45);
+    rotatedlabel.top(textext "Rotated!", origin, 45);
   endfig;
 \end{mplibcode}%
 \par
@@ -259,7 +259,7 @@
 \endmppattern
 \mpfig
 draw unitsquare shifted -center unitsquare scaled 45 withpostscript "collect" ;
-draw fullcircle scaled 100 withpattern "mypatt" withpen pencircle scaled 1
+filldraw fullcircle scaled 100 withmppattern "mypatt" withpen pencircle scaled 1
   withcolor \mpcolor{red!50!blue!50} withpostscript "evenodd" ;
 \endmpfig
 \begin{mppattern}{pattuncolored}
@@ -277,11 +277,11 @@
     j:=0;
     for item within mpliboutlinepic[i]:
       j:=j+1;
-      draw pathpart item scaled 10
+      filldraw pathpart item scaled 10
       if j < length mpliboutlinepic[i]:
           withpostscript "collect"
       else:
-          withpattern "pattuncolored"
+          withmppattern "pattuncolored"
           withpen pencircle scaled 1/2
           withcolor (i/4)[red,blue]
       fi;
@@ -343,7 +343,7 @@
 \mpfig
   picture test; test = mplibgraphictext "\textbf{MPLIB}"
     fakebold 1 fillcolor "red!70" drawcolor .7red scaled 7;
-  draw test withpattern "mypatt" ;
+  draw test withmppattern "mypatt" ;
 \endmpfig
 \mpfig
   picture tex;
@@ -370,6 +370,33 @@
     draw TEX(mplibucsubstring (k,k+1) of Test) scaled 1.5 shifted (20k,0);
   endfor
 \endmpfig
+\par
+\mppattern{p1}
+  \mpfig
+    fill fullcircle scaled 3
+    withcolor .7red
+    ;
+  \endmpfig
+\endmppattern
+\mppattern{p2}
+  \mpfig
+    fill fullcircle scaled 9
+    withmppattern "p1"
+    ;
+  \endmpfig
+\endmppattern
+\mppattern{p3}
+  \mpfig
+    fill fullcircle scaled 27
+    withmppattern "p2"
+    ;
+  \endmpfig
+\endmppattern
+\mpfig
+  fill fullcircle scaled 108
+  withmppattern "p3"
+  ;
+\endmpfig
 \mpliblegacybehavior{true}%
 \tracingcommands0
 

Modified: trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex	2025-03-20 10:47:33 UTC (rev 74708)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex	2025-03-20 19:59:11 UTC (rev 74709)
@@ -34,7 +34,7 @@
     tex code
     100 \% color
   etex shifted (20,0);
-draw textext("\tracingcommands0 textext 50\% color") shifted (10,-10) withcolor .5white;
+draw textext "\tracingcommands0 textext 50\% color" shifted (10,-10) withcolor .5white;
 draw bbox currentpicture;
 endfig;
 
@@ -161,7 +161,7 @@
   enddef;
 
   beginfig(1);
-    rotatedlabel.top(textext("Rotated!"), origin, 45);
+    rotatedlabel.top(textext "Rotated!", origin, 45);
   endfig;
 \endmplibcode
 \par
@@ -249,8 +249,8 @@
 \endmppattern
 \mpfig
   fill fullcircle scaled 100 withpostscript "collect";
-  draw unitsquare shifted - center unitsquare scaled 45
-    withpattern "mypatt"
+  fill unitsquare shifted - center unitsquare scaled 45
+    withmppattern "mypatt"
     withpostscript "evenodd"
     ;
 \endmpfig
@@ -269,11 +269,11 @@
     j:=0;
     for item within mpliboutlinepic[i]:
       j:=j+1;
-      draw pathpart item scaled 10
+      filldraw pathpart item scaled 10
       if j < length mpliboutlinepic[i]:
           withpostscript "collect"
       else:
-          withpattern "pattuncolored"
+          withmppattern "pattuncolored"
           withpen pencircle scaled 1/2
           withcolor (i/4)[red,blue]
       fi;
@@ -317,8 +317,9 @@
 \mpfig
   picture test; test = mplibgraphictext "\bf MPLIB"
   fakebold 1 fillcolor .7[white,blue] drawcolor .7blue scaled 7;
-  draw test withpattern "pattuncolored" ;
+  draw test withmppattern "pattuncolored" ;
 \endmpfig
+\leavevmode
 \mpfig
   draw btex \bf\TeX etex rotated 30 scaled 3
     withshadingmethod "linear"
@@ -326,6 +327,25 @@
     withshadingvector (0,1)
     ;
 \endmpfig
+\mppattern{p1}
+  \mpfig
+    fill fullcircle scaled 3
+    withcolor .7red
+    ;
+  \endmpfig
+\endmppattern
+\mppattern{p2}
+  \mpfig
+    fill fullcircle scaled 12
+    withmppattern "p1"
+    ;
+  \endmpfig
+\endmppattern
+\mpfig
+  fill fullcircle scaled 48
+  withmppattern "p2"
+  ;
+\endmpfig
 \tracingcommands0
 
 \vskip 2\baselineskip

Modified: trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
===================================================================
--- trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx	2025-03-20 10:47:33 UTC (rev 74708)
+++ trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx	2025-03-20 19:59:11 UTC (rev 74709)
@@ -85,7 +85,7 @@
 %<*driver>
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesFile{luamplib.drv}%
-  [2025/02/18 v2.37.1 Interface for using the mplib library]%
+  [2025/03/20 v2.37.2 Interface for using the mplib library]%
 \documentclass{ltxdoc}
 \usepackage{metalogo,multicol,xspace}
 \usepackage[x11names]{xcolor}
@@ -155,7 +155,7 @@
 % \author{Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang and Kim Dohyun\\
 % Current Maintainer: Kim Dohyun\\
 % Support: \url{https://github.com/lualatex/luamplib}}
-% \date{2025/02/18 v2.37.1}
+% \date{2025/03/20 v2.37.2}
 %
 % \maketitle
 %
@@ -185,8 +185,8 @@
 %
 % \begin{itemize}
 % \item possibility to use |btex ... etex| to typeset \TeX\ code.
-%   |textext()| is a more versatile macro equivalent to |TEX()| from \pkg{TEX.mp}.
-%   |TEX()| is also allowed and is a synonym of |textext()|.
+%   |textext|\,\meta{string} is a more versatile macro equivalent to |TEX|\,\meta{string} 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.
 %
@@ -320,7 +320,7 @@
 %   On the other hand, \TeX\ code in |verbatimtex ... etex|
 %   between |beginfig()| and |endfig| will be inserted
 %   after flushing out the \metapost figure.
-%   As shown in the example below, |VerbatimTeX()| is a synonym of |verbatimtex| |...| |etex|.
+%   As shown in the example below, |VerbatimTeX| \meta{string} is a synonym of |verbatimtex| |...| |etex|.
 %\begin{verbatim}
 %     \mplibcode
 %       D := sqrt(2)**7;
@@ -354,7 +354,7 @@
 %   \cs{mplibtextextlabel\{enable\}} enables
 %   the labels typeset via |textext| instead of |infont| operator.
 %   So, |label("my text",origin)| thereafter is exactly the same as
-%   |label(textext("my text"),origin)|.
+%   |label(textext "my text", origin)|.
 %
 %   \textsc{n.b.} In the background,
 %   luamplib redefines |infont| operator so that the right side
@@ -565,13 +565,13 @@
 % \item[|alt=...|] sets an alternative text of the figure as given.
 %   This key is needed for ordinary \metapost figures.
 %   You can give alternative text within \metapost code as well:
-%   |VerbatimTeX| |("\mplibalttext{...}");|
+%   |VerbatimTeX| |"\mplibalttext{...}";|
 % \item[|actualtext=...|] starts a |Span| tag implicitly and sets an actual text as given.
 %   Horizontal mode is forced by \cs{noindent} command. BBox info will not be added.
 %   This key is intended for figures which can be represented by a character or
 %   a small sequence of characters.
 %   You can give actual text within \metapost code as well:
-%   |VerbatimTeX| |("\mplibactualtext{...}");|
+%   |VerbatimTeX| |"\mplibactualtext{...}";|
 % \item[|artifact|] starts an |artifact| MC (marked content).
 %   BBox info will not be added.
 %   This key is intended for decorative figures which have no semantic quality.
@@ -606,11 +606,11 @@
 %
 % \subsection{\textsc{MetaPost}}
 %
-% \subsubsection{\texttt{mplibdimen(...)}, \texttt{mplibcolor(...)}}
+% \subsubsection{\texttt{mplibdimen ...}, \texttt{mplibcolor ...}}
 %   These are \metapost interfaces for the \TeX\ commands
 %   \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\}}.
+%   |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,
 %   which cannot have \TeX\ commands outside of the |btex| or |verbatimtex| |...| |etex|.
 %
@@ -716,7 +716,8 @@
 %   \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.
 %
-% \subsubsection{\cs{mppattern\{...\} ...} \cs{endmppattern}, \texttt{... withpattern ...}}
+% \subsubsection{\cs{mppattern\{...\} ...} \cs{endmppattern}, \texttt{... withpattern ...},
+%     \texttt{withmppattern ...}}
 %   \hypertarget{mppattern}{}\relax
 %   \TeX\ macros
 %   \cs{mppattern}\marg{name} |...| \cs{endmppattern} define a tiling pattern
@@ -730,6 +731,10 @@
 %   of the |btex| command (though technically this is not a true textual picture)
 %   or the |infont| operator.
 %
+%   |withmppattern| \meta{string} is a command virtually the same as |withpattern|,
+%   but the former does not force the result of \metapost picture. So users can
+%   use any drawing command suitable, such as |fill| or |filldraw| as well as |draw|.
+%
 %   An example:
 %\begin{verbatim}
 %    \mppattern{mypatt}               % or \begin{mppattern}{mypatt}
@@ -754,8 +759,8 @@
 %      draw fullcircle scaled 90
 %        withpostscript "collect"
 %        ;
-%      draw fullcircle scaled 200
-%        withpattern "mypatt"
+%      filldraw fullcircle scaled 200
+%        withmppattern "mypatt"
 %        withpen pencircle scaled 1
 %        withcolor \mpcolor{red!50!blue!50}
 %        withpostscript "evenodd"
@@ -814,11 +819,11 @@
 %          j:=0;
 %          for item within mpliboutlinepic[i]:
 %            j:=j+1;
-%            draw pathpart item scaled 10
+%            filldraw pathpart item scaled 10
 %            if j < length mpliboutlinepic[i]:
 %                withpostscript "collect"
 %            else:
-%                withpattern "pattnocolor"
+%                withmppattern "pattnocolor"
 %                withpen pencircle scaled 1/2
 %                withcolor (i/4)[red,blue]          % paints the pattern
 %            fi;
@@ -829,7 +834,7 @@
 %\end{verbatim}
 % A much simpler and efficient way to obtain a similar result
 % (without colorful characters in this example)
-% is to give a \emph{textual picture} as the operand of |withpattern|:
+% is to give a \emph{textual picture} as the operand of |withpattern| or |withmppattern|:
 %\begin{verbatim}
 %      \begin{mplibcode}
 %        beginfig(2)
@@ -839,7 +844,7 @@
 %                fillcolor 1/3[red,blue]            % paints the pattern
 %                drawcolor 2/3[red,blue]
 %                scaled 10 ;
-%        draw pic withpattern "pattnocolor" ;
+%        draw pic withmppattern "pattnocolor" ;
 %        endfig;
 %      \end{mplibcode}
 %\end{verbatim}
@@ -1057,9 +1062,6 @@
 %   \item When you give shading effect to a picture made by `|infont|' operator,
 %     the result of |withshadingvector| will be the same as that of |withshadingdirection|,
 %     as luamplib considers only the bounding box of the picture.
-%   \item Inside tiling pattern cells (see \hyperlink{mppattern}{above}),
-%     you shall not give shading effect to pictures (paths are OK).
-%     Anyway, that is the current phase of development.
 %   \end{itemize}
 % Macros provided by luamplib are:
 % \begin{description}
@@ -1216,8 +1218,8 @@
 
 luatexbase.provides_module {
   name          = "luamplib",
-  version       = "2.37.1",
-  date          = "2025/02/18",
+  version       = "2.37.2",
+  date          = "2025/03/20",
   description   = "Lua package to typeset Metapost with LuaTeX's MPLib.",
 }
 
@@ -2699,10 +2701,10 @@
 luamplib.preambles = {
   mplibcode = [[
 texscriptmode := 2;
-def rawtextext (expr t) = runscript("luamplibtext{"&t&"}") enddef;
-def mplibcolor (expr t) = runscript("luamplibcolor{"&t&"}") enddef;
-def mplibdimen (expr t) = runscript("luamplibdimen{"&t&"}") enddef;
-def VerbatimTeX (expr t) = runscript("luamplibverbtex{"&t&"}") enddef;
+def rawtextext primary t = runscript("luamplibtext{"&t&"}") enddef;
+def mplibcolor primary t = runscript("luamplibcolor{"&t&"}") enddef;
+def mplibdimen primary t = runscript("luamplibdimen{"&t&"}") enddef;
+def VerbatimTeX primary t = runscript("luamplibverbtex{"&t&"}") enddef;
 if known context_mlib:
   defaultfont := "cmtt10";
   let infont = normalinfont;
@@ -2717,7 +2719,7 @@
     fi
   enddef;
 else:
-  vardef textext@# (text t) = rawtextext (t) enddef;
+  vardef textext@# primary t = rawtextext (t) enddef;
   def message expr t =
     if string t: runscript("mp.report[=["&t&"]=]") else: errmessage "Not a string" fi
   enddef;
@@ -2892,6 +2894,9 @@
     fi;
   ) mplib_do_outline_options_r; )
 enddef ;
+def withmppattern primary p =
+  withprescript "mplibpattern=" & if numeric p: decimal fi p
+enddef;
 primarydef t withpattern p =
   image(
     if cycle t:
@@ -3729,6 +3734,9 @@
 % Shading Patterns: much similar to the metafun's shade,
 % but we can apply shading to textual pictures as well as paths.
 %    \begin{macrocode}
+if not pdfmode then
+  pdfetcs.patternresources = {}
+end
 local function add_pattern_resources (key, val)
   if pdfmanagement then
     texsprint {
@@ -3740,6 +3748,9 @@
       texsprint { "\\csname ", pdfetcs.pgfpattern, "\\endcsname{", res, "}" }
     else
       pdfetcs.fallback_update_resources("Pattern",res,"@MPlibPt")
+      if not pdfmode then
+        tableinsert(pdfetcs.patternresources, res) -- for gather_resources()
+      end
     end
   end
 end
@@ -3811,8 +3822,7 @@
   if pdfmode then
     if pdfmanagement then
       for _,v in ipairs(names) do
-        local pp = get_macro(format("g__pdfdict_/g__pdf_Core/Page/Resources/%s_prop",v))
-        if pp and pp:find"__prop_pair" then
+        if ltx.__pdf.Page.Resources[v] then
           t[#t+1] = format("/%s %s 0 R", v, ltx.pdf.object_id("__pdf/Page/Resources/"..v))
         end
       end
@@ -3832,15 +3842,12 @@
   else
     if pdfmanagement then
       for _,v in ipairs(names) do
-        local pp = get_macro(format("g__pdfdict_/g__pdf_Core/Page/Resources/%s_prop",v))
-        if pp and pp:find"__prop_pair" then
-          run_tex_code {
-            "\\mplibtmptoks\\expanded{{",
-            format("/%s \\csname pdf_object_ref:n\\endcsname{__pdf/Page/Resources/%s}",v,v),
-            "}}",
-          }
-          t[#t+1] = texgettoks'mplibtmptoks'
-        end
+        run_tex_code ({
+          "\\mplibtmptoks\\expanded{{",
+          "\\pdfdict_if_empty:nF{g__pdf_Core/Page/Resources/", v, "}",
+          "{/", v, " \\pdf_object_ref:n{__pdf/Page/Resources/", v, "}}}}",
+        },ccexplat)
+        t[#t+1] = texgettoks'mplibtmptoks'
       end
     elseif is_defined(pdfetcs.pgfextgs) then
       run_tex_code ({
@@ -3851,6 +3858,9 @@
         "}}",
       }, catat11)
       t[#t+1] = texgettoks'mplibtmptoks'
+      if pdfetcs.resadded.Shading then
+        t[#t+1] = format("/Shading %s", pdfetcs.resadded.Shading)
+      end
     else
       for _,v in ipairs(names) do
         local vv = pdfetcs.resadded[v]
@@ -3860,6 +3870,36 @@
       end
     end
   end
+  if do_pattern then return tableconcat(t) end
+  -- get pattern resources
+  local mytoks
+  if pdfmanagement then
+    run_tex_code ({
+      "\\mplibtmptoks\\expanded{{",
+      "\\pdfdict_if_empty:nF{g__pdf_Core/Page/Resources/Pattern}",
+      "{\\pdfdict_use:n{g__pdf_Core/Page/Resources/Pattern}}", "}}",
+    },ccexplat)
+    mytoks = texgettoks"mplibtmptoks"
+    if not pdfmode then
+      mytoks = mytoks:gsub("\\str_convert_pdfname:n%s*{(.-)}","%1") -- why not expanded?
+    end
+  elseif is_defined(pdfetcs.pgfextgs) then
+    if pdfmode then
+      mytoks = get_macro"pgf at sys@pgf at resource@list at patterns"
+    else
+      local tt, abc = {}, get_macro"pgfutil at abc" or ""
+      for v in abc:gmatch"@pgfpatterns%s*<<(.-)>>" do
+        tt[#tt+1] = v
+      end
+      mytoks = tableconcat(tt)
+    end
+  else
+    local tt = pdfmode and pdfetcs.Pattern_res or pdfetcs.patternresources
+    mytoks = tt and tableconcat(tt)
+  end
+  if mytoks and mytoks ~= "" then
+    t[#t+1] = format("/Pattern<<%s>>",mytoks)
+  end
   return tableconcat(t)
 end
 function luamplib.registerpattern ( boxid, name, opts )
@@ -4601,7 +4641,7 @@
 %    \begin{macrocode}
   \NeedsTeXFormat{LaTeX2e}
   \ProvidesPackage{luamplib}
-    [2025/02/18 v2.37.1 mplib package for LuaTeX]
+    [2025/03/20 v2.37.2 mplib package for LuaTeX]
 \fi
 \ifdefined\newluafunction\else
   \input ltluatex

Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua	2025-03-20 10:47:33 UTC (rev 74708)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua	2025-03-20 19:59:11 UTC (rev 74709)
@@ -11,8 +11,8 @@
 
 luatexbase.provides_module {
   name          = "luamplib",
-  version       = "2.37.1",
-  date          = "2025/02/18",
+  version       = "2.37.2",
+  date          = "2025/03/20",
   description   = "Lua package to typeset Metapost with LuaTeX's MPLib.",
 }
 
@@ -1226,10 +1226,10 @@
 luamplib.preambles = {
   mplibcode = [[
 texscriptmode := 2;
-def rawtextext (expr t) = runscript("luamplibtext{"&t&"}") enddef;
-def mplibcolor (expr t) = runscript("luamplibcolor{"&t&"}") enddef;
-def mplibdimen (expr t) = runscript("luamplibdimen{"&t&"}") enddef;
-def VerbatimTeX (expr t) = runscript("luamplibverbtex{"&t&"}") enddef;
+def rawtextext primary t = runscript("luamplibtext{"&t&"}") enddef;
+def mplibcolor primary t = runscript("luamplibcolor{"&t&"}") enddef;
+def mplibdimen primary t = runscript("luamplibdimen{"&t&"}") enddef;
+def VerbatimTeX primary t = runscript("luamplibverbtex{"&t&"}") enddef;
 if known context_mlib:
   defaultfont := "cmtt10";
   let infont = normalinfont;
@@ -1244,7 +1244,7 @@
     fi
   enddef;
 else:
-  vardef textext@# (text t) = rawtextext (t) enddef;
+  vardef textext@# primary t = rawtextext (t) enddef;
   def message expr t =
     if string t: runscript("mp.report[=["&t&"]=]") else: errmessage "Not a string" fi
   enddef;
@@ -1419,6 +1419,9 @@
     fi;
   ) mplib_do_outline_options_r; )
 enddef ;
+def withmppattern primary p =
+  withprescript "mplibpattern=" & if numeric p: decimal fi p
+enddef;
 primarydef t withpattern p =
   image(
     if cycle t:
@@ -2192,6 +2195,9 @@
   return shade_no
 end
 
+if not pdfmode then
+  pdfetcs.patternresources = {}
+end
 local function add_pattern_resources (key, val)
   if pdfmanagement then
     texsprint {
@@ -2203,6 +2209,9 @@
       texsprint { "\\csname ", pdfetcs.pgfpattern, "\\endcsname{", res, "}" }
     else
       pdfetcs.fallback_update_resources("Pattern",res,"@MPlibPt")
+      if not pdfmode then
+        tableinsert(pdfetcs.patternresources, res) -- for gather_resources()
+      end
     end
   end
 end
@@ -2258,8 +2267,7 @@
   if pdfmode then
     if pdfmanagement then
       for _,v in ipairs(names) do
-        local pp = get_macro(format("g__pdfdict_/g__pdf_Core/Page/Resources/%s_prop",v))
-        if pp and pp:find"__prop_pair" then
+        if ltx.__pdf.Page.Resources[v] then
           t[#t+1] = format("/%s %s 0 R", v, ltx.pdf.object_id("__pdf/Page/Resources/"..v))
         end
       end
@@ -2279,15 +2287,12 @@
   else
     if pdfmanagement then
       for _,v in ipairs(names) do
-        local pp = get_macro(format("g__pdfdict_/g__pdf_Core/Page/Resources/%s_prop",v))
-        if pp and pp:find"__prop_pair" then
-          run_tex_code {
-            "\\mplibtmptoks\\expanded{{",
-            format("/%s \\csname pdf_object_ref:n\\endcsname{__pdf/Page/Resources/%s}",v,v),
-            "}}",
-          }
-          t[#t+1] = texgettoks'mplibtmptoks'
-        end
+        run_tex_code ({
+          "\\mplibtmptoks\\expanded{{",
+          "\\pdfdict_if_empty:nF{g__pdf_Core/Page/Resources/", v, "}",
+          "{/", v, " \\pdf_object_ref:n{__pdf/Page/Resources/", v, "}}}}",
+        },ccexplat)
+        t[#t+1] = texgettoks'mplibtmptoks'
       end
     elseif is_defined(pdfetcs.pgfextgs) then
       run_tex_code ({
@@ -2298,6 +2303,9 @@
         "}}",
       }, catat11)
       t[#t+1] = texgettoks'mplibtmptoks'
+      if pdfetcs.resadded.Shading then
+        t[#t+1] = format("/Shading %s", pdfetcs.resadded.Shading)
+      end
     else
       for _,v in ipairs(names) do
         local vv = pdfetcs.resadded[v]
@@ -2307,6 +2315,36 @@
       end
     end
   end
+  if do_pattern then return tableconcat(t) end
+  -- get pattern resources
+  local mytoks
+  if pdfmanagement then
+    run_tex_code ({
+      "\\mplibtmptoks\\expanded{{",
+      "\\pdfdict_if_empty:nF{g__pdf_Core/Page/Resources/Pattern}",
+      "{\\pdfdict_use:n{g__pdf_Core/Page/Resources/Pattern}}", "}}",
+    },ccexplat)
+    mytoks = texgettoks"mplibtmptoks"
+    if not pdfmode then
+      mytoks = mytoks:gsub("\\str_convert_pdfname:n%s*{(.-)}","%1") -- why not expanded?
+    end
+  elseif is_defined(pdfetcs.pgfextgs) then
+    if pdfmode then
+      mytoks = get_macro"pgf at sys@pgf at resource@list at patterns"
+    else
+      local tt, abc = {}, get_macro"pgfutil at abc" or ""
+      for v in abc:gmatch"@pgfpatterns%s*<<(.-)>>" do
+        tt[#tt+1] = v
+      end
+      mytoks = tableconcat(tt)
+    end
+  else
+    local tt = pdfmode and pdfetcs.Pattern_res or pdfetcs.patternresources
+    mytoks = tt and tableconcat(tt)
+  end
+  if mytoks and mytoks ~= "" then
+    t[#t+1] = format("/Pattern<<%s>>",mytoks)
+  end
   return tableconcat(t)
 end
 function luamplib.registerpattern ( boxid, name, opts )

Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty	2025-03-20 10:47:33 UTC (rev 74708)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty	2025-03-20 19:59:11 UTC (rev 74709)
@@ -11,7 +11,7 @@
 \ifcsname ProvidesPackage\endcsname
   \NeedsTeXFormat{LaTeX2e}
   \ProvidesPackage{luamplib}
-    [2025/02/18 v2.37.1 mplib package for LuaTeX]
+    [2025/03/20 v2.37.2 mplib package for LuaTeX]
 \fi
 \ifdefined\newluafunction\else
   \input ltluatex



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