Define an expandable string case changing function. Here
\ExplSyntaxOn\NewExpandableDocumentCommand{\Titlecasestring}{m} { \str_uppercase:f { \str_head:e { #1 } } \str_tail:e { #1 } }\cs_generate_variant:Nn \str_head:n { e }\cs_generate_variant:Nn \str_tail:n { e }\ExplSyntaxOff
With \str_head:e
you first expand the argument and then take the first item in the obtained string. Strings are used here because the construct is to be used inside \csname
.
Full code.
\usepackage{pgfopts}\usepackage{iftex}\RequireLuaTeX\newcommand*{\keymwe@selectunits}{}\newcommand*{\keymwe@selectprecision}{}\newcommand*{\keymwe@selectapproximate}[2]{#1}\newcommand*{\keymwe@selectprecise}[2]{#2}\newcommand*{\keymwe@selectbaseunits}[3]{#1}\newcommand*{\keymwe@selectderivedunits}[3]{#2}\newcommand*{\keymwe@selectalternateunits}[3]{#3}\NewDocumentCommand{\AlwaysUseBaseUnits}{} {\renewcommand*{\keymwe@selectunits}{\keymwe@selectbaseunits}}\NewDocumentCommand{\AlwaysUseDerivedUnits}{} {\renewcommand*{\keymwe@selectunits}{\keymwe@selectderivedunits}}\NewDocumentCommand{\AlwaysUseAlternateUnits}{} {\renewcommand*{\keymwe@selectunits}{\keymwe@selectalternateunits}}\NewDocumentCommand{\AlwaysUseApproximateConstants}{} {\renewcommand*{\keymwe@selectprecision}{\keymwe@selectapproximate}}\NewDocumentCommand{\AlwaysUsePreciseConstants}{} {\renewcommand*{\keymwe@selectprecision}{\keymwe@selectprecise}}\NewDocumentCommand{\HereUseBaseUnits}{ m }{\begingroup\AlwaysUseBaseUnits#1\endgroup}\NewDocumentCommand{\HereUseDerivedUnits}{ m }{\begingroup\AlwaysUseDerivedUnits#1\endgroup}\NewDocumentCommand{\HereUseAlternateUnits}{ m }{\begingroup\AlwaysUseAlternateUnits#1\endgroup}\NewDocumentCommand{\HereUseApproximateConstants}{ m }{\begingroup\AlwaysUseApproximateConstants#1\endgroup}\NewDocumentCommand{\HereUsePreciseConstants}{ m }{\begingroup\AlwaysUsePreciseConstants#1\endgroup}\NewDocumentEnvironment{UseBaseUnits}{}{\AlwaysUseBaseUnits}{}\NewDocumentEnvironment{UseDerivedUnits}{}{\AlwaysUseDerivedUnits}{}\NewDocumentEnvironment{UseAlternateUnits}{}{\AlwaysUseAlternateUnits}{}\NewDocumentEnvironment{UseApproximateConstants}{}{\AlwaysUseApproximateConstants}{}\NewDocumentEnvironment{UsePreciseConstants}{}{\AlwaysUsePreciseConstants}{}\newif\ifusingpreciseconstants\pgfkeys{ /keymwe/options/.cd, initial@setup/.style={ /keymwe/options/buffered@units/.initial=alternate, }, initial@setup, preciseconstants/.is if=usingpreciseconstants, units/.is choice, units/.default=derived, units/alternate/.style={/keymwe/options/buffered@units=alternate}, units/base/.style={/keymwe/options/buffered@units=base}, units/derived/.style={/keymwe/options/buffered@units=derived}, .unknown/.code={% \typeout{}% \typeout{keymwe: You used unknown option '\pgfkeyscurrentname'.}% },}\ProcessPgfPackageOptions{/keymwe/options}\ExplSyntaxOn\NewExpandableDocumentCommand{\Titlecasestring}{m} { \str_uppercase:f { \str_head:e { #1 } } \str_tail:e { #1 } }\cs_generate_variant:Nn \str_head:n { e }\cs_generate_variant:Nn \str_tail:n { e }\ExplSyntaxOff\newcommand*{\keymwe@do@setup}{% \csname AlwaysUse\Titlecasestring{\pgfkeysvalueof{/keymwe/options/buffered@units}}Units\endcsname \typeout{keymwe: You will get \pgfkeysvalueof{/keymwe/options/buffered@units}\space units.}% \ifusingpreciseconstants \AlwaysUsePreciseConstants \typeout{keymwe: You will get precise constants.}% \else \AlwaysUseApproximateConstants \typeout{keymwe: You will get approximate constants.}% \fi \typeout{}%}%\keymwe@do@setup\NewDocumentCommand{\keymwesetup}{ m }% {% \IfValueT{#1}% {% \pgfqkeys{/keymwe/options}{#1}% \typeout{}% \typeout{keymwe: keymwesetup options...}% \keymwe@do@setup }% }