I try to change the font from the Lua side. I tried to change to small caps (see Obtain small caps font from OpenType font when diffining a `\font`, thanks to egreg's code) but, whereas everything works fine with Latin Modern, if I use fourier-otf (but other OpenType packages give same results), the font is changed (numerically) but there is no small caps in the output.
Any ideas?
\documentclass{article}
\usepackage{luacode}
\usepackage{fourier-otf}
\begin{document}
\sbox0{\scshape \global\expandafter\let\expandafter\firstlinefont\the\font}
\font\firstlinefontB={file:lmromancaps10-regular.otf}
\setbox1\hbox{Test}
\setbox2\hbox{Test}
Test
\luadirect{
local firstlinefont = font.id("firstlinefontB")
print(firstlinefont)
glyphn=node.id('glyph')
h=tex.getbox(1)
for n in node.traverse_id(glyphn,h.list) do
if not (n.font == firstlinefont) then
n.font = firstlinefont
end
end
tex.print(h)
}
\luadirect{
firstlinefont = font.id("firstlinefont")
h=tex.getbox(2)
print(firstlinefont)
for n in node.traverse_id(glyphn,h.list) do
if not (n.font == firstlinefont) then
n.font = firstlinefont
end
end
tex.print(h)
}
\end{document}
n.char
, notn.font
.'\hbox
. The shaping does not get reexecuted, so kerning, ligaturing and all other font features are applied for the wrong font (which caused your current issues) but also the width and other dimension have been calculated for the wrong font. Unless you know that the fonts are 100% metric compatible (and a font and it's small caps is almost guaranteed not to) this will lead to wrongly positioned and maybe even more broken output.