# Line in set definition

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.

• 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`. Sep 5 '13 at 8:48
• quite like `\mod` in fact: `\mid` :-) Sep 5 '13 at 8:48

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 \,\}\$
``````

but

``````\$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:

``````\newcommand{\Set}{%
\{\, #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.

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.