12

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?

  • Possible Duplicate: Absolute Value Symbols. – Peter Grill Oct 8 '17 at 8:22
  • 2
    The first is right, the second one can produce unexpected results, the last one is wrong. – egreg Oct 8 '17 at 8:34
  • @egreg ; (+1) Clear and concise, thank you my dear egreg. – Jungle Boy Oct 8 '17 at 9:05
15

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.

  • 2
    Is the spacing for log |x-1| in the first line considered correct? Personally, I find the version in the second line a lot better-looking (for that last formula only). – Federico Poloni Oct 8 '17 at 15:22
  • @FedericoPoloni I consider the absolute value just like a parenthesized expression, so the top is right, but I wouldn't turn down consistent usage like in the second line. – egreg Oct 8 '17 at 15:23
  • Does "so and so" mean "acceptable"? – Ooker Oct 9 '17 at 11:10
  • 1
    @Ooker It means that in some cases it's right, in others it's wrong; precisely, the first is right, the last might be acceptable (see another comment), the middle ones are plainly wrong. – egreg Oct 9 '17 at 11:51
  • Can TeX be complied like programming languages? For example in your example can I use a loop to print the sin, log three times with different cases? – Ooker Oct 9 '17 at 22:07

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.