[luatex] How to define an internal register?

Henri Menke henrimenke at gmail.com
Sat Jan 26 06:58:34 CET 2019


Dear list,

I am trying to define a command which behaves like an internal register
using the `token` library.  However, there are some complications.  For
example a register has to be settable using both

   \register=<number>
   \register<number>

Additionally, if no number is given it should raise a “cannot be used in
vmode” error or similar.  Also it has to be possible to get the value
using `\the`.  Below you can find a minimal example where I have already
achieved some of these things but others fail miserably.

Cheers, Henri

P.S.: I have also attached a much more complex example, so you can see
that I actually want to emulate pdfTeX's \pdfadjustinterwordglue.

---

\directlua{
local value = 0
%
function register()
    local str = token.scan_string()
    %
    if str then
        local int = string.gsub(str,"=","")
        value = tonumber(int)
    else
        tex.sprint([[\numexpr]] .. value .. [[\relax]])
    end
end
}

\protected\def\register{\directlua{register()}}

\register=1
\register=12
\register=123

\register1
\register12
\register123

\the\register
\the\register
\the\register

\bye
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.tex
Type: text/x-tex
Size: 2302 bytes
Desc: not available
URL: <https://tug.org/pipermail/luatex/attachments/20190126/68ab5549/attachment.bin>


More information about the luatex mailing list