1

similar to DeclareMathOperator does not respect math font . Here is my mwe:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{texgyretermes-regular.otf}
\usepackage[]{newtxmath}
\begin{document}
$ \sin x $ 
\end{document}

It output

enter image description here

But my expected output is

enter image description here

How can I get my expected output when only loading newtxmath package without newtxtext.

Edit

The reason why I can't use newtx or newtxtext package: I'm a ctex package user, newtx(text) is incompatible with ctex package, so I have to set main font myself. I put mwes below, all of them should be compiled with xelatex:

\documentclass{ctexart}
\usepackage{newtxtext}
% \usepackage{newtx}
\begin{document}
  测试\textbf{测试}\textit{测试}{\heiti 测试}{\kaishu 测试}
  English\textbf{English}\textit{English}\textbf{\textit{English}}
\end{document}
! Package fontspec Error: The font "SimHei" cannot be found.

For immediate help type H <return>.
 ...

l.4   测试\textbf{测试}\textit{测试}{\heiti
                                      测试}{\kaishu 测试}

If I change newtxtext to newtx, I'll get

! LaTeX Error: Option clash for package fontspec.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.465     \ifnum
                \ntx@id=10\relax % libertinus

If I use nofontspec or type1 option to load newtxtext package, it will break itself with xelatex

\documentclass{article}
\usepackage[type1]{newtxtext}
\begin{document}
  English\textbf{English}\textit{English}\textbf{\textit{English}}
\end{document}

enter image description here

3
  • I found this question: tex.stackexchange.com/q/638757/180617 . But I don't know how to fix it.
    – Syvshc
    May 2, 2022 at 13:58
  • Try the newtx package maintainer!
    – murray
    May 2, 2022 at 18:18
  • @murray well, I'm a ctex package user, newtx(text) is incompatible with ctex package, so I have to set main font myself:(
    – Syvshc
    May 3, 2022 at 12:31

2 Answers 2

4

You want to teach LaTeX what's the operators font.

\documentclass{article}
\usepackage[no-math]{fontspec}
\usepackage{newtxmath}

\setmainfont{texgyretermes}[
  Extension=.otf,
  UprightFont=*-regular,
  ItalicFont=*-italic,
  BoldFont=*-bold,
  BoldItalicFont=*-bolditalic,
  NFSSFamily=texgyretermes,
]

\DeclareSymbolFont{operators}{TU}{texgyretermes}{m}{n}

\begin{document}

$ 2\sin x $

\end{document}

enter image description here

On the other hand, the most recent versions of NewTX can recognize when XeLaTeX or LuaLaTeX are used and you can simply do

\usepackage{newtxtext,newtxmath}

which will employ a variant of TeX Gyre Termes, but essentially the same.

1
  • In fact, with current newtx (since version 1.7), you need only use \usepackage{newtx}.
    – murray
    May 2, 2022 at 18:34
1

Most of the fixes that I’d usually recommend break with newtxmath, which is not very compatible with other packages. I’d therefore recommend you do one of two things.

Cut the Gordian Knot

If you can use fontspec, you can use unicode-math and load an OpenType math font, instead of newtxmath.

\usepackage{unicode-math}

\setmainfont{TeX Gyre Termes}
\setmathfont{TeX Gyre Termes Math}

Variations include: TeX Gyre Termes X as a text font closer to newtxtext, XITS and XITS Math, or \usepackage[times]{fontsetup}.

Go Back to Legacy Fonts

The package does work with

\usepackage[T1]{fontenc}
\usepackage{newtxtext, newtxmath}

If you need Greek or Cyrillic, you might use another font, such as tempora.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .