This question already has an answer here:

Does anyone know an easy way to check if an item is a member in a comma-separated list?

Something like this would be excellent:


The above would expand to true since elem1 is in the list.


marked as duplicate by David Carlisle, Alenanno, Svend Tveskæg, user13907, Henri Menke Jan 11 '16 at 16:46



LaTeX has such a test built in already, so you just need to define your requested syntax:






  • 1
    actually The question is a duplicate (and Heiko's answer there covers this) I'll vote to close. – David Carlisle Jan 11 '16 at 15:53

Here's a quick expl3 (well, xparse method, for checking whether the second argument is in the list. However, the clist-variable would be in a command macro, usually,otherwise you would know if it is in the list.



  \clist_set:Nx \l_tmpa_clist {#1}
  \clist_if_in:NnTF \l_tmpa_clist {#2} {#3} {#4}


