TeX will provide the correct spacing if you inform it that you are using ]
and [
in a non-standard way, which can be done by means of \mathopen
and \mathclose
:
\[ \mathopen]-\pi,0\mathclose[ \]
This tells TeX exactly what is going on.
More precisely, TeX assumes that [
is an Open[ing] atom and the ]
is a Close[ing] one (and I sympathize with it! ;-) If you write
\[ ]-\pi,0[ \]
TeX will build the following list of atoms: Close, Bin, Ord, Punct, Ord, Open; this leads it to compute the difference between ]
and \pi
, as Werner has already said; indeed, compare the above with the formula
(a+b)-c
where the minus is the second Bin atom in the resulting sequence Open, Ord, Bin, Ord, Close, Bin, Ord.
Note that Werner’s suggestion, that is,
]{-\pi},0[
yields Close, Ord{…}, Punct, Ord, Open, which does not correspond to the intended meaning, although it gives the correct spacing (but only, of course, in this particular case—see @egreg’s answer), as you can check in the table on p. 170 of The TeXbook.
IMHO, however, the best thing of all is to define an abstract command: it’s very easy to do so using the mathtools
package and its \DeclarePairedDelimiterX
command; the command defined in this way provides easy means to deal with size issues: see the documentation of the mathtools
package, subsection 3.6, for details.
Here is a complete example that illustrates both solutions:
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{mathtools}
% [ bracket matching
\DeclarePairedDelimiterX{\openinterval}[2]{]}{[}{#1,#2}
% ] bracket matching
\begin{document}
Wrong:
\[ ]-\pi,0[ \]
Direct method, not recommended:
\[ \mathopen]-\pi,0\mathclose[ \]
With an abstract command:
\[ \openinterval{-\pi}{0} \]
Variants of the abstract command:
\begin{align*}
&\openinterval*{-\frac{\pi}{2}}{+\frac{\pi}{2}}
&& \text{auto-resizing;} \\
&\openinterval[\bigg]{-\frac{\pi}{2}}{+\frac{\pi}{2}}
&& \text{with optional argument for size specification.}
\end{align*}
\end{document}
And here is the output it produces: