# Sans serif and serif greek fonts in math expression

I am wondering how to alternate sans and serif greek fonts within mathematical expressions. The package sansmathfonts changes the font to the whole document, which I don't want to. I have read related posts and I think one has to define a special math alphabet, say \mathsfgreek, in some sense similarly to

\SetSymbolFont{letters}{sans}{OML}{cmbrm}{m}{it}.


I tried to use something like \usefont with similar parameters without success. I would like to have the choice between sans normal (upright), sans italic, sans bold normal, and sans bold italic, which should all be available in cmss. I would like to write something like

$\alpha\mathsfgreek{\alpha}$


where \alpha on the left is normal and \alpha on the right is sans (upright). Can you give me some hint?

Thank you!

Declare a new symbol font:

\documentclass{article}

\usepackage{amsmath}

\DeclareSymbolFont{sfletters}{OML}{cmbrm}{m}{it}

\DeclareMathSymbol{\salpha}{\mathord}{sfletters}{"0B}
\DeclareMathSymbol{\sbeta}{\mathord}{sfletters}{"0C}
\DeclareMathSymbol{\sgamma}{\mathord}{sfletters}{"0D}
\DeclareMathSymbol{\sdelta}{\mathord}{sfletters}{"0E}
\DeclareMathSymbol{\sepsilon}{\mathord}{sfletters}{"0F}
\DeclareMathSymbol{\szeta}{\mathord}{sfletters}{"10}
\DeclareMathSymbol{\seta}{\mathord}{sfletters}{"11}
\DeclareMathSymbol{\stheta}{\mathord}{sfletters}{"12}
\DeclareMathSymbol{\siota}{\mathord}{sfletters}{"13}
\DeclareMathSymbol{\skappa}{\mathord}{sfletters}{"14}
\DeclareMathSymbol{\slambda}{\mathord}{sfletters}{"15}
\DeclareMathSymbol{\smu}{\mathord}{sfletters}{"16}
\DeclareMathSymbol{\snu}{\mathord}{sfletters}{"17}
\DeclareMathSymbol{\sxi}{\mathord}{sfletters}{"18}
\DeclareMathSymbol{\spi}{\mathord}{sfletters}{"19}
\DeclareMathSymbol{\srho}{\mathord}{sfletters}{"1A}
\DeclareMathSymbol{\ssigma}{\mathord}{sfletters}{"1B}
\DeclareMathSymbol{\stau}{\mathord}{sfletters}{"1C}
\DeclareMathSymbol{\supsilon}{\mathord}{sfletters}{"1D}
\DeclareMathSymbol{\sphi}{\mathord}{sfletters}{"1E}
\DeclareMathSymbol{\schi}{\mathord}{sfletters}{"1F}
\DeclareMathSymbol{\spsi}{\mathord}{sfletters}{"20}
\DeclareMathSymbol{\somega}{\mathord}{sfletters}{"21}
\DeclareMathSymbol{\svarepsilon}{\mathord}{sfletters}{"22}
\DeclareMathSymbol{\svartheta}{\mathord}{sfletters}{"23}
\DeclareMathSymbol{\svarpi}{\mathord}{sfletters}{"24}
\DeclareMathSymbol{\svarrho}{\mathord}{sfletters}{"25}
\DeclareMathSymbol{\svarsigma}{\mathord}{sfletters}{"26}
\DeclareMathSymbol{\svarphi}{\mathord}{sfletters}{"27}

\begin{document}

$\alpha\salpha\beta\sbeta\gamma\sgamma$

\end{document}


You can define a \msf command:

\documentclass{article}

\usepackage{amsmath}

\DeclareRobustCommand{\msf}[1]{%
\ifcat\noexpand#1\relax\msfgreek{#1}\else\mathsf{#1}\fi
}
\makeatletter
\newcommand{\msfgreek}[1]{\csname s\expandafter\@gobble\string#1\endcsname}
\makeatother

\DeclareSymbolFont{sfletters}{OML}{cmbrm}{m}{it}

\DeclareMathSymbol{\salpha}{\mathord}{sfletters}{"0B}
\DeclareMathSymbol{\sbeta}{\mathord}{sfletters}{"0C}
\DeclareMathSymbol{\sgamma}{\mathord}{sfletters}{"0D}
\DeclareMathSymbol{\sdelta}{\mathord}{sfletters}{"0E}
\DeclareMathSymbol{\sepsilon}{\mathord}{sfletters}{"0F}
\DeclareMathSymbol{\szeta}{\mathord}{sfletters}{"10}
\DeclareMathSymbol{\seta}{\mathord}{sfletters}{"11}
\DeclareMathSymbol{\stheta}{\mathord}{sfletters}{"12}
\DeclareMathSymbol{\siota}{\mathord}{sfletters}{"13}
\DeclareMathSymbol{\skappa}{\mathord}{sfletters}{"14}
\DeclareMathSymbol{\slambda}{\mathord}{sfletters}{"15}
\DeclareMathSymbol{\smu}{\mathord}{sfletters}{"16}
\DeclareMathSymbol{\snu}{\mathord}{sfletters}{"17}
\DeclareMathSymbol{\sxi}{\mathord}{sfletters}{"18}
\DeclareMathSymbol{\spi}{\mathord}{sfletters}{"19}
\DeclareMathSymbol{\srho}{\mathord}{sfletters}{"1A}
\DeclareMathSymbol{\ssigma}{\mathord}{sfletters}{"1B}
\DeclareMathSymbol{\stau}{\mathord}{sfletters}{"1C}
\DeclareMathSymbol{\supsilon}{\mathord}{sfletters}{"1D}
\DeclareMathSymbol{\sphi}{\mathord}{sfletters}{"1E}
\DeclareMathSymbol{\schi}{\mathord}{sfletters}{"1F}
\DeclareMathSymbol{\spsi}{\mathord}{sfletters}{"20}
\DeclareMathSymbol{\somega}{\mathord}{sfletters}{"21}
\DeclareMathSymbol{\svarepsilon}{\mathord}{sfletters}{"22}
\DeclareMathSymbol{\svartheta}{\mathord}{sfletters}{"23}
\DeclareMathSymbol{\svarpi}{\mathord}{sfletters}{"24}
\DeclareMathSymbol{\svarrho}{\mathord}{sfletters}{"25}
\DeclareMathSymbol{\svarsigma}{\mathord}{sfletters}{"26}
\DeclareMathSymbol{\svarphi}{\mathord}{sfletters}{"27}

\begin{document}

$\alpha\salpha\beta\sbeta\gamma\sgamma$

$\alpha\msf{\alpha}x\msf{x}$

\end{document}


Uppercase Greek is not covered, here. Exercise for the reader. ;-)

• Hi egreg, thank you for your reply. However, in your proposed method, I have to manually write a different name for the greek letter (e.g. \ssigma instead of \sigma). Is there a way to automate it? (e.g. writing \mathsf{\alpha} uses \salpha instead of \alpha: it seems to be a natural behavior for the \mathsf command, isn't it?). – Monte Carlo Oct 25 '16 at 16:22
• It is OK with me to define all different commands, also for capital letters, but then eventually the end user shouldn't remember all the different cases (imagine having \sSigma and also \supsigma and so on). She should just write \mathsf{\Sigma} and get the capital, sans \Sigma. Then for upright letters there's a different new symbol font I guess. I can do it by myself if I have the command for the lower case letters. – Monte Carlo Oct 25 '16 at 16:24
• Is it useful to use \SetMathAlphabet, e.g. something along the line of \SetMathAlphabet{\mathsf}{normal}{\math@lph@encoding}{\mathsf@lph}{m}{n} ? (just an idea) – Monte Carlo Oct 25 '16 at 19:14
• @MonteCarlo No, it can't work. – egreg Oct 25 '16 at 19:30
• Ok, so probably the only thing I can do is as follows (let me know your opinion): 0) use the new symbol font approach you proposed; 1) define a command \sansfont that can take latin or greek letters; 2) use \ifcat\noexpand#1\relax to check whether the argument is latin or greek (not very robust but it works as long as we are aware that the argument has to be a latin or greek letter); 3) if the argument is a latin letter, use \mathsf; 4) otherwise, modify (in some way I am unaware of) the argument (which is a greek letter) by adding an s at the beginning, e.g. from \alpha to \salpha – Monte Carlo Oct 26 '16 at 0:07