I'm currently trying to write a command using xparse, which translates into
\A
\A{Test}
\mathbb{A}
\mathbb{A}(Test)
Also the full functionality of paired delimiters should work (\A[\Big]{Test}
or \A*{Test}
). I already found a way to achieve the desired behaviour:
\usepackage{xparse}
\DeclarePairedDelimiter{\parens}{(}{)}
\NewDocumentCommand{\A}{sog}{%
\operatorname{\mathbb{A}}%
\IfValueT{#3}{%
\IfBooleanTF{#1}%
{\parens*{#3}}%
{\parens[#2]{#3}}}
}
Now, I'm wondering whether there is a way to write this code more elegantly (for example without passing the star manually).
g
is deprecated and not in the pre-loaded version It is still available if you loadxparse
package for compatibility but we recommend not using it in new code.g
?{}
delimited arguments shouldn't be optional (breaks so many latex syntax assumptions), so the recommended syntax would be\A[\big]{text}, \A{}
so making the text argument mandatory, but dropping the parens when it is empty, or making it optional so\A[\big][text]
but that form might be messy to code with the * form as well.semantex
, is more or less built to create commands of the type you mention. Note that it does useg
-type argument, despite the LaTeX3 team’s recommendations, as I do not agree with the team that this practise should be deprecated. I, on the other hand, find theg
-syntax entirely natural.