# When should each type of vertical bar (pipe) be used?

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.

• Honestly, I think that this might be a better question for either the main site, or (even better) the TeX sister sister. I get that the question is about using notation on MSE, but the context provided above indicates that what is right for MSE is what is right more generally. – Xander Henderson Aug 21 '19 at 18:17
• Also it depends on, if you want it to scale or not. Sometimes left and right commands get involved. – Roddy MacPhee Aug 21 '19 at 18:32
• en.m.wikipedia.org/wiki/Vertical_bar#Usage – Roddy MacPhee Aug 21 '19 at 18:37
• On tex.se one finds for example tex.stackexchange.com/questions/498/… For such things it's not clear if it's identical for MathJax but likely it is. Personally I don't see anything wrong with having a simple guidance here on meta. – quid Aug 21 '19 at 19:16
• I saw this on the sidebar and expected it to be about black, galvanized, PVC, and other pipe materials. – Ross Millikan Aug 21 '19 at 22:24
• @Ross, and you expected to vote to close it as off-topic, I imagine. – Gerry Myerson Aug 22 '19 at 0:54
• Aside from the main question of which pipe to use, rather than |-2| for $|-2|$ you should use |{-2}| for $|{-2}|$, solving the spacing issue. (Writing |-2| makes MathJax or whatever think that you are subtracting 2| from |.) – Misha Lavrov Aug 24 '19 at 0:22
• No mention of vector norm $\|\vec v\|$? – Wood Aug 30 '19 at 19:42

Since you asked about some specific meanings when the vertical line appears:

• For divisibility, you use \mid (and \nmid) for "does not divide". For example, $a\mid b$ $$a\mid b$$, $4\mid8$ $$4\mid8$$, $4\nmid7$ $$4\nmid7$$. The advantage over typing just $4|8$ $$4|8$$ is that \mid yields extra spacing (but some authors prefer $$4|8$$).
• For conditions in set notation, use again \mid. (However, other symbols are also used for this purpose, not just vertical bar.)
• For absolute value, you can use simply |, for example, $|x+2|+|x-2|=4$ $$|x+2|+|x-2|=4$$. Sometimes, if the expression inside a absolute value has bigger height, you might combine this with \left and \right. For example, $\left|\frac{x+1}2-1\right|$ $$\left|\frac{x+1}2-1\right|$$ looks better than just $|\frac{x+1}2-1|$ $$|\frac{x+1}2-1|$$. You can also use \lvert and \rvert. $\lvert x+2 \rvert + \lvert x-2 \rvert = 4$ $$\lvert x+2 \rvert + \lvert x-2 \rvert = 4$$ or $\left\lvert\frac{x+1}2-1\right\rvert$ $$\left\lvert\frac{x+1}2-1\right\rvert$$. You can treat the order of a group or the cardinality of a set in the same way.
• For determinants, you can use vmatrix environment. For example, $$\begin{vmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{vmatrix}$$ is obtained using

$$\begin{vmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{vmatrix}$$

Although MathJax is different from LaTeX, many things which can be used in LaTeX apply also in MathJax. So if you find some advice on math mode in LaTeX, it is reasonable to try them also here.

• This is a community wiki post, if somebody has further additions and improvements, feel free to edit them. – Martin Sleziak Aug 22 '19 at 4:11
• I don't like \mid for divides because of the extra space around it. I generaly use either \vert or \divides. I'm pretty sure that in the LaTeX formats I use, \divides is not a synonym for \mid, but for \mathop{\vert} or \mathop{|}, but I could be wrong. Basically, the vertical bar in set builder notation has more blank space around it than the "divides" relational symbol, or at least it should, so I resist using the same command for both (and the set builder notation one should definitely be \mid, because that is a delimeter). – Arturo Magidin Aug 22 '19 at 22:35
• For "divides" both the "little space" and "extra space" \mid are used in popular number theory textbooks so there does not seem to be any standard. In particular, it is wrong to call one the "correct spacing". That's merely a personal opinion. – Bill Dubuque Aug 23 '19 at 3:13
• Good thing the word “correct” doesn’t appear in my comment, and it starts with “I don’t like”, thus expressing my personal opinion. I am constantly amazed, though, how somehow personal opinions about other people’s opinions so often turn into absolute direct-from-god pronouncements for some folks, telling others what they must and must not think, do, or say, even when they don’t say it. On this and oh so many other topics past and present. – Arturo Magidin Aug 23 '19 at 3:56
• @ArturoMagidin Well, an advantage of a CW post is that it is edited by the community - so if I originally got something wrong/incomplete, it can be edited by others. Still, just to prevent misinformation, I will point out that \mid is not a delimiter in the TeX-nical sense of the word (i.e., the construction with \left\mid...\right\mid does not work). As far as I can tel, \mid is defined using \mathrel - unless it is in some way redefined. – Martin Sleziak Aug 23 '19 at 5:43
• @MartinSleziak TeXnically, \mid is \mathchar"326A. That is class 3, i.e., a relation. So you're mostly right. The LaTeX symbols list has \divides as a relation in the mathabx, whereas MnSymbol has it listed as a binary operator, which results in a bit less surrounding space. (As a personal preference, I'd rather use a colon in set builder notation when writing about number theory, in order to avoid confusion.) – Harald Hanche-Olsen Aug 23 '19 at 6:20
• @Arturo (and readers). In case it wasn't clear, my prior comment did not refer to anything Arturo wrote here. Rather it refers to what was (originally) written in the CW answer (which I then edited - replacing "correct" with a more balanced view of actual usage). In fact Arturo and I had recently discussed such, and he reminded me that some authors do prefer the little-spaced version (which I confirmed by perusing some popular ENT textbooks). – Bill Dubuque Aug 23 '19 at 15:01
• @MartinSleziak: Yes, in the TeX-nichal sense, \mid is a relational symbol; you need to use \Bigm| or \middle| for resizable delimeters. Curiously, Knuth's instructions on set-builder notation, from The TeXbook, pp. 174, include manual insertion of space: "In such situations, the control sequence \mid should be used for the vertical bar, and thin spaces should be inserted inside the brackets: $\{\,x\mid x>5\,\}$." – Arturo Magidin Aug 23 '19 at 15:12

I believe the word "pipe" is used more in computer science than in mathematics.

Unlike the strict syntax requirement in programming languages, how to type out this vertical bar in mathematical writing is mostly about typographical consideration. There are discussions regarding different commands in this question at https://tex.stackexchange.com. Mathematically, it does not really matter.

• Yes,I know the term "pipe" from using Unix long ago. But nowadays mathematicians will not know that "pipe" means $\vert$. – GEdgar Aug 23 '19 at 13:39
• As an R programmer, I expected "pipe" to mean %>% – David Aug 29 '19 at 14:56