# Math digits are in CM with newtxmath and fontspec (LuaLaTeX, TeX Live 2017)

This issue is not new on this site, but I’ve tried earlier solutions and neither works for me. Related questions:

My goal is to use newtxmath together with setting system OpenType fonts through fontspec. No matter in which order I load the package, the digits in math mode are rendered in Computer Modern, not Times.

% !TEX program = lualatex

\documentclass[12pt,a4paper]{article}

\usepackage{newtxmath}

\usepackage[no-math]{fontspec}

\setmainfont{Times New Roman}

\begin{document}
Text: 2, Math: $$x=\sqrt{2}$$
\end{document}


Per the newtxmath documentation:

As far as I can tell, newtxmath works with both [XeLaTeX and LuaLaTeX], but requires a very specific loading order and choice of options. [...] the math options must all be loaded prior to loading and using fontspec.

Which I’ve done right in my opinion. My packages are all up-to-date as well.

I’ve tried to adapt this answer for the Times font, but couldn’t make it work.

• Not sure the quoted passage from the user guide of the nextx package is (still) correct. For sure, \usepackage[no-math]{fontspec} followed by \usepackage{newtxtext,newtxmath} works fine. – Mico Oct 1 '17 at 18:12
• @Mico: Thanks, your proposal does work, but I still want to set my main font via fontspec so I can use the Times OTF files I want (using Semibold in my case) instead of the newtxtext fonts. – lblb Oct 1 '17 at 18:29
• Since newtx is based on TeX Gyre Termes, why not just use unicode-math and \setmathfont{TeX Gyre Termes Math}? – Henri Menke Oct 1 '17 at 20:13
• @HenriMenke: This is a good alternative, but I'm still curious about what is happening in my MWE and how to fix it ... and the \pi is disturbingly mirrored with the TeX Gyre Termes Math font. – lblb Oct 1 '17 at 20:20

newtxmath more or less assumes that the default encoding is T1 or OT1. But you can reset the operator font:

\documentclass[12pt,a4paper]{article}

\usepackage{newtxmath}
\DeclareSymbolFont{operators}{OT1}{ntxtlf}{m}{n}
\SetSymbolFont{operators}{bold}{OT1}{ntxtlf}{b}{n}
\usepackage[no-math]{fontspec}

\setmainfont{Times New Roman}

%
\begin{document}
Text: 2, Math: $$x=\sqrt{2}$$

\end{document}


An alternative is to give times the newtx-family name, so that newtxmath can use it.

\documentclass[12pt,a4paper]{article}

\usepackage[no-math]{fontspec}

\setmainfont{Times New Roman}[NFSSFamily=ntxtlf]

\usepackage{newtxmath}

%
\begin{document}
Text: 2, Math: $$x=\sqrt{2}$$

\end{document}


• I've found that your second solution with [NFSSFamily=ntxtlf] disables OpenType superior figures (VerticalPosition=Superior in fontspec), so I'm using the first solution now. – lblb Oct 3 '17 at 9:57
• I am trying this solution with Linux Libertine instead of Times New Roman, but the numbers are still coming differently. – Damitr Apr 6 '18 at 11:30

Remove the no-math option and use the trick in my answer to Math digits are rendered in CM when using libertine and newtxmath with XeLaTeX in TeX Live 2016, but augmented for taking care also of other glyphs.

\documentclass[12pt,a4paper]{article}

\usepackage{newtxmath}
\usepackage{fontspec}
\setmainfont{Times New Roman}

\DeclareSymbolFont{oldoperators}{OT1}{ntxtlf}{m}{n}
\SetSymbolFont{oldoperators}{bold}{OT1}{ntxtlf}{b}{n}

