latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.82k stars 251 forks source link

Adding a leading `v` if it is missing in lua module version #1364

Closed Udi-Fogiel closed 2 weeks ago

Udi-Fogiel commented 1 month ago

Brief outline of the enhancement

LaTeX2e generally cannot add new features without an extreme amount of care to accommodate backwards compatibility. Please do not be offended if your request is closed for being infeasible.

Currently lua module version is printed to the log as is, which means l3build does not normalize the version if it is missing in a leading v (https://github.com/latex3/l3build/issues/354)

Minimal example showing the current behaviour

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}

\begin{filecontents*}[overwrite]{foo.lua}
luatexbase.provides_module ({
    name          = 'foo',
    version       = '1.0',
})
\end{filecontents*}

\directlua{require('foo')}

\stop

The log file shows Lua module: foo 1.0)

Minimal example showing the desired new behaviour

Following the suggestion in https://github.com/latex3/l3build/issues/354

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}

\begin{filecontents*}[overwrite]{foo.lua}
luatexbase.provides_module ({
    name          = 'foo',
    version       = '1.0',
})
\end{filecontents*}

\directlua{
local function provides_module(info)
  if not (info and info.name) then
    luatexbase.module_error("luatexbase","Missing module name for provides_module")
  end
  local function spaced(text)
    return text and (" " .. text) or ""
  end
  texio.write_nl("log",
    "Lua module: " .. info.name
      .. spaced(info.date)
      .. spaced(string.gsub(info.version,"^(\csstring\%d)","v\csstring\%1"))
      .. spaced(info.description)
  )
  modules[info.name] = info
end
luatexbase.provides_module = provides_module

require('foo')}

\stop