# Why fontspec breaks extarrows package

Why

\documentclass{book}
\usepackage{extarrows}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\begin{document}
$$Q\xLongrightarrow{\text{Maximum}} P$$
\end{document}


produces this output:

and how can you fix this?

# More Details

With

\documentclass{minimal}
\usepackage{extarrows}
\usepackage{palatino}
\begin{document}
$$Q\xLongrightarrow{Maximum} P$$
\end{document}


there are no palatino font. It seems to be a fontspec bug then.

-
– Thérèse Jul 13 '14 at 12:56
@Thérèse: What about it should concern me? – user56799 Jul 13 '14 at 12:59
It hasn’t enough features for testing anything sophisticated. And your “More Details” section loads an obsolete package (palatino), and does not load fontspec, but concludes to a fontspec bug. – Thérèse Jul 13 '14 at 13:06
@Thérèse: I do not need many features. Please try minimal class with fontspec and without it and it should demonstrate my point. – user56799 Jul 13 '14 at 13:13

You have to use the no-math option to fontspec:

\documentclass{book}
\usepackage{extarrows}
\usepackage[no-math]{fontspec}
\setmainfont{Times New Roman}
\begin{document}
$Q\xLongrightarrow{\text{Maximum}} P$
\end{document}


But the result is disputable, as Computer Modern math fonts don't combine well with Times.

What happens without the no-math option is that the upright math family (family 0) is changed to use the normal text font; the equals sign is taken from math family 0, so it doesn't combine with the double arrow taken from Computer Modern Math Symbols.

Should you want to use TeX Gyre Termes Math along with Times New Roman for the text font, some workarounds are necessary, since the developers didn't provide for the double arrows to combine with the equals sign.

\documentclass{book}
\usepackage{extarrows}
\usepackage{unicode-math}
\setmainfont{Times New Roman}
\setmathfont{TeX Gyre Termes Math}
\setmathfont[
range={=,\Longrightarrow,\Rightarrow,\Longleftarrow,\Leftarrow}
]{Asana Math}
\setmathfont[range=\int]{TeX Gyre Termes Math}

\begin{document}

$Q\xLongrightarrow{\text{Maximum}} P$

$Q\xLongleftarrow{\text{Maximum}} P$

\end{document}


A complete workaround covering also extendable single arrows.

\documentclass{book}
\usepackage{extarrows}
\usepackage{unicode-math}
\setmainfont{Times New Roman}
\setmathfont{TeX Gyre Termes Math}
\setmathfont[
range={
=,\Longrightarrow,\Rightarrow,\Longleftarrow,\Leftarrow,
\harrowextender,\longrightarrow,\rightarrow,\longleftarrow,\leftarrow
}
]{Asana Math}
\setmathfont[range=\int]{TeX Gyre Termes Math}

\renewcommand{\relbar}{\mathrel{\harrowextender}}

\begin{document}
$Q\xlongrightarrow{\text{Maximum}} P$

$Q\xlongleftarrow{\text{Maximum}} P$

\end{document}


-
Is this a new change to fontspec? I know that no-math option existed for a long time but a user reported that thid did not happen until he updated his TeXLive today. – user56799 Jul 13 '14 at 12:57
@user56799 That user probably had something like TeX Live 2009 or earlier. – egreg Jul 13 '14 at 13:01
Thanks. I got what has changed. I will fix it in my package and it should fix it. – user56799 Jul 13 '14 at 13:12
Adding the no-math option works in this case, but it wouldn't appear to be a general solution. For instance, if TeX Gyre Termes is loaded as the text font and TeX Gyre Termes Math as the math font, one gets an ugly arrow head even if no-math is specified for fontspec. Now this may have more to do with the Texgyre Termes fonts than with the way fontspec is loaded, but it's still worth keeping in mind. – Mico Jul 13 '14 at 13:16
@Mico Unfortunately, the developers of TeX Gyre Termes made the double arrows not combining with the equal sign. The same is for TeX Gyre Pagella Math. Conversely, XITS, Asana and Lucida Bright are good. Unicode has a single arrow extender character, none for double arrows. – egreg Jul 13 '14 at 13:33

You need to load a math font that's compatible with the chosen text font. (A give-away that you're using Computer Modern is contained in the shapes of the letters P and Q.) I suggest you load the package unicode-math and set \setmathfont{XITS Math}.

If you choose this route, I would also recommend you set XITS (a Times Roman clone) as the main text font.

% !TEX TS-program = xelatex
\documentclass{book}
\usepackage{extarrows}
\usepackage{fontspec}
\setmainfont{XITS}
\usepackage{unicode-math}
\setmathfont{XITS Math}
\begin{document}
$Q\xLongrightarrow{\text{Maximum}} P$
\end{document}

-
I am told this did not happen with older versions of fontspec. Any ideas? – user56799 Jul 13 '14 at 12:10
@user56799 - I'm afraid I have no particular knowledge of the differences between the various vintages of fontspec. For all I know, the problem you've encountered may not even be caused by fontspec itself. – Mico Jul 13 '14 at 12:14
I think textfont should have nothing to do with this. Please see my edited question. You can try any other only text font package and see what happens. – user56799 Jul 13 '14 at 12:38

Change the order of the packages:

\documentclass{book}
\usepackage{fontspec}
\usepackage{extarrows}
\setmainfont{Times New Roman}
\begin{document}
$Q\xLongrightarrow{\text{Maximum}} P$
\end{document}


-
This solution isn't robust to the addition of the loading of arbitrary math fonts. E.g., if one switches from Times New Roman to TeX Gyre Termes (another Times Roman clone) and adds the instructions \usepackage{unicode-math} and \setmathfont{TeX Gyre Termes Math}, one either gets a bad arrow if extarrows is loaded before unicode-math or an error message if it's loaded afterwards. – Mico Jul 13 '14 at 13:12
sure, with another math font you have to use the old order but loading unicode-math. But then it also works. – Herbert Jul 13 '14 at 13:15
Actually, I was trying to make a different point: if TeX Gyre Termes and TeX Gyre Termes Math are loaded, then \xLongrightarrow will create an ugly result irrespective of the loading order. Changing the loading order thus isn't a general solution. – Mico Jul 13 '14 at 13:19
Why should someone load a math font like TeX Gyre Termes Math which has at this time a lot of missing charcters?? However, a simple \setmathfont[range=\Longrightarrow]{XITS Math} will do. – Herbert Jul 13 '14 at 14:04