Hi Werner,

On Sat, 2025-09-13 at 10:30 +0000, Werner LEMBERG wrote:
> > The current Lua font loading code essentially goes directly from the
> > binary font files to the "tfmdata" table. Specifically, mark-to-base
> > is handled by lines 1906--1908 of "fontloader-font-dsp.lua".
>
> Thanks again, very helpful.  BTW, how could I debug this code?  What's
> the right way to use, say, `debugger.lua` while loading a font?

Lua does have a "debug" module

    https://www.lua.org/manual/5.3/manual.html#6.10

(that you can enable in LuaTeX with "--luadebug"), but I've never found
it helpful for debugging. Usually I just manually add "print(var)"
and/or "inspect(var)" calls to the source code. You can use
"debug.traceback()" without "--luadebug", so sometimes
"print(debug.traceback())" can be helpful. Another common trick to trace
a function is the following:

    -- Assuming that a function "some_function" exists
    do
        local saved = some_function
        function some_function(...)
            local out = { saved(...) }
            inspect {
                ["in"] = { ... },
                out = out,
            }
            return unpack(out)
        end
    end

The ConTeXt fonts manual ("texdoc fonts-mkiv") and the CLD manual
("texdoc cld") might also be useful; although they only claim to
describe ConTeXt, 90% of both manuals apply to LuaLaTeX as well.

Also, luaotfload only loads the "fontloader-2023-12-28.lua" file, but it
does this at runtime, so you shouldn't need to rebuild the formats for
testing. However, this file has all the comments and indentation
stripped, so it's fairly challenging to read. So it's best to read the
"$TEXMFDIST/tex/luatex/luaotfload/fontloader-font-*.lua" files to figure
out what's going on, but then apply any changes to
"fontloader-2023-12-28.lua" directly.

Also, depending on what you're doing, the caches might cause problems,
so if something isn't working right, delete
"$TEXMFVAR/luatex-cache/generic/".

Thanks,
-- Max

Reply via email to