4

I have been reading through mathtools' docs, and they provide an example that declared a paired delimiter that has a default behaviour if blank, using etoolbox:

\DeclarePairedDelimiterX\norm[1]\lVert\rVert{
    \ifblank{#1}{\:\cdot\:}{#1}
}

Then, typing \norm{x} gives

image for latex norm

but typing \norm{} gives

second image for latex norm with cdot

which is pretty handy.

I want to know how this would apply to cases with multiple parameters. For example, suppose I had something simple like:

\DeclarePairedDelimiterX{\inner}[2]{\langle}{\rangle}{#1,#2}

Is there a better way than checking all four cases of missing parameters? Or is there a better way?

Edit: Sorry, I forgot to add my current approach. At the moment, I have

\DeclarePairedDelimiterX{\inner}[2]{\langle}{\rangle}{
    \ifblank{#1}{\:\cdot\:}{#1},
    \ifblank{#2}{\:\cdot\:}{#2}
}

I am not sure this feels right, but I am not experienced enough to know any better. Hence I am hoping to reach out on what would be the better approach.

3
  • " all four cases of missing parameters?" 4?? there are only 2 and as you want to separately test each and use cdot I am not sure what else you could do but have 2 tests? Mar 27, 2023 at 7:50
  • 1
    you have 4 cases only if you want to condition the insertion of the , to one or both of the arguments being empty
    – user691586
    Mar 27, 2023 at 8:14
  • Apologies for the confusion. I meant that because it is a two-parameter command, either one could be missing, both could be missing, or neither could be missing, which is four cases, which I wasn't certain how it would be best handled. Mar 27, 2023 at 9:32

1 Answer 1

7

It is right, but you can dispense with etoolbox, because the current LaTeX kernel has \IfBlankTF for the same purpose.

\documentclass{article}
\usepackage{mathtools}

\newcommand{\blank}{\:{\cdot}\:}

\DeclarePairedDelimiterX{\inner}[2]{\langle}{\rangle}{%
  \IfBlankTF{#1}{\blank}{#1},\IfBlankTF{#2}{\blank}{#2}%
}


\begin{document}

\[
\inner{}{}+\inner{a}{}+\inner{}{b}+\inner{a}{b}
\]

\end{document}

I suggest using an abstraction \blank command, so you can later change your mind about how to represent a void argument.

enter image description here

1
  • Thank you for your advice and feedback. I did not know about \IfBlankTF, so this is interesting to know. Very much appreciated. Mar 27, 2023 at 9:27

You must log in to answer this question.

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