[Tex/LaTex] Using Linux Libertine fonts for math without newtxmath

amsmathfontslibertinemathspecxetex

I'm trying to use Linux Libertine as the math (and main) font, and I used this answer to set the math fonts. However, the math output is still CM.

\documentclass{minimal}   
\usepackage{amsmath, mathspec, libertine, lipsum}
%\usepackage[libertine]{newtxmath}
\setmathsfont[ItalicFont={LinLibertine_RI.otf}]{LinLibertine_R.otf}
\setmathrm{LinLibertine_R.otf}
\setboldmathrm{LinLibertine_RB.otf}
\setmathsf{LinBiolinum_RB.otf}


\begin{document}
\lipsum[1]

\begin{equation}
    \hat{Q}_i=\int_0^\infty \mathcal{G}^2(x) \Sigma^{-1}(x^2) f_i(x)dx
\end{equation}

\end{document}

enter image description here

If I try to uncomment the newtxmath line, I get an error

Package mathspec Error: amsmath' must be loaded earlier thanmathspec'

But I have loaded amsmath before mathspec!

How do I fix these issues (fixing either is fine, since the goal is to use LL fonts for math).


As pointed out, moving newtxmath before amsmath solves the problem in the above MWE. Now let me change it a bit and include amsthm as well, which now leads to a host of other errors such as:

! LaTeX Error: Command \openbox already defined.
Or name \end… illegal, see p.192 of the manual.

Best Answer

The right order to load those packages is amsthm, newtxmath, mathspec

\usepackage{amsthm}
\usepackage[libertine]{newtxmath}
\usepackage{mathspec}

You don't need to load amsmath since it is already loaded by newtxmath. That's also the reason why mathspec complains when you load newtxmath after it.

Moreover, note that both amsthm and newtxmath define the \openbox command. But, while the former defines it through a \newcommand, the latter does it through a \DeclareRobustCommand, so it does not complain...