3

After upgrading to TeX Live 2022, I found a lot of my previous code broken due to the clash between newtx and fontspec. Here is a minimal example (The engine is XeLaTeX under Windows):

\documentclass[11pt]{article}
\usepackage{xeCJK}
\usepackage{newtxtext} % !!!
\usepackage{newtxmath} % !!!
\usepackage{fontspec}

\setsansfont{TeX Gyre Heros}
\setCJKmainfont{Noto Serif CJK SC}

\begin{document}
    \[ x^2+y^2=z^2 \]

    Test English.

    测试中文。
\end{document}

The code will not compile and shows error:

! Package fontspec Error: The font "TeX Gyre Heros" cannot be found.
...
! Package fontspec Error: The font "Noto Serif CJK SC" cannot be found.

However, if I comment out the two lines with !!!, then it compiles.

With this A/B test I know that it is the recent (official) support of unicode-engine in newtx that breaks my code, because newtx uses fontspec now. I tried to pass [nofontspec] to newtx but the font turned out to be wrong.

What exactly is happening here? Any suggestions for fixing all my codes (I use newtx with fontspec heavily) without doing too much work?

4
  • Are the mentioned fonts installed? And you probably want to note which engine and os you're using
    – daleif
    Apr 11, 2022 at 11:14
  • Yes, they are installed and usable --- confirmed by successful compilation after commenting out newtx. The engine is XeLaTeX under Windows. Apr 11, 2022 at 11:20
  • Why do you attempt to run both \usepackage{newtxtext} and \setCJKmainfont{Noto Serif CJK SC}, i.e., why are you trying to set up two rather mutually incompatible text fonts?
    – Mico
    Apr 11, 2022 at 11:21
  • @Mico \setCJKmainfont{Noto Serif CJK SC} specifies the fonts for CJK characters. Even if I remove this line, the file won't compile and says TeX Gyre Heros is not found. Apr 11, 2022 at 11:24

2 Answers 2

3

I have observed the same problem with newpx and fontspec recently. See this question (and answer). I sent an e-mail to the author of newpx (and newtx) but didn't get an answer.

Add \defaultfontfeatures{} after loading newtx.

1
  • Works! Will accept after some delay in case anyone else has other ideas :) Apr 11, 2022 at 11:34
3

Unless you're strongly committed to pursuing the xeCJK approach, I'd like to suggest that you employ the unicode-math package and issue suitable \setmainfont, \setsansfont, and \setmathfont directives.

Since you're using the Noto Serif SC font family for the main (serif) text font, I wouldn't use Helvetica as the main sans-serif font. Instead, I'd employ the Noto Sans SC font family. If you must use a Times Roman clone as the math font, I'd ditch the newtxmath math font and, instead, issue the directive \setmathfont{Stix Two Math}.

I compiled the following code with MacTeX2022 and LuaLaTeX.

enter image description here

\documentclass[11pt]{article}
\usepackage{unicode-math}
\setmainfont{Noto Serif SC}
\setsansfont{Noto Sans SC}[Scale=MatchLowercase]
\setmathfont{Stix Two Math}[Scale=MatchLowercase]

\begin{document}
Test serif font. 

\textsf{Test sans-serif.} 

$x^2+y^2=z^2$.

测试中文。\quad \textsf{测试中文。}
\end{document}
1
  • Agree. I was previous told that newtx should only be used with a non-unicode engine. Would refactor the code now. Apr 11, 2022 at 12:27

You must log in to answer this question.

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