[Tex/LaTex] unicode-math and various fonts fail at giving decent spacing in formula

fontsunicode-mathxetex

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}
\setsansfont[Scale=MatchLowercase]{Myriad Pro}
\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
XITS Math
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
Latin Modern Math

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)

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

Neo Euler
Asana Math

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?

Best Answer

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.