When using document command arguments for case distinctions I routinely have been using the \str_case:nn function, which works fine as is evident from the output of the \myStrCase command. When attempting to use the \tl_case:Nn function instead, by loading the argument into a _tl type variable, things go miserably wrong. The variable seems to be loaded with the correct value, and is then flagged as correct as far as the \tl_case:Nn function is concerned, but the corresponding code is not executed. Why?

\tl_new:N \l_rn_Aux_tl
    \str_case:nnTF {#1}
  }  %  \myStrCase
    \tl_set:Nx \l_rn_Aux_tl {#1}
checking~what~was~passed:~\l_rn_Aux_tl \\
    \tl_case:NnTF \l_rn_Aux_tl
        emph {\textit{#2}}
        Emph {\textbf{\textit{#2}}}
        uline {\underline{#2}}
  }  %  \myTlCase
\subsection{using str\_case:}
  \myStrCase{Hi There}\\
  \myStrCase[emph]{Hi There}\\
  \myStrCase[Emph]{Hi There}\\
  \myStrCase[uline]{Hi There}\\
  \myStrCase[xxx]{Hi There}
\subsection{using tl\_case:}
  \myTlCase[emph]{Hi There}\\
  \myTlCase[xxx]{Hi There}

The documentation (interface3) already contains your answer:

\tl_case:NnTF <test token list variable>
<token list variable case1> {<code case1>}
<token list variable case2> {<code case2>}
<token list variable casen> {<code casen>}
{<true code>}
{<false code>}

You will find "token list variable" and not "token list" therein. Hence you are asked to provide one token (a variable/N-type argument). So to use this construction you would need to save your options into variables and use these within \tl_case.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.