7

I’m trying to define an abs command for absolute values using DeclarePairedDelimiter from the mathtools package, but I’m running into some spacing issues.

I’d normall write \sup_n \abs{a_n} defined by \DeclarePairedDelimiter{\abs}{\lvert}{\rvert}. But then there is some space missing.

Actual output.

I would instead expect the following output, which I get using \sup_n |a_n|.

Expected output

With \sup_n {\abs{a_n}} this issue does not appear, but I find this additional pair of curly braces too cumbersome. I also tried some variations, but both versions of \abs seem to have the same issue.

\documentclass[a4paper,10pt]{scrartcl}

\usepackage{mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\altabs}{|}{|}

\begin{document}
\[
  \sup_n |a_n|              \quad % expected output
  \sup_n \abs{a_n}          \quad
  \sup_n {\abs{a_n}}        \quad % expected output
  \sup_n \lvert a_n \rvert  \quad
  \sup_n \altabs{a_n}       \quad
  \sup_n {\altabs{a_n}}           % expected output
\]
\end{document}

Complete output

Where is this problem coming from, and how can I get DeclarePairedDelimiter to give the right spacing?

3
  • 5
    The fact is that the space should not be there: if you use the proper \sup_n\lvert a_n\rvert, you see it. Just like \sup(a_1,\dots,a_n) should not have space.
    – egreg
    Commented Nov 26, 2018 at 11:33
  • 1
    In addition to egregs comment, remember that |...| is not the correct syntax for absolute value. | is a normal symbol (an ord), whereas \lvert and \rvert are | with type math open and math close respectfully (just as ()). When \sub sees an ord like a letter or | it inserts a space, whereas it does not insert a space when it sees something of type math open. Internally \DeclarePairedDelimiter will always make the fences into open and close types which is why your \abs and \altabs gives the same result.
    – daleif
    Commented Nov 26, 2018 at 11:56
  • I guess then that my latex code does not properly reflect what I actually want to express: I understand something like “sup(f)” as “sup( ) applied to f”, but “sup |f|” as “sup (written without paratheses) applied |f|”, not as “sup| | applied to f”. Hence I expect the same spacing for both “sup f” and “sup |f|”. Commented Nov 26, 2018 at 12:19

1 Answer 1

10

There should be no space between the operator name and a delimiter, so the output one gets from

\sup_{n}\lvert a_{n}\rvert

is right (and is one of the reasons why amsmath introduced \lvert and \rvert to begin with).

On the other hand, you may like the thin space when the delimiter is a vertical bar. Easy enough: add a dummy \mathop{} before it.

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{mathtools}

\DeclarePairedDelimiter{\absinner}{\lvert}{\rvert}
\DeclarePairedDelimiter{\altabsinner}{|}{|}

\newcommand{\abs}{\mathop{}\absinner}
\newcommand{\altabs}{\mathop{}\altabsinner}

\begin{document}
\[
  \sup_n |a_n|              \quad % expected output
  \sup_n \abs{a_n}          \quad
  \sup_n {\abs{a_n}}        \quad % expected output
  \sup_n \altabs{a_n}       \quad
  \sup_n {\altabs{a_n}}           % expected output
\]

\begin{alignat*}{3}
a_n - \abs{a_n} &\quad& a_n-\lvert a_n\rvert &\quad& a_n-|a_n|\\
 -\abs{a_n} && -\abs{a_n} && -|a_n|
\end{alignat*}

\end{document}

enter image description here

I'd not do it myself, though.

3
  • Is there a reason why you chose an \mathop{} instead of just {}? Commented Dec 1, 2018 at 11:31
  • 1
    @JendrikStelzner Try and see the differences in the examples.
    – egreg
    Commented Dec 1, 2018 at 11:36
  • 1
    I ended up going with this solution but used \DeclarePairedDelimiterXPP to place the dummy \mathop{}. Commented Apr 16, 2019 at 22:45

You must log in to answer this question.

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