Quantcast
Channel: Check for group as argument (expandable) - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 5

Answer by egreg for Check for group as argument (expandable)

$
0
0

This ignores spaces (but doesn't deal with the edge case):

\documentclass{article}\usepackage{xparse}\ExplSyntaxOn\NewDocumentCommand{\MyIfGroup}{mmm} {  \regex_match:nnTF { \A\s*\cB\{.*\cE\}\s*\Z } { #1 } { #2 } { #3 } }\ExplSyntaxOff\begin{document}\MyIfGroup{{}}{true}{false}   $\to$ true\MyIfGroup{ {}}{true}{false}  $\to$ true\MyIfGroup{{} }{true}{false}  $\to$ true\MyIfGroup{ {} }{true}{false} $\to$ true\MyIfGroup{ }{true}{false}    $\to$ false\MyIfGroup{a}{true}{false}    $\to$ false\MyIfGroup{{}a}{true}{false}  $\to$ false\end{document}

enter image description here

If you want to deal with the edge case and make it return false:

\documentclass{article}\usepackage{xparse}\ExplSyntaxOn\NewDocumentCommand{\MyIfGroup}{mmm} {  \regex_match:nnTF { \A\s*\cB\{.*\cE\}\s*\Z } { #1 }   {    \int_compare:nNnTF { \tl_count:n { #1 } } > { 1 } { #3 } { #2 }   }   { #3 } }\ExplSyntaxOff\begin{document}\MyIfGroup{{}}{true}{false}   $\to$ true\MyIfGroup{ {}}{true}{false}  $\to$ true\MyIfGroup{{} }{true}{false}  $\to$ true\MyIfGroup{ {} }{true}{false} $\to$ true\MyIfGroup{ }{true}{false}    $\to$ false\MyIfGroup{a}{true}{false}    $\to$ false\MyIfGroup{{}a}{true}{false}  $\to$ false\MyIfGroup{{}{}}{true}{false} $\to$ false\end{document}

enter image description here


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>