2

I notice that, in math mode (i.e., in quarto, $$...$$ or $...), letters and numbers are being set in a default font irrespective of the mainfont or mathfont. Thus, variable names and numbers are being typeset in a different font.

mathfont does have effect on math operators, e.g. \log will be typeset using the mathfont. However, letters and numbers are not. Is this expected behavior?

I know a workaround. That is to use \mathit{} for the entire equation, then use \mathrm{} for numbers that need to be upright. Then it looks right, but it makes the coding so much more heavy (than it already may be).

Compile the following document to see the issue:

---
documentclass: article
mainfont: Lato
mathfont: Lato
---
$$ y = 123\cdot\log{x} $$
$$ \mathit{y = \mathrm{123}\cdot\log{x}} $$

(Eventually substitute your own font). The second equation looks how it ought to be. In the irst equation, only operators (log) use the mathfont. Other items use a default "latex" font (the same you have when not specifying a mainfont).

vanadium
  • 178
  • 5

2 Answers2

3

Not every font contains the necessary math symbols, Lato does not contain them. You'll see a warning like this in your .log file:

Package fontspec Warning: Font "Lato" does not contain requested Script
(fontspec)                "Math".

In particular for sans serif fonts, there aren't a lot to choose from and the few which exist are often incomplete.

One sans serif font which provides a fairly good coverage is Fira Math (... but it's design might be a bit polarizing)

---
documentclass: article
mainfont: Lato
mathfont: Fira Math
format:
  pdf
---
$$ y = 123\cdot\log{x} $$
$$ \mathit{y = \mathrm{123}\cdot\log{x}} $$

enter image description here


If you'd like to use the letters and numbers from the text font in math mode, you could use the mathastext package:

% !TeX TS-program = lualatex
\documentclass{article}

\usepackage[no-math]{fontspec}
\setmainfont{Lato}
\usepackage{mathastext}

\begin{document}

\[ y = 123\cdot\log{x} \] 

\end{document}

enter image description here

  • Thank you for your reply. My question, however, is not as much about the specific coice of font, but by the fact that I seem unable to select the font of letters and numbers in equations in xelatex pdf output (quarto default). Operators, (like "log") are rendered by the mathfont specified, no problem there. Letters and numbers for me are always rendered in the default font, and I seem not able to control that. Many fonts obviously will support letters and numbers. – vanadium Jan 31 '23 at 09:41
  • You are able to select the font for letters and numbers, but the font you choose does not have them so it will fall back on computer modern. Operators are by default not rendered by the math font, but with upright font. While most fonts will have letters and numbers for text, most are lacking the necessary series for math. The characters used in math and text are not the same. – samcarter_is_at_topanswers.xyz Jan 31 '23 at 09:48
  • If you want to use text letters and numbers in math mode, you could use the `mathastext` package, but using this in quarto might be painful because of the all the unnecessary and interfering packages it loads by default.... – samcarter_is_at_topanswers.xyz Jan 31 '23 at 09:51
  • Thank you. Your feedback has given me more insight in how it works. Indeed, it is a matter of selecting a font that has math support, and matches the mainfont somewhat better. I accepted your anwser, thanks again! – vanadium Jan 31 '23 at 15:40
  • https://github.com/abccsss/LatoMath this repo contains an open type version of lato with math support, but I was not able to find this on ctan. – Apoorv Potnis Mar 07 '23 at 11:02
  • @ApoorvPotnis You should post an answer :) – samcarter_is_at_topanswers.xyz Mar 07 '23 at 12:22
  • @ApoorvPotnis ... and maybe add it to https://tex.stackexchange.com/questions/425098/which-opentype-math-fonts-are-available – samcarter_is_at_topanswers.xyz Mar 07 '23 at 13:29
  • 1
    @ApoorvPotnis Great! Just curios: why did you delete your answer to this post? It was really nice! (if you would undelete it, I could add a quarto version to your answer...) – samcarter_is_at_topanswers.xyz Mar 07 '23 at 14:05
  • My answer didn't really answer the question; I don't know about the quarto thing. But since you are willing to help, I will undelete it. Thanks. – Apoorv Potnis Mar 07 '23 at 18:10
  • @ApoorvPotnis I added a short example how to use it in quarto to your answer. Behind the scenes, quarto already uses the `unicode-math` package, so one really only needs to tell it the name of the font. The important part of your answer is that you were able find this font. – samcarter_is_at_topanswers.xyz Mar 07 '23 at 19:24
  • @ApoorvPotnis You're welcome! I also added a second place where one can download the .oft file and removed the sentence about the font not being on ctan. As unicode math requires either xelatex or lualatex, one has access to all system fonts. This means one can simply install the font on one's computer and is not limited to what is on ctan. – samcarter_is_at_topanswers.xyz Mar 07 '23 at 19:42
  • Ah! Being new to GitHub, I didn't look for the `.otf` file in Releases and had to compile it on my own. – Apoorv Potnis Mar 07 '23 at 21:28
2

There exists math support in open type format for Lato: Lato Math.

The generated .otf file can be downloaded from: LatoMath.otf or Github release.

In traditional latex, it can be used like this:

\documentclass{article}

\usepackage{unicode-math}
\setmainfont{Lato}
\setmathfont{LatoMath.otf}

\begin{document}
    \section{Some section header.}
    The quick brown fox jumps over the lazy dog.
    THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
    1234567890
    \begin{align*}
        \oint_{\gamma} \sum_{i=0}^n \int \bigcup \bigcap \\
        \symup{\alpha \beta \gamma \delta \epsilon \zeta \eta \theta \iota \kappa \lambda \mu \nu \xi \omega \pi \rho \sigma \phi \psi \tau \omega}\\
        \alpha \beta \gamma \delta \epsilon \zeta \eta \theta \iota \kappa \lambda \mu \nu \xi \omega \pi \rho \sigma \phi \psi \tau \omega \\
        \partial \hbar \symbb{R, C, N, Z, Q}
    \end{align*}
    $$ y = 123\cdot\log{x} $$
    $$ \mathit{y = \mathrm{123}\cdot\log{x}} $$
\end{document}

latomath


In Quarto, one can use this font like this:

---
documentclass: article
mainfont: Lato
mathfont: Lato Math
format:
  pdf
---
$$ y = 123\cdot\log{x} $$

enter image description here

Apoorv Potnis
  • 243
  • 1
  • 11