[Tex/LaTex] Math mode spacing (or glyph bounds) with mathspec

fontsmathspecspacingxetex

With mathspec, when you change the math font to an OpenType font, the spacing within equations is not fine: it is the same than the text mode spacing. For example in the equation $e^j$, the 'j' will collide with the 'e', most of time. So with mathspec you have to type $e^{"j}$ to space the 'j'. This is refered as the 'glyph bounds' problem in the mathspec doc.
What is really too bad is that it breaks compatibility with LaTeX.

Is there any way to both have correct spacing AND compatibility with LaTeX?

Here is an example with two clashes :

\documentclass{article}
\usepackage{mathspec}
\setmathsfont(Latin,Digits){Times New Roman}

\begin{document}
$e^j + |f|$ should be written $e^{"j} + |"f|$.
$\"abcdefghijklmnopqrstuvw"$
$abcdefghijklmnopqrstuvw$ : the spacing is too thin, suitable for text, not for math.
\end{document}

Best Answer

Lierre: Thanks for posting a complete MWE. Good news: I can reproduce your problems. Better news: On my system at least, they go away entirely when I omit the "(Latin,Digits)" option. Why do you specify these options, incidentally?


Addendum, 18/20 Sept 2011: I've just found out about the latest release of the XITS math (and text) fonts; see the XITS site for the five .otf files. The XITS Math letters have much better, i.e., larger sidebearings. If XITS and XITS Math are sufficiently Times-like for your needs, I think you'll be very pleased. The new MWE would look something like

% !TeX program = xelatex
\documentclass{article}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\begin{document}
\noindent
$e^j + |f|$ \\
$abcdefghijklmnopqrstuvwxyz$ XITS-Math math italics\\    
\textit{abcdefghijklmnopqrstuvwxyz} XITS text italics\\    
\setmainfont{Times New Roman}
\textit{abcdefghijklmnopqrstuvwxyz} TNR text italics
\end{document}

enter image description here

I guess the right-hand sidebearing of the f in the first line could still be a bit more generous, but it's a huge improvement over the example with TNR that you posted originally!

Comparing the italics letters of the XITS Math font with the (text) italics letters of Times New Roman, the main new characteristics of the new math font seem to be:

  • very different shapes of v and w
  • larger "teardrop" terminals of the letters f and r
  • the letter z has a rudimentary "swash" (but it's nowhere near as pronounced as the swash of the italic z in either Computer Modern or MathtimePro (the latter with the zswash option set)
  • most letters are a bit more condensed and their vertical strokes are a bit thicker

Second Addendum, 27 May 2017: Recently, the STIX fonts project has released version 2.0 of the Stix Fonts. The STIX Two Text and STIX Two Math fonts may be obtained for free from https://sourceforge.net/projects/stixfonts/. The STIX Two Math (and Text) fonts represent a major step forward relative to the XITS and orginal Stix fonts. To wit, the math kerning is much improved in the following screenshot relative to what would be provided by XITS Math (see the screenshot above). The STIX Two italic glyphs -- in both text and math mode -- are also less slanted (or: more upright) than their Stix, XITS, and Times New Roman counterparts.

enter image description here

% !TeX program = lualatex
\documentclass{article}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}
\begin{document}
\obeylines % just for this example
$e^j + |f|$ 
$abcdefghijklmnopqrstuvwxyz$ --- STIX Two Math, math italics   
\textit{abcdefghijklmnopqrstuvwxyz} --- STIX Two Text, text italics

\setmainfont{XITS}[Scale=MatchLowercase] % make sure x-heights match
\emph{abcdefghijklmnopqrstuvwxyz} --- XITS Text, text italics
\end{document}