texlive[70861] Master/texmf-dist: luamplib (4apr24)
commits+karl at tug.org
commits+karl at tug.org
Thu Apr 4 22:37:40 CEST 2024
Revision: 70861
https://tug.org/svn/texlive?view=revision&revision=70861
Author: karl
Date: 2024-04-04 22:37:40 +0200 (Thu, 04 Apr 2024)
Log Message:
-----------
luamplib (4apr24)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS
trunk/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
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-04-04 20:37:30 UTC (rev 70860)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS 2024-04-04 20:37:40 UTC (rev 70861)
@@ -1,5 +1,14 @@
History of the luamplib package
+2024/04/04 2.27.2
+ * for warning/info/error messages we now use our own lua function,
+ instead of ltluatex's. As a result, mplib's multi-line messages are
+ printed as they are with no module name prepended to each line.
+ * terminal messages are now much conciser than before, printing only
+ the most relevant part.
+ * mplibcode which has no figure output does not print a warning, but
+ just an info to the log.
+
2024/03/29 2.27.1
* fix a bug regarding local textext boxes
Modified: trunk/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
===================================================================
--- trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx 2024-04-04 20:37:30 UTC (rev 70860)
+++ trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx 2024-04-04 20:37:40 UTC (rev 70861)
@@ -85,7 +85,7 @@
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luamplib.drv}%
- [2024/03/29 v2.27.1 Interface for using the mplib library]%
+ [2024/04/04 v2.27.2 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{2024/03/29 v2.27.1}
+% \date{2024/04/04 v2.27.2}
%
% \maketitle
%
@@ -189,7 +189,7 @@
% \begin{itemize}
% \item a \LaTeX\ environment
% \item all \TeX\ macros start by |mplib|
-% \item use of luatexbase for errors, warnings and declaration
+% \item use of our own function for errors, warnings and informations
% \item possibility to use |btex ... etex| to typeset \TeX\ code.
% |textext()| is a more versatile macro equivalent to |TEX()| from TEX.mp.
% |TEX()| is also allowed and is a synomym of |textext()|.\par\smallskip
@@ -455,23 +455,11 @@
luatexbase.provides_module {
name = "luamplib",
- version = "2.27.1",
- date = "2024/03/29",
+ version = "2.27.2",
+ date = "2024/04/04",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}
-local format, abs = string.format, math.abs
-
-local err = function(...)
- return luatexbase.module_error ("luamplib", format(...))
-end
-local warn = function(...)
- return luatexbase.module_warning("luamplib", format(...))
-end
-local info = function(...)
- return luatexbase.module_info ("luamplib", format(...))
-end
-
% \end{macrocode}
%
% Use the |luamplib| namespace, since |mplib| is for the metapost library
@@ -480,6 +468,41 @@
luamplib = luamplib or { }
local luamplib = luamplib
+local format, abs = string.format, math.abs
+
+% \end{macrocode}
+%
+% Use our own function for warn/info/err.
+% \begin{macrocode}
+local function termorlog (target, text, kind)
+ if text then
+ local mod, write, append = "luamplib", texio.write_nl, texio.write
+ kind = kind
+ or target == "term" and "Warning (more info in the log)"
+ or target == "log" and "Info"
+ or target == "term and log" and "Warning"
+ or "Error"
+ target = kind == "Error" and "term and log" or target
+ local t = text:explode"\n+"
+ write(target, format("Module %s %s:", mod, kind))
+ if #t == 1 then
+ append(target, format(" %s", t[1]))
+ else
+ for _,line in ipairs(t) do
+ write(target, line)
+ end
+ write(target, format("(%s) ", mod))
+ end
+ append(target, format(" on input line %s", tex.inputlineno))
+ write(target, "")
+ if kind == "Error" then error() end
+ end
+end
+
+local warn = function(...) termorlog("term and log", format(...)) end
+local info = function(...) termorlog("log", format(...)) end
+local err = function(...) termorlog("error", format(...)) end
+
luamplib.showlog = luamplib.showlog or false
% \end{macrocode}
@@ -762,8 +785,27 @@
input %s ;
]]
-local logatload
-local function reporterror (result, indeed)
+% \end{macrocode}
+%
+% |plain| or |metafun|,
+% though we cannot support |metafun| format fully.
+% \begin{macrocode}
+local currentformat = "plain"
+local function setformat (name)
+ currentformat = name
+end
+luamplib.setformat = setformat
+
+% \end{macrocode}
+%
+% v2.9 has introduced the concept of ``code inherit''
+% \begin{macrocode}
+luamplib.codeinherit = false
+
+local mplibinstances = {}
+local instancename
+
+local function reporterror (result, prevlog)
if not result then
err("no result object returned")
else
@@ -775,31 +817,32 @@
local log = l or t or "no-term"
log = log:gsub("%(Please type a command or say `end'%)",""):gsub("\n+","\n")
if result.status > 0 then
- warn(log)
+ local first = log:match"(.-\n! .-)\n! "
+ if first then
+ termorlog("term", first)
+ termorlog("log", log, "Warning")
+ else
+ warn(log)
+ end
if result.status > 1 then
err(e or "see above messages")
end
- elseif indeed then
- local log = logatload..log
+ elseif prevlog then
+ log = prevlog..log
% \end{macrocode}
%
% v2.6.1: now luamplib does not disregard |show| command,
% even when |luamplib.showlog| is false. Incidentally,
-% it does not raise error but just prints a warning,
+% it does not raise error but just prints an info,
% even if output has no figure.
% \begin{macrocode}
- if log:find"\n>>" then
- warn(log)
- elseif log:find"%g" then
- if luamplib.showlog then
- info(log)
- elseif not result.fig then
- info(log)
- end
+ local show = log:match"\n>>? .+"
+ if show then
+ termorlog("term", show, "Info (more info in the log)")
+ info(log)
+ elseif luamplib.showlog and log:find"%g" then
+ info(log)
end
- logatload = ""
- else
- logatload = log
end
return log
end
@@ -836,59 +879,21 @@
if luamplib.textextlabel then
preamble = preamble .. luamplib.textextlabelpreamble
end
- local result
+ local result, log
if not mpx then
result = { status = 99, error = "out of memory"}
else
result = mpx:execute(format(preamble, replacesuffix(name,"mp")))
end
- reporterror(result)
- return mpx, result
+ log = reporterror(result)
+ return mpx, result, log
end
% \end{macrocode}
%
-% |plain| or |metafun|,
-% though we cannot support |metafun| format fully.
-% \begin{macrocode}
-local currentformat = "plain"
-
-local function setformat (name)
- currentformat = name
-end
-luamplib.setformat = setformat
-
-% \end{macrocode}
-%
% Here, excute each |mplibcode| data,
% ie |\begin{mplibcode} ... \end{mplibcode}|.
% \begin{macrocode}
-local function process_indeed (mpx, data)
- local converted, result = false, {}
- if mpx and data then
- result = mpx:execute(data)
- local log = reporterror(result, true)
- if log then
- if result.fig then
- converted = luamplib.convert(result)
- else
- warn("No figure output. Maybe no beginfig/endfig")
- end
- end
- else
- err("Mem file unloadable. Maybe generated with a different version of mplib?")
- end
- return converted, result
-end
-
-% \end{macrocode}
-%
-% v2.9 has introduced the concept of ``code inherit''
-% \begin{macrocode}
-luamplib.codeinherit = false
-local mplibinstances = {}
-local instancename
-
local function process (data)
% \end{macrocode}
%
@@ -900,25 +905,41 @@
% end
% \end{verbatim}
% \begin{macrocode}
- 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
+ local currfmt
+ if instancename and instancename ~= "" then
+ currfmt = instancename
+ else
+ currfmt = currentformat..(luamplib.numbersystem or "scaled")
+ ..tostring(luamplib.textextlabel)..tostring(luamplib.legacy_verbatimtex)
end
local mpx = mplibinstances[currfmt]
local standalone = false
- if currfmt == defaultinstancename then
+ if currfmt ~= instancename then
standalone = not luamplib.codeinherit
end
if mpx and standalone then
mpx:finish()
end
+ local log = ""
if standalone or not mpx then
- mpx = luamplibload(currentformat)
+ mpx, _, log = luamplibload(currentformat)
mplibinstances[currfmt] = mpx
end
- return process_indeed(mpx, data)
+ local converted, result = false, {}
+ if mpx and data then
+ result = mpx:execute(data)
+ local log = reporterror(result, log)
+ if log then
+ if result.fig then
+ converted = luamplib.convert(result)
+ else
+ info"No figure output. Maybe no beginfig/endfig"
+ end
+ end
+ else
+ err"Mem file unloadable. Maybe generated with a different version of mplib?"
+ end
+ return converted, result
end
% \end{macrocode}
@@ -1024,13 +1045,6 @@
[[\def\__color_backend_select:nn#1#2{\global\mplibtmptoks{#1 #2}}]]..
[[\def\__kernel_backend_literal:e#1{\global\mplibtmptoks\expandafter{\expanded{#1}}}]]..
[[\color_select:n%s\endgroup]],
- l3xcolor = [[\begingroup\color_if_exist:nTF%s{]]..
- [[\def\__color_select:N#1{\expandafter\__color_select:nn#1}]]..
- [[\def\__color_backend_select:nn#1#2{\global\mplibtmptoks{#1 #2}}]]..
- [[\def\__kernel_backend_literal:e#1{\global\mplibtmptoks\expandafter{\expanded{#1}}}]]..
- [[\color_select:n%s}{\let\XC at mcolor\relax]]..
- [[\def\set at color{\global\mplibtmptoks\expandafter{\current at color}}]]..
- [[\color%s}\endgroup]],
}
local colfmt = is_defined'color_select:n' and "l3color" or "xcolor"
@@ -1069,7 +1083,7 @@
end
end
end
- run_tex_code(myfmt:format(str,str,str), ccexplat or catat11)
+ run_tex_code(myfmt:format(str), ccexplat or catat11)
local t = texgettoks"mplibtmptoks"
return format('1 withprescript "MPlibOverrideColor=%s"', t)
end
@@ -1078,10 +1092,7 @@
% \end{macrocode}
%
-% \cs{mpdim} is expanded before MPLib process, so code below will not be
-% used for |mplibcode| data. But who knows anyone would want it
-% in |.mp| input file. If then, you can say |mplibdimen(".5\textwidth")|
-% for example.
+% for \cs{mpdim} or |mplibdimen|
% \begin{macrocode}
local function process_dimen (str)
if str then
@@ -1850,7 +1861,11 @@
elseif not pdfmode then
override = prev_override_color
if override then
- texsprint(format("\\special{color push %s}",override))
+ if override:find"^pdf:" then
+ texsprint(format("\\special{%s}",override))
+ else
+ texsprint(format("\\special{color push %s}",override))
+ end
end
end
end
@@ -2193,7 +2208,7 @@
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2024/03/29 v2.27.1 mplib package for LuaTeX]
+ [2024/04/04 v2.27.2 mplib package for LuaTeX]
\ifx\newluafunction\@undefined
\input ltluatex
\fi
Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua 2024-04-04 20:37:30 UTC (rev 70860)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua 2024-04-04 20:37:40 UTC (rev 70861)
@@ -11,25 +11,44 @@
luatexbase.provides_module {
name = "luamplib",
- version = "2.27.1",
- date = "2024/03/29",
+ version = "2.27.2",
+ date = "2024/04/04",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}
+luamplib = luamplib or { }
+local luamplib = luamplib
+
local format, abs = string.format, math.abs
-local err = function(...)
- return luatexbase.module_error ("luamplib", format(...))
+local function termorlog (target, text, kind)
+ if text then
+ local mod, write, append = "luamplib", texio.write_nl, texio.write
+ kind = kind
+ or target == "term" and "Warning (more info in the log)"
+ or target == "log" and "Info"
+ or target == "term and log" and "Warning"
+ or "Error"
+ target = kind == "Error" and "term and log" or target
+ local t = text:explode"\n+"
+ write(target, format("Module %s %s:", mod, kind))
+ if #t == 1 then
+ append(target, format(" %s", t[1]))
+ else
+ for _,line in ipairs(t) do
+ write(target, line)
+ end
+ write(target, format("(%s) ", mod))
+ end
+ append(target, format(" on input line %s", tex.inputlineno))
+ write(target, "")
+ if kind == "Error" then error() end
+ end
end
-local warn = function(...)
- return luatexbase.module_warning("luamplib", format(...))
-end
-local info = function(...)
- return luatexbase.module_info ("luamplib", format(...))
-end
-luamplib = luamplib or { }
-local luamplib = luamplib
+local warn = function(...) termorlog("term and log", format(...)) end
+local info = function(...) termorlog("log", format(...)) end
+local err = function(...) termorlog("error", format(...)) end
luamplib.showlog = luamplib.showlog or false
@@ -258,8 +277,18 @@
input %s ;
]]
-local logatload
-local function reporterror (result, indeed)
+local currentformat = "plain"
+local function setformat (name)
+ currentformat = name
+end
+luamplib.setformat = setformat
+
+luamplib.codeinherit = false
+
+local mplibinstances = {}
+local instancename
+
+local function reporterror (result, prevlog)
if not result then
err("no result object returned")
else
@@ -267,24 +296,25 @@
local log = l or t or "no-term"
log = log:gsub("%(Please type a command or say `end'%)",""):gsub("\n+","\n")
if result.status > 0 then
- warn(log)
+ local first = log:match"(.-\n! .-)\n! "
+ if first then
+ termorlog("term", first)
+ termorlog("log", log, "Warning")
+ else
+ warn(log)
+ end
if result.status > 1 then
err(e or "see above messages")
end
- elseif indeed then
- local log = logatload..log
- if log:find"\n>>" then
- warn(log)
- elseif log:find"%g" then
- if luamplib.showlog then
- info(log)
- elseif not result.fig then
- info(log)
- end
+ elseif prevlog then
+ log = prevlog..log
+ local show = log:match"\n>>? .+"
+ if show then
+ termorlog("term", show, "Info (more info in the log)")
+ info(log)
+ elseif luamplib.showlog and log:find"%g" then
+ info(log)
end
- logatload = ""
- else
- logatload = log
end
return log
end
@@ -308,67 +338,54 @@
if luamplib.textextlabel then
preamble = preamble .. luamplib.textextlabelpreamble
end
- local result
+ local result, log
if not mpx then
result = { status = 99, error = "out of memory"}
else
result = mpx:execute(format(preamble, replacesuffix(name,"mp")))
end
- reporterror(result)
- return mpx, result
+ log = reporterror(result)
+ return mpx, result, log
end
-local currentformat = "plain"
-
-local function setformat (name)
- currentformat = name
-end
-luamplib.setformat = setformat
-
-local function process_indeed (mpx, data)
+local function process (data)
+ local currfmt
+ if instancename and instancename ~= "" then
+ currfmt = instancename
+ else
+ currfmt = currentformat..(luamplib.numbersystem or "scaled")
+ ..tostring(luamplib.textextlabel)..tostring(luamplib.legacy_verbatimtex)
+ end
+ local mpx = mplibinstances[currfmt]
+ local standalone = false
+ if currfmt ~= instancename then
+ standalone = not luamplib.codeinherit
+ end
+ if mpx and standalone then
+ mpx:finish()
+ end
+ local log = ""
+ if standalone or not mpx then
+ mpx, _, log = luamplibload(currentformat)
+ mplibinstances[currfmt] = mpx
+ end
local converted, result = false, {}
if mpx and data then
result = mpx:execute(data)
- local log = reporterror(result, true)
+ local log = reporterror(result, log)
if log then
if result.fig then
converted = luamplib.convert(result)
else
- warn("No figure output. Maybe no beginfig/endfig")
+ info"No figure output. Maybe no beginfig/endfig"
end
end
else
- err("Mem file unloadable. Maybe generated with a different version of mplib?")
+ err"Mem file unloadable. Maybe generated with a different version of mplib?"
end
return converted, result
end
-luamplib.codeinherit = false
-local mplibinstances = {}
-local instancename
-
-local function process (data)
- 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
- if standalone or not mpx then
- mpx = luamplibload(currentformat)
- mplibinstances[currfmt] = mpx
- end
- return process_indeed(mpx, data)
-end
-
local catlatex = luatexbase.registernumber("catcodetable at latex")
local catat11 = luatexbase.registernumber("catcodetable at atletter")
@@ -432,13 +449,6 @@
[[\def\__color_backend_select:nn#1#2{\global\mplibtmptoks{#1 #2}}]]..
[[\def\__kernel_backend_literal:e#1{\global\mplibtmptoks\expandafter{\expanded{#1}}}]]..
[[\color_select:n%s\endgroup]],
- l3xcolor = [[\begingroup\color_if_exist:nTF%s{]]..
- [[\def\__color_select:N#1{\expandafter\__color_select:nn#1}]]..
- [[\def\__color_backend_select:nn#1#2{\global\mplibtmptoks{#1 #2}}]]..
- [[\def\__kernel_backend_literal:e#1{\global\mplibtmptoks\expandafter{\expanded{#1}}}]]..
- [[\color_select:n%s}{\let\XC at mcolor\relax]]..
- [[\def\set at color{\global\mplibtmptoks\expandafter{\current at color}}]]..
- [[\color%s}\endgroup]],
}
local colfmt = is_defined'color_select:n' and "l3color" or "xcolor"
@@ -477,7 +487,7 @@
end
end
end
- run_tex_code(myfmt:format(str,str,str), ccexplat or catat11)
+ run_tex_code(myfmt:format(str), ccexplat or catat11)
local t = texgettoks"mplibtmptoks"
return format('1 withprescript "MPlibOverrideColor=%s"', t)
end
@@ -1153,7 +1163,11 @@
elseif not pdfmode then
override = prev_override_color
if override then
- texsprint(format("\\special{color push %s}",override))
+ if override:find"^pdf:" then
+ texsprint(format("\\special{%s}",override))
+ else
+ texsprint(format("\\special{color push %s}",override))
+ end
end
end
end
Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty 2024-04-04 20:37:30 UTC (rev 70860)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty 2024-04-04 20:37:40 UTC (rev 70861)
@@ -14,7 +14,7 @@
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2024/03/29 v2.27.1 mplib package for LuaTeX]
+ [2024/04/04 v2.27.2 mplib package for LuaTeX]
\ifx\newluafunction\@undefined
\input ltluatex
\fi
More information about the tex-live-commits
mailing list.