In the accepted answer to this question a method of swapping the starred and non-starred versions of the macros from \DeclarePairedDelimiter is presented. For example, for the \abs function we could use


This is a nice solution, because the results from \DeclarePairedDelimiter are much better than \left and \right (especially when it comes to spacing), and often the starred version is more desirable than the non-starred so it's best to have it as the default.

Is there a way to combine the above method into a macro that does the swapping automatically? It's not too big a deal in this case, only two lines of code per definition, but it's often considered best practice to define a function or macro to encapsulate processes that are done multiple times. In this case I would think that a suitable macro would look something like:



I could then go on to define lots of delimiters, one line each. However, the above code produces an error, and in hindsight it was obviously not going to work because \abs is taken as an input and not defined. How can I fix my definition of \DeclarePairedDelimiterSwapped so that it actually defines commands? Alternatively, let me know if this is not an easy fix.

  • Trust me: you don't want to swap. Using indiscriminately autosizing delimiters is a good road to bad math typography.
    – egreg
    Commented May 7, 2021 at 20:24

1 Answer 1


You can do it. But should you? Look at \abs{\hat{f}} and judge for yourself.


 {% first define \DeclarePairedDelimiter on a different command
  \exp_args:Nc \DeclarePairedDelimiter { eddy @ \cs_to_str:N #1 } { #2 } { #3 }
  % now define your swapped command
    \IfBooleanTF { ##1 }
     {% * is used, ignore the optional argument
      \use:c { eddy @ \cs_to_str:N #1 } { ##3 }
     {% no *
      \IfNoValueTF { ##2 }
       {% no optional argument
        \use:c { eddy @ \cs_to_str:N #1 } * { ##3 }
       {% optional argument
        \use:c { eddy @ \cs_to_str:N #1 } [ ##2 ] { ##3 }



\abs{\frac{1}{2}} % auto sizing
\abs{\hat{f}} % auto sizing
\abs*{\hat{f}} % no auto sizing
\abs[\big]{1} % big size
\abs[\Big]{\frac{1}{2}} % Big size


enter image description here

This is just one of the reasons why the autosizing feature should be used with great care and not used indiscriminately.

Now that you know, use the plain \DeclarePairedDelimiter and add * only when really needed (that is, very rarely).

You must log in to answer this question.

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