5

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!

1 Answer 1

5

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}

enter image description here

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. ;-)

9
  • 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?). Oct 25, 2016 at 16:22
  • 1
    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. Oct 25, 2016 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) Oct 25, 2016 at 19:14
  • @MonteCarlo No, it can't work.
    – egreg
    Oct 25, 2016 at 19:30
  • 1
    @Matifou Did you try \mathsf{\Gamma}?
    – egreg
    Apr 11, 2022 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .