16

Due to the typographic traditions I'm used to, I prefer my \ldots to have no spacing in between, ideally exactly the same amount as in text. In math mode I would like to write things like \(1, 2, \ldots, n\) and have the spacing be adaptive:

  • if the next character is a comma, I'd like something very thin like \kern .08333em (i.e., half of a \thinspace) afterwards;
  • if there is an opening parenthesis ("(", "[", "{", ...) before or a closing parenthesis (")", "]", "}", ...) after the dots, there should be no or only tiny additional spacing (i.e., less than \kern .08333em);
  • and whatever other adaptations of space around \ldots or \dots are normally produced by (La)TeX;
  • feel free to add other ideas.

What is the best way of redefining \ldots for these purposes?

  • 1
    Please tell us how you are typing ellpsis in text and what packages you are loading. In standard LaTeX the spacing between the dots in \dots and \( \ldots \) look the same for standard fonts, however the math and text definitions are different, with the text definition "misusing" fontdim3. Similarly there are differences for the surrounding spacing that can be affected by packages. – Andrew Swann Oct 4 '12 at 8:02
  • @AndrewSwann In text, I usually type them as "..."; I work with memoir, times-itsc (like times but with small-caps in italics), [T1]-fontenc, microtype, amsmath, hyperref as the packages I would consider most important and of course a couple of others; hope that is useful. – Lover of Structure Oct 4 '12 at 17:37
16

\ldots is using \mathellipsis for the dots. It could be redefined to use the text version, but the mixup of text and math fonts might not always a good idea. \mathellipsis itself uses three dots as punctuation characters. That means, there is additional thin space between the dots. This can be changed by putting them into a subformula, then they are treated as \mathord atoms without additional space.

\documentclass[12pt]{article}
\usepackage{amsmath}
\renewcommand*{\mathellipsis}{%
  \mathinner{{\ldotp}{\ldotp}{\ldotp}}%
}
\begin{document}
$1,2,\ldots,3$
$(1,2,\ldots)$
\end{document}

Result

Smaller spaces

Usually thin space is the smallest space in math mode, but to some degree \ldots can be adopted to smaller spaces:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{letltxmacro}
\renewcommand*{\mathellipsis}{%
  \mathinner{{\ldotp}{\ldotp}{\ldotp}}%
}
\makeatletter
\@ifdefinable{\org@ldots}{%
  \LetLtxMacro\org@ldots\ldots
  \DeclareRobustCommand*{\ldots}{%
    \ifmmode
      \expandafter\my@ldots
    \else
      \expandafter\textellipsis
    \fi
  }%
}
\newcommand*{\neghalfmskip}{%
  \nonscript\mskip-.5\muexpr\thinmuskip\relax%
}
\newcommand*{\my@ldots}{%
  \mathellipsis
  \@ifnextchar,\neghalfmskip{%
  \@ifnextchar:\neghalfmskip{%
  \@ifnextchar;\neghalfmskip{%
  \@ifnextchar.\neghalfmskip{%
  \@ifnextchar!\neghalfmskip{%
  \@ifnextchar?\neghalfmskip{%
  \@ifnextchar){\mskip-.5\muexpr\thinmuskip\relax}{% negative kerning
  }}}}}}}%
}
\makeatother

\begin{document}
\noindent
$1,2,\ldots,3_{1,2,\ldots,3}$ (ldots)\\
$1,2,\mathellipsis,3_{1,2,\mathellipsis,3}$ (mathellipsis)\\
$(1,2,\ldots)_{(1,2,\ldots)}$ (ldots)\\
$(1,2,\mathellipsis)_{(1,2,\mathellipsis)}$ (mathellipsis)
\end{document}

Result

TeX sets a thin space between inner atoms and punctuation chars in display and text style only, therefore the use of \nonscript. There is no space in case of the closing ), but because of the character shape, you probably want to have a negative kerning, this is applied in all math styles.

More generalized detection of a closing delimiter

The example uses Andrew's hint of \rightdelim@:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{letltxmacro}
\renewcommand*{\mathellipsis}{%
  \mathinner{{\ldotp}{\ldotp}{\ldotp}}%
}
\makeatletter
\@ifdefinable{\org@ldots}{%
  \LetLtxMacro\org@ldots\ldots
  \DeclareRobustCommand*{\ldots}{%
    \ifmmode
      \expandafter\my@ldots
    \else
      \expandafter\textellipsis
    \fi
  }%
}
\newcommand*{\neghalfmskip}{%
  \nonscript\mskip-.5\muexpr\thinmuskip\relax%
}
\newcommand*{\my@ldots}{%
  \mathellipsis
  \@ifnextchar,\neghalfmskip{%
  \@ifnextchar:\neghalfmskip{%
  \@ifnextchar;\neghalfmskip{%
  \@ifnextchar.\neghalfmskip{%
  \@ifnextchar!\neghalfmskip{%
  \@ifnextchar?\neghalfmskip{%
    \rightdelim@
    \ifgtest@
      \mskip-.5\muexpr\thinmuskip\relax% negative kerning
    \fi
  }}}}}}%
}
\makeatother

\begin{document}
\noindent
$1,2,\ldots,3_{1,2,\ldots,3}$ (ldots)\\
$1,2,\mathellipsis,3_{1,2,\mathellipsis,3}$ (mathellipsis)\\
$(\neghalfmskip\ldots)_{(\neghalfmskip\ldots)}$ (neghalfmskip + ldots)\\
$(\ldots)_{(\ldots)}$ (ldots)\\
$(\mathellipsis)_{(\mathellipsis)}$ (mathellipsis)\\
$\{\ldots\}_{\{\ldots\}}$ (ldots)\\
$\{\mathellipsis\}_{\{\mathellipsis\}}$ (mathellipsis)
\end{document}

Result

But for the detection of an opening delimiter before I do not see a way. There isn't a "\lastmathatom". Manually the space correction can be applied as the example file shows with \neghalfmskip.

  • This is a very nice solution. Only one little quibble is that you have missed the other brackets from the original question. As amsmath.sty is loaded you could use its \rightdelim@ for detecting these. – Andrew Swann Oct 4 '12 at 15:53
  • @AndrewSwann Thanks; actually I've clarified my parenthesis requirement/request and made the question (a tad) more general. – Lover of Structure Oct 4 '12 at 18:18
  • @AndrewSwann Thanks for the hint with \rightdelim@. However for the detection of the opening delimiters I do not see a way, the execution time of \ldots is too late. – Heiko Oberdiek Oct 4 '12 at 23:14
  • 1
    My latest example file shows such a use case that inserts \neghalfmskip. But feel free to use a better macro name. – Heiko Oberdiek Oct 5 '12 at 18:51
  • 1
    @user14996 \muexpr\thinmuskip is the mathematical equivalent of \thinspace, the negative spacing was just achieved by the minus sign. \nonscript means that the glue is not inserted in script and scriptscript styles. – Heiko Oberdiek Oct 15 '12 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.