Skip to content

Enable LuaMetaTeX in ConTeXt tests and examples #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Witiko
Copy link
Owner

@Witiko Witiko commented Feb 20, 2025

This PR enables LuaMetaTeX in ConTeXt tests and examples after #551.

@Witiko Witiko added lua Related to the Lua interface and implementation technical debt Related to code smells and refactoring labels Feb 20, 2025
@Witiko Witiko added this to the 3.11.0 milestone Feb 20, 2025
@Witiko Witiko self-assigned this Feb 20, 2025
@Witiko Witiko force-pushed the fix/remove-selene-unicode branch from 600a7fc to 40aa8a2 Compare February 20, 2025 23:35
@Witiko Witiko changed the title Clean up code after #551 Reenable LuaMetaTeX and mention more contributors after #551 Feb 21, 2025
@Witiko Witiko force-pushed the fix/remove-selene-unicode branch 3 times, most recently from 8c981c0 to 98e0b37 Compare February 21, 2025 09:26
@Witiko Witiko changed the title Reenable LuaMetaTeX and mention more contributors after #551 Enable LuaMetaTeX in ConTeXt tests and examples Feb 21, 2025
@Witiko Witiko marked this pull request as draft February 21, 2025 10:02
@Witiko Witiko modified the milestones: 3.11.0, 3.11.1 Feb 21, 2025
@Witiko Witiko force-pushed the fix/remove-selene-unicode branch from 98e0b37 to c8aba5e Compare February 21, 2025 10:03
@Witiko Witiko added context Related to the ConTeXt interface and implementation and removed lua Related to the Lua interface and implementation labels Feb 21, 2025
@Witiko
Copy link
Owner Author

Witiko commented Feb 21, 2025

I wanted to test the new support for ConTeXt LMTX but I am still seeing some issues, namely the lack of support for the KPathSea library in LMTX, even in TeX Live, see the CI failure from this PR:

make FAIL_FAST=true test
make -C tests
make[1]: Entering directory '/__w/markdown/markdown/tests'
find testfiles/ -type f -name '*.test' -exec ./test.sh  {} +

Creating a Python virtual environment in /__w/markdown/markdown/tests/test-virtualenv.
2025-02-21 10:09:14,197 Running tests for 836 testfiles.
2025-02-21 10:09:14,197 Will fail at first error.
Testfile testfiles/regression/github/issue-508-fancy-lists.test:

  Some commands produced non-zero exit codes:
  - Command context [...] --luatex [...] test.tex [...] exited successfully.
  - Command context [...]          [...] test.tex [...] produced exit code 1.
  
  Some commands produced unexpected outputs:
  - Command context [...] --luatex [...] test.tex [...] produced expected output.
  - Command context [...]          [...] test.tex [...] produced unexpected output with the following diff:
  
    [...]

make[1]: *** [Makefile:13: all] Error 1
make[1]: Leaving directory '/__w/markdown/markdown/tests'
make: *** [Makefile:213: test] Error 2

Looking into the file test.log, I see the following:

lua error       > lua error on line 5 in file ./test.tex:

token call, execute: ...live/2024/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: module 'kpse' not found:
	no field package.preload['kpse']
	no file '/usr/local/share/lua/5.5/kpse.lua'
	no file '/usr/local/share/lua/5.5/kpse/init.lua'
	no file '/usr/local/lib/lua/5.5/kpse.lua'
	no file '/usr/local/lib/lua/5.5/kpse/init.lua'
	no file './kpse.lua'
	no file './kpse/init.lua'
stack traceback:
	[C]: in upvalue 'requiem'
	...live/2024/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: in function <...live/2024/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:165>
	(...tail calls...)
	[ctxlua]:2: in main chunk
 1     % Load the package.
 2     \startluacode
 3     local kpse = require("kpse")
 4     kpse.set_program_name("luatex")
 5 >>  \stopluacode
 6     \usemodule[t][markdown]
 7     
 8     % Load the support files.
 9     \setupmarkdown [
10       eagerCache = false,
11       import = {
12         witiko/markdown/test = snippet as testsnippet,
13       }
14     ]
15

This is perhaps to be expected: Even if KPathSea is available for LuaMetaTeX in TeX Live, we apparently need to use the predefined object optional.kpse instead of require("kpse") according to luametatex.pdf. Regardless, KPathSea is unlikely to be widely available in ConTeXt standalone and therefore, we shouldn't rely on it.

@Witiko
Copy link
Owner Author

Witiko commented Feb 21, 2025

