Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am looking for a pipe symbol that can be made to vary in height automatically.

One of the common ways of writing "such that" in mathematics is with the pipe symbol (|). The pipe can be represented in LaTeX directly as the character | or as \vert, but neither of these expands vertically in math presentation mode. I can adjust it manually this way:

\[\mathcal{H}=\left\lbrace h(x)=\sum_{i=0}^{k-1}a_{i}x_{i}\mod m\ \Bigg\vert
     \ a_{i}\in\mathbb{Z}_{m^{k}}\right\rbrace\]

Using \Bigg\vert

but I am looking for a true variable-sized option, parallel to \lbrace etc.

The amsmath package provides \lvert and \rvert, but I do not find them expanding as expected, and the amsmath documentation specifies that they should be used as binary delimiters (one on each side of something else), rather than alone.

share|improve this question
    
As a side-note, rather use \[ ... \] for display math as opposed to $$ ... $$. See the l2tabu documentation. –  Werner Oct 19 '11 at 15:54
    
Not relevant to your question, but (as you can seen in our answers) you really shouldn't use $$ ... $$ for displayed math. See Why is [ .. ] preferable to $$ .. $$ –  Alan Munn Oct 19 '11 at 15:54
    
@Werner, @Alan Munn, yes, I always use \[ ... ]`, but for some reason the code did not convert to mathematics and only the brackets were showing when I posted. So I thought I'd be safer with the $$`. I'll change them back now, though. –  brannerchinese Oct 20 '11 at 3:32
    
not exactly relevant to the question asked, but what happened to the minus in the upper limit on the sum? –  barbara beeton Oct 20 '11 at 11:38
    
@barbara beeton: Not so nice-looking, right? I think I'm supposed to insert an "italic correction" (\/) there. But I didn't; lazy, no excuse, your forbearance please. –  brannerchinese Oct 20 '11 at 22:09

4 Answers 4

up vote 27 down vote accepted

You can use the braket package for this kind of thing.

\documentclass{article}
\usepackage{braket}
\usepackage{amsmath}
\usepackage{bbold}
\begin{document}

\[
\mathcal{H}=\Set{ h(x)=\sum_{i=0}^{k-1}a_{i}x_{i}\mod m\ |
     \ a_{i}\in\mathbb{Z}_{m^{k}}}
\]

\end{document}

It defines a \Set macro which automatically puts its contents in variable sized braces, and any instance of the | symbol inside will adjust accordingly. This solution also has the advantage of making your source code more semantic.

output of code

share|improve this answer
    
How about if there is a | symbol inside the set that denotes something else (e.g. conditional probability) and needs to be of normal size? –  3lectrologos May 29 at 23:06
    
@3lectrologos In the \Set macro, only the first | encountered will be large; other ones will be regular size. If you need a | on the left hand side of the large vertical, you can use \vert or \mid. For conditional probability I would use \mid. –  Alan Munn May 30 at 1:40
    
Ah, I see, thanks a lot for that! –  3lectrologos May 30 at 5:27

You can also use \middle which goes with \left and \right:

\[
\mathcal{H}=\left\{ h(x)=\sum_{i=0}^{k-1}a_{i}x_{i}\mod m\ \middle|\ 
     a_{i}\in\mathbb{Z}_{m^{k}}\right\}
\]

This saves you having to use \left. or \right. unnecessarily.

share|improve this answer
5  
One might add that \middle is an e-TeX feature. (The solution by Alan Munn will rely on this when available.) –  Harald Hanche-Olsen Oct 19 '11 at 18:51
    
Ah, thank you - I had a vague recollection that this was a relatively recent feature but was mildly surprised to find I didn't need to load any packages to get this to work. That'll be why. –  Ant Oct 19 '11 at 19:12

You could use \left| stuff \right. or \left. stuff \right| depending on where you want the | and where it should take it's size from. For instance:

\[
  \left.\sum_{i \in I} x_i \right| x_i > 2
\]

takes the size from the sum. (Yes, I realize its a stupid example). Whereas

\[
  \sum_{i \in I} x_i \left| x_i > 2 \right.
\]

takes the size of the x_i > 2.

I see you added an example, that would become:

\[
  \mathcal{H}=\left\lbrace h(x)=\left.\sum_{i=0}^{k-1}a_{i}x_{i}\mod m\ \right|\ a_{i}\in\mathbb{Z}_{m^{k}}\right\rbrace
\]

With the result:

enter image description here

share|improve this answer
    
This doesn't work if you want to use the | in the following context: \left\{x | \sum_i x >10\right\} for example. –  Seamus Oct 19 '11 at 15:27
4  
\left\{x \left| \sum_i x >10\right.\right\} will work fine if you want the | to be the size of the sum. –  Roelof Spijker Oct 19 '11 at 15:31
    
Ah you need a second \right. and it needs a dot. OK. –  Seamus Oct 19 '11 at 16:02

Here is my solution with a syntax much closer to the mathematical meaning

\usepackage{mathtools}
\providecommand\given{} % is redefined in \Set
\newcommand\SetSymbol[1][]{\nonscript\:#1\vert\nonscript\:}
\DeclarePairedDelimiterX\Set[1]{\{}{\}}{
  \renewcommand\given{\SetSymbol[\delimsize]}
  #1
}

Now we can simply use

\Set{ x\in A \given x^2 > 1 }

much much closer to the mathematical meaning.

In the OPs case, I'd use

\Set[\Big]{ h(x)=\sum_{i=0}^{k-1}a_{i}x_{i}\mod m \given  a_{i}\in\mathbb{Z}_{m^{k}} }

as there is no reason to scale the fences excessively.

I use the separate \SetSymbol macro, because there are very complicated set constructions, where one cannot use \Set (as in \{ and \} on separate lines), and thus in that case one may want to be able to refer to the given symbol for sets, just in case one want change the symbol later on.

share|improve this answer

Your Answer

 
discard

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.