[Tex/LaTex] Difference between symbols for absolute value

symbols

I know all of the following are used for showing the absolute value:

  • $\lvert x \rvert$
  • $| x |$
  • $\mid x \mid$

I myself think that there is another one \abs; but I can't use this last one.

What is the difference between them?

Best Answer

You ask for the differences and here's an analysis for them.

First let's get rid of the last case: \mid is a relation symbol like = or < and TeX adds spaces around it that disqualify the command from being used for the absolute value.

The other two seem good, but the first one is better as it doesn't need precautions. The fact is that | is considered an ordinary symbol, whereas \lvert is an opening (like [) and \rvert is a closing (like ]).

Let's compare some cases.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$\begin{array}{lllll}
\text{good} &
  \lvert x\rvert\le 1 & \lvert-1\rvert=1 &
  \lvert\sin x\rvert & \log\lvert x-1\rvert \\[3ex]
\text{so and so} &
  |x|\leq 1 & |-1|=1 & |\sin x| & \log|x-1| \\[3ex]
\text{wrong} &
  \mid x\mid \leq 1 & \mid -1\mid =1 &
  \mid \sin x\mid  & \log\mid x-1\mid
\end{array}$

\end{document}

You can see in the picture that \lvert and \rvert produces the right spacing in all cases, whereas |...| doesn't. Not to speak about \mid.

Using | would force you to input

|{-1}|
|{\sin x}|
\log\!|x-1|

enter image description here

You can define \abs as suggested in answers to Absolute Value Symbols but I recommend not to follow the suggestion of making \left and \right automatic, because it will most of the time choose a wrong size.