@andreiborisov: Can you please test that you can compile the example file examples/context-lmtx.tex using LMTX and version 3.11.0 of the Markdown package for TeX? You will need to remove the following part that loads KPathSea:

\startluacode
local kpse = require("kpse")
kpse.set_program_name("luatex")
\stopluacode

Furthermore, you will also need to copy all dependencies to the directory examples/. As discussed in #402 (comment), this includes at least the following files and packages from CTAN:

  1. The expl3-generic.tex plain TeX file from l3kernel
  2. The lua-uni-algos Lua package
  3. The lt3luabridge plain TeX package
  4. The tinyyaml Lua package

Please, let me know how that goes!

If you manage to compile the example document, I will use your feedback to hopefully have the CI running the LMTX tests and compiling the LMTX examples in the next version, to be released by the end of March at the latest. 🤞

This was referenced Feb 21, 2025
This was linked to issues Feb 21, 2025
@Witiko Witiko force-pushed the main branch 3 times, most recently from 97ee0f0 to 4902747 Compare March 11, 2025 20:20
@Witiko Witiko modified the milestones: 3.11.1, 3.11.2 Mar 30, 2025
@Witiko
Copy link
Owner Author

Witiko commented Mar 31, 2025

@andreiborisov seems unavailable with no GitHub activity since at least January. Therefore, I will jump on this in the meantime and try to get things moving before the end of April. This includes adding examples and tests for LuaMetaTeX and ConTeXt LMTX, writing instructions for installation with ConTeXt standalone, and fixing any issues I find along the way.

Adding a Dockerfile for ConTeXt standalone, continuously building a Docker image, running tests with it, and releasing it sounds great on paper but I am not using ConTeXt nearly enough to feel comfortable as the only maintainer of this part of the Markdown Package for TeX. Therefore, this is currently not a goal.

@Witiko
Copy link
Owner Author

Witiko commented Apr 15, 2025

@andreiborisov: Can you please test that you can compile the example file examples/context-lmtx.tex using LMTX and version 3.11.0 of the Markdown package for TeX? You will need to remove the following part that loads KPathSea: [...] Furthermore, you will also need to copy all dependencies to the directory examples/. As discussed in #402 (comment), this includes at least the following files and packages from CTAN: [...] Please, let me know how that goes!

@andreiborisov seems unavailable with no GitHub activity since at least January. Therefore, I will jump on this in the meantime and try to get things moving before the end of April.

I removed the part of file context-lmtx.tex that loaded KPathSea and symlinked all dependencies to examples/:

lrwxrwxrwx 1 root    root      68 Apr 15 12:43 expl3-code.tex -> /usr/local/texlive/2025/texmf-dist/tex/latex/l3kernel/expl3-code.tex
lrwxrwxrwx 1 root    root      71 Apr 15 12:42 expl3-generic.tex -> /usr/local/texlive/2025/texmf-dist/tex/latex/l3kernel/expl3-generic.tex
lrwxrwxrwx 1 root    root      63 Apr 15 12:47 expl3.lua -> /usr/local/texlive/2025/texmf-dist/tex/latex/l3kernel/expl3.lua
lrwxrwxrwx 1 root    root      72 Apr 15 12:45 lt3luabridge.sty -> /usr/local/texlive/texmf-local/tex/generic/lt3luabridge/lt3luabridge.sty
lrwxrwxrwx 1 root    root      72 Apr 15 12:45 lt3luabridge.tex -> /usr/local/texlive/texmf-local/tex/generic/lt3luabridge/lt3luabridge.tex
lrwxrwxrwx 1 root    root      77 Apr 15 12:44 lua-uni-algos.lua -> /usr/local/texlive/2025/texmf-dist/tex/luatex/lua-uni-algos/lua-uni-algos.lua
lrwxrwxrwx 1 root    root      76 Apr 15 12:44 lua-uni-case.lua -> /usr/local/texlive/2025/texmf-dist/tex/luatex/lua-uni-algos/lua-uni-case.lua
lrwxrwxrwx 1 root    root      81 Apr 15 12:44 lua-uni-graphemes.lua -> /usr/local/texlive/2025/texmf-dist/tex/luatex/lua-uni-algos/lua-uni-graphemes.lua
lrwxrwxrwx 1 root    root      81 Apr 15 12:44 lua-uni-normalize.lua -> /usr/local/texlive/2025/texmf-dist/tex/luatex/lua-uni-algos/lua-uni-normalize.lua
lrwxrwxrwx 1 root    root      77 Apr 15 12:44 lua-uni-parse.lua -> /usr/local/texlive/2025/texmf-dist/tex/luatex/lua-uni-algos/lua-uni-parse.lua
lrwxrwxrwx 1 root    root      74 Apr 15 12:45 t-lt3luabridge.tex -> /usr/local/texlive/texmf-local/tex/generic/lt3luabridge/t-lt3luabridge.tex
lrwxrwxrwx 1 root    root      64 Apr 15 12:46 tinyyaml.lua -> /usr/local/texlive/texmf-local/scripts/lua-tinyyaml/tinyyaml.lua

