I'm trying convert an argument to lowercase, strip out the spaces, and then search for the resulting string in a list. Thus far, I've had no luck.

Here's the code I would instinctively expect to work:


\StrDel{#1}{ }[\temp]


I would expect that to print yes, but it does not.

I've found numerous questions also dealing with this topic, but so far none of the solutions have worked for me. The closest I came to a solution was in \uppercase does not work with \IfSubStr?, but trying to alter that solution to my code just resulted in both yes and no being printed. I also made some slight progress with Pass a macro (with arguments) as an argument for another macro, but ultimately failed in the end there as well.

If there's a better way to strip spaces, force case, and check in a list of things, I am entirely open to something completely different. I have no real reason to stick with any of the commands I'm currently using over any others.

  • Are you open to expl3 features? – user31729 Jan 6 '16 at 23:14
  • \lowercase is not expandable. You should lowercase the string in advance, then do the search. – egreg Jan 6 '16 at 23:14
  • @ChristianHupfer I don't know anything about expl3 to know why I'd be opposed, so I suppose not – SnoringFrog Jan 6 '16 at 23:33
  • @SnoringFrog: It's the 'new' LaTeX 'programming syntax -- quite powerful ;-) – user31729 Jan 6 '16 at 23:37

The primitive \lowercase is not expandable; you have to first lowercase the argument and then use the lowercased string:



  \StrDel{\temp}{ }[\temp]%




\checkinlist{o N e}

\checkinlist{o N f}


enter image description here

  • I tried something like this at one point, but was using \def\temp{\lowercase{#1}}. Putting lowercase on the outside never occurred to me. – SnoringFrog Jan 6 '16 at 23:29

Here's an expl3 version



\newcommand{\mylist}{one,two,three, egreg was faster}

  \tl_set:Nx \l_tmpa_tl {\text_lowercase:n {#1}} %transform the list lowercase
  \clist_set:Nx \l_tmpa_clist {\l_tmpa_tl} % make a real list
  \tl_set:Nx \l_tmpb_tl {\text_lowercase:n {#2}} % lower case second arg
  \clist_if_in:NVTF \l_tmpa_clist {\l_tmpb_tl} {Yes!} {No!} % Check if #2 is in the list



\CheckInList{\mylist}{Egreg was faster}

\CheckInList{\mylist}{Should egreg get the tick?}


enter image description here

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.