Dear list members,

I want to process cross-references in ConTeXt/LuaTeX, that is, to do some calculations in Lua with the page and line numbers returned by the \at and \inlinerange commands.

But this does not work, as these commands are obviously not being expanded before they are passed to Lua.

Here is a minimal example:



function TestVar(var)
print('VARIABLE: ')

\def\TestLua#1{\ctxlua{TestVar([==[#1]==])}} % Cf.

\dorecurse{100}{Words, words, words. }


Counter: \TestLua{\rawcountervalue[test]}\par % The counter is expanded before being passed to Lua.
Lineref: \TestLua{\inlinerange[1]}\par % The line reference is not expanded before being passed to Lua.

\someline[1]LABEL 1


\TestLua just passes the argument to the Lua command TestVar, which prints it to stdout and returns it to TeX. The pdf result looks good at first glance, showing the correct values as expected, but in stdout we read:

\inlinerange [1]

The line reference obviously has not been expanded before but only after having been passed to the Lua command. Accordingly, when trying to perform mathematical calculations on it in Lua, there will be an error.

So how can I pass the value of my reference to Lua?

Best regards,