Then, I ran context context-lmtx.tex with the following result:

lua error       > lua error on line 155 in file expl3-code.tex:

token call, execute: expl3.lua:77: attempt to call a nil value (upvalue 'set_char')
stack traceback:
	expl3.lua:77: in local 'token_create_safe'
	expl3.lua:86: in main chunk
	[C]: in upvalue 'requiem'
	...live/2025/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: in function 'SAVEDREQUIRE'
	(...tail calls...)
	[ctxlua]:1: in main chunk
145       \else
146         \begingroup\expandafter\expandafter\expandafter\endgroup
147         \expandafter\ifx\csname newcatcodetable\endcsname\relax
148           \input{ltluatex}%
149         \fi
150         \begingroup\expandafter\expandafter\expandafter\endgroup
151         \expandafter\ifx\csname newluabytecode\endcsname\relax
152         \else
153           \newluabytecode\@expl@luadata@bytecode
154         \fi
155 >>      \directlua{require("expl3")}%
156         \ifnum 0%
157           \directlua{
158             if status.ini_version then
159               tex.write("1")
160             end
161           }>0 %
162           \everyjob\expandafter{%
163             \the\expandafter\everyjob
164             \csname\detokenize{lua_now:n}\endcsname{require("expl3")}%
165           }%
mtx-context     | fatal error: return code: 1

The line 77 from file expl3.lua reads set_char(s, 0), where set_char is set to token.set_char on line 68 of the same file. Apparently, whereas the function token.set_char was available in LuaTeX, it is now gone in LuaMetaTeX. I did a little digging in the repository contextgarden/luametatex and token.set_char was commented out in commit contextgarden/luametatex@c4ef1cb from LuaMetaTeX 2.11.05 (2024-10-31) for no apparent reason.

I opened a ticket tracking this issue upstream: latex3/latex3#1724. Any further work on this PR is blocked until the upstream ticket has been resolved.

@Witiko
Copy link
Owner Author

Witiko commented Apr 15, 2025

Continuing #557 (comment) by patching the file expl3.lua and running context context-lmtx.tex produces the following error instead:

loading         > ConTeXt User Module / markdown
open source     > level 3, order 8, name 'markdown/markdown.tex'
open source     > level 4, order 9, name 'lt3luabridge.tex'

tex error       > tex error on line 114 in file lt3luabridge.tex: Missing number, case 7, treated as zero



<to be read again> 
    
    P
<line 7.114> 
      }

