# Problem of Arabic numbers in math mode with 'New TX' math font option [Libertine] compiled by XeLaTeX

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}


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}


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?

-

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}

-
How to invoke the command " \setmathrm{Linux Libertine O}"? I just got the error info: The font "Linux Libertine O" cannot be found by: \usepackage{fontspec} ; \usepackage[lining]{libertine}; \setmathrm{Linux Libertine O} ; \usepackage[libertine]{newtxmath} ; Maybe it is now not supported by XeLatex? –  KOF Dec 28 '12 at 22:02
GAH! I keep on forgetting XeLaTeX cannot find distro font by name, and that one has to use the filename instead! try \setmathrm{LinLibertine_R.otf}. And you drop the \usepackage{newtxmath} here as it does not do anything (I think). –  ArTourter Dec 28 '12 at 22:17
yes, you are right. \setmathrm{LinLibertine_R.otf} passed XeLatex, but the Arabic numbers still look like CM font... –  KOF Dec 28 '12 at 22:36
\setmathrm{LinLibertine_R.otf}; \setboldmathrm{LinLibertine_RB.otf} passed XeLatex, but the Arabic numbers still look like CM font... as well as \setmathsf{LinBiolinum_RB.otf}. (can not find LinMono_M.otf) –  KOF Dec 28 '12 at 22:42
Indeed, reading the fontspec manual, fontspec is not enough to do this. you need to use the mathspec package instead (it will also load fontspec). This is where using XeLaTeX becomes a bit of a drag as you have to specify every single files for each shape. See the edit to the answer. –  ArTourter Dec 28 '12 at 23:36

A simpler solution that works for me (with XeLaTeX) is this:

\usepackage[no-math]{fontspec}
\setmainfont[Ligatures={TeX,Historic}]{Linux Libertine O}
\usepackage[libertine]{newtxmath}


The order of packages is important: If the line \usepackage[libertine]{newtxmath} is above the others, Arabic fonts look like the CM font.

The idea for the answer came from here.

-

Thanks ArTourter, now everything looks great.

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


and

\usepackage[libertine]{newtxmath}


-
This is not related to your original question and definitely not an answer to it. you do not mention anywhere the use of hyperref. I suggest you ask another question with an appropriate MWE –  ArTourter Dec 29 '12 at 2:36
This are not errors but warnings, as you can clearly see. You are using some characters in section titles etc. which are not allowed in PDF bookmarks. Search this site for the warning message and/or check the hyperref manual. –  Martin Scharrer Dec 29 '12 at 15:45
I'm turning this post now to a comment of the mentioned answer. This site is a Q&A site with a strict format, not a forum, so only real answers to the question should be posted here, not follow-up posts to answers. Feel free to post a follow-up question about the hyperref warnings which links back to this question, but only if you don't find an existing question about it. –  Martin Scharrer Dec 29 '12 at 15:53