I am trying to make a macro for typesetting higher-categories, and would like to automatically enclose the optional argument in brackets if it is an expression containing + or -.
In particular I would like to have something like \cat[<optional_rank>]{<name>}
, so that for example \cat{Bord}
, \cat[n]{Fus}
, and \cat[2]{Rep}
typeset Bord, nFus, and 2Rep respectively, but \cat[n+1]{Fus}
and \cat[n-k-2]{Rep}
typeset (n+1)Fus and (n-k-2)Rep respectively.
How can I achieve the automatic bracketing? I am almost sure that the answer will involve xparse
, but I don't know how to do it myself.
For convenience here is a MWE (that does not do exactly what I want yet)
\documentclass{article}
\newcommand{\cat}[2][]{{#1}\mathbf{#2}}
\begin{document}
\(\cat{Bord}\), \(\cat[n]{Fus}\), \(\cat[2]{Rep}\), \(\cat[n+1]{Fus}\), \(\cat[n-k-2]{Rep}\)
\end{document}
xparse
, can we just look for+
and-
? Then someexpl3
string match might be enough (see also thexstring
package)xparse
loaded anyway (since I always load the packagephysics
which requiresxparse
). I don't know how whatexpl3
does, but I'll have a look, thanks.physics
package is not well recommended due to many poor design choices.