104           }
105       }
106       {
107         \cs_generate_variant:Nn
108           \msg_error:nnn
109           { nnV }
110         \msg_error:nnV
111           { luabridge }
112           { unknown-method }
113           \g_luabridge_method_int
114 >>    }
115     \int_compare:nNnT
116       { \g_luabridge_method_int }
117       =
118       { \c_luabridge_method_shell_int }
119       {
120         \sys_if_platform_unix:TF
121           {
122             \str_const:Nn
123               \c_luabridge_default_output_dirname_str
124               { $TEXMF_OUTPUT_DIRECTORY }
A number should have been here; I inserted '0'. (If you can't figure out why I
needed to see a number, look up 'weird error' in the index to The TeXbook.)
mtx-context     | fatal error: return code: 1

This still seems to be an issue with expl3, not with lt3luabridge, as I discuss in latex3/latex3#1702 (comment).

@Witiko
Copy link
Owner Author

Witiko commented Apr 16, 2025

After @josephwright's patch from latex3/latex3@885643a, running context context-lmtx.tex produces the following error instead:

resolvers       | formats | executing runner 'run luametatex format': /usr/local/texlive/2025/bin/x86_64-linux/luametatex --jobname="./context-lmtx.tex" --socket --shell-escape --fmt=/usr/local/texlive/2025/texmf-var/luametatex-cache/context/a86c089b384a3076dc514ba966a1fac9/formats/luametatex/cont-en.fmt --lua=/usr/local/texlive/2025/texmf-var/luametatex-cache/context/a86c089b384a3076dc514ba966a1fac9/formats/luametatex/cont-en.lui  --c:currentrun=1 --c:fulljobname="./context-lmtx.tex" --c:input="./context-lmtx.tex" --c:kindofrun=1 --c:maxnofruns=9 --c:texmfbinpath="/usr/bin"
system          > 
system          > ConTeXt  ver: 2025.02.28 18:12 LMTX  fmt: 2025.3.30  int: english/english
system          > 
system          > 'cont-new.mkxl' loaded
open source     > level 1, order 1, name '/usr/local/texlive/2025/texmf-dist/tex/context/base/mkxl/cont-new.mkxl'
system          > beware: some patches loaded from cont-new.mkiv
close source    > level 1, order 1, name '/usr/local/texlive/2025/texmf-dist/tex/context/base/mkxl/cont-new.mkxl'
system          > 'cont-sys.mkxl' loaded
open source     > level 1, order 2, name '/usr/local/texlive/2025/texmf-dist/tex/context/texlive/cont-sys.mkxl'
close source    > level 1, order 2, name '/usr/local/texlive/2025/texmf-dist/tex/context/texlive/cont-sys.mkxl'
system          > files > jobname './context-lmtx', input './context-lmtx.tex', result './context-lmtx'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > level 1, order 3, name './context-lmtx.tex'
fonts           > preloading latin modern fonts (third stage)
fonts           > 'fallback modern rm 10pt' is loaded
modules         > 'markdown' is loaded
open source     > level 2, order 4, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdown.tex'
open source     > level 3, order 5, name 'expl3-generic.tex'
Package: expl3 2025-04-14 L3 programming layer (loader)

open source     > level 4, order 6, name 'expl3-code.tex'
Package: expl3 2025-04-14 L3 programming layer (code)

close source    > level 4, order 6, name 'expl3-code.tex'
backend         > calling unavailable pdf.getcreationdate function
open source     > level 4, order 7, name 'l3backend-dvips.def'
File: l3backend-dvips.def 2025-04-14 v L3 backend support: dvips

close source    > level 4, order 7, name 'l3backend-dvips.def'
close source    > level 3, order 7, name 'expl3-generic.tex'
loading         > ConTeXt User Module / markdown
open source     > level 3, order 8, name 'markdown/markdown.tex'
open source     > level 4, order 9, name 'lt3luabridge.tex'

Package luabridge Info: Using direct Lua access as the bridging method


close source    > level 4, order 9, name 'lt3luabridge.tex'
tex error       > tex error on line 3164 in file markdown/markdown.tex: Missing number, case 7, treated as zero

\exp_not:n {j}\s__tl B106\s__tl 

<to be read again> 
    
    e
<line 6.3164> 
      }

<empty file>
A number should have been here; I inserted '0'. (If you can't figure out why I
needed to see a number, look up 'weird error' in the index to The TeXbook.)
mtx-context     | fatal error: return code: 1

This is different from calling context --luatex context-lmtx.tex, which produces the following result instead:

mtx-context     | redirect luametatex -> luatex: luatex --luaonly --socket "/usr/bin/mtxrun.lua" --script mtx-context --luatex context-lmtx.tex --redirected

resolvers       | formats | executing runner 'run luatex format': /usr/local/texlive/2025/bin/x86_64-linux/luatex --jobname="context-lmtx" --socket --shell-escape --fmt=/usr/local/texlive/2025/texmf-var/luatex-cache/context/a86c089b384a3076dc514ba966a1fac9/formats/luatex/cont-en.fmt --lua=/usr/local/texlive/2025/texmf-var/luatex-cache/context/a86c089b384a3076dc514ba966a1fac9/formats/luatex/cont-en.lui cont-yes.mkiv --c:currentrun=1 --c:engine="luatex" --c:fulljobname="./context-lmtx.tex" --c:input="./context-lmtx.tex" --c:kindofrun=1 --c:luatex --c:maxnofruns=9 --c:redirected --c:texmfbinpath="/usr/local/texlive/2025/bin/x86_64-linux"
This is LuaTeX, Version 1.22.0 (TeX Live 2025) 
 system commands enabled.
open source     > level 1, order 1, name '/usr/local/texlive/2025/texmf-dist/tex/context/base/mkiv/cont-yes.mkiv'
system          > 
system          > ConTeXt  ver: 2025.02.28 18:12 MKIV  fmt: 2025.3.30  int: english/english
system          > 
system          > 'cont-new.mkiv' loaded
open source     > level 2, order 2, name '/usr/local/texlive/2025/texmf-dist/tex/context/base/mkiv/cont-new.mkiv'
system          > beware: some patches loaded from cont-new.mkiv
close source    > level 2, order 2, name '/usr/local/texlive/2025/texmf-dist/tex/context/base/mkiv/cont-new.mkiv'
system          > 'cont-sys.mkiv' loaded
open source     > level 2, order 3, name '/usr/local/texlive/2025/texmf-dist/tex/context/texlive/cont-sys.mkiv'
close source    > level 2, order 3, name '/usr/local/texlive/2025/texmf-dist/tex/context/texlive/cont-sys.mkiv'
system          > files > jobname 'context-lmtx', input './context-lmtx', result 'context-lmtx'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > level 2, order 4, name '/workdir/examples/context-lmtx.tex'
fonts           > preloading latin modern fonts (third stage)
fonts           > 'fallback modern-designsize rm 10pt' is loaded
modules         > 'markdown' is loaded
open source     > level 3, order 5, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdown.tex'
open source     > level 4, order 6, name 'expl3-generic.tex'
open source     > level 5, order 7, name 'expl3-code.tex'
close source    > level 5, order 7, name 'expl3-code.tex'
backend         > calling unavailable pdf.getcreationdate function
open source     > level 5, order 8, name '/root/texmf/tex/latex-dev/l3backend/l3backend-luatex.def'
close source    > level 5, order 8, name '/root/texmf/tex/latex-dev/l3backend/l3backend-luatex.def'
close source    > level 4, order 8, name 'expl3-generic.tex'
loading         > ConTeXt User Module / markdown
open source     > level 4, order 9, name '/usr/local/texlive/texmf-local/tex/generic/markdown/markdown.tex'
open source     > level 5, order 10, name 'lt3luabridge.tex'
close source    > level 5, order 10, name 'lt3luabridge.tex'
close source    > level 4, order 10, name '/usr/local/texlive/texmf-local/tex/generic/markdown/markdown.tex'
modules         > 'markdownthemewitiko_markdown_defaults' is loaded
open source     > level 4, order 11, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdownthemewitiko_markdown_defaults.tex'
open source     > level 5, order 12, name '/usr/local/texlive/texmf-local/tex/generic/markdown/markdownthemewitiko_markdown_defaults.tex'
close source    > level 5, order 12, name '/usr/local/texlive/texmf-local/tex/generic/markdown/markdownthemewitiko_markdown_defaults.tex'
modules         > 'database' is loaded
open source     > level 5, order 13, name '/usr/local/texlive/2025/texmf-dist/tex/context/modules/mkiv/m-database.mkiv'
resolvers       > lua > loading file '/usr/local/texlive/2025/texmf-dist/tex/context/modules/mkiv/m-database.lua' succeeded
close source    > level 5, order 13, name '/usr/local/texlive/2025/texmf-dist/tex/context/modules/mkiv/m-database.mkiv'
close source    > level 4, order 13, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdownthemewitiko_markdown_defaults.tex'
close source    > level 3, order 13, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdown.tex'

lua error       > lua error on line 85 in file /workdir/examples/context-lmtx.tex:

lua-uni-parse.lua:50: Please call kpse.set_program_name() before using the library
stack traceback:
	[C]: in function 'kpse.find_file'
	lua-uni-parse.lua:50: in function 'lua-uni-parse.parse_file'
	lua-uni-case.lua:28: in main chunk
	[C]: in upvalue 'requiem'
	...live/2025/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: in function <...live/2025/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:165>
	(...tail calls...)
	lua-uni-algos.lua:17: in main chunk
	[C]: in upvalue 'requiem'
	...live/2025/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: in function <...live/2025/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:165>
	(...tail calls...)
	...live/texmf-local/tex/luatex/markdown/markdown-parser.lua:83: in main chunk
	[C]: in upvalue 'requiem'
	...live/2025/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:180: in function <...live/2025/texmf-dist/tex/context/base/mkiv/l-sandbox.lua:165>
	(...tail calls...)
	...cal/texlive/texmf-local/tex/luatex/markdown/markdown.lua:193: in local 'transform'
	...cal/texlive/texmf-local/tex/luatex/markdown/markdown.lua:151: in field 'cache'
	...cal/texlive/texmf-local/tex/luatex/markdown/markdown.lua:205: in local 'convert'
	[ctxlua]:1: in main chunk

75           },
76         },
77       ]
78     
79     \startyaml
80     
81     title:  An Example *Markdown* Document
82     author: Vít Starý Novotný
83     date:   `\currentdate`{=tex}
84     
85 >>  \stopyaml
86     
87     % Typeset the document `example.md` by letting the Markdown package handle
88     % the conversion internally. Optionally, we can specify additional options
89     % between the square brackets similarly to the command `\setupmarkdown`.
90     % Unlike `\setupmarkdown`, the options will only apply for this document.
91     \inputmarkdown[smart_ellipses = yes]{./example.md}
92     
93     % Typeset the document `example.tex` that we prepared separately using the
94     % Lua command-line interface and that contains a plain TeX representation
95     % of the document `example.md`.