\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}%
\DeclareMathSymbol{\Gamma}{\mathalpha}{oldoperators}{"00}%
\DeclareMathSymbol{\Delta}{\mathalpha}{oldoperators}{"01}%
\DeclareMathSymbol{\Theta}{\mathalpha}{oldoperators}{"02}%
\DeclareMathSymbol{\Lambda}{\mathalpha}{oldoperators}{"03}%
\DeclareMathSymbol{\Xi}{\mathalpha}{oldoperators}{"04}%
\DeclareMathSymbol{\Pi}{\mathalpha}{oldoperators}{"05}%
\DeclareMathSymbol{\Sigma}{\mathalpha}{oldoperators}{"06}%
\DeclareMathSymbol{\Upsilon}{\mathalpha}{oldoperators}{"07}%
\DeclareMathSymbol{\Phi}{\mathalpha}{oldoperators}{"08}%
\DeclareMathSymbol{\Psi}{\mathalpha}{oldoperators}{"09}%
\DeclareMathSymbol{\Omega}{\mathalpha}{oldoperators}{"0A}%
\DeclareMathSymbol{!}{\mathclose}{operators}{"21}%
\DeclareMathSymbol{+}{\mathbin}{operators}{"2B}%
\DeclareMathSymbol{:}{\mathrel}{operators}{"3A}%
\DeclareMathSymbol{;}{\mathpunct}{operators}{"3B}%
\DeclareMathSymbol{=}{\mathrel}{operators}{"3D}%
\DeclareMathSymbol{?}{\mathclose}{operators}{"3F}%
\DeclareMathDelimiter{(}{\mathopen} {operators}{"28}{largesymbols}{"00}%
\DeclareMathDelimiter{)}{\mathclose}{operators}{"29}{largesymbols}{"01}%
\DeclareMathDelimiter{[}{\mathopen} {operators}{"5B}{largesymbols}{"02}%
\DeclareMathDelimiter{]}{\mathclose}{operators}{"5D}{largesymbols}{"03}%
\DeclareMathAccent{\acute}{\mathalpha}{operators}{"B4}%
\DeclareMathAccent{\grave}{\mathalpha}{operators}{"60}%
\DeclareMathAccent{\ddot}{\mathalpha}{operators}{"A8}%
\DeclareMathAccent{\tilde}{\mathalpha}{oldoperators}{"7E}%
\DeclareMathAccent{\bar}{\mathalpha}{oldoperators}{"16}%
\DeclareMathAccent{\breve}{\mathalpha}{oldoperators}{"15}%
\DeclareMathAccent{\check}{\mathalpha}{oldoperators}{"14}%
\DeclareMathAccent{\hat}{\mathalpha}{oldoperators}{"5E}%
\DeclareMathAccent{\dot}{\mathalpha}{oldoperators}{"5F}%
\DeclareMathAccent{\mathring}{\mathalpha}{oldoperators}{"17}%
\DeclareMathSymbol{\mathdollar}{\mathord}{operators}{"24}%
}

\begin{document}

Text: 2, Math: $$x=\sqrt{2}+1234567890$$

!+:;=?()[]

${!}{+}{:}{;}{=}{?}{(}{)}{[}{]}$

\'a\a\"a\~a\=a\u{a}\v{a}\^a\.a\r{a}

$\acute{\mathrm{a}} \grave{\mathrm{a}} \ddot{\mathrm{a}} \tilde{\mathrm{a}} \bar{\mathrm{a}} \breve{\mathrm{a}} \check{\mathrm{a}} \hat{\mathrm{a}} \dot{\mathrm{a}} \mathring{\mathrm{a}}$

$\Gamma\Delta\Theta$

\end{document}


Some accents must be taken from newtx instead of Times New Roman, for technical limitations.

• This solution now has the equal sign = (and possibly others) in CM, though. – lblb Oct 2 '17 at 14:54
• @lblb I used the equals and plus sign from Times New Roman, because they are quite different in NewTX. There are small differences in tilde, bar, breve, hat, check and dot, for technical limitations in the font. – egreg Oct 2 '17 at 20:14
• Please add the missing \makeatother. Is it even necessary there? I see no @ signs. – lblb Nov 2 '17 at 19:38
• @lblb Thanks, probably \makeatletter` was a remain from earlier code. – egreg Nov 2 '17 at 21:05