9

When I have an operator (\sin,\det, or defined with \operatorname, \DeclareMathOperator) enclosed in |...|, it seems that there is an extra spacing on the left.

See the output of $|\sin x|$ $\lvert \sin x|$ (there is no difference between | and \rvert): enter image description here

I don't like this spacing now that I have noticed it. Is there a way to make |\sin x| output the same as \lvert \sin x| without manually editing each occurence? And similarly for other operators (and of course, without messing up other things)

This seems related to but unanswered by: Spacing before an operatorname macro

Complete MWE:

\documentclass{standalone}
\usepackage{amsmath}
\begin{document}
$|\sin x|$ $\lvert \sin x|$
\end{document}

1 Answers1

14

Typing in

|\sin x|

is a very common error and my eyes bleed every time I see it.

The problem is that | is treated as an ordinary symbol, which makes it handy to type |x|, but fails miserably when one has

|-x|

(try it) because the rule is that a binary operation symbol surrounded by ordinary ones will get \medmuskip space around it. Similarly, if a math operator follows an ordinary symbol, a thin space will be inserted, which is good for

2\sin x

where we don't want the “2” to be attached to the “s”. But the rule applies to |\sin x| as well. No space is inserted between x and |, because they're two ordinary symbols.

A way out would be to type

|{\sin x}|

or, better,

\mathopen|\sin x|

because no space is inserted between an Open atom and an Op atom.

In view of this deficiency, amsmath defines two new kinds of delimiters, namely \lvert and \rvert, in a way that's equivalent to doing \mathopen| and \mathclose| respectively (but not really so, in order to allow having \bigl\lvert, for instance.

Actually, doing \bigl\lvert is the same as \bigl|, because \bigl will give its following symbol the role of an Open atom. Similarly for \bigr\rvert and \bigr|.

So, no, there's not much you can do once your typescript has |\sin x|. You cannot redefine | to become an Open atom, because this would disrupt the instances in which it is used where a Close atom would be (the second one in |\sin x|).

I've trained myself to type in \lvert...\rvert every time.

You might also use mathtools and do

\DeclareMathDelimiter{\abs}{|}{|}

so

\abs{\sin x}

would do the right thing.

egreg
  • 1,121,712