mtx-context     | fatal error: return code: 256

The latter seems reasonable: The library lua-uni-algos requires the library KPathSea, which is generally unavailable in ConTeXt LMTX, as discussed in #557 (comment) and elsewhere. We may need to get rid of our dependency on the library lua-uni-algos if we wish to support ConTeXt LMTX (and ConTeXt standalone more generally) properly.

The former does not seem reasonable and seems to indicate that there are still corner cases where token.set_char and tex.chardef produce different results.

@Witiko
Copy link
Owner Author

Witiko commented Apr 21, 2025

I applied the latest update from @josephwright in latex3/latex3#1725 and removed all calls to the library KPathSea from the file markdown-parser.lua.

75,83d74
< ;(function()
<   local should_initialize = package.loaded.kpse == nil
<                        or tex.initialize ~= nil
<   kpse = require("kpse")
<   if should_initialize then
<     kpse.set_program_name("luatex")
<   end
< end)()
< local uni_algos = require("lua-uni-algos")
6933,6934c6924
<     for _, pathname in ipairs{kpse.lookup(language_map,
<                                           {all=true})} do
---
>     for _, pathname in ipairs{} do
8881,8883c8871
<       local pathname = assert(kpse.find_file(filename),
<         [[Could not locate user-defined syntax extension "]]
<         .. filename)
---
>       local pathname = filename

After these changes, running context context-lmtx.tex produces the following error:

resolvers       | formats | executing runner 'run luametatex format': /usr/local/texlive/2025/bin/x86_64-linux/luametatex --jobname="./context-lmtx.tex" --socket --shell-escape --fmt=/usr/local/texlive/2025/texmf-var/luametatex-cache/context/a86c089b384a3076dc514ba966a1fac9/formats/luametatex/cont-en.fmt --lua=/usr/local/texlive/2025/texmf-var/luametatex-cache/context/a86c089b384a3076dc514ba966a1fac9/formats/luametatex/cont-en.lui  --c:currentrun=1 --c:fulljobname="./context-lmtx.tex" --c:input="./context-lmtx.tex" --c:kindofrun=1 --c:maxnofruns=9 --c:texmfbinpath="/usr/bin"
system          > 
system          > ConTeXt  ver: 2025.02.28 18:12 LMTX  fmt: 2025.3.30  int: english/english
system          > 
system          > 'cont-new.mkxl' loaded
open source     > level 1, order 1, name '/usr/local/texlive/2025/texmf-dist/tex/context/base/mkxl/cont-new.mkxl'
system          > beware: some patches loaded from cont-new.mkiv
close source    > level 1, order 1, name '/usr/local/texlive/2025/texmf-dist/tex/context/base/mkxl/cont-new.mkxl'
system          > 'cont-sys.mkxl' loaded
open source     > level 1, order 2, name '/usr/local/texlive/2025/texmf-dist/tex/context/texlive/cont-sys.mkxl'
close source    > level 1, order 2, name '/usr/local/texlive/2025/texmf-dist/tex/context/texlive/cont-sys.mkxl'
system          > files > jobname './context-lmtx', input './context-lmtx.tex', result './context-lmtx'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > level 1, order 3, name './context-lmtx.tex'
fonts           > preloading latin modern fonts (third stage)
fonts           > 'fallback modern rm 10pt' is loaded
modules         > 'markdown' is loaded
open source     > level 2, order 4, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdown.tex'
open source     > level 3, order 5, name 'expl3-generic.tex'
Package: expl3 2025-04-14 L3 programming layer (loader)

open source     > level 4, order 6, name 'expl3-code.tex'
Package: expl3 2025-04-14 L3 programming layer (code)

close source    > level 4, order 6, name 'expl3-code.tex'
backend         > calling unavailable pdf.getcreationdate function
open source     > level 4, order 7, name 'l3backend-dvips.def'
File: l3backend-dvips.def 2025-03-14 v L3 backend support: dvips

close source    > level 4, order 7, name 'l3backend-dvips.def'
close source    > level 3, order 7, name 'expl3-generic.tex'
loading         > ConTeXt User Module / markdown
open source     > level 3, order 8, name 'markdown/markdown.tex'
open source     > level 4, order 9, name 'lt3luabridge.tex'

Package luabridge Info: Using direct Lua access as the bridging method


close source    > level 4, order 9, name 'lt3luabridge.tex'
close source    > level 3, order 9, name 'markdown/markdown.tex'

Package markdown Info: Loading version latest of ConTeXt Markdown theme
(markdown)             witiko/markdown/defaults


modules         > 'markdownthemewitiko_markdown_defaults' is loaded
open source     > level 3, order 10, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdownthemewitiko_markdown_defaults.tex'

Package markdown Info: Loading version latest of plain TeX Markdown theme
(markdown)             witiko/markdown/defaults


open source     > level 4, order 11, name 'markdownthemewitiko_markdown_defaults.tex'
close source    > level 4, order 11, name 'markdownthemewitiko_markdown_defaults.tex'
modules         > 'database' is loaded
open source     > level 4, order 12, name '/usr/local/texlive/2025/texmf-dist/tex/context/modules/mkiv/m-database.mkiv'
pages           > flushing realpage 1, userpage 1, subpage 1
pages           > flushing realpage 2, userpage 2, subpage 2
pages           > flushing realpage 3, userpage 3, subpage 3
resolvers       > lua > loading file '/usr/local/texlive/2025/texmf-dist/tex/context/modules/mkiv/m-database.lua' succeeded
close source    > level 4, order 12, name '/usr/local/texlive/2025/texmf-dist/tex/context/modules/mkiv/m-database.mkiv'
close source    > level 3, order 12, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdownthemewitiko_markdown_defaults.tex'
close source    > level 2, order 12, name '/usr/local/texlive/texmf-local/tex/context/third/markdown/t-markdown.tex'

Package markdown Info: Buffering block-level markdown input into the temporary
(markdown)             input file "context-lmtx.markdown.in" and scanning for
(markdown)             the closing token sequence "\stopyaml"



Package markdown Info: The ending token sequence was found



Package markdown Info: Including markdown document
(markdown)             "./context-lmtx.markdown.in"


lua error       > lua error on line 85 in file ./context-lmtx.tex:

token call, execute: ...live/texmf-local/tex/luatex/markdown/markdown-parser.lua:6630: attempt to index a nil value (global 'uni_algos')
stack traceback:
	...live/texmf-local/tex/luatex/markdown/markdown-parser.lua:6630: in function <...live/texmf-local/tex/luatex/markdown/markdown-parser.lua:6626>
	(...tail calls...)
	...cal/texlive/texmf-local/tex/luatex/markdown/markdown.lua:151: in field 'cache'
	...cal/texlive/texmf-local/tex/luatex/markdown/markdown.lua:205: in local 'convert'
	[ctxlua]:1: in main chunk
75           },
76         },
77       ]
78     
79     \startyaml
80     
81     title:  An Example *Markdown* Document
82     author: Vít Starý Novotný
83     date:   `\currentdate`{=tex}
84     
85 >>  \stopyaml
86     
87     % Typeset the document `example.md` by letting the Markdown package handle
88     % the conversion internally. Optionally, we can specify additional options
89     % between the square brackets similarly to the command `\setupmarkdown`.
90     % Unlike `\setupmarkdown`, the options will only apply for this document.
91     \inputmarkdown[smart_ellipses = yes]{./example.md}
92     
93     % Typeset the document `example.tex` that we prepared separately using the
94     % Lua command-line interface and that contains a plain TeX representation
95     % of the document `example.md`.
mtx-context     | fatal error: return code: 1

