texlive[74104] Master/texmf-dist: luamplib (18feb25)

commits+karl at tug.org commits+karl at tug.org
Tue Feb 18 22:07:17 CET 2025


Revision: 74104
          https://tug.org/svn/texlive?view=revision&revision=74104
Author:   karl
Date:     2025-02-18 22:07:17 +0100 (Tue, 18 Feb 2025)
Log Message:
-----------
luamplib (18feb25)

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	2025-02-18 21:07:08 UTC (rev 74103)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS	2025-02-18 21:07:17 UTC (rev 74104)
@@ -1,5 +1,14 @@
                        History of the luamplib package
 
+2025/02/18 2.37.1
+   * A new operator 'mplibuclength <string>' returns the number of unicode
+   grapheme clusters in the string.
+
+   * A new operator 'mplibucsubstring <pair> of <string>' returns the part of
+   the string indexed by unicode grapheme clusters.
+
+   * These two operators require lua-uni-algos package.
+
 2025/02/06 2.37.0
    * introduce a new operator 'mpliblength <string>', a unicode-aware version of
    the 'length' primitive

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-02-18 21:07:08 UTC (rev 74103)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/test-luamplib-latex.tex	2025-02-18 21:07:17 UTC (rev 74104)
@@ -6,6 +6,7 @@
 \fi
 \usepackage{fontspec}
 \setmainfont{latin modern roman}
+\newfontfamily\hangulfont{NotoSansCJKKR}[Script=Hangul,Language=Korean]
 \usepackage{luamplib}
 \usepackage{graphicx,xcolor}
 \everymplib{ beginfig(0); }
@@ -353,6 +354,7 @@
     withshadingcolors (red,blue)
     ;
 \endmpfig
+\leavevmode
 \mpfig
   string Test; Test="abçdéf";
   for k=0 upto mpliblength(Test)-1:
@@ -359,6 +361,16 @@
     draw TEX(mplibsubstring (k,k+1) of Test) scaled 2 shifted (20k,0);
   endfor
 \endmpfig
+\qquad
+\mpliblegacybehavior{false}%
+\mpfig
+  verbatimtex \hangulfont etex;
+  string Test; Test="나랏말ᄊᆞ미";
+  for k=0 upto mplibuclength(Test)-1:
+    draw TEX(mplibucsubstring (k,k+1) of Test) scaled 1.5 shifted (20k,0);
+  endfor
+\endmpfig
+\mpliblegacybehavior{true}%
 \tracingcommands0
 
 \vskip 2\baselineskip

Modified: trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
===================================================================
--- trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx	2025-02-18 21:07:08 UTC (rev 74103)
+++ trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx	2025-02-18 21:07:17 UTC (rev 74104)
@@ -85,7 +85,7 @@
 %<*driver>
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesFile{luamplib.drv}%
-  [2025/02/06 v2.37.0 Interface for using the mplib library]%
+  [2025/02/18 v2.37.1 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/06 v2.37.0}
+% \date{2025/02/18 v2.37.1}
 %
 % \maketitle
 %
@@ -1084,7 +1084,7 @@
 %   \item[\texttt{withshadingcenter} \meta{pair}]
 %     Values for shifting starting center.
 %     For instance,
-%     |(0,0)| means that center of starting circle is |center p|;
+%     |(0,0)| means that the center of starting circle is |center p|;
 %     |(1,1)| means |urcorner p|.
 %   \item[\texttt{withshadingtransform} \meta{string}]
 %     where \meta{string} shall be |"yes"| (respect transform) or |"no"| (ignore transform).
@@ -1103,18 +1103,34 @@
 %     Default value: |(white,black)|
 % \end{description}
 %
-% \subsubsection{\texttt{mpliblength ...}}
+% \subsubsection{\texttt{mpliblength ...}, \texttt{mplibuclength ...}}
 %   |mpliblength| \meta{string} returns the number of unicode characters in the string.
 %   This is a unicode-aware version equivalent to the \metapost primitive |length|, but
 %   accepts only a string-type argument.
 %   For instance, |mpliblength| |"abçdéf"| returns |6|, not |8|.
 %
-% \subsubsection{\texttt{mplibsubstring ... of ...}}
+%   On the other hand,
+%   |mplibuclength| \meta{string} returns the number of unicode grapheme clusters in the string.
+%   For instance, |mplibuclength| |"Äpfel"|,
+%   where |Ä| is encoded using two codepoints (U+0041 and U+0308),
+%   returns |5|, not |6| or |7|.
+%   This operator requires \pkg{lua-uni-algos} package.
+%
+% \subsubsection{\texttt{mplibsubstring ... of ...}, \texttt{mplibucsubstring ... of ...}}
 %   |mplibsubstring| \meta{pair} |of| \meta{string} is a unicode-aware version equivalent to the
-%   \metapost's |substring ... of ...| primitive. The syntax is the same as the latter.
+%   \metapost's |substring ... of ...| primitive. The syntax is the same as the latter,
+%   but the string is indexed by unicode characters.
 %   For instance, |mplibsubstring| |(2,5)| |of| |"abçdéf"| returns |"çdé"|,
 %   and |mplibsubstring| |(5,2)| |of| |"abçdéf"| returns |"édç"|.
 %
+%   On the other hand,
+%   |mplibucsubstring| \meta{pair} |of| \meta{string} returns the part of the string indexed
+%   by unicode grapheme clusters.
+%   For instance, |mplibucsubstring| |(0,1)| |of| |"Äpfel"|,
+%   where |Ä| is encoded using two codepoints (U+0041 and U+0308),
+%   returns |"Ä"|, not |"A"|.
+%   This operator requires \pkg{lua-uni-algos} package.
+%
 % \subsection{Lua}
 %
 % \subsubsection{\texttt{runscript ...}}
