# unicode-math and various fonts fail at giving decent spacing in formula

I want to check if this problem is due to my configuration or if it is some kind of bug.

This are the packages I load and the configuration for them (all very minimal in order to test the problem). I'm usin XeTeX 0.9998.

\documentclass[12pt,a4paper]{scrbook}
\usepackage{polyglossia}
\setmainlanguage{italian}
\usepackage{amsmath,amsthm,mathtools}
\usepackage{mathcomp,mathrsfs,xfrac,bbm}
\usepackage{unicode-math}
\usepackage{xunicode}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\setmonofont{Inconsolata}
\setmathfont{XITS Math}


When I was writing I kind of noticed that something was strange with spacing in mathematical formulas, then I wrote this which is quite terrible. The spacing is not good at all, there are a lot of clashes. Then I tried with some other fonts, choosing among the one supported by unicode-math (found the list in the README), it turns out that I have the same effect with STIX Math and with Latin Modern Math, as you can see

Here the problem is less evident because, the font is lighter, but confront with the standard version of Latin Modern (without using opentype fonts and unicode-math)

This is correct, so I thought it was something related to unicode-math, but using Neo Euler and Asana Math it looks OK

Does anybody have a clue of what might be the cause of this problem? Maybe the fonts? I hope not because I'd really like to use XITS or STIX... Can you reproduce the problem?

-
It is most likely the problem with xelatex. Try lualatex, which is much better at Unicode math right now. Also update to tl2012. The xelatex in tl2012 has some noticeable improvement –  Yan Zhou Sep 1 '12 at 3:06
The version I'm using is the latest one! Anyway I'll try with Lualatex too –  justmyfault Sep 1 '12 at 7:28
OK I tried with lualatex and it's OK, I'll guess I'll stick with it for the moment, even though I prefer XeTeX... –  justmyfault Sep 1 '12 at 8:33

The main problem is that XeTeX is not applying math italic correction:

• XITS has italic correction and needs it for proper spacing.
• In case of Latin Modern the font does bot provide italic correction at all.
• Asana math lacks italic correction as well, but the glyphs are spaced in a way that alleviates the need of italic correction.
• Euler, though have italic correction, its upright design makes lack of italic correction not very visible (though your example is wrong, you have to pass math-style=upright option for Euler alphabets to be used).

Why XeTeX stopped applying italic correction is unclear to me, that part of the code have not been touched for ages, but the code was flawed anyway so my guess is that it worked accidentally and some of the recent math cleanup broke.

However, there is a workaround: open the XITS font in a font editor (preferably FontForge) and set the width of space glyph to 0, this will cause the engine to apply italic correction again.

For the curious, the application of italic correction or not depends on whether the space factor of the font is zero, even in the OpenType math branch of the code, and though this is true for TFM math fonts, it is not essentially the case for OpenType font.

Also, OpenType math spec diverges from TeX algorithm on when italic correction should be applied, but it is very vague, and MS implementation seems to differ from what is actually documented, so it is not very well supported by XeTeX and LuaTeX yet.

Update: XeTeX's master branch handles this better now, until a more robust handling of italic correction is devised.

-
I'm not a specialist in modifying fonts, but I tried and I think I succeded in make the width of space glyph 0 because in libreoffice i have no space, BUT this workaround didn't solve the problem.... I realy wanted to use XITS though –  justmyfault Sep 1 '12 at 7:52
Are you sure XeTeX is loading the modified font, how did you install it? –  Khaled Hosny Sep 1 '12 at 8:34
@KhaledHosny I copied in my /.fonts diretory in my home (I use ubuntu), I can see use it from other softwares (Libre Office for example –  justmyfault Sep 1 '12 at 9:14
If the other version is in the font path (e.g. if you added texlive font directories to your fontconfig configuration), either can be picked randomly (by XeTeX at least), so you should make sure only the modified font is accessible to XeTeX. –  Khaled Hosny Sep 1 '12 at 9:21
I tried saving the font with a different name and it doesn't help... I have correcyly space widht=0 on libre office but doesn't help solving my problem... Anyway I solved switching to lualatex for the moment... –  justmyfault Sep 1 '12 at 12:39