# LuaLaTeX + libertine… the issue of math font

Would it be possible to use Libertine otf font (using LuaLaTeX and, for example, package libertine for automatic settings) for everything but in math mode where I'd like to use newtxmath and its libertine option (which produces acceptable output with pdfLaTeX)?

Neither :

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

nor

\usepackage[libertine]{newtxmath}
\usepackage[no-math]{fontspec}
\setmainfont[Ligatures={TeX}]{Linux Libertine O}

are successful. I get CM font for maths using the following:

%!TEX program = lualatex

\documentclass[]{scrbook}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}

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

\begin{document}

$$\mathit{TRUC} = \frac{1}{10} \times \sum _{d=0.2}^{12.8} \frac{\pi \times d \times A_{d}}{E_{d}}$$

\end{document}
• Both variants work fine for me with both xelatex and lualatex. Please add a complete minimal working example (MWE) which exhibits the error you are experiencing. – Henri Menke Dec 9 '15 at 10:20
• You just added “I get CM font for maths” to your question. It is still lacking a complete minimal working example (MWE) to reproduce this, though. In this state your question will not receive attention and might be closed and/or downvoted. – Henri Menke Dec 9 '15 at 10:28
• But isn't it still possible to answer such a question? In case there is another interesting answer, it is possible to upvote it (for everyone) and if there is an even "better answer" I can switch validation... If this is what you were talking about. Anyway, this was my first question addressed on TeX Stackexchange and if there are different "traditions" than elsewhere (e.g. Stackoverflow where I already got requests to validate), I can adapt for the next one! – user2165907 Dec 9 '15 at 13:43

Since you give the no-math option, you have to help fontspec:

\documentclass[]{scrbook}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}

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

\DeclareSymbolFont{operators}{\encodingdefault}{\familydefault}{\mddefault}{n}
\DeclareMathAlphabet{\mathit}{\encodingdefault}{\familydefault}{\mddefault}{it}
\DeclareMathAlphabet{\mathbf}{\encodingdefault}{\familydefault}{\bfdefault}{n}

\begin{document}

$$\mathit{TRUC} = \frac{1}{10} \times \sum _{d=0.2}^{12.8} \frac{\pi \times d \times A_{d}}{E_{d}}$$

$\mathbf{ABC}$

\end{document}

Otherwise you need to restore the standard math codes for the digits.

\documentclass[]{scrbook}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}

\usepackage[libertine]{newtxmath}
\usepackage{fontspec}
\usepackage{libertine}

\AtBeginDocument{%
\DeclareMathSymbol{0}{\mathalpha}{operators}{0}%
\DeclareMathSymbol{1}{\mathalpha}{operators}{1}%
\DeclareMathSymbol{2}{\mathalpha}{operators}{2}%
\DeclareMathSymbol{3}{\mathalpha}{operators}{3}%
\DeclareMathSymbol{4}{\mathalpha}{operators}{4}%
\DeclareMathSymbol{5}{\mathalpha}{operators}{5}%
\DeclareMathSymbol{6}{\mathalpha}{operators}{6}%
\DeclareMathSymbol{7}{\mathalpha}{operators}{7}%
\DeclareMathSymbol{8}{\mathalpha}{operators}{8}%
\DeclareMathSymbol{9}{\mathalpha}{operators}{9}%
}

\begin{document}

\showthe\mathcode`1

$$\mathit{TRUC} = \frac{1}{10} \times \sum _{d=0.2}^{12.8} \frac{\pi \times d \times A_{d}}{E_{d}}$$

$\mathbf{ABC}$

\end{document}

Another approach is as follows, using the Linux Libertine system fonts, e.g., under lualatex:

\documentclass[]{scrbook}

\usepackage{luacode,luatexbase}
\usepackage{mathtools}
\usepackage{amssymb}

\usepackage[T1]{fontenc}
\usepackage[scaled=.85]{beramono}% used \mathtt; could use Libertine Mono
\usepackage[type1,scaled=.9]{cabin}% used \mathsf; could use Biolinum

\usepackage[libertine]{newtxmath}%

\providecommand\mathbfit[1]{\bm{\mathit #1}}% since unicode-math not loaded here.

\usepackage[no-math]{fontspec}
\setmainfont{Linux Libertine O}
\setmonofont{Linux Libertine Mono O}[Scale=0.89]
\setsansfont{Linux Biolinum O}[Scale=MatchUppercase]

\begin{document}

$$\mathit{TRUC} = \frac{1}{10} \times \sum _{d=0.2}^{12.8} \frac{\pi \times d \times A_{d}}{E_{d}}$$

$\mathbf{ABC}$

$\mathbfit{ABC}$

\end{document}