This seems comparable to the output of the command context --luatex context-lmtx.tex from #557 (comment), i.e. no errors besides those related to the library lua-uni-algos.

Then, I removed all uses of the library lua-uni-algos from the file markdown-parser.lua.

3025,3028d3024
<     if not options.unicodeNormalization
<        or options.unicodeNormalizationForm ~= "nfc" then
<       normalized_s = uni_algos.normalize.NFC(normalized_s)
<     end
3072,3073d3067
<         -- Case-fold all alphabetic characters.
<         char = uni_algos.case.casefold(char)
3095,3098d3088
<     if not options.unicodeNormalization
<        or options.unicodeNormalizationForm ~= "nfc" then
<       normalized_s = uni_algos.normalize.NFC(normalized_s)
<     end
3142,3143d3131
<         -- Case-fold all alphabetic characters.
<         char = uni_algos.case.casefold(char)
4849d4836
<     tag = uni_algos.case.casefold(tag, true, false)
6627,6641d6613
<       if options.unicodeNormalization then
<         local form = options.unicodeNormalizationForm
<         if form == "nfc" then
<           input = uni_algos.normalize.NFC(input)
<         elseif form == "nfd" then
<           input = uni_algos.normalize.NFD(input)
<         elseif form == "nfkc" then
<           input = uni_algos.normalize.NFKC(input)
<         elseif form == "nfkd" then
<           input = uni_algos.normalize.NFKD(input)
<         else
<           return writer.error(
<             format("Unknown normalization form %s.", form))
<         end
<       end

