[Tex/LaTex] Using two different math fonts with LuaLaTeX

luatexsans-serif

In a document I need to use both TrueType and some Type1, so I switched to LuaLatex. But I found a problem when setting math fonts.
Here is what I need:

  • the document uses a TrueType serif font (Crimson) as its main font, but apparently the only suitable match for math is the Type1 font Cochineal, available through newtxmath

  • in certain parts of the document I need to switch to a sans font (Asap), and there is some math, which I want to be printed with the same font. I rely on the package sansmath for this.

The problems is that the no-math option in fontspec seems to be an all-or-nothing option.

Here is my setup (I use my specific fonts, but I guess it would be the same with any other similar font setup)

\documentclass{article}
\usepackage[cochineal]{newtxmath}
\usepackage{sansmath}
\usepackage[no-math]{fontspec} % luatex
\setmainfont{Crimson-Roman}[Ligatures=TeX,
           ItalicFont = {Crimson-Italic},
           BoldFont = {Crimson-Semibold},
           BoldItalicFont = {Crimson-SemiboldItalic}]
\setsansfont{Asap-Regular}[
           ItalicFont ={Asap-Italic},
           BoldFont = {Asap-SemiBold},
           BoldItalicFont = {Asap-SemiboldItalic}]
\DeclareSymbolFont{operators}{\encodingdefault}{\familydefault}{m}{n}

\begin{document}

This is a text with the main font, and some math: $\sum_ix_i^2$

\sffamily\sansmath and here is some other text in sans, with some math too $\sum_ix_i^2/2$.

\end{document}

However, because I set the math font with newtxmath (and the no-math option in fontspec) the result is that not all symbols are printed properly when the formula is sans (namely, the "/" symbol disappears from the formula).

On the other hand, if I don't set newtxmath (or, equivalently, if I don't set the option no-math), everything is fine with the math in sans, but the main math formulas (in serif) are printed in ComputerModern instead of Crimson.

It seems there is no way to tell LuaTex to rely selectively on a Type1 font only for one math font (the one matching the main/serif font) and not the other (the one used with the sans font).

Or maybe there is something wrong with my setup.

There's an additional problem with \DeclareSymbolFont{operators}...: this command seems necessary, otherwise numbers are not printed properly with the (cochineal) math font; however, the command affect all math fonts.

Best Answer

A bit late, but it’s a good question.

To use a Type1 math font with an OpenType text font, you can \usepackage{mathspec} after \newtxmath, and \setmathsfont to use your text font in math mode. As long as the text font matches the math symbols, you’re golden.

Another method is mathastext, which now supports fontspec.

Finally, in unicode-math, use \defaultfontfeatures{Scale=MatchLowercase} and consider whether any of the available OpenType math fonts would match well if you loaded \setmathfont[range=it]{Crimson Roman Italic}, \setmathfont[range=up]{Crimson Roman}, etc., after it.

Related Question