3

I have to typeset a document in Calibri upright letters. There is a problem with mathematics: When I typeset the following minimal-example, letters are right Calibri, but numbers are italic by default. Numbers in equations should be upright by default. So what can I do? By the way, I compile with XeLaTeX.

\documentclass[a4paper, 11pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{fontspec}
\setmainfont{Calibri}
\usepackage[eulergreek]{sansmath}
\sansmath
\begin{document}
$A=3$
\end{document}
  • 1
    By the way, fontspec sets the main encoding to Unicode, so you shouldn't use fontenc too. – Davislor Jul 11 '18 at 20:37
2

I would recommend unicode-math whenever you aren't forced to use the legacy encodings. I particularly recommend that over mixing the modern and legacy packages. This scales the fonts you select automatically so that their heights, at least, match. It supports both Unicode input and output that you can copy and paste. It even lets you use the Greek letters of Calibri.

Warning: I'm not currently on my Windows box, so I wasn't able to test this for you, but it works with different fonts.

\documentclass[varwidth, preview]{standalone}

\usepackage{amsmath} % Or mathtools    
\usepackage[math-style=upright]{unicode-math}
\usepackage[ngerman]{babel} % Or polyglossia

\setmainfont{Calibri}
\defaultfontfeatures{Scale=MatchUppercase}
\setsansfont{Calibri}
\setmonofont{Consolas}

\setmathfont[slash-delimiter=frac]{Cambria Math}
\setmathfont[range=up]{Calibri}
\setmathfont[range=it]{Calibri Italic}
\setmathfont[range=bfup]{Calibri Bold}
\setmathfont[range=bfit]{Calibri Bold Italic}

\setoperatorfont\normalfont % For log, sin, cos, etc.

\begin{document}
$A=3$
\end{document}

Here is a version using Carlito and other free fonts. It also demonstrates how you can use some of the math symbols your text font supports in math mode. (The list of symbols in Calibri will be different, and also, you should be alert to inconsistencies such as one of <, ≮, ≤, ≦, etc. not matching the others, if you use one of them that you didn’t change to the same font.)

\documentclass[varwidth, preview]{standalone}

\usepackage{mathtools}
\usepackage[math-style=upright]{unicode-math}
%\usepackage[ngerman]{babel} % Or polyglossia

\usepackage[sfdefault]{carlito}
\defaultfontfeatures{Scale=MatchUppercase}
\usepackage{inconsolata}

\setmathfont{Asana Math}
\setmathfont[range={up,"002B,"002D,`±,`×,`·,`÷,`¬,`∂,`∆,`∕,`∞,`⌐}]{Carlito}
\setmathfont[range=it]{Carlito Italic}
\setmathfont[range=bfup]{Carlito Bold}
\setmathfont[range=bfit]{Carlito Bold Italic}

\setoperatorfont\normalfont % For log, sin, cos, etc.

\begin{document}
Foo bar baz.

$A \log b = 3$
\end{document}

Carlito

Edit: In the comments, you indicate that you wanted the math letters to be italicized. If so, delete the [math-style=upright] option to the unicode-math package, or change it to [math-style=ISO] if you want italic uppercase Greek letters as well. (TeX doesn’t do that by default only because legacy math fonts usually didn’t have those letters.)

| improve this answer | |
  • If I use \mathbf{b} rather than b, say, I get Latin Modern Roman bold. (unicode-math is very buggy in my experience. At least the range stuff really doesn't work.) – cfr Jul 11 '18 at 3:21
  • @cfr Yeah, \symbfup works and the mathbf=sym package option is a workaround to that. Still a WIP, I agree, but very usable already. – Davislor Jul 11 '18 at 3:49
  • @Davislor Thank you, it works fine on my Window-Computer. The unicode-version I need is without the upright option. Letters should be italic, only numbers should be upright by default. – Florian Jul 11 '18 at 12:52
  • @Florian Okay. In that case, either remove the [math-style=upright] option to the package, as you've done, or change it to [math-style=ISO] if you also want uppercase Greek letters to be italicized. By default, they aren't, only because legacy math fonts usually didn't include them. – Davislor Jul 11 '18 at 16:16
1

[EDIT] as suggested by Davislor, both fontspec and mathspec are not needed here

A solution is to use the mathspec package and set your math fonts manually. I do not have access to Calibri right now, so this MWE is with Roboto, but it should work with Calibri too

% !TEX program = xelatex
\documentclass[a4paper, 11pt]{scrartcl}
\usepackage[ngerman]{babel}


\usepackage[eulergreek]{sansmath}
\sansmath

\usepackage{amsmath}
\usepackage{mathspec}
\setmainfont{Roboto} 

\setmathsfont(Digits,Latin){Roboto}


\begin{document}
Text mode gives A=3 \\
Math mode gives $A=3$ \\
Greeks are still in Euler : $\Omega = \rho / \rho_{crit.}$
\end{document}

enter image description here

I suggest section 4 of the mathspec manual for more options, where you will find how to also make Latin characters upright as well if that's what you want. Using mathspec to set your Greek math font would also probably be more elegant.

| improve this answer | |
  • Also a good answer. Suggestion: mathspec automatically includes fontspec, and you shouldn't load both fontspec and fontenc, so you can take both those packages out of the template. – Davislor Jul 11 '18 at 21:04
  • Additionally, \setmathfont is available as an undocumented alias, but the mathspec command, according to the manual, is \setmathsfont. I personally prefer \setmathsfont for mathspec, since there is a different \setmathfont in unicode-math. Spelling the commands differently avoids confusion. – Davislor Jul 11 '18 at 21:07
  • 1
    That's true. I tend to forget this and use [no-math]{fontspec} and then mathspec because of a different use case - thank you for the reminder, I'll edit. No excuse for fontenc though ;) – fkrz Jul 12 '18 at 17:58
0

Fira Math is available here.

\documentclass[a4paper, 11pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{unicode-math}
\setsansfont{Calibri}
\setmathfont[mathrm=sym]{Fira Math}
%\setmathfont{GFSNeohellenic Math}
\renewcommand\familydefault{\sfdefault}

\begin{document}
Some math in Sans Serif
$A=3$ 
$\Omega = \rho / \rho_{\text{crit.}}$   
\end{document}

enter image description here

| improve this answer | |
  • Isn't the problem that the OP needs upright letters and numbers? That's how I read the question. – cfr Jul 11 '18 at 3:24
  • @cfr That was how I read it too. But the OP clarified in a comment that the math letters should be italic. – Davislor Jul 11 '18 at 21:09
  • @Davislor Oh, I see. I thought numbers in maths were upright by default :-). I guess that's font-dependent. – cfr Jul 11 '18 at 22:30
  • @cfr Same. Some package must've changed it. – Davislor Jul 11 '18 at 22:53

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.