Conditional in LaTeX (\mid)
- LaTeX command
\mid- Package
- No package needed: built into LaTeX
- Mode
- Math mode only
- Copy the Unicode character
- ∣
U+2223
Where it is used
Vertical bar with relation spacing, read as 'given', 'such that' or 'divides'.
Unlike a plain |, \mid adds space on both sides, which is exactly what conditional probability P(A \mid B), set-builder notation \{x \mid x > 0\} and divisibility 3 \mid 12 need. Use | or \vert for absolute values, where no extra space is wanted, and \lvert ... \rvert when the bar brackets something. In set-builder notation with tall content, \middle| between \left\{ and \right\} grows the bar to match. Its negation is \nmid, for does not divide. Many authors use a colon in set-builder notation instead, which avoids confusion when divisibility also appears.
Also listed under: Number Theory, Quantifiers, Computer Science
Minimal compilable example
Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.
\documentclass{article}
\usepackage{amssymb}
\begin{document}
Conditional: $\mid$
\[ \{x \in \mathbb{Z} \mid 3 \mid x\} \]
\end{document}Related symbols
- Given
P(A \mid B) - Independence symbol (double perp)
\perp\!\!\!\perp - Rho
\rho - Perpendicular
\perp - Chi-Squared
\chi^2 - Normal Distribution
\mathcal{N}(\mu, \sigma^2)
Frequently asked questions
- How do I write Conditional in LaTeX?
- Type \mid in math mode, for example $\{x \in \mathbb{Z} \mid 3 \mid x\}$. It works in plain LaTeX without loading any package.
- Which package do I need for \mid?
- None. \mid is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
- Can I use \mid in text mode, or only in math mode?
- Only in math mode. Outside $...$ LaTeX stops with "Missing $ inserted", so write $\mid$ in running text. If you only need the glyph in text, paste the Unicode character ∣ instead (with XeLaTeX or LuaLaTeX and a font that has it).
Pinakamahusay na AI LaTeX Editor, Alternatibo sa Overleaf
Tinutulungan ng Octree ang mga researcher mula sa 15+ na unibersidad na sumulat ng research papers nang mas mabilis gamit ang AI
- Gumawa ng magagandang TikZ diagrams gamit ang AI
- Mag-upload ng larawan at i-convert ito sa LaTeX nang walang problema
- Makakuha ng instant na tulong sa pagsulat at pag-format ng research papers