# Caveats of newtxmath and fontspec together

I'm able to typeset a ~50 page set of lecture notes with heavy math using

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


with both PDFLaTeX and XeLaTeX. I know that the libertine package automatically loads and uses fontspec if used with XeTeX. However, someone here mentioned that it's not a good idea to use Type1 and OpenType fonts together. So, what could go wrong?

• Why shouldn't it be a good idea? – egreg Feb 11 '14 at 10:39
• It should be not a problem to use type1 math fonts - that is the default if you load only fontspec. Perhaps you mixed up T1-encoding and type1 fonts: to use in text T1-encoding is generally not a good idea.) – Ulrike Fischer Feb 11 '14 at 10:43

Works for xelatex and pdflatex

\documentclass{article}
\usepackage{iftex}
\ifXeTeX
\usepackage[no-math]{fontspec}
\usepackage[libertine]{newtxmath}
\else
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\fi
\usepackage{libertine}
\begin{document}
$\mathbf{\Delta}$
\end{document}

• The example code only loads newtxmath when compiled with xelatex. This is easily fixed, but another problem arises when the document contains something more complex than \Delta, for example \blindmathpaper from package blindtext: Internal error: bad native font flag (XeLaTeX, fontspec, newtxmath, libertine, \dot) – mvkorpel Aug 28 '14 at 9:34
• it is a problem with command \bar{x} – user2478 Aug 28 '14 at 10:05

It's important not to confuse math fonts and text fonts. Loading fontspec with the [no-math] option keeps the math font untouched, so math font packages should work as usual. Font packages written for PDFLaTeX may not work.

However, before switching an existing document to XeLaTeX, proofreading is necessary. I found that there are some special cases that do go wrong. The code below is rendered correctly with PDFLaTeX, but with XeLaTeX I get a ☒ character:

\documentclass{article}
\usepackage{iftex}
\ifXeTeX\else
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\fi
\usepackage{libertine}
\usepackage[libertine]{newtxmath}
\begin{document}
$\mathbf{\Delta}$
\end{document}