There are many ways to type a pipe. You could use \$|\$ ($|$), \$\vert\$ ($\vert$), \$\mid\$ ($\mid$), or just a plain | (not surrounded by dollar signs). You could also use vmatrix to indicate matrix determinants.
I wanted to know when is it appropriate to use each type of pipe on Mathematics Stack Exchange. For example, pipes can be used in the following cases:
- To indicate that one integer is a factor (or divisor) of another (e.g. $2|4$)
- To indicate conditions in set notation (e.g. $Dom(\sqrt{x}) = \{x \in \mathbb{R} \mid x \ge 0\}$)
- To indicate absolute value (e.g. $|-2019| = |2019| = 2019$)
- To indicate the cardinality of a set (e.g. $|\emptyset|=0$)
- To indicate the order of an element of a group (e.g. $\forall x \in K_4 ((x=e) \lor (|x|=2))$, where $K_4$ is the Klein four-group)
- To indicate the determinant of a square matrix (e.g. $\begin{vmatrix} 2 & 3\\5 & 7 \end{vmatrix}=-1$)
There is also of course the double pipe symbol ($||$), which is used for logical or in programming, concatenation, and parallel lines; and should not be confused with the number eleven.
|-2|
for $|-2|$ you should use|{-2}|
for $|{-2}|$, solving the spacing issue. (Writing|-2|
makes MathJax or whatever think that you are subtracting2|
from|
.) $\endgroup$