@@ -1200,8 +1216,8 @@
 
 luatexbase.provides_module {
   name          = "luamplib",
-  version       = "2.37.0",
-  date          = "2025/02/06",
+  version       = "2.37.1",
+  date          = "2025/02/18",
   description   = "Lua package to typeset Metapost with LuaTeX's MPLib.",
 }
 
@@ -2644,13 +2660,26 @@
 
 %    \end{macrocode}
 %
-%    lua function for |mplibsubstring ... of ...|
+%    lua functions for |mplib(uc)substring ... of ...|
 %    \begin{macrocode}
-function luamplib.utf8substring (s,b,e)
-  local t, tt, step = { }, { }
-  for _, c in utf8.codes(s) do
-    table.insert(t, utf8.char(c))
+function luamplib.getunicodegraphemes (s)
+  local t = { }
+  local graphemes = require'lua-uni-graphemes'
+  for _, _, c in graphemes.graphemes(s) do
+    table.insert(t, c)
   end
+  return t
+end
+function luamplib.unicodesubstring (s,b,e,grph)
+  local tt, t, step = { }
+  if grph then
+    t = luamplib.getunicodegraphemes(s)
+  else
+    t = { }
+    for _, c in utf8.codes(s) do
+      table.insert(t, utf8.char(c))
+    end
+  end
   if b <= e then
     b, step = b+1, 1
   else
@@ -3091,10 +3120,18 @@
   runscript("return utf8.len[===[" & t & "]===]")
 enddef;
 def mplibsubstring expr p of t =
-  runscript("return luamplib.utf8substring([===[" & t & "]===],"
+  runscript("return luamplib.unicodesubstring([===[" & t & "]===],"
     & decimal xpart p & ","
     & decimal ypart p & ")")
 enddef;
+def mplibuclength primary t =
+  runscript("return #luamplib.getunicodegraphemes[===[" & t & "]===]")
+enddef;
+def mplibucsubstring expr p of t =
+  runscript("return luamplib.unicodesubstring([===[" & t & "]===],"
+    & decimal xpart p & ","
+    & decimal ypart p & ",true)")
+enddef;
 ]],
   legacyverbatimtex = [[
 def specialVerbatimTeX (text t) = runscript("luamplibprefig{"&t&"}") enddef;
@@ -4564,7 +4601,7 @@
 %    \begin{macrocode}
   \NeedsTeXFormat{LaTeX2e}
   \ProvidesPackage{luamplib}
-    [2025/02/06 v2.37.0 mplib package for LuaTeX]
+    [2025/02/18 v2.37.1 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-02-18 21:07:08 UTC (rev 74103)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua	2025-02-18 21:07:17 UTC (rev 74104)
@@ -11,8 +11,8 @@
 
 luatexbase.provides_module {
   name          = "luamplib",
-  version       = "2.37.0",
-  date          = "2025/02/06",
+  version       = "2.37.1",
+  date          = "2025/02/18",
   description   = "Lua package to typeset Metapost with LuaTeX's MPLib.",
 }
 
@@ -1193,11 +1193,24 @@
   return tableconcat(res) .. format("mpliboutlinenum:=%i;", #res)
 end
 
-function luamplib.utf8substring (s,b,e)
-  local t, tt, step = { }, { }
-  for _, c in utf8.codes(s) do
-    table.insert(t, utf8.char(c))
+function luamplib.getunicodegraphemes (s)
+  local t = { }
+  local graphemes = require'lua-uni-graphemes'
+  for _, _, c in graphemes.graphemes(s) do
+    table.insert(t, c)
   end
+  return t
+end
+function luamplib.unicodesubstring (s,b,e,grph)
+  local tt, t, step = { }
+  if grph then
+    t = luamplib.getunicodegraphemes(s)
+  else
+    t = { }
+    for _, c in utf8.codes(s) do
+      table.insert(t, utf8.char(c))
+    end
+  end
   if b <= e then
     b, step = b+1, 1
   else
@@ -1634,10 +1647,18 @@
   runscript("return utf8.len[===[" & t & "]===]")
 enddef;
 def mplibsubstring expr p of t =
-  runscript("return luamplib.utf8substring([===[" & t & "]===],"
+  runscript("return luamplib.unicodesubstring([===[" & t & "]===],"
     & decimal xpart p & ","
     & decimal ypart p & ")")
 enddef;
+def mplibuclength primary t =
+  runscript("return #luamplib.getunicodegraphemes[===[" & t & "]===]")
+enddef;
+def mplibucsubstring expr p of t =
+  runscript("return luamplib.unicodesubstring([===[" & t & "]===],"
+    & decimal xpart p & ","
+    & decimal ypart p & ",true)")
+enddef;
 ]],
   legacyverbatimtex = [[
 def specialVerbatimTeX (text t) = runscript("luamplibprefig{"&t&"}") enddef;

Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty	2025-02-18 21:07:08 UTC (rev 74103)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty	2025-02-18 21:07:17 UTC (rev 74104)
@@ -11,7 +11,7 @@
 \ifcsname ProvidesPackage\endcsname
   \NeedsTeXFormat{LaTeX2e}
   \ProvidesPackage{luamplib}
-    [2025/02/06 v2.37.0 mplib package for LuaTeX]
+    [2025/02/18 v2.37.1 mplib package for LuaTeX]
 \fi
 \ifdefined\newluafunction\else
   \input ltluatex



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