6

I need to write a document with the Helvetica font and found sansmathfonts to be good matching counterpart for math, but I'm open for other suggestions.

Now I'm really struggling to get sans serif upright greek letters in math-mode. Is there any way to achieve that?

For serif fonts I was previously using either upgreek or this great answer. Both are not working for helvet+sansmathfonts.

\documentclass{article}

\usepackage[utf8]{luainputenc}
\usepackage[T1]{fontenc}
\usepackage{siunitx}
\usepackage{sansmathfonts}
\usepackage[scaled=0.95]{helvet}
\renewcommand{\familydefault}{\sfdefault}

\usepackage{upgreek}

\begin{document}

Upright greek in math mode:
$\mathrm{\mu\alpha\beta\gamma}$, $\upmu\upalpha\upbeta\upgamma$, 

\end{document}

MWE regarding Steven B. Segletes comment:

\documentclass{article}

\usepackage[utf8]{luainputenc}
\usepackage[T1]{fontenc}
\usepackage{siunitx}
\usepackage{sansmathfonts}
\usepackage[scaled=0.95]{helvet}
\renewcommand{\familydefault}{\sfdefault}

\usepackage{tikz}

\usepackage{scalerel}
\newsavebox{\foobox}
\newcommand{\slantbox}[2][0]{\mbox{%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\newcommand\unslant[2][-.2]{%
  \mkern1mu%
  \ThisStyle{\slantbox[#1]{$\SavedStyle#2$}}%
  \mkern-1mu%
}

\newcommand\upmu{\unslant\mu} 

\begin{document}

Upright greek in math mode: $\mathrm{\mu}$, $\upmu$, 

\begin{tikzpicture}
\node[color=red,] {$\upmu$$\mu$};
\end{tikzpicture}

\end{document}

enter image description here

8
  • If you are using pdflatex (which it seems you are not), my answer here is a direct fix: tex.stackexchange.com/questions/145926/…. (Note: for this font, set the default \unslant optional argument value to -.2) Jun 9, 2016 at 16:59
  • @StevenB.Segletes It actually works also with lualatex. The problem I always have with this solution when used with tikz (I tried it in multiple situations in the past) is that the letters do not adapt the color of nodes. Do you know how to fix that? I updated my MWE. Jun 9, 2016 at 17:24
  • @StevenB.Segletes By the way, you should make it a package ;) Jun 9, 2016 at 17:25
  • Well, a workaround is surely \node {\textcolor{red}{$\upmu$$\mu$}}; Jun 9, 2016 at 17:27
  • I think that would make a good question as to why \slantbox does not take on a tikz node's color. It obeys \textcolor and \color outside of tikz, For something real interesting, try \node[color=red,] {$\upmu$$\mu$ and \textcolor{red}{$\upmu$}$\mu$}; Jun 9, 2016 at 17:37

2 Answers 2

2

This answer comes following discussion in the comments to the question, to which I refer the reader. I pointed out that my solution at Upright Greek font fitting to Computer Modern works directly at unslanting a font (it is based on Bruno's answer at Shear transform a "box"). I show there how to apply it to greek letter forms, but noted that it only applies to pdflates, whereas the OP had lualatex invocations in the preamble.

The OP then tells me that the \unslant method works in lua as well (halle-lua-jah), but that the underlying \slantbox has a problem accepting the color of tikz nodes. That was news to me, since \slantbox accepts color just fine as part of a \textcolor argument, or following a \color declaration.

I then came across a pgf bug report, https://sourceforge.net/p/pgf/bugs/362/, that would seem to be related to the problem. Since I can't solve that problem myself, I looked for a workaround.

Heiko's answer at How to save the current colour shows a cool technique of \colorlet{slantcolor}{.} to save the current color (before going into the \mbox, and then I just re-issued a \color{slantcolor} inside the \foobox. That seemed to fix the problem.

To recap, the \unslant method allows existing italic letters to be made upright in the same font design, and the \colorlet fix allows this solution to work with colored tikz nodes. The overall approach works with pdflatex and lualatex.

\documentclass{article}
%\usepackage[utf8]{luainputenc}
\usepackage[T1]{fontenc}
\usepackage{siunitx}
\usepackage{sansmathfonts}
\usepackage[scaled=0.95]{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{tikz}
\usepackage{scalerel}
\newsavebox{\foobox}
\newcommand{\slantbox}[2][0]{\colorlet{slantcolor}{.}\mbox{%
        \sbox{\foobox}{\color{slantcolor}#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\newcommand\unslant[2][-.2]{%
  \mkern1mu%
  \ThisStyle{\slantbox[#1]{$\SavedStyle#2$}}%
  \mkern-1mu%
}
\newcommand\upmu{\unslant\mu} 
\begin{document}
Upright greek in math mode: $\mathrm{\mu}$, $\upmu$, 

\begin{tikzpicture}
\node[color=red,] {$\upmu$$\mu$};
\end{tikzpicture}
\end{document}

enter image description here

6
  • Thank you! Are you aware of this answer? It makes a great addition to you unslant approach as it recognizes also \mathrm. Jun 10, 2016 at 11:15
  • @thewaywewalk Thank you. And no, I was not aware of the answer, though I am certainly aware of wipet's proficiency at such things. That looks like a really useful approach. Jun 10, 2016 at 11:35
  • I have two questions: (1) Does this work with any sans serif font? (2) What’s the purpose of the scaling in \usepackage[scaled=0.95]{helvet}? May 7, 2020 at 23:39
  • And two more, if you don’t mind: (3) Why do \Bbb and \mathbb not work when I use this preamble? (4) Why does \mathbf not seem to do anything to Greek letters? May 7, 2020 at 23:47
  • 1
    @gen-zreadytoperish 1) To use \mathbb, you need \usepackage{amssymb}. 2) The scale= literally scales the font size uniformly (as I understand it), because for some reason, the helvet font seemed too large to the OP. 3) As to \mathbf, not all fonts have a bold version...generally, greek math letters do not. 4) Finally, \slantbox should work with any font. May 8, 2020 at 0:10
6

You can use CB fonts

\documentclass{article}

\usepackage[scaled=0.95]{helvet}
\usepackage{sansmathfonts}
\renewcommand{\familydefault}{\sfdefault}

\DeclareFontEncoding{LGR}{}{}
\DeclareSymbolFont{sfgreek}{LGR}{cmss}{m}{n}
\SetSymbolFont{sfgreek}{bold}{LGR}{cmss}{bx}{n}
\DeclareMathSymbol{\alpha}{\mathord}{sfgreek}{`a}
\DeclareMathSymbol{\beta}{\mathord}{sfgreek}{`b}
\DeclareMathSymbol{\gamma}{\mathord}{sfgreek}{`g}
\DeclareMathSymbol{\delta}{\mathord}{sfgreek}{`d}
\DeclareMathSymbol{\epsilon}{\mathord}{sfgreek}{`e}
\DeclareMathSymbol{\zeta}{\mathord}{sfgreek}{`z}
\DeclareMathSymbol{\eta}{\mathord}{sfgreek}{`h}
\DeclareMathSymbol{\theta}{\mathord}{sfgreek}{`j}
\DeclareMathSymbol{\iota}{\mathord}{sfgreek}{`i}
\DeclareMathSymbol{\kappa}{\mathord}{sfgreek}{`k}
\DeclareMathSymbol{\lambda}{\mathord}{sfgreek}{`l}
\DeclareMathSymbol{\mu}{\mathord}{sfgreek}{`m}
\DeclareMathSymbol{\nu}{\mathord}{sfgreek}{`n}
\DeclareMathSymbol{\xi}{\mathord}{sfgreek}{`x}
\DeclareMathSymbol{\omicron}{\mathord}{sfgreek}{`o}
\DeclareMathSymbol{\pi}{\mathord}{sfgreek}{`p}
\DeclareMathSymbol{\rho}{\mathord}{sfgreek}{`r}
\DeclareMathSymbol{\sigma}{\mathord}{sfgreek}{`s}
\DeclareMathSymbol{\tau}{\mathord}{sfgreek}{`t}
\DeclareMathSymbol{\upsilon}{\mathord}{sfgreek}{`u}
\DeclareMathSymbol{\phi}{\mathord}{sfgreek}{`f}
\DeclareMathSymbol{\chi}{\mathord}{sfgreek}{`q}
\DeclareMathSymbol{\psi}{\mathord}{sfgreek}{`y}
\DeclareMathSymbol{\omega}{\mathord}{sfgreek}{`w}
\let\varepsilon\epsilon
\let\vartheta\theta
\let\varpi\pi
\let\varrho\rho
\DeclareMathSymbol{\varsigma}{\mathord}{sfgreek}{`c}
\let\varphi\phi
\DeclareMathSymbol{\Gamma}{\mathalpha}{sfgreek}{`G}
\DeclareMathSymbol{\Delta}{\mathalpha}{sfgreek}{`D}
\DeclareMathSymbol{\Theta}{\mathalpha}{sfgreek}{`J}
\DeclareMathSymbol{\Lambda}{\mathalpha}{sfgreek}{`L}
\DeclareMathSymbol{\Xi}{\mathalpha}{sfgreek}{`X}
\DeclareMathSymbol{\Pi}{\mathalpha}{sfgreek}{`P}
\DeclareMathSymbol{\Sigma}{\mathalpha}{sfgreek}{`S}
\DeclareMathSymbol{\Upsilon}{\mathalpha}{sfgreek}{`U}
\DeclareMathSymbol{\Phi}{\mathalpha}{sfgreek}{`F}
\DeclareMathSymbol{\Psi}{\mathalpha}{sfgreek}{`Y}
\DeclareMathSymbol{\Omega}{\mathalpha}{sfgreek}{`W}



\begin{document}

Upright greek in math mode:
$\mu\alpha\beta\gamma$

$\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda\mu$

$\nu\xi\omicron\pi\rho\sigma\varsigma\tau\upsilon\phi\chi\psi\omega$

$\mathrm{A}\mathrm{B}\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

\end{document}

enter image description here

5
  • If you declare the math symbols like \DeclareMathSymbol{\upGamma}{ ... than you can combine it with this answer - which is great. Thank you! Jun 10, 2016 at 11:14
  • Your use of \let\varepsilon\epsilon etc means there is no varepsilon provided by the font? Jun 10, 2016 at 11:27
  • @thewaywewalk Correct
    – egreg
    Jun 10, 2016 at 11:27
  • @egreg This is a wonderful solution. I was wondering whether there is some version for cmbr instead of cmss... by browsing the babel folder (e.g. in lib/texmf/tex/generic/babel) it seems that there is everything (cmr, cmtt, even cmro...) but cmbr... I'm wondering why... Nov 21, 2016 at 23:45
  • @MonteCarlo The problem are the lowercase letters, I'm not sure there is support for them with cmbr.
    – egreg
    Nov 22, 2016 at 6:59

You must log in to answer this question.

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