Plain | works but LaTeX cannot tell an opening bar from a closing one, so spacing is sometimes off. amsmath's \lvert and \rvert fix that and are in KaTeX. For tall contents use \left| … \right|. The double bar \| is the norm.
All ways to write it
| Command | Use | Package | Copy |
|---|---|---|---|
|x| | plain bars | none | |
\lvert x \rvert | correctly spaced bars | amsmath | |
\left| \frac{a}{b} \right| | scaling bars | none | |
\|x\| | norm | none | |
\lVert x \rVert | correctly spaced norm | amsmath | |
\abs{x} | with the physics or mathtools package | physicsnot in KaTeX |
Commands marked with a package need that \usepackage line in a LaTeX document. “Not in KaTeX” means the command will not render in KaTeX- or MathJax-based tools such as Markdown previews, Jupyter and Confluence math apps; use one of the other forms there.
Example
\left| \frac{x}{y} \right| = \frac{\lvert x \rvert}{\lvert y \rvert}, \qquad \lVert \mathbf{v} \rVert = \sqrt{v_1^2 + v_2^2}Scaling bars around a fraction, and the Euclidean norm.
Questions
Why is the spacing wrong with plain | bars?
| is an ordinary symbol with no left/right identity. Use \lvert…\rvert or \left|…\right| so LaTeX knows which side is which.
Related symbols
- Vertical bar |
| - Divides ∣
\mid - Modulus / mod mod
|z|
Using absolute value in Confluence
Confluence Cloud has no built-in LaTeX. With LaTeX Math for Confluence you add a math macro to any page, type |x| and it renders inline or as a block, with a live preview while you edit. The app uses KaTeX, so pick one of the commands above that is not marked “not in KaTeX”.