9

I have a macro for absolute value (using \DeclarePairedDelimiter from mathtools):

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

This works great in terms of adjusting the size of fences etc. But the superscript position when I use \abs{x}^2 is too high. See the following:

PDF output

Any idea if this is a bug or not, or how I can fix it? Edit: It appears that the above behavior due to the fact that DeclarePairedDelimiter calls \mathclose / makes a subformula. I don't know if this was a design choice or not -- but I would certainly like to know if there is an easy way to work around it.

Here's my code for the above.

\documentclass{minimal}
\usepackage[active,tightpage]{preview}
\usepackage{varwidth,mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\begin{document}
  \begin{preview}\begin{varwidth}{360pt}
    The superscript following \verb'\abs{x}' is higher than that following \verb'\lvert x\rvert'.
    Here is an example:

    \begin{center}
      \verb'\abs{x}^2 \lvert x\rvert^2' produces $\abs{x}^2 \lvert x\rvert^2$.
    \end{center}
    The same happens in displayed math:
    \begin{equation*}
      \abs{x}^2 \lvert x\rvert^2
    \end{equation*}
  \end{varwidth}\end{preview}
\end{document}

Thanks in advance.

9

This is a design choice in mathtools. Not all users know \rvert is better than |, so we help them, also it helps us if someone wanted to use )(as the delimiter pair. Short of repeating the fenced material in a \vpahntom after the fence, I don't know a better method.

But, in this case, as you are using the proper left and right fences, there is an out:

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\reDeclarePairedDelimiterInnerWrapper{\abs}{nostar}{#1#2#3}
  • Thanks. This works. I didn't get what you mean by someone wanting to use )( as the delimiter pair? Do you mean use the parenthesis in the wrong order? – gi1242 Apr 11 '17 at 21:30
  • @gi1242 if ( is the right delimiter in a construction like this (let's call it foo) then the minus in \foo{x} - 2 comes out wrong as ( has the class of a math open and then the minus following it is unitary not additional (wrong spacing). So when you remove the explicit you need to be sure the right delimiter is of type math closing (rvert is) – daleif Apr 11 '17 at 21:35
  • Addition: I meant to write:_if you remove the explicit \mathclose..._ – daleif Apr 12 '17 at 6:08
  • @gi1242 please note that this code will produce an error in the upcomming mathtools update. I had to split nostar into two separate macros. Attempting to change nostar will now give an error. On the other hand your original problem is now fixed. – daleif May 24 '17 at 8:17
4

DeclarePairedDelimiter produces a subformula. EDIT as @Daleif suggested this is due to DeclarePairedDelimiter to call \mathclose on the right brace.

This is equivalent of using braces ({ and }), which also produce math subformulas, which can cause alignment issues sometimes. (Incidentally, that's why you don't usually have adjacent braces {}) in math mode.

See following examples:

\documentclass{minimal}
\usepackage{amsmath,mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\begin{document}

    \begin{gather}
      \left|x\right|^2 \lvert x\rvert^2 \\
      \abs{x}^{2} \lvert x\rvert^{2} \\
      {|x|}^{2} \lvert x\rvert^{2} 
    \end{gather}
\end{document}

Producing:

enter image description here

You can clearly see that the second example (which is your text) and the subformula produce the same alignment.

It seems that the exponent is applied to the whole subformula, and not carried as the exponent of your variable.

  • @Mico Yup, that's caused by DeclarePairedDelimiter creating a subformula, thus I guess that the exponent is applied to the fence and not to the variable. I corrected my post – Moriambar Apr 11 '17 at 20:51
  • 1
    It seems to be due to the fact that \abs is using \mathclose on the right delimiter. Unstarred left/right is not used – daleif Apr 11 '17 at 20:55
  • Thanks. You're right, the subformula has the same alignment of subscripts. is there a way I can get around it? That is can I get \DeclarePairedDelimiter to not create a subformula...? – gi1242 Apr 11 '17 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.