Typesetting an integer interval

Let's see how I can make a command that is like a \dots but with two dots. Firstly, I use the wisdom of TeX.SE and find how to find the content of a standard definition; then a bit of command line:

[romano:~] % texdef -t latex dots  
\dots:
macro:->\protect \dots  
\dots :
\long macro:->\ifmmode \mathellipsis \else \textellipsis \fi 

[romano:~] % texdef -t latex mathellipsis
\mathellipsis:
macro:->\mathinner {\ldotp \ldotp \ldotp }

and finally:

 \newcommand{\twodots}{\mathinner {\ldotp \ldotp}}

which results in:

twodots macro

(This is just for math mode, but you can easily extend it for text too, mimicking the \dots definition)


Here is a solution with mathtools and xparse. I define a command \Iintvl{m,n}. You need a font which contains the relevant delimiters, \llbracket and \rrbracket (fourier and stmaryrd) or equivalents (MnSymbol and MdSymbol have \lsem and \rsem). The star version of the command adapts the size of the delimiters to the contents, and you can fine-tune their size with an optional argument (\big, \Big, …).

\documentclass{article}
\usepackage{mathtools, stmaryrd}
\usepackage{xparse} \DeclarePairedDelimiterX{\Iintv}[1]{\llbracket}{\rrbracket}{\iintvargs{#1}}
\NewDocumentCommand{\iintvargs}{>{\SplitArgument{1}{,}}m}
{\iintvargsaux#1} %
\NewDocumentCommand{\iintvargsaux}{mm} {#1\mkern1.5mu..\mkern1.5mu#2}

\begin{document}

\[ \Iintv{-2,5} \quad \Iintv*{2^n, 2^{n + 1} } \quad \Iintv*{2^{2^n} + 1, 2^{2^{n + 1}} + 1}\]

\end{document} 

enter image description here


I like the two dots, too. My usual code is

[a\mathrel{{.}\,{.}}\nobreak b]

of course hidden in a macro.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\isep}{\mathrel{{.}\,{.}}\nobreak}

\begin{document}

$[0\isep m-1]$

\end{document}

enter image description here

A more elaborate solution for coping with intervals of any kind, while keeping a syntax that doesn't force a choice.

\documentclass{article}
\usepackage{amsmath,mleftright}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\interval}{O{}>{\SplitArgument{1}{,}}m}
 {
  \group_begin:
  \keys_set:nn { calcolo/interval } { o, #1 }
  \bool_if:NTF { \l_calcolo_interval_auto_bool }
   {\mleft\l_calcolo_interval_left_tl}
   {\mathopen{\l_calcolo_interval_size_tl\l_calcolo_interval_left_tl}}
  \calcolo_interval_set:nn #2
  \bool_if:NTF { \l_calcolo_interval_auto_bool }
   {\mright\l_calcolo_interval_right_tl}
   {\mathclose{\l_calcolo_interval_size_tl\l_calcolo_interval_right_tl}}
  \group_end:
 }
\cs_new_protected:Nn \calcolo_interval_set:nn
 {
  #1 \mathrel{{.}\,{.}}\nobreak #2
 }
\keys_define:nn { calcolo/interval }
 {
  size .code:n =
   \tl_if_eq:nnTF { #1 } { * }
    { \bool_set_true:N \l_calcolo_interval_auto_bool }
    { \tl_set:Nn \l_calcolo_interval_size_tl { #1 } },
  o .code:n =
   \tl_set:Nn \l_calcolo_interval_left_tl { ( }
   \tl_set:Nn \l_calcolo_interval_right_tl { ) },
  oo .code:n =
   \tl_set:Nn \l_calcolo_interval_left_tl { ( }
   \tl_set:Nn \l_calcolo_interval_right_tl { ) },
  c .code:n =
   \tl_set:Nn \l_calcolo_interval_left_tl { [ }
   \tl_set:Nn \l_calcolo_interval_right_tl { ] },
  cc .code:n =
   \tl_set:Nn \l_calcolo_interval_left_tl { [ }
   \tl_set:Nn \l_calcolo_interval_right_tl { ] },
  oc .code:n =
   \tl_set:Nn \l_calcolo_interval_left_tl { ( }
   \tl_set:Nn \l_calcolo_interval_right_tl { ] },
  co .code:n =
   \tl_set:Nn \l_calcolo_interval_left_tl { [ }
   \tl_set:Nn \l_calcolo_interval_right_tl { ) },
  o .value_forbidden:n = true,
  oo .value_forbidden:n = true,
  c .value_forbidden:n = true,
  cc .value_forbidden:n = true,
  oc .value_forbidden:n = true,
  co .value_forbidden:n = true,
 }

\tl_new:N \l_calcolo_interval_left_tl
\tl_new:N \l_calcolo_interval_right_tl
\tl_new:N \l_calcolo_interval_size_tl
\bool_new:N \l_calcolo_interval_auto_bool
\ExplSyntaxOff


\begin{document}

$\interval{a,b}$

$\interval[c]{a,b}$

$\interval[co]{a,b}$

$\interval[oc]{a,b}$

$\interval[size=\Big]{a,b}$

\bigskip

$\interval[size=*,co]{\dfrac{\dfrac{1}{2}}{\dfrac{3}{4}},b}$

\end{document}

enter image description here

Tags:

Spacing