This question is an extension of conditionals inside newcommand with empty argument

I have a macro that looks like


It is the third input where I would like to perform conditionals. If #3 is empty, I want nothing (not even the round brackets).

A desired output for

\item $\pcs{a}{b}{c}$
\item $\pcs{a}{b}{}$

should look like

enter image description here

  • 2
    use etoolbox, then \ifblank{#3}{}{^{(#3)}} might be what you are after. Note that here I'd use ^{\smash{(}#3\smash{)}} as the ^{(...)} often gets excessively large and disturbs line spacing.
    – daleif
    Commented Sep 18, 2023 at 14:19
  • 1
    You don't need to load etoolbox with a reasonable up to date LaTeX installation. You can use \IfBlankF{#3}{^{(#3)}} instead.
    – Skillmon
    Commented Sep 18, 2023 at 14:28
  • @Skillmon I know it had something similar, just could not remember if it was public
    – daleif
    Commented Sep 18, 2023 at 14:40

1 Answer 1


If your last argument is only optional you might as well define it as an optional argument.


\NewDocumentCommand \pcs { m m o } {{#1}_{#2}\IfValueT{#3}{^{(#3)}}}

$\pcs{a}{b}[c]$ and $\pcs{a}{b}$

enter image description here

  • This is really useful and convenient. Thanks a lot!
    – Sayan
    Commented Sep 19, 2023 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .