6

For typesetting the absolute value of $f(x)$, which of the following gives the proper spacing about "$f(x)$"?

$\big\vert f(x) \big\vert$
$\big\lvert f(x) \big\rvert$
$\bigl\lvert f(x) \bigr\rvert$
  • 3
    Usually, I once typed \bigl|...\bigr|, but it is even shorter to define an \abs command with \DeclarePairedDelimiter from mathtools and type \abs[\big]{...} (and it is semantically better). – Bernard Oct 2 '19 at 23:24
  • 1
    never use \big in a document, it is just the internal shared code for \bigl and \bigr, not something to use directly. big is also far too big for f(x), \lvert f{x}\rvert would be better. – David Carlisle Oct 3 '19 at 7:04
  • 1
    @DavidCarlisle \big (or maybe \Big) has its use cases: for instance, one can use f\big|_{A} to denote restriction or “evaluation at”. Besides such cases, most of the times one should use \bigl (opening), \bigr (closing) or else \bigm (relation). – egreg Oct 3 '19 at 7:43
  • 1
    @egreg yes I know but there is a tex tradition to give simple rules first, and break them later:-) – David Carlisle Oct 3 '19 at 8:24
  • 2
    There are other differences, the outer spacing is affected not just the inner eg an operator so \log\vert x \vert is not the same as \log\lvert x \rvert (actually you might prefer the first spacing in that case, but they are different) – David Carlisle Oct 3 '19 at 11:56
7

You asked,

which of the following gives the proper spacing about "$f(x)$"?

$\big\vert f(x) \big\vert$
$\big\lvert f(x) \big\rvert$
$\bigl\lvert f(x) \bigr\rvert$

First off, you actually left off the following, relevant option:

$\bigl\vert f(x) \bigr\vert$

Second, it so happens that if the "math atom" (to use some TeX jargon) that is placed between the vertical bars is f(x), then all four options produce the exact same output.

Third, does the preceding finding mean that writing

$\big\vert <some math atom> \big\vert$

is always typographically ok -- and maybe even best because it's the simplest of the four options? Not at all! To verify this, consider the following MWE (minimum working example):

\documentclass{article}
\usepackage{amsmath} % for '\lvert' and '\rvert' directives
\begin{document}
\obeylines
$\big\vert   -1 \big\vert$ 
$\big\lvert  -1 \big\rvert$
$\bigl\vert  -1 \bigr\vert$
$\bigl\lvert -1 \bigr\rvert$
\end{document}

and its output:

enter image description here

Only the latter two are typographically correct, as they treat the - ("minus") symbols as a unary rather than as a binary operator.

In short, \bigl\vert <some math atom> \bigr\vert is definitely better than \big\vert <some math atom> \big\vert, typographically speaking, as it produces the correct spacing in all cases.

A final remark, prompted by a comment from barbara beeton: For the code examples used here, it's not necessary to increase the size of the vertical bars. However, I'm assuming your real use case involves expressions such as $\bigl\vert -\int_0^1 f(x)\,dx \bigr\vert$.

  • 1
    I appreciate your careful explanation. As you saw, I did not get such an explanation from the pdf file that was suggested to me. – user74973 Oct 3 '19 at 1:52
  • 2
    You might also mention that any "big" is definitely not needed in the case of $-1$ or $f(x) since it won't make any difference in the size of the verts. "big" should probably also not be used for, say, $f(x^2)$ -- it's overkill. – barbara beeton Oct 3 '19 at 2:56
  • @barbarabeeton - You're right, of course. I was hoping -- but didn't say so outright -- that the OP's real use case involves taking absolute values of something (typographically) bigger than f(x) or -1. I'll edit my answer to put in a remark to this effect. – Mico Oct 3 '19 at 4:13
  • Well, you forget the easiest \bigl|-1\bigr|. ;-) Similarly, one can abbreviate \bigl\langle into \bigl< and \bigr\rangle into \bigr>. – egreg Oct 3 '19 at 7:44
  • @barbarabeeton \big? does make a difference: \bigl|-1\bigr| is different from \lvert-1\rvert. No difference in size would be with \left|-1\right|. – egreg Oct 3 '19 at 7:46
6

Differences when \big is used

There's no difference at all between \big|, \big\vert and \big\lvert. The reason is that \big (and also its siblings \Big, \bigg and \Bigg) make an ordinary symbol out of the following delimiter, after forcing it to be a larger size.

