# font setup cochineal for text and stix2 for math

Experienced coder but newbie on latex, I can't wrap my head around the way font and font packages behaves !

I would be glad to have a working snippet, but if you have some generic advises about the philosophy of the system, I take.

I'm trying to use the cochineal font for all text, and the stix2 font for all math. My first attempt was :

\documentclass{article}
\usepackage{amsmath}
\usepackage{cochineal}
\setmathfont(STIX2Math.otf)
\usepackage[T1]{fontenc}


where I got:

! Undefined control sequence.

l.7 \setmathfont
(STIX2Math.otf)


which seems strange, since this control sequence is used by me on numerous other templates! So I tried some other random combinations, and also black magic, and rabbit paws, in vain.

How can I set a math font and a text font? How does fallback works? Where do the Latin and Greek letters come from in math, from the main font? And about unicode-math should I still use \usepackage[T1]{fontenc} with it? And what's the logic here?

The easiest way to use Cochineal for text and STIX2 for math is probably to use cochineal and newtxmath with stix2 option.

\documentclass{article}
\usepackage{cochineal}
\usepackage[stix2]{newtxmath}
\begin{document}
A test to see the cochineal text font.
$f(z) = \frac{1}{2\pi i} \int \frac{f(\zeta)}{\zeta - z} \,\mathrm{d}\zeta.$
\end{document}


Also, in your example, it's not surprising that \setmathfont is undefined: this command is defined by the unicode-math package, which is not loaded.

• Thank you ! it seems to do the job :) I'm still struggling to understand what is the role of newtxmath and why \usepackage{stix2} \usepackage[T1]{fontenc} and \usepackage[stix2]{newtxmath} gives different symbols for integrals or sums... (I preferred the stix2 ones :D) – yota May 19 '20 at 15:23