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.

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 want to write open and half-open intervals using the following notation:

]a, b[
]a, b]
]-∞, b]

When writing them just like that in the LaTeX source, the spacing doesn't come out right. For example, for this equation:

 \(X = ]-\frac{π}{2}, +\frac{π}{2}[\)

the minus sign is typeset as a binary operator. I can solve this by surrounding the whole value in braces, but then the spacing around the equal sign is still not correct. For other combinations of intervals and operators, different spacing inconsistencies arise.

What is the correct and easy way to input intervals in order to avoid having to take care of this at all?

share|improve this question
\(X = \left]-\frac{π}{2}, +\frac{π}{2}\right[\) ? – Martin Scharrer Jul 20 '11 at 21:24
...or you could use wrap the interval in {}: \(X = ]{-\frac{π}{2}, +\frac{π}{2}}[\). However, this would work best when the contents is not in displaymath mode. – Werner Jul 20 '11 at 21:33
@Martin and Werner: thanks for your responses. Please post them as answers so I can accept them. – Roberto Bonvallet Jul 20 '11 at 21:35
take a look at \DeclarePairedDelimiter from mathtools. (i haven't time to write a more complete answer.) – barbara beeton Sep 28 '13 at 21:52
up vote 10 down vote accepted

You can use \left] and \right[ then the brackets are taken as delimiters (and also get resized accordantly to the content):

\(X = \left]-\frac{π}{2}, +\frac{π}{2}\right[\)


share|improve this answer
I had overlooked this obvious solution, since I had always used \left and \right only for the resizing behavior. Thanks! – Roberto Bonvallet Jul 20 '11 at 21:43
Knuth speaks about "perverse mathematicians" that use this notation. :) In case the resizing is not needed, it's better to say \mathopen]a^2,b^2\mathclose[ (this is indeed a case where resizing is bad). – egreg Jul 20 '11 at 22:05
@egreg: Thanks, I didn't know \mathopen and \mathclose before. I'm not a mathematician at all, neither a perverse one or otherwise :-) – Martin Scharrer Jul 20 '11 at 22:50
@egreg, @Martin: Then all French mathematicians are perverse ;-) More seriously, the best for intervals is a macro which takes care of everything (and allows to choose between the resizing and non-resizing version). Since with \left/\right you can have spacing problems (e.g. in \left]a,b\right[. the dot is too far away) due to the fact that it makes what it encloses of type \mathinner instead of \mathopen to the left and \mathclose to the right, the best when you want the resizing behavior is to use \mathopen{}\mathclose{\left]...\right[}. – Philippe Goutet Jul 21 '11 at 8:29
@Philippe: I'm not fond of "automatic" \left and \right; in the case of the interval (sqrt(2),2), for example, or (a^2,b^2), using \left and \right produces too big delimiters. That all French mathematician are perverse is well known. :) – egreg Jul 21 '11 at 9:56

While I'm a little late to the party, here goes for a slightly more concise solution:


\NewDocumentCommand{\INTERVALINNARDS}{ m m }{
    #1 {,} #2
\NewDocumentCommand{\interval}{ s m >{\SplitArgument{1}{,}}m m o }{
        \left#2 \INTERVALINNARDS #3 \right#4
            #5{#2} \INTERVALINNARDS #3 #5{#4}
            #2 \INTERVALINNARDS #3 #4

which allows you to do:

    \interval[{a,b}] &&           && \\
    \interval[{a,b}) && \text{or} && \interval[{a,b}[ \\
    \interval({a,b}] && \text{or} && \interval]{a,b}] \\
    \interval({a,b}) && \text{or} && \interval]{a,b}[

to obtain something like: Interval open / closed example

Or to use manual or automatic resizing:

    \interval[{a,\infty})[\Bigg] \quad \text{or} \quad

to obtain:

enter image description here

Edit: Added the changes suggested by egreg (this was my answer, was just unregistered at the time).

share|improve this answer
Welcome to TeX.SX! This is nice; I'd exchange the conditions and use * to get the \left-\right version: I don't like this kind of automation that can give unwanted spacing; also macros defined with \DeclarePairedDelimiters (mathtools package) use the *-version for the "automatic size" version. It wouldn't be difficult to add an optional argument for accommodating \big and friends in a similar fashion. – egreg Sep 28 '13 at 21:25
It looks like you've got two separate accounts, which means you cannot edit your original post or leave comments. The StackExchange staff can merge them together for you. – Werner Sep 29 '13 at 14:31

At least two options exist.

Option 1: \(X = \left]-\frac{π}{2}, +\frac{π}{2}\right[\)

This works well, even in displaymath mode (\[...\]) since the delimiters are extensible. However, in inline math mode you'll notice the braces may expand more than your liking. For that, use Option 2.

Option 2: Wrap the interval in {}: \(X = ]{-\frac{π}{2}, +\frac{π}{2}}[\)

share|improve this answer
The latter option has the advantage that it doesn't clutter the markup too much. I may end up prefering it for simple cases. Thanks! – Roberto Bonvallet Jul 22 '11 at 23:18

You have the ‘interval’ package, which takes care of the spacing and the scaling of the brackets.

share|improve this answer

Here is a macro which takes care of the spacing and allows you to choose between a resizable version (when followed by a star, for use in display) and a fixed-size version (without a star, for use in text). You have four macros \intervalcc, \intervaloo, \intervaloc and \intervalco for the various types of intervals (o is for open and c for closed):




$I = \intervalcc{-a^2}{b^2} \cap \intervalcc{-\frac{\pi}{2}}{\frac{\pi}{2}}.$

\[I = \intervalcc{-a^2}{b^2} \cap \intervalcc*{-\frac{\pi}{2}}{\frac{\pi}{2}}.\]

$I = \intervaloo{-a^2}{b^2} \cap \intervaloo{-\frac{\pi}{2}}{\frac{\pi}{2}}.$

\[I = \intervaloo{-a^2}{b^2} \cap \intervaloo*{-\frac{\pi}{2}}{\frac{\pi}{2}}.\]

$I = \intervaloc{-a^2}{b^2} \cap \intervaloc{-\frac{\pi}{2}}{\frac{\pi}{2}}.$

\[I = \intervaloc{-a^2}{b^2} \cap \intervaloc*{-\frac{\pi}{2}}{\frac{\pi}{2}}.\]

$I = \intervalco{-a^2}{b^2} \cap \intervalco{-\frac{\pi}{2}}{\frac{\pi}{2}}.$

\[I = \intervalco{-a^2}{b^2} \cap \intervalco*{-\frac{\pi}{2}}{\frac{\pi}{2}}.\]


share|improve this answer
I don't like how the markup ends up looking like. Too much clutter! Thanks anyway, I always learn something new when looking at someone else's macros :) – Roberto Bonvallet Jul 22 '11 at 23:23
@Roberto: if your TeX editor uses different colors to highlight differently nested braces, the formulas remain very legible. The reason these macro are useful is if you need to do things more complicated with, e.g., the interval separator (I use \mathclose{}\mathpunct{}; for a correct spacing of the semi-colon in French and these macros allow me not to have to type it each time). – Philippe Goutet Jul 23 '11 at 12:39

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.