This allowed me to compile the file context-lmtx.tex, producing the PDF document context-lmtx.pdf with the command context context-lmtx.tex with no errors. This indicates that getting rid of the library lua-uni-algos is the main obstacle in supporting ConTeXt LMTX.

There are other concerns, which seem minor in comparison. Namely, there are numerous occurrences of the texts "haracter U+007D 'right curly bracket'" and "haracter U+007B 'left curly bracket'" in the PDF document. Namely, the first three pages of the document consist entirely of these:

image

However, they also occur elsewhere in the document:

image

These texts aren't present in the output of the command context --luatex context-lmtx.tex and seem to be a result of the interplay between expl3 and LuaMetaTeX. More analysis is needed to determine the exact cause; I will try to isolate a minimum working example.

@Witiko
Copy link
Owner Author

Witiko commented Apr 23, 2025

There are other concerns, [...]

I created a minimal working example and opened a ticket upstream in latex3/latex3#1728.

@Witiko
Copy link
Owner Author

Witiko commented Apr 23, 2025

This allowed me to compile the file context-lmtx.tex, producing the PDF document context-lmtx.pdf with the command context context-lmtx.tex [...]. There are other concerns, [...]. Namely, there are numerous occurrences of the texts "haracter U+007D 'right curly bracket'" and "haracter U+007B 'left curly bracket'" in the PDF document.

