4

My requirements are:

  1. Use Calibri as the main font. This is easy with XeLaTeX.
  2. Use Calibri as the math font. Also quite easy using e.g. mathspec. But this takes care only of letters and numbers.
  3. Use Calibri as the font for math symbols (e.g. \times, =, +) in equations. This is the difficult part.

It took me a few years and two iterations to figure this out, but I finally found a solution. Both are discussed in the answer below.

2 Answers 2

6

Iteration 1

\documentclass[10pt]{article}
\usepackage[MnSymbol]{mathspec}  % Includes amsmath.
\setmathsfont(Digits,Latin,Greek,Symbols)[Numbers={Lining,Proportional}]{Calibri}
\setmainfont[Mapping=tex-text, Ligatures={NoRequired,NoCommon,NoContextual}]{Calibri}
\usepackage[italic]{mathastext}

\begin{document}
ABCDEFGHIJKLMNOPQRSTUVWXYZ
  \begin{align}
    \dfrac{5a + 10b}{10} &= c \times |XY| - \alpha\beta\gamma^{2}\\
    x &= 5~\mathsf{°C}
  \end{align}
\end{document}

This ticks the first two boxes in my requirements, and here is what you get out:

Iteration 1 You can notice this approach has multiple problems though:

  1. The fraction line is not typeset in Calibri "style".
  2. The \times symbol is not typeset using Calibri.
  3. The \circ (degree) symbol is completely missing.
  4. The "C" in the equation is not typeset using Calibri. because I used \mathsf. Therefore, the Computer Modern sans font was used.

Iteration 2

My first solution was good-enough, so I stuck with it for a few years. However, during that time the great unicode-math package emerged.

The key ingredient (or hack) that satisfied my third requirement was the line \setmathfont[range={"0000-"FFFF}]{Calibri} which means: "Use Calibri for all Unicode characters 0x0000 to 0xFFFF, i.e. the vast majority of symbols I would ever want to use in equations."

Also note the \setmathfont[slash-delimiter=frac]{Cambria Math}. This is necessary, as Calibri is not available as a LaTeX math font. So we use Cambria Math, because it matches Calibri in style better, e.g. it has more matching fraction lines. However, we use the trick described above to use Calibri for the Unicode range of most of the characters anyone will see.

\documentclass[10pt]{article}
\usepackage{amsmath}  % Same for amsmath.
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont[Mapping=tex-text,Ligatures={NoRequired,NoCommon,NoContextual}]{Calibri}
\setmathfont[slash-delimiter=frac]{Cambria Math}
\setmathfont[range={"0000-"FFFF}]{Calibri}
\setmathfont[range=up]{Calibri}
\setmathfont[range=sfup]{Calibri}
\setmathfont[range=it]{Calibri Italic}
\setmathfont[range=bfup]{Calibri Bold}
\setmathfont[range=bfit]{Calibri Bold Italic}
\setsansfont{Calibri}  % Make \mathsf and \textsf also Calibri

\begin{document}
ABCDEFGHIJKLMNOPQRSTUVWXYZ
  \begin{align}
    \dfrac{5a + 10b}{10} &= c \times |XY| - \alpha\beta\gamma^{2}\\
    x &= 5~\mathsf{°C}
  \end{align}
\end{document}

Here is the lovely result:

Iteration 2

Final notes

  • I verified that this works with XeLaTeX. It should work with LuaTeX as well.
  • This should work with any other font.
  • I hope this helps you typesetting beautiful documents.
6
  • Add a \neq ... Apr 7, 2019 at 20:38
  • @UlrikeFisher: Nice catch with the \neq. It works if I increase the range to "0000-"FFFF.
    – Augustin
    Apr 7, 2019 at 20:42
  • One suggestion: if you examine the coverage of a font, e.g. with otfinfo, you can then turn that into a range= that tries to use only the characters a font actually has.
    – Davislor
    Apr 7, 2019 at 23:10
  • I’d also recommend adding \defaultfontfeatures{Scale=MatchLowercase} to the top, and the option Scale=1.0 to \setmainfont. This will improve the scaling if you try to use Calibri with some other font family, such as a monospace, serif, script or blackboard-bold font.
    – Davislor
    Apr 7, 2019 at 23:19
  • 1
    If your document uses the sans-serif family (as, for example, Koma’s headers do by default), you’d also want to \setsansfont.
    – Davislor
    Apr 7, 2019 at 23:21
0

I also struggled with this, trying to use setmainfont and setmathfont but what ended up working was:

\setallmainfonts[
Path = /path/,
Extension=.otf,
BoldFont = LocalFont-Cond,
ItalicFont = LocalFont-ExtObl,
BoldItalicFont = LocalFont-BoldExtObl]{LocalFont}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.