0

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.
<recently read> \setmathfont

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?

2 Answers 2

2

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.

1
  • 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, 2020 at 15:23
2

Under 2023 texlive the font is STIXTwo. I can also see the file cochineal.fontspec in texlive hence I can make the undocumented \setmainfont{cochineal} call. I am stealing the example of @Vincent.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{cochineal}
% This also works
% \usepackage{cochineal}
\usepackage{unicode-math}
\setmathfont{STIXTwoMath-Regular}

\begin{document}


A \strong{test} to see the \textit{cochineal} text font with
\textbf{\textit{STIXTwo}} math.

\[
\sum {f(z)} = \frac{1}{2\pi i} \int \frac{f(\zeta)}{\zeta - z} \,\mathrm{d}\zeta.
\]

\end{document}

stixtwo + cochineal

It's another matter if the difference between the x-sizes and overall styles of the two fonts can be matched satisfactorily enough just to have that cute stixtwo inline integral sign.

x size differences

Here is the code for the above example.

\documentclass{article}

\usepackage{fontspec}
\setmainfont{cochineal}
% \setmainfont{STIXTwoText}
\usepackage{unicode-math}
\setmathfont{STIXTwoMath}%[Scale = MatchAveragecase]

\newcommand{\comp}[1]{\emph{#1}$#1$}

\begin{document}
A test to see if the \textbf{cochineal} text font with
\textbf{STIXTwo} math match well each other.\medskip

\comp{a}\comp{b}\comp{c}\comp{d}\comp{e}\comp{f}\comp{g}
\comp{h}\comp{i}\comp{j}\comp{k}\comp{l}\comp{m}\comp{n}
\comp{o}\comp{p}\comp{q}\comp{r}\comp{s}\comp{t}\comp{u}
\comp{v}\comp{w}\comp{x}\comp{y}\comp{z} and how about \emph{v}$\nu$?

\newtheorem{thm}{Theorem}

\begin{thm}
Let $a,b,c$ the sides of a right angle triangle, where $a$ and $b$ are
the legs and $c$ is the hypotenuse. We then have $a^2+b^2=c^2$. 
\end{thm}

\begin{thm}
  Consider the set $J$ (Jordan measurable!), and let $d$ denote the
  linear distance. Then the average distance between $J$ and $J+i$ is
  less than $2$, that is, $\int_I d(J,J+i)di<2$, confirming the
  conjecture of Erdős.
\end{thm}

\end{document} 

You must log in to answer this question.

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