I created a minimal working example and opened a ticket upstream in latex3/latex3#1728.

I am getting a clean compile of the file examples/context-lmtx.tex since latex3/latex3@a3a1df8 by @josephwright:

image

Based on #557 (comment) and below, here are the necessary steps than need to be taken before the CI is green:

  1. In markdown-parser.lua, remove dependency on library lua-uni-algos.
  2. Remove the part of file context-lmtx.tex that loads KPathSea.
  3. Make all uses of KPathSea in markdown-parser.lua optional: both initialization and use should fail softly.

To fully resolve #436 and close ticket #402, here are some of the next steps for v3.11.3, first outlined in #557 (comment):

  1. Add ConTeXt LMTX to the testing framework.
  2. Write installation instructions for ConTeXt standalone.
  3. Adding a Dockerfile for ConTeXt standalone, continuously build a Docker image, and run tests with it.

After this has been done, we should publicize the support for ConTeXt LMTX:

  1. Let @hason know that they can revert the last hunk of minidocks/context@e3d8d3b that disables Markdown package.
  2. Respond to the thread at the [email protected] mailing list from November 2024.

Don't forget to mention @josephwright's numerous contributions in CHANGES.md. Specifically, Ctrl+F "latex/latex3#" in this PR to find references to all upstream changes to the LaTeX3 kernel needed to get this PR working.

@Witiko
Copy link
Owner Author

Witiko commented Apr 23, 2025

  1. Respond to the thread at the [email protected] mailing list from November 2024.

The linked message contains the following remarks by @hanshagen:

[I]n order to test this ; issue I downloaded the expl generic file and (with a change in the lua file -- different function) it could be loaded but esp the unicode part takes quite some time, likely more than users will accept in an edit-run cycle that normally takes a few seconds per run. [...] Of course, when you need some specific helpers we can provide them[.]

Let's perhaps respond with a question about if and how we could recompile the ConTeXt format files to include expl3-generic.tex. Then, we can:

  1. Include steps to recompile ConTeXt format files to include expl3 in installation instructions and our Dockerfiles.

In the future, if there is sufficient demand, expl3 could perhaps be included with ConTeXt; if not by default, then with a simple runtime switch. Official support for expl3 in ConTeXt would ensure better long-term support. At the moment, expl3 contains some support for LuaMetaTeX with minimal tests thanks to @josephwright's efforts but there is currently no testing at the ConTeXt side and any changes to LuaMetaTeX are potentially breaking for us.

@Witiko Witiko modified the milestones: 3.11.2, 3.11.3 Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context Related to the ConTeXt interface and implementation technical debt Related to code smells and refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support LuaMetaTeX Support ConTeXt standalone
1 participant