[NTG-context] protected macro vs protected luacall

Henri Menke henri at henrimenke.de
Thu Jan 26 21:33:31 CET 2023

Dear list,

I have noticed a somewhat strange difference between protected macros
and protected luacalls, namely that the latter cannot be expanded by
\the.  In the example below I define a Lua function that prints
\numexpr 17\relax to the token stream and I call it once from a
protected TeX macro wrapping \directlua and once from a protected
luacall registered with token.set_lua.

  userdata = userdata or {}
  function userdata.test()
    tex.print("\string\\numexpr 17\string\\relax")


  local t = lua.get_functions_table()
  t[\string#t + 1] = userdata.test
  token.set_lua("test", userdata.test, \string#t, "protected")


However, the second \the\test fails with the following error:

! You can't use `luacall 0' after \the.
l.21 \the\test

Is this asymmetry between luacalls and regular macros intended? Is
there a workaround where I can have a luacall that doesn't expand
inside of \edef but still expands after \the?

Cheers, Henri

More information about the ntg-context mailing list