[Tex/LaTex] Upright bold greek with condition in math mode

etoolboxgreekxstring

Good day!

I googled the whole stackechange, but was not able to find the answer. I'm quite new to Latex, so my approach is not proper. I try to define a macro, that should format greek letter as upright bold. I know there are several ways to do it, I would like to avoid usage of isomath and stick to upgreek package.

I want to be able to write

\gb{\alpha}
\gb{\Alpha}

and in both cases get upright bold characters. So, here is my code inside:

\newcommand{\gb}[1]{ % Imagine #1=\Psi
\StrGobbleLeft{\detokenize{#1}}{1}[\chrcodet] % variable "\Psi"
\StrGobbleRight{\chrcodet}{1}[\chrcode] % variable "Psi"
\StrLeft{\chrcode}{1}[\chrfirst] % first character "P"
\IfSubStr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}{\chrfirst} % Is it capital?
    {\boldsymbol{#1}} % Yes - no modification
    {\boldsymbol{\csname up\chrcode\endcsname}} % No - glue \up+Psi (that what happens!)
}

I'm trying to get the first character of the control sequence and if it's capital, I call just \boldsymbol with no modifications, otherwise I want to modify control sequence by placing \up at the beginning. So, when I do that, it produces the following error

! Undefined control sequence.
\bm@command ->\upPsi

It looks like the "if" condition always gives false, i.e. "P" is not recognized as capital, thus the following MWE will write twice "lowercase":

\documentclass{article}
\usepackage{bm,upgreek}
\usepackage{etoolbox}
\usepackage{xstring}

\newcommand{\gb}[1]{
    \StrGobbleLeft{\detokenize{#1}}{1}[\chrcodet]
    \StrGobbleRight{\chrcodet}{1}[\chrcode]
    \StrLeft{\chrcode}{1}[\chrfirst]
    #1 - \IfSubStr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}{\chrfirst}{uppercase}{lowercase}
}

\begin{document}

\begin{equation}
    \psi,\Psi,\gb{\psi},\gb{\Psi}
\end{equation}

\end{document}

Can anyone give me an idea, why it does not work as expected?

Best Answer

Does not bm just do what you want without any further redefinitions?

enter image description here

\documentclass{article}
\usepackage{bm,upgreek}


\begin{document}

\begin{equation}
    \psi, \uppsi, \Psi,\bm{\psi},\bm{\uppsi},\bm{\Psi}
\end{equation}

\end{document}