4

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

  • 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) – Steven B. Segletes Jun 9 '16 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. – thewaywewalk Jun 9 '16 at 17:24
  • @StevenB.Segletes By the way, you should make it a package ;) – thewaywewalk Jun 9 '16 at 17:25
  • Well, a workaround is surely \node {\textcolor{red}{$\upmu$$\mu$}}; – Steven B. Segletes Jun 9 '16 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$}; – Steven B. Segletes Jun 9 '16 at 17:37
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

  • Thank you! Are you aware of this answer? It makes a great addition to you unslant approach as it recognizes also \mathrm. – thewaywewalk Jun 10 '16 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. – Steven B. Segletes Jun 10 '16 at 11:35
5

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

  • If you declare the math symbols like \DeclareMathSymbol{\upGamma}{ ... than you can combine it with this answer - which is great. Thank you! – thewaywewalk Jun 10 '16 at 11:14
  • Your use of \let\varepsilon\epsilon etc means there is no varepsilon provided by the font? – thewaywewalk Jun 10 '16 at 11:27
  • @thewaywewalk Correct – egreg Jun 10 '16 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... – Monte Carlo Nov 21 '16 at 23:45
  • @MonteCarlo The problem are the lowercase letters, I'm not sure there is support for them with cmbr. – egreg Nov 22 '16 at 6:59

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.