4

In Short: I can change the math font, but it is not working for numbers.

My document has a few formulae but only basic alphanumeric characters with very limited symbols (square root being the only particular character outside of the most common)

I have looked at the following questions:

And have gotten this far using the mathastext package (I'm on v1.3w):

enter image description here

I have made sure to load mathastext after fontspec.

But, while letters show as expected, numbers still have serifs.

Constraints:

  • I am compiling with LuaLatex due to other packages in the mix

MWE:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{RUBIK-REGULAR}[
    Path=fonts/,
    Extension=.ttf
]
\usepackage{mathastext}
\begin{document}
    \[T=2\sqrt{\frac{D}{A}}\]
    \center{Body Text}
\end{document}
6

You have to load fontspec with the no-math option.

\documentclass{article}
\usepackage[no-math]{fontspec}
%\setmainfont{RUBIK-REGULAR}[
%    Path=fonts/,
%    Extension=.ttf
%]
\setmainfont{Impact} % a random distinctive font on my system
\usepackage{mathastext}


\begin{document}

\[T=2\sqrt{\frac{D}{A}}\]

\begin{center}Body Text\end{center}

\end{document}

By the way, the command \center exists but

  • it has no argument
  • it should only be used implicitly via the center environment

enter image description here

1
  • Thank you, this worked perfectly. The \center was just to create the sample image, I should have removed it from my MWE, apologies for any confusion it may have caused. – agryson Jul 1 '20 at 10:11
2

You could also load

\usepackage[math-style=upright]{unicode-math}

And set the fonts to something like (if you’ve added a Rubik.fontspec file to your project directory):

\defaultfontfeatures{ Scale=MatchUppercase, Ligatures=TeX }
\setmainfont{Rubik}[Scale=1.0]
\setmathfont{Fira Math}
\setmathfont{Rubik}[range=up]

You can add to this any other characters the Rubik font contains, either with a hex code like "FF, a macro name, or a backtick literal. You can also do ranges, so if the font supports all of Latin-1, you could write range={up,"20-"FF}.

If the font you select does not have Greek letters, use instead:

\setmathfont{Rubik}[range=up/{Latin,latin,digits}]
3
  • I have seen "fone" into your answer and after I have understood that the word is font 😄 – Sebastiano Jul 2 '20 at 12:12
  • Nice, if I understand correctly, this would give me total granularity to have a specific character or set of characters in a specific font for formulae ? (That's much more than I need for this specific case but a nice tool to keep in the bag for later. - Thanks!) – agryson Jul 2 '20 at 20:37
  • @agryson Yes. You can also apply any other transformation from fontspec, such as changing their color. – Davislor Jul 2 '20 at 20:41

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.