I've been writing some code that expands macros and catches characters and non-expandable primitives as they reach TeX's stomach, and I encountered an issue: since I gather letters one by one, with non-expandable code (at least
\futurelet), kerning between letters is destroyed, as well as ligatures. It would thus be better to grab letters until encountering a non-letter typesetting command. However, my code must cope with things like
a b\ifdim\lastskip>0pt hi!\fi c
If I typeset
b before continuing expansion, then the kerning between
c is destroyed. But if I first continue expansion, then
\lastskip will see the previous space, and not be
0pt as it should. My solution is to insert an
\hskip 0pt\relax when starting the word, then collect letters, performing expansion, then remove the given skip and typeset the letters. This also ensures that
\lastpenalty and others are zero, as they should.
To make sure that my solution is correct, I need to know what primitives can access information about what is being typeset. In TeX, there is at least
\lastbox since it is not expandable). What about pdfTeX primitives? XeTeX primitives (in particular, can information about the last character be obtained)? LuaTeX is probably another can of worms altogether because everything can be done expandably through
\directlua: I cannot have any control.