Is there any way a macro can know either of the following?
- The last printable character TeX read from the source file
- The contents of the last character box TeX produced
Rationale: I am working on a XeLaTeX package that will support Stone Sans Phonetic, an old commercial IPA font. Stone Sans Phonetic was created before the Unicode era, and handles accents using ligatures rather than combining characters — that is, to put an ø̂ on the page, you write code that prints the characters ø and ^ side-by-side, and the font has a ligature that combines them.
Unfortunately, some ligatures are missing. For instance, printing n and ^ side-by-side doesn't put an n̂ on the page.
What I'd like to do, then, is use \newunicodechar to make a Unicode combining circumflex trigger a macro that does the following:
- Determine whether the character to its left was one that will produce a ligature with
^. - If it was, print a
^in Stone Sans Unicode. - If it wasn't, print a Unicode combining circumflex in some fallback font.
Is this feasible?
(FWIW, I would have expected \lastbox to do what I'm looking for, but this code
\documentclass{article}
\begin{document}
\newbox\temp
a\setbox\temp=\lastbox
\showbox\temp
\end{document}
shows \temp to be void. What am I missing, and/or is there a different way to do what I need?)


test.tex, is that after runningxelatex test.texthe filetest.logwould show\tempto contain a lettera. The behavior I saw is that\tempwas shown to be void. I think this means I've misunderstood what\lastboxdoes, and I'd like to know if there is some other way of getting the behavior I wanted. – Leah Velleman Oct 23 '17 at 13:05In xelatex I do want to preserve the behavior that Unicode input Just Works as often as possible, so if xelatex doesn't offer a way to examine the last character, it probably makes sense to always use combining accents in a fallback font under xelatex.
– Leah Velleman Oct 23 '17 at 14:43.vfvirtual font that has the accents and use that , or to fix the font in fontforge or similar – David Carlisle Oct 23 '17 at 17:02\lastboxdoes nothing to help here – David Carlisle Oct 23 '17 at 17:07