[Tex/LaTex] Sans serif upright greek in math mode

fontsgreekmath-mode

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

Best Answer

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