# Parentheses differ (XeLaTeX, fontspec, newtxmath, libertine)

After Internal error: bad native font flag I stumbled upon another weird problem with the combination XeLaTeX/fontspec/Libertine/newtxmath:

\documentclass{scrartcl}
\usepackage[no-math]{fontspec}
\usepackage{libertineotf}
\usepackage{amsmath}
\usepackage[libertine]{newtxmath}

\begin{document}
$$( \frac{1}{1} ) \left( \frac{1}{2} \right) \bigl( \frac{1}{3} \bigr) \Bigl( \frac{1}{4} \Bigr) \biggl( \frac{1}{5} \biggr) \Biggl( \frac{1}{6} \Biggr)$$
\end{document}


The up-scaled result is:

It seems to me that the Libertine font is used for ( and and CM for ).
Compare the closing parentheses from the above image to the following where the fontspec package was not used:

The parentheses have the correct size but again CM is used for the numbers.
pdfLaTeX and the libertine package produce the same output as XeLaTeX without fontspec.

-
The newtxmath package was updated significantly just a few days ago. Are you running the latest version (0.98, I believe)? –  Mico Jul 15 '12 at 18:36
I still don't know why the thing happens; however, loading newtxmath before fontspec seems to solve the issue. You should also load amsmath before newtxmath –  egreg Jul 15 '12 at 21:15
@Mico I'm running version 0.99 from 2012/06/25. I could try to update manually to 1.00; but I don't see many changes. MikTeX's updater doesn't show me any updateable packages, though. –  Qrrbrbirlbel Jul 16 '12 at 0:25
@egreg Have you read my other question? There are some similarities to when things fail: Loading newtxmath before fontspec results in the same output: correct sized parentheses (but as it seems from CM) and numbers in CM. –  Qrrbrbirlbel Jul 16 '12 at 0:28
This seems to depend on Linux Libertine that gets in the way with \left( (but not with \left[, for instance). I've tried other fonts and newtxmath is used for the left parenthesis in those cases. –  egreg Jul 16 '12 at 8:02

This seems to depend on Linux Libertine, that gets in the way with \left( (which is implicitly used also in the \big commands), so that \left( chooses the parenthesis from Libertine and not from the newtxmath defined font.

Other fonts instead of Linux Libertine don't exhibit this issue.

A workaround. Add the following lines after the definition of the fonts:

\DeclareSymbolFont{parenthesis}{OT1}{ntxr}{m}{n}
\DeclareMathDelimiter{(}{\mathopen}{parenthesis}{"28}{largesymbols}{"00}
\DeclareMathDelimiter{)}{\mathclose}{parenthesis}{"29}{largesymbols}{"01}


We are explicitly requesting that the parentheses are chosen from the newtxmath font. This gives another issue, though: the parentheses in math mode (normal size) will be different from the text mode ones.

-
Thank you, that was helpful! But I have also different fonts for {} and []. Compare: (a) [a\} $$(\text{a}) \left[\text{a}\right\}$$ • Why not \DeclareSymbolFont{parenthesis}{T1}{fxl}{m}{n}? Only downside I can see is that the horizontal size for the \big command family is different than with ntxr –  Qrrbrbirlbel Jul 17 '12 at 2:20
And to fix the fonts for {} and []: \DeclareMathDelimiter{[}{\mathopen}{parenthesis}{"5B}{largesymbols}{"02} \DeclareMathDelimiter{]}{\mathclose}{parenthesis}{"5D}{largesymbols}{"03} \DeclareMathDelimiter{\lbrace}{\mathopen}{parenthesis}{"7B}{largesymbols}{"08} \DeclareMathDelimiter{\rbrace}{\mathclose}{parenthesis}{"7D}{largesymbols}{"09}‌​? –  Qrrbrbirlbel Jul 17 '12 at 2:49
@Qrrbrbirlbel In my experiment, the square bracket in normal size is taken from Linux Libertine. Not the brace in math mode, which is by default always from a math font. The idea of using fxl for the parenthesis in normal size is good. –  egreg Jul 17 '12 at 6:30

This seems to be bug in the libertine fonts. When you use newtxmath it will set the operator font (the one used for small parentheses) to the roman font (libertine). For some reason the font will use the operator font for large opening parentheses too instead of the correct large symbols font. The handling of closing parentheses is correct The problem disappears when you don't use the no-math option of fontspec as in this case the operator font is reset to cmr.

The bug is present in version 5.1.3 and also in the newest 5.3 of the fonts, with 4.7.5. it works fine. I boiled down the example to this (if exhibits the problem with xelatex + lualatex for me):

\documentclass{scrartcl}
\usepackage[no-math]{fontspec}
%\setmainfont{LinLibertine_Re-4.7.5.otf} %works
\setmainfont{LinLibertine_R.otf} % fails, version 5.1.3 and 5.3
\DeclareSymbolFont{operators}{\encodingdefault}{\rmdefault}{m}{n}
\pagestyle{empty}

% without no-math the following is used:
% \DeclareSymbolFont{legacymaths}{OT1}{cmr}{m}{n}
% \SetSymbolFont{legacymaths}{bold}{OT1}{cmr}{bx}{n}
% \DeclareMathDelimiter{(}{\mathopen} {legacymaths}{40}{largesymbols}{0}
% \DeclareMathDelimiter{)}{\mathclose}{legacymaths}{41}{largesymbols}{1}

\DeclareMathDelimiter{(}{\mathopen} {operators}{40}{largesymbols}{0}
\DeclareMathDelimiter{)}{\mathclose}{operators}{41}{largesymbols}{1}
\begin{document}
$\Bigg( \Biggl( % libert %without no-math: txex \Bigg) \Biggr) % txex %without no-math: txex$
\end{document}


I think you should make a bug report to the font authors.

Btw: I get a warning from xdvipdfmx which is perhaps related:

** WARNING ** agl: fix parenrightBigg --> parenright.Bigg

-
Indeed the warning explains why the open parenthesis is used, but not the closed one. There would be no problem if both were taken from Linux Libertine, of course. –  egreg Jul 16 '12 at 9:16
Well from the Declarations the large symbols should be taken from txex. So the right parenthese (\Biggr)) is correct and the left is faulty. But I couldn't find a decisive definition which parenthese is meant by "parentrightBigg" in the warning so perhaps it refers to the opening brace. –  Ulrike Fischer Jul 16 '12 at 9:29
What happens is that XeTeX sees a "larger variant" for the open (left) parentheses, so it uses that one instead of going to the largesymbols one (these are TeX rules, after all). I guess that the wrong name (parentrightBigg instead of parentright.Bigg) makes impossible using the larger variant for the closed (right) parentheses, so the NewTX one is used. –  egreg Jul 16 '12 at 9:40
The font seems to have very rudimentary OpenType math support covering composite versions of left parenthesis, left brace and integral only. Looks like some experiment that slipped into the release. –  Khaled Hosny Jul 16 '12 at 9:50
@egreg: Yes this way it makes sense. –  Ulrike Fischer Jul 16 '12 at 9:53