I am in the process of writing a macro which takes a 4 digit hex value and does something based on the input. I want to achieve, that a user can use uppercase or lowercase characters for the hex code. What already works is:
\documentclass{article}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\actionForHEX}{m}{%
\str_case:nnF {#1}
{
{E085} {This is E085}
{E086} {This is E086}
}
{Unknown}
}
\ExplSyntaxOff
\begin{document}
Works: \actionForHEX{E085}
Does not work: \actionForHEX{e085}
\end{document}
So in principal I can define actions, but I do not understand the use of \str_flipcase:n to allow the case to work for lowercase as well.
Based on Expandable case insensitive switch case for string comparison I tried something, but this had no success at all:
\ExplSyntaxOn
\NewDocumentCommand{\actionForHEX}{m}{%
\str_case_e:nn { \str_foldcase:e { #1 } }
{
{E085} {This is E085}
{E086} {This is E086}
}
}
\ExplSyntaxOff
Ok, based on your input I tried my luck again, but it seems I still don't understand something. This is my new approach:
\documentclass{article}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\actionForHEX}{m}{%
\str_case:nnF { \str_foldcase:n { #1 } }
{
{e085} {This~is~E085}
{e086} {This~is~E086}
}
{Cannot~find~it}
}
\ExplSyntaxOff
\begin{document}
Does not work: \actionForHEX{E085}
Does not work: \actionForHEX{e085}
\end{document}
This results in Canot find it for both calls of \actionForHEX

e085ande086, resp.? – cgnieder May 11 '20 at 03:59\str_foldcaseyou case-fold the input, now your comparison text must be case-folded as well. Case folding is largely based on lowercase, so you need to compare againste085ande086. If you want to use\str_foldcase:eyou'll need\cs_generate_variant:Nn \str_foldcase:n { e }as in the linked answer. You probably also want to writeThis~is~E085to get spaces between the words. – moewe May 11 '20 at 04:52\str_case_e:nnF {\str_foldcase:n{#1}}? This results in an undefined control sequence for\actionForHEX– TobiBS May 11 '20 at 10:08\str_foldcase:n, otherwise the comparison will be between the literal strings\str_foldcase:n{e085}ande085. Try\exp_args:Ne \str_case:nnF { \str_foldcase:n { #1 } }– Phelype Oleinik May 11 '20 at 11:51\exp_argswas introduced in May 2018 and\str_foldcaseNovember 2019. Hence they are both not available with TeX Live 2017 and a MikTeX version from early 2018 that I used. Thanks for explaining the misconception about expansion and sorry for not seeing earlier, that this is a problem of the used version. – TobiBS May 11 '20 at 12:32\exp_args:Ne \str_case:nnF { \str_foldcase:n { #1 } }and\str_case:enF { \str_foldcase:n { #1 } }(after\cs_generate_variant:Nn \str_case:nn { en })? – moewe May 12 '20 at 06:29\prg_generate_conditional_variant:Nnninstead). Also you can omit trailingnandNwhen generating variants – Phelype Oleinik May 12 '20 at 11:34