TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying a simple definition of a set.

My try: $M=\{x\,|\,1\le x\le p-2\}$

Is there a more comfortable way of getting a little space before and after the |? I'm thinking of something like the \mod which does the spacing on its own.

share|improve this question
The correct command to use is \mid: \{x\mid 1\le x\le p-2\}. Many people add thin spaces (that is, \,) after \{ and before \} when using \mid. – egreg Sep 5 '13 at 8:48
quite like \mod in fact: \mid :-) – David Carlisle Sep 5 '13 at 8:48
up vote 9 down vote accepted

The vertical bar is usually produced by using \mid, which prints the same symbol as | (or \vert, which is a synonym).

The difference is that \mid is treated as a relation symbol, so it will have thick spaces on its sides:

$M = \{ x \mid 1 \le x \le p-2 \}$

Many people (including Knuth) recommend adding thin spaces in order to detach the braces when using a condition with \mid:

$M = \{\, x \mid 1 \le x \le p-2 \,\}$


$X = \{1,2,3,4\}

when listing elements. Take your pick. For a small number of set denotations in the document this should not be a problem; but when there are many of them it's better to add a command, in order to ensure uniformity:

  \{\, #1 \mid #2 \, \}%

(the % aren't really necessary in this case) so you can call

$M = \Set{x}{1\le x\le p-2}$

and forget about the details. You'll also have the advantage that, if a fussy copy editor says they want colons and not vertical bars, it will be just a matter of changing \mid into : in the definition of \Set.

In a paper I was fine tuning for publication in a conference proceedings volume, sets were denoted in three different ways: sometimes the separation was with the bar, sometimes with a colon, sometimes with a semicolon. Being consistent in notation is a necessity, not an option.

share|improve this answer

An interesting option for you may be to load the braket package and use its commands \set and \Set. The lowercase-spelled version, \set, uses fixed-size (small) curly braces and central vertical bars; the uppercase-spelled version lets the "fence" symbols grow automatically with the material they enclose.

You could thus enter an expression such as

$M=\set{x|1\le x\le p-2}$

and let the package do the job of formatting the expression properly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.