17
$\begingroup$

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.

$\endgroup$
  • 10
    $\begingroup$ 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. $\endgroup$ – Xander Henderson Aug 21 at 18:17
  • 1
    $\begingroup$ Also it depends on, if you want it to scale or not. Sometimes left and right commands get involved. $\endgroup$ – Roddy MacPhee Aug 21 at 18:32
  • 1
    $\begingroup$ en.m.wikipedia.org/wiki/Vertical_bar#Usage $\endgroup$ – Roddy MacPhee Aug 21 at 18:37
  • 2
    $\begingroup$ 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. $\endgroup$ – quid Aug 21 at 19:16
  • $\begingroup$ I saw this on the sidebar and expected it to be about black, galvanized, PVC, and other pipe materials. $\endgroup$ – Ross Millikan Aug 21 at 22:24
  • 1
    $\begingroup$ @Ross, and you expected to vote to close it as off-topic, I imagine. $\endgroup$ – Gerry Myerson Aug 22 at 0:54
  • 1
    $\begingroup$ 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 |.) $\endgroup$ – Misha Lavrov Aug 24 at 0:22
  • $\begingroup$ No mention of vector norm $\|\vec v\|$? $\endgroup$ – Wood Aug 30 at 19:42
16
$\begingroup$

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.

See also:

$\endgroup$
  • 2
    $\begingroup$ This is a community wiki post, if somebody has further additions and improvements, feel free to edit them. $\endgroup$ – Martin Sleziak Aug 22 at 4:11
  • 3
    $\begingroup$ 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). $\endgroup$ – Arturo Magidin Aug 22 at 22:35
  • $\begingroup$ 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. $\endgroup$ – Bill Dubuque Aug 23 at 3:13
  • 1
    $\begingroup$ 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. $\endgroup$ – Arturo Magidin Aug 23 at 3:56
  • 2
    $\begingroup$ @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. $\endgroup$ – Martin Sleziak Aug 23 at 5:43
  • 4
    $\begingroup$ @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.) $\endgroup$ – Harald Hanche-Olsen Aug 23 at 6:20
  • $\begingroup$ @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). $\endgroup$ – Bill Dubuque Aug 23 at 15:01
  • 2
    $\begingroup$ @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\,\}$." $\endgroup$ – Arturo Magidin Aug 23 at 15:12
5
$\begingroup$

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .