# Change bounding box of math glyphs in LuaTeX

I'm trying to use the Garamond-Math font in LuaTeX (despite the documentation saying I should use it with XeTeX only :-). It's working more or less OK with LuaTeX, except for some unfortunate glyph combinations, mostly at the end of inline math, such as “where $T$ is the period”.

I used \fbox to draw the bounding box of the glyph and noticed that the bounding boxes are different in LuaTeX:

and in XeTeX:

In XeTeX the glyph fits almost entirely in the bounding box, but in LuaTeX it overshoots far too much.

I'm not a font guy, so I have no idea why this happens. I thought the bounding box was a property of the font, so in my imagination the result should be the same. Thus the first question is: what actually happens that the bounding boxes are different?

The second question, in the title, is: can I change the bounding box of specific glyphs (using LuaTeX) so that the output looks more like XeTeX's?

I tried manually adding some spacing after the glyphs, but this looks hideous and will go down the drain if I happen to change the font or engine, so I'd really like not to do that. I also tried using the italic correction \/ but it seems to have no effect in math.

Here's the code to produce the pictures above:

\documentclass{standalone}
\usepackage{unicode-math}
\setmathfont{Garamond-Math.otf}
\begin{document}
\fboxrule=1sp
\fboxsep=0pt
In Lua\TeX{} this \fbox{$T$} looks horrible, but the \fbox{$X$} looks OK. \Huge\fbox{$T$}\quad.
\end{document}


I'm using TL 2018:

This is LuaTeX, Version 1.07.0 (TeX Live 2018)  (format=lualatex 2019.3.29)  13 APR 2019 12:43
restricted system commands enabled.
**test.tex
(./test.tex
LaTeX2e <2018-12-01>


The problem is that you are at the end of the math and luatex doesn't insert the italic correction at the boundary between math and text. You can avoid the problem by inserting some invisible char but it is not quite clear which char is the best choice, in the chat we discussed this a few times and suggestions were \Uchar"200B and 🦆:

\documentclass{standalone}
\usepackage{unicode-math}
\setmathfont{Garamond-Math.otf}
\begin{document}
\fboxrule=1sp
\fboxsep=0pt
In Lua\TeX{} this \fbox{$T$}  looks horrible,
but \fbox{$T\Uchar"200B$} and \Huge\fbox{$T🦆$} looks ok.

\end{document}


• I should have imagined that a duck would save the day :-) – Phelype Oleinik Apr 13 '19 at 16:19