Thus whether you use |, \vert or \lvert after \big is immaterial. In the first case TeX looks at the \delcode of |, which is "26A30C. In the second case it looks at the definition of \vert, which is \delimiter"026A30C; the definition of \lvert is \delimiter 69640972 (hexadecimal "426A30C). If we supplement this with the information that the \mathcode of | is "026A we have the whole picture.

How does \big work?

When we say \big<symbol>, the <symbol> can be either a character or a control sequence; if it is a character, it must have a positive \delcode; if it is a control sequence it must be a macro whose meaning starts with \delimiter followed by a 27 bit number. These are the same requirements for something following \left and not by chance: indeed \big<symbol> is realized by doing something like

{\left<symbol><empty box>\right.}

where the <empty box> has suitable vertical size to trigger \left choosing a larger variant. (I'm hiding some detail, as usual.) The braces around the construction make the object an ordinary symbol.

What's the difference between \vert and |?

None, as far as the behavior in math formulas is concerned. They behave as ordinary symbols.

What's the difference between \lvert and \vert?

This is a big one! \lvert is considered as an opening atom; its companion \rvert is a closing atom. The commands have been introduced by amsmath (not by the LaTeX kernel), in order to avoid bad spacing: just considering the output of

|-1|+\vert\sin x\vert

versus

\lvert-1\rvert+\lvert\sin x\rvert

clears up the matter. In the first formula, using | instead of \vert or conversely produces the same output.

How does \bigl work?

With \bigl<symbol>, TeX will do

\mathopen{\left<symbol><empty box>\right.}

that is, the same as before, but with \mathopen acting on the object, which makes it to be spaced correctly. Again it's immaterial whether we use

\bigl|  \bigl\vert  \bigl\lvert

The action of \bigr is similar: with \bigr<symbol> we obtain

\mathclose{\left<symbol><empty box>\right.}

which is appropriate for a closing atom.

There's also \bigm

If we do \bigm<symbol> we obtain

\mathrel{\left<symbol><empty box>\right.}

which is appropriate for the <symbol> used as a relation symbol. For instance, it would be correct to use

\bigl\{ x\in X \bigm| <condition> \bigr\}

in case we need larger fences. Again, \bigm|, \bigm\vert, \bigm\lvert or even \bigm\rvert are exactly the same.

Should I use \lvert and \rvert after \bigl and \bigr?

Yes, we should. But laziness has its merits, so the simpler \bigl| is handier.

Is \big| banned from use?

Not at all! If we want a larger vertical bar to denote restriction of a function or evaluation at a point, we can certainly use \big|, say for

f\big|_{A}
f(x)\big|_{x=0}

(in the second case, perhaps \Big| would be better, but it's a matter of taste).

Graphical examples

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}

\renewcommand{\arraystretch}{1.2}

\begin{tabular}{@{}ll@{}}
Input & Output \\
\midrule
\verb!|-1|+\vert\sin x\vert! &
  $|-1|+\vert\sin x\vert$ \\
\verb!\lvert-1\rvert+\lvert\sin x\rvert! &
  $\lvert-1\rvert+\lvert\sin x\rvert$ \\
\midrule
\verb!\big|-1\big|+\big\vert\sin x\big\vert! &
  $\big|-1\big|+\big\vert\sin x\big\vert$ \\
\verb!\bigl\lvert-1\bigr\rvert+\bigl\lvert\sin x\bigr\rvert! &
  $\bigl\lvert-1\bigr\rvert+\bigl\lvert\sin x\bigr\rvert$ \\
\verb!\bigl|-1\bigr|+\bigl|\sin x\bigr|! &
  $\bigl|-1\bigr|+\bigl|\sin x\bigr|$ \\
\end{tabular}

\end{document}

enter image description here

  • You said "\lvert is considered as an opening atom." Does that change the spacing before the vertical bar in the pdf file? Which of f\bigl|_{x=0}, f\bigl\vert_{x=0}, f\bigl\lvert_{x=0} is preferred? – user74973 Oct 3 '19 at 15:33
  • @user74973 As I wrote in my answer, \big is good for this application – egreg Oct 3 '19 at 16:05
  • What is the difference between f\big|_{x=0} and f\bigl|_{x=0}? – user74973 Oct 3 '19 at 16:40
  • 1
    @user74973 \big| is an ordinary atom; \bigl| is an opening atom that can affect spacing with what follows. – egreg Oct 3 '19 at 16:42
  • 2
    @user74973 Try for yourself \big|_{x=0}\sin y and \bigl|_{x=0}\sin y. The choice would more likely be betwee \big and \bigr; \bigl is out of the question. For this application \big is better. – egreg Oct 3 '19 at 17:20
1

Depending on whether you wish to get long bars or standard bars, use $\bigl\lvert f(x) \bigr\rvert$ or simply $\lvert f(x) \rvert$, respectively.

Further reading: § 4.14.2 "Vertical bar notations" from "User’s Guide for the amsmath Package (Version 2.1)" by AMS, dated 2018-04-05 and typically located in amsldoc.pdf in an installation.

  • Here is the link. – user74973 Oct 3 '19 at 0:46
  • I think that this says that there is no difference in the display in the pdf file. The suggestion is to pick one and consistently use it to represent the absolute value function. Pick another to represent the "divides relation" if you also have something like "$d \vert n$" in the same file. – user74973 Oct 3 '19 at 0:48
  • 1
    @user74973 - On your last question: The answer is NO. Compare the outputs of $\vert -1\vert$ and $\lvert -1\rvert$. Only the latter is typographically correct, as it treats the - symbol as a unary rather than as a binary operator. – Mico Oct 3 '19 at 1:04
  • 1
    @Mico "or" does not create this impression. Still, posting improved. – user49915 Oct 3 '19 at 13:25

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.