In a package of mine there are many lines of code like this:
\lowercase{\IfStrEqCase{#1}}{%
{cn}{\PJLlang@langconfig@SC}%
{chinese}{\PJLlang@langconfig@SC}%
{schinese}{\PJLlang@langconfig@SC}%
{simplifiedchinese}{\PJLlang@langconfig@SC}%
{tc}{\PJLlang@langconfig@TC}%
...
The code receives a string (like "Chinese" or "SC"), converts it to the corresponding abbreviation (like "SC"), and run the corresponding command. Since code of this type appears quite a lot in this package, as an attempt to simplify the code, I defined a command \StrToABBR
for this propose:
\NewDocumentCommand{\StrToABBR}{m}{%
\expandafter\lowercase{\IfStrEqCase{#1}}{%
{cn}{SC}%
{chinese}{SC}%
{schinese}{SC}%
...
}%
}
However, as @moewe pointed out in the comment of this question, it is not expandable and thus cannot appear in \csname...\endcsname
, thus \csname PJLlang@langconfig@\StrToABBR{#1}\endcsname
won't work. In the comment of the same question, Ulrike Fischer suggests to use etoolbox
or expl3
. Thus I wish to ask that how should I define \StrToABBR
with expl3
to allow it appear in \csname...\endcsname
?