[Tex/LaTex] Problem of Arabic numbers in math mode with ‘New TX’ math font option [Libertine] compiled by XeLaTeX

libertineligaturesnewtxpdftexxetex

Recently i decided to use the Libertine font to write my dissertation, because finally there is kinda math font for Libertine: \usepackage[libertine]{newtxmath}. Since I want to enable of the beautiful historical ligature supported by this font, XeLaTeX is used to compile the .tex file.

However, it seems that the Arabic font seems to look like CM font, which is quite bigger than the original Libertine number fonts. As with pdflatex, there is no problem but the ligature feature can not be activated.

In Ubuntu system

  1. xelatex + libertine + newtxmath + ligature on

    \usepackage[T1]{fontenc}  
    \usepackage[lining]{libertine}
    \usepackage[libertine]{newtxmath}  
    \addfontfeature{RawFeature=+hlig}
    

    enter image description here

    The text looks really great except the Arabic numbers in math mode.

  2. pdflatex + libertine + newtxmath

    \usepackage[lining]{libertine}
    \usepackage[T1]{fontenc}  
    \usepackage[libertine]{newtxmath}
    

    enter image description here

    The Arabic font in math mode is identical to text font in this case.

I just wonder the New TX math font is only based on pdflatex?

Best Answer

There are several issues here.

XeLaTeX and LuaLaTeX handle font differently from LaTeX and pdfLaTeX. The first two use fontspec and the latter, fontenc. One should not use \usepackage{fontenc} when using XeLaTeX or LuaLaTeX. In your case, the libertine package will have detected which engine you are using and will have loaded the right one, if you had not loaded it before, but you should remove fontenc if you are compiling with XeLaTeX exclusively.

This difference in font handling means that you are not using the same format of the font with fontspec than you would have used with fontenc. The OpenType format (.otf) will be used by fontspec, and these fonts formats contain a lot more features than the usual Type1 Postscript font. Some of the features you are amongst other are these ligatures. You can only access these when using the OTF fonts.

Regarding the behaviour of newtxmath, looking at the source it seems that, at least for the version I have, it is not compatible with fontspec.

if you want to use the libertine font for the maths with fontspec you have to use the mathspec or unicode-math packages (however I do not think that unicode-math will work here as libertine is not all self contained).

\usepackage{mathspec}
\usepackage{libertine}
\setmathsfont[ItalicFont={LinLibertine_RI.otf}]{LinLibertine_R.otf}
\setmathrm{LinLibertine_R.otf}
\setboldmathrm{LinLibertine_RB.otf}

Note that you will get a few warning about shapes not being found and replaced with default.

however I have never tried that and do not know if the OTF font contains all the glyphs for maths. You can also change the sans serif and monospace fonts with the \setmathsf{} and \setmathtt{} commands respectively. If you want to use the same as what the libertine package gives you, you can use:

\setmathsf{LinBiolinum_RB.otf}
\setmathtt{LinMono_M.otf}