1

I'm seeing a build failure when trying to build the following minimal document:

\documentclass{article}

\usepackage{newtxmath}
\usepackage{unicode-math}

\begin{document}
abc
\end{document}

Running xelatex -halt-on-error min.tex shows the following error:

! LaTeX error: "kernel/command-already-defined"
!
! Control sequence \not= already defined.

I'm attaching the full log here instead of in the question since it's a little lengthy. Interestingly, reversing the order of the two packages shows a different error message:

! LaTeX Error: Command `\arrowvert' already defined.

I'm using a fresh install of MacTex 2018. Any help would be appreciated!

zale
  • 123
  • There's no point in loading both newtxmath and unicode-math. – egreg Aug 30 '18 at 21:15
  • what do you want the effect of loading these two packages to be? While the specific error messages are low level accidental clashes, at a higher level they are completely incompatible, as they are making completely different and conflicting changes to the way math is configured. – David Carlisle Aug 30 '18 at 21:15
  • 2
    oh no I agreed with @egreg. – David Carlisle Aug 30 '18 at 21:16
  • For context, I was trying to build this document, which imports both packages; the combination seemed to be working with texlive 2017 so I figured it could be an issue in texlive 2018. Thanks a lot for the answers; they clarified things! – zale Sep 02 '18 at 13:26

4 Answers4

2

There's no point in loading both newtxmath and unicode-math. The former implements Times compatible math fonts in legacy TeX engines (pdftex), the latter uses Unicode math fonts. Therefore the two packages are largely incompatible.

If you want Times based math fonts, you can do

\usepackage{unicode-math}

\setmathfont{STIX Two Math}

or

\usepackage{unicode-math}

\setmathfont{TeX Gyre Termes Math}

The precise syntax for choosing the font may differ depending on your TeX distribution and OS setup. Possibly

\setmathfont{STIX2Math.otf}

or

\setmathfont{texgyretermes-math.otf}

would be required.

egreg
  • 1,121,712
2

I assume that you wish to load the newtxmath package because it provides some math-mode glyphs that aren't provided by other math font packages.

Page 10 of the user guide of the newtx pair of packages -- type texdoc newtx at a command prompt to bring up this document -- explains how to make use of the newtxtext and/or newtxmath packages under LuaLaTeX and XeLaTeX. An excerpt from the user guide:

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

For instance, the following should work for you. Note that the fontspec package, but not the unicode-math package (which loads fontspec automatically, by the way), should be loaded when using newtxmath. In addition, do note that the fontspec package should be loaded with the option no-math.

...
\usepackage[T1]{fontenc}
\usepackage{newtxmath}
\usepackage[no-math]{fontspec}
% load a suitable text font
...

Alternatively -- a thought already pointed out in egreg's answer -- keep loading the unicode-math package but ditch the newtxmath package. Instead, look into using a Times Roman-clone math font such as Stix Two Math (which may be downloaded, along with Stix Two Text, from http://stixfonts.org/.


Here's a full MWE (minimum working example):

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

\begin{document}
$abc$def\emph{ghi}
\end{document}
Mico
  • 506,678
2

You shouldn’t load both unicode-math and a legacy (NFSS) math font. If you want the appearance of newtxmath, \setmathfont[Scale=MatchLowercase]{TeX Gyre Termes Math}. There’s also a variant of Times that’s tweaked to look more like newtx, but you probably want to \setmainfont{TeX Gyre Termes}.

TeX Gyre Termes should include any symbol you need from newtxmath. If somehow one is missing, you can import it from a font such as XITS with something like \setmathfont[range="220E, Scale=MatchUppercase]{XITS Math}.

To use an OpenType or TrueType text font in math mode with legacy math symbols, use mathspec. To use a legacy text font in math mode with a Unicode math font, use mathastext.

Davislor
  • 44,045
1

Perhaps you need to override newtxmath with unicode-math, for instance because you're using a journal's class file that unconditionally loads newtxmath. This incantation will do the job:

\usepackage{expl3}  % if necessary
\ExplSyntaxOn
\makeatletter
\@ifpackageloaded{unicode-math}{}{%else
  % both newtxmath and unicodemath try to define these, producing
  % multiple definition errors
  \cs_undefine:c { not= }
  \cs_undefine:c { not> }
  \cs_undefine:c { not< }

% tweak as you see fit \usepackage{unicode-math} \setmathfont[Scale=MatchLowercase]{TeX Gyre Termes Math} } \makeatother \ExplSyntaxOff

I'm using expl3 here strictly for \cs_undefine:c, which is ever so much easier to type than the 2e equivalent (which I believe is something like \expandafter\let\csname ... \endcsname\@undefined — not tested). The \@ifpackageloaded is for futureproofing: if a future version of the class file loads unicode-math itself, the block will turn itself off.

zwol
  • 2,919