# Using Linux Libertine fonts for math without newtxmath

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]

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

\end{document}


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.

• @karlkoeller Strange, that seems to work for this example. However, if I add amsthm as well, it gives lots of errors... Sep 12 '13 at 19:58
• The right order is amsthm, newtxmath, mathspec. Don't load amsmath since it is loaded by newtxmath. Sep 12 '13 at 20:14
• @karlkoeller Oh dear... never would've though that. If you'd like to answer, I'll accept it. Sep 12 '13 at 20:57

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...

Libertinus is a fork of Linux Libertine with bug fixes and very good math support (check out this example document). It would enable you to use Linux Libertine for math without using newtxmath. This is the question title ... (see XY problem).

To be compiled with xelatex and Libertinus fonts installed.

\documentclass[varwidth,border=1mm]{standalone}

\usepackage[
math-style=ISO,
bold-style=ISO,
partial=upright,
nabla=upright
]{unicode-math}

\setmainfont{Libertinus Serif}
\setsansfont{Libertinus Sans}
\setmathfont{Libertinus Math}

\begin{document}
The formula $$E=mc^2$$ is arguably the most famous formula in physics.

In mathematics, it could be $$\mathrm{e}^{\mathrm{i}\uppi}-1=0$$.

$$\displaystyle \sum_{k=0}^\infty \frac{1}{k^2} = \frac{\uppi^2}{6}$$, and
$$\displaystyle \int\displaylimits_{-\infty}^\infty \exp\left(-\frac{x^2}{2}\right) = \sqrt{2\uppi}$$.

$$\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda\mu\nu\xi\pi\rho\sigma\tau\upupsilon\phi\chi\psi\omega \varepsilon\vartheta\varrho\varsigma\varphi\varkappa$$

$$\upalpha\upbeta\upgamma\updelta\upepsilon\upzeta\upeta\uptheta\upiota\upkappa\uplambda\upmu\upnu\upxi\uppi\uprho\upsigma\uptau\upupsilon\upphi\upchi\uppsi\upomega \upvarepsilon\upvartheta\upvarrho\upvarsigma\upvarphi\upvarkappa$$

$$\Alpha\Beta\Gamma\Delta\Epsilon\Zeta\Eta\Theta\Iota\Kappa\Lambda\Mu\Nu\Xi\Pi\Rho\Sigma\Tau\Upsilon\Phi\Chi\Psi\Omega$$

$$\upAlpha\upBeta\upGamma\upDelta\upEpsilon\upZeta\upEta\upTheta\upIota\upKappa\upLambda\upMu\upNu\upXi\upPi\upRho\upSigma\upTau\upUpsilon\upPhi\upChi\upPsi\upOmega$$
\end{document}


Be aware though: xe(la)tex currently (TeX Live 2016) has a bug, which is visible in my screenshot: Why is the fraction off the math axis in XeTeX? . lualatex of TeX Live 2016 has a bug as well: spacing in LuaLaTeX with unicode-math