[luatex] \Ucharcat

David Carlisle d.p.carlisle at gmail.com
Fri May 22 23:02:52 CEST 2015


Hi,

xetex in the tl2015 release has added a new primitive \Ucharcat
which is like Uchar but takes a second integer specifying a catcode.

\Ucharcat 65 11  expands to letter A
\Ucharcat 65 12  expands to a character A, etc.

This is rather more useful than \Uchar as it allows arbitrary character
tokens to be generated via expansion.

Would there be interest in adding a matching primitive in luatex?

It can be implemented in lua at the cost of one extra expansion step
(although the same is true of \Uchar of course)

Whether or not it gets implemented as a primitive, I wonder if this is the best
lua implementation? Comments welcome:-)

\ifx\newcatcodetable\@undefined
  \chardef\ucharcat at table"7000
\else
  \newcatcodetable\ucharcat at table
\fi
\luatexinitcatcodetable\ucharcat at table
\directlua{%
function UcharcatLua()
  local mych = newtoken.scan_int()
  local mycat = newtoken.scan_int()
  tex.setcatcode(\the\numexpr\ucharcat at table\relax,mych,mycat)
  tex.sprint(\the\numexpr\ucharcat at table\relax,unicode.utf8.char(mych))
end
}
\def\Ucharcat{\directlua{UcharcatLua()}}



I'd hoped to avoid dedicating a catcode table table for this
and instead just set the catcode, print, and set back.
However it seems that the printing happens with the catcode
table value in force at the end of \directua not the value at
the point of the tex.sprint. (The manual could be more explicit
on that point but I think that's right?)



David


More information about the luatex mailing list