# XeLaTeX does not load newtxmath with LinuxLibertine (sometimes)

I'd like to use newtxmath along with LinuxLibertine under XeLaTeX. What maybe sounds simple really drives me crazy. Here's an MWE:

\documentclass{article}

\PassOptionsToPackage{no-math}{fontspec}
\usepackage{libertine}
\usepackage[libertine]{newtxmath}

\begin{document}

\begin{tabular}{rl}
with mathmode: & without mathmode: \\
$1+2=3$ & 1+2=3 \\
\end{tabular}

Footnote\footnote{}$^,$\footnote{$123$}$^,$\footnote{}

\end{document}


The result, however, doesn't show the intended math font:

This is XeTeX, Version 3.14159265-2.6-0.99992 (TeX Live 2015/W32TeX) (preloaded format=xelatex 2016.3.4)

With PDFLaTeX everything looks fine:

Now, the real puzzle starts when compiling this with XeLaTeX under cygwin:

This is XeTeX, Version 3.14159265-2.6-0.99992 (TeX Live 2015/Cygwin) (preloaded format=xelatex 2015.10.12)

The math font seems to be the right one, but in the case of multiple footnotes, the footnote numbers in the text are messed up if one of them contains a mathematical environment (or \url)! The last comma and the 3 are slightly lower than the preceding marks.

Any idea what's going on?

The newtxmath package has a peculiar way of setting the operators symbol font when XeTeX or LuaTeX is used, which explains the problems with numbers.

You can use the standard font by doing some adjustments, but in this case the strange bug with XeTeX shows up, see Bug in xelatex + unicode+math + vphantom

There's a way out, which is patching \textsuperscript so it typesets some math in text style (but the bug might show up elsewhere, too).

\documentclass{article}
\usepackage{xpatch}

\PassOptionsToPackage{no-math}{fontspec}
\usepackage{libertine}
\usepackage[libertine]{newtxmath}

\xpretocmd{\textsuperscript}
{{\sbox0{$\textstyle x$}}}
{}{}

\AtBeginDocument{%
\DeclareSymbolFont{operators}{\encodingdefault}{\familydefault}{m}{n}%
\SetSymbolFont{operators}{bold}{\encodingdefault}{\familydefault}{b}{n}%
}

%% Alternative
%\usepackage{unicode-math}
%\setmainfont{Libertinus Serif}
%\setsansfont{Libertinus Sans}
%\setmathfont{Libertinus Math}

\begin{document}

\begin{tabular}{rl}
with mathmode: & without mathmode: \\
$1+2=3$ & 1+2=3 \\
\end{tabular}

Footnote\footnote{123}\textsuperscript{,}\footnote{$123$}\textsuperscript{,}\footnote{123}

\end{document}


(Note: the output has been produced with \textheight=3cm)

• Thanks! It's like magic. xetex now behaves as desired (both in win32 and cygwin). Still, this is very confusing and does not boost my confidence in xetex/newtxmath. – Timm Mar 4 '16 at 21:47
• There's a related bug when using \url in footnotes, just with libertine and xetex (hence even when I don't use newtxmath). Your patch solves this for me too: \xpretocmd{\textsuperscript} {{\sbox0{$\textstyle x$}}} {}{}. – Timm Mar 5 '16 at 9:50