1

Very similar to this question I would like to have a different, sans serif math font in (small) parts of my document. As suggested by this answer to said question, this can be acieved using \DeclareMathAlphabet and the Computer Modern fonts as follows.

\documentclass{article}

\DeclareMathVersion{sans}
\SetSymbolFont{operators}{sans}{OT1}{cmbr}{m}{n}
\SetSymbolFont{letters}{sans}{OML}{cmbrm}{m}{it}
\SetSymbolFont{symbols}{sans}{OMS}{cmbrs}{m}{n}
\SetMathAlphabet{\mathit}{sans}{OT1}{cmbr}{m}{sl}
\SetMathAlphabet{\mathbf}{sans}{OT1}{cmbr}{bx}{n}
\SetMathAlphabet{\mathtt}{sans}{OT1}{cmtl}{m}{n}
\SetSymbolFont{largesymbols}{sans}{OMX}{iwona}{m}{n}

\begin{document}

1234 CQ $1234 CQ$

\sffamily\mathversion{sans}
1234 CQ $1234 CQ$

\end{document}

Computer modern example


However, in my document, I would like to use Roboto as the sans serif font. Doing so results in noticable differences between the document and the math font.

\documentclass{article}

\usepackage[light,medium]{roboto}

\DeclareMathVersion{sans}
\SetSymbolFont{operators}{sans}{OT1}{cmbr}{m}{n}
\SetSymbolFont{letters}{sans}{OML}{cmbrm}{m}{it}
\SetSymbolFont{symbols}{sans}{OMS}{cmbrs}{m}{n}
\SetMathAlphabet{\mathit}{sans}{OT1}{cmbr}{m}{sl}
\SetMathAlphabet{\mathbf}{sans}{OT1}{cmbr}{bx}{n}
\SetMathAlphabet{\mathtt}{sans}{OT1}{cmtl}{m}{n}
\SetSymbolFont{largesymbols}{sans}{OMX}{iwona}{m}{n}

\begin{document}

1234 CQ $1234 CQ$

\sffamily\mathversion{sans}
1234 CQ $1234 CQ$

\end{document}

Roboto example 1

Note, for example, the different shapes of digit 1 or letter Q. Obviously, I would like to have the math and the document sans serif font as similar as possible. This will certainly not work (easily) for special symbols, but getting numbers, letters and ideally greek letters from the Roboto font would already be great.


Changing the first \SetSymbolFont, I can already get one step closer.

\documentclass{article}

\usepackage[light,medium]{roboto}

\DeclareMathVersion{sans}
\SetSymbolFont{operators}{sans}{OT1}{Roboto-LF}{l}{n}
\SetSymbolFont{letters}{sans}{OML}{cmbrm}{m}{it}
\SetSymbolFont{symbols}{sans}{OMS}{cmbrs}{m}{n}
\SetMathAlphabet{\mathit}{sans}{OT1}{cmbr}{m}{sl}
\SetMathAlphabet{\mathbf}{sans}{OT1}{cmbr}{bx}{n}
\SetMathAlphabet{\mathtt}{sans}{OT1}{cmtl}{m}{n}
\SetSymbolFont{largesymbols}{sans}{OMX}{iwona}{m}{n}

\begin{document}

1234 CQ $1234 CQ$

\sffamily\mathversion{sans}
1234 CQ $1234 CQ$

\end{document}

Roboto example 2

Now the numbers are from the correct font! Trying the same approach for the second \SetSymbolFont fails, however.

\SetSymbolFont{letters}{sans}{OML}{Roboto-LF}{l}{it}

results in

LaTeX Font Warning: Font shape `OML/Roboto-LF/l/it' undefined
(Font)              using `OML/cmm/m/it' instead on input line 19.

and the missing font is evident from the output.

Roboto example 3

Is there any way I can also get letters (and greek letters) in the right font?


In case there are approaches both with pdflatex and xelatex/lualatex, I would be mainly interested in pdflatex, since I am also using the microtype package, which is well-known to be not fully compatible with xelatex/lualatex. If the latter can do the thing, but pdflatex cannot, I may still look into ditching microtype, though.

ranguwud
  • 367
  • Can't be done. (At least, cannot be done in any way you could possibly want to do it.) OML is a maths encoding. Roboto is not provided in that encoding (presumably it will lack many of the characters required). – cfr Nov 28 '19 at 01:15
  • That's what I suspected might be the answer. Is this also true for xelatex? From what I understand, unicode-math can be used with any font, but I may be mistaken in that. Could \DeclareMathVersion be translated to that scenario? – ranguwud Nov 28 '19 at 10:09
  • unicode-math needs a maths font(s) i.e. something with a MATH font table. I don't know if you could use it to take letters from a non-maths font. mathspec (I think the name is) might be an option. However, I don't know that that would make it any easier. You could presumably redeclare a bunch of maths stuff, but you could do that anyway. – cfr Nov 29 '19 at 00:52

0 Answers0