# Formatting for a math notation of the form $[a:b]$

I would like to use a notation for ranges of integers

$[a:b] = \{ a, a+1, \dots, b-1, b \}$.


However, the spacing of $[a:b]$ is often not quite satisfying. The colon : seems to push the glyphs a and b very much to the sides, and there is not much space between the square brackets and the numbers.

Which options do I have to type such an integer range? I am particular concerned about the spacing.

• Did you see the posting What commands are there for horizontal spacing? Aside: In math mode, the : symbol is of type mathrel by default. To eliminate the horizontal whitespace that surrounds objects of type mathrel, type either {:} or \mathord{:}. – Mico Mar 3 '20 at 7:13
• For no space around :, type {:}. – CarLaTeX Mar 3 '20 at 7:16

This is a bit tricky: a simple \,{:}\, might seem enough, but there would be problems if the right boundary is a negative number. Thus some precautions are needed.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\rg}{\mathclose{}{\,{:}\,}\mathopen{}}

\begin{document}

$[a\rg b]$ $[2\rg 5]$ $[-4\rg -2]$

\end{document}