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 b and 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 \lastkern, \lastpenalty and \lastskip (not \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.


for etex there is \lastnodetype which for example expands to 0 and 1 in these examples

aaa\the\lastnodetype bbb

aa\hbox{a}\the\lastnodetype bbb


Not sure what information you consider in scope for the question eg \parshape and etex's \parshapelength etc tell you "something about the current paragraph" but perhaps you do not mean to include that (or if you do then then \leftskip and \rightskip) Perhaps you mean current horizontal list rather than current paragraph?

  • You are right, I meant current horizontal list. I fixed the title accordingly. This lastnodetype business will be tricky to replicate. I guess I'll have to cheat and make \lastnodetype into a protected macro somehow. – Bruno Le Floch May 30 '13 at 18:55
  • @BrunoLeFloch I'm not sure quite how your macro is working but if it has already seen the previous tokens you could set lastnotetype "by hand" since you know what the last node was. – David Carlisle May 30 '13 at 19:07
  • just like \lastskip, \lastnodetype is read-only. I need to turn it into a register, but at the same time I don't want to be tracking its value at all times, so I probably need to switch it back and forth between the primitive and a register. – Bruno Le Floch May 31 '13 at 11:47
  • @BrunoLeFloch something like that, yes... – David Carlisle May 31 '13 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.