24

E.g., I have this set:

\{ \alpha \in \Sigma^\omega | \exists^\omega n : \alpha [0,n] \notin \Sigma^* a_1 \Sigma^* a_2 \dotsb a_n \Sigma^* \}

Here, I use | as the separator for the condition part. But LaTeX doesn't add any spaces around it, thus it looks a bit strange/wrong. I could manually add some space here but I wondered if there is some more "correct" way. E.g. also to make it behave similar as : (which I actually want to behave different here; in this case, : adds too much space in front of it for my taste).


Related questions: here or here.

Albert
  • 2,707

3 Answers3

18

I sometimes do something a little more evil

\documentclass[a4paper]{memoir}
\usepackage{mathtools}
\DeclarePairedDelimiterX\Set[2]{\lbrace}{\rbrace}%
 { #1 \,\delimsize| \,\mathopen{} #2 }
\begin{document}
\[
\Set*{ x }{ x>0 }
\]
\end{document}

and thus hide the symbol inside the construction. Both a starred and non-starred \Set is created with \Set* autoscaling braces and vertical line is used.

Update August 2014: I no longer recommend a two argument solution, but rather this as I feel it gives an interface much closer to the mathematical meaning

\documentclass[a4paper]{memoir}
\usepackage{mathtools}
\providecommand\given{} % so it exists
\newcommand\SetSymbol[1][]{
   \nonscript\,#1\vert \allowbreak \nonscript\,\mathopen{}}
\DeclarePairedDelimiterX\Set[1]{\lbrace}{\rbrace}%
 { \renewcommand\given{\SetSymbol[\delimsize]} #1 }
\begin{document}
\[
\Set*{ x \given x>0 }
\]
\end{document}

BTW: notice the added \mathopen{} withput it \Set{ X \given -a < x < a} would give us the wrong -a (a subtraction minus, not a sign minus)

Update March 2015: Moved the \allowbreak in front of the proceeding inserted space. Then that space disappears if a line break happens.

daleif
  • 54,450
  • Hehe, yea, I actually use some similar construct now. Whereby I used \newcommand. Is there any advantage with \DeclarePairedDelimiterX? – Albert Mar 16 '11 at 15:20
  • 1
    Test the document, it defines more than one command, try \Set[\big]{...}{...} – daleif Mar 16 '11 at 15:23
  • Hm, it seems something is wrong there. I get the error `Runaway argument? ./texdefs.tex:33: Paragraph ended before \DeclarePairedDelimiterX was complete. \par l.33

    ? `

    – Albert Mar 16 '11 at 15:25
  • @Albert: @daleif 's code works OK in my system. The error message suggests that you forgot a closing brace. If that's not the case, we'll need to see the problematic code to detect the problem. – Gonzalo Medina Mar 16 '11 at 15:35
  • My code: \DeclarePairedDelimiterX\SetC[2]{\lbrace}{\rbrace}{ #1 \,\delimsize|\, #2 } – Albert Mar 16 '11 at 15:37
  • @Albert: Well, with just that line we surely can detect any problem; we need a complete, minimal version of the problematic code. – Gonzalo Medina Mar 16 '11 at 15:41
  • @albert: which version of mathtools? It needs version 1.10 from Feb 2011, and earlier version had a similar macro but with different options, it was reimplemented to provide an easier interface. So I guess you need to update your LaTeX installation – daleif Mar 16 '11 at 15:47
  • @daleif: Ah, I guess that's it. It's from 2010. It's the mac distribution here. – Albert Mar 16 '11 at 16:44
  • @albert: then run the updating utility, there should be one in the TeX folder somewhere under the applications folder – daleif Mar 16 '11 at 17:04
  • 1
    There's a closing brace } missing after \given{\SetSymbol[\delimsize] in the second block of code. – Suzanne Soy Feb 09 '16 at 13:17
17

You should use \mid instead of |. And use \colon instead of : after the existential quantifier (although I would just put a thinspace).

Michael Ummels
  • 8,604
  • 3
  • 36
  • 27
  • 1
    I started to use \bigl\{ and \bigr\} now. What about \bigm| instead of \mid? Is there a difference except that it is slightly bigger? – Albert Mar 16 '11 at 15:19
  • 3
    I would think : might be correct there whereas \colon is more for F\colon A\to B – daleif Mar 16 '11 at 15:23
  • 1
    The problem with \mid is that it is not a fence, thus not scalable – daleif Mar 16 '11 at 15:24
  • If you use big braces, you should indeed use \bigm| instead of \mid since \mid is not defined as a delimiter and thus cannot be used with \bigm. – Michael Ummels Mar 16 '11 at 15:24
9

The braket package contains a \set command which does what you want :

\set{\alpha \in \Sigma^\omega | \exists^\omega n : \alpha [0,n] \notin \Sigma^* a_1 \Sigma^* a_2 \dotsb a_n \Sigma^*}

It also defines \Set, where the first | is expandable, which allows to properly typeset sets like

\Set{x| x\in\mathbb R, |x|<\frac12 }
Torbjørn T.
  • 206,688