19

I am trying to typeset a integer interval like this: [0..m-1]

However, the space between 0,., and m - 1 are too small. Is there a package to improve this?

Henricus V.
  • 813
  • 1
  • 6
  • 14

5 Answers5

20

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)

Rmano
  • 40,848
  • 3
  • 64
  • 125
13

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

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
egreg
  • 1,121,712
12

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

Bernard
  • 271,350
1

Use \enleadertwodots in the stix package is perfect (aside from tiny spacing). I've added a couple variations on spacing so you can see how it looks:

\documentclass[10pt]{article}
\usepackage{stix}
\begin{document}

\[[1\, \enleadertwodots\, m-1] \quad [1 \enleadertwodots\, m-1] \quad [1 \enleadertwodots m-1]\]

\end{document}

p1

I found this after scanning through this huge list of symbols in latex.

ryan
  • 111
0

Much less robust than others (it can of course be made more robust, but may be this is enough), but it might be nice looking and readable code

\def\intv#1[#2..#3]{\mathopen{#1[}#2\mathrel{{.}\,{.}}\nobreak#3\mathclose{#1]}}
$
\intv[a..b]
\intv\big[a..b]
\intv\Bigg[\frac{a}{b}..c]
$

If you need \left[ .. \right] I can add the code.

Manuel
  • 27,118
  • 2
    \nobreak is necessary after \mathrel{...} or TeX would be allowed to put a line break. – egreg Apr 16 '16 at 21:42
  • Sorry, I definitely tried to copy your output code (while varying the input) but miss that one. – Manuel Apr 16 '16 at 21:43