# How to make \dots from amsmath and ellipsis work together

The amsmath package changes the \dots command to have different vertical alignment depending on context (I'm not sure if it does anything else to it). The ellipsis package changes the \dots command to ensure correct spacing in certain textual contexts. However, it seems to undo the changes made by amsmath. Is there a way to make the features work simultaneously?

The following is an mwe:

\documentclass[a4paper]{book}

\usepackage{amsmath}
\usepackage{ellipsis}

\begin{document}

a \dots{} b

a\dots{}b
$a + \dots + b$

\end{document}


If the ellipsis package is used, the ellipsis in math is not vertically centered. If it is not used, there is an extra (thin?) space after the ellipsis in the text. The order of \usepackage's do not seem to matter.

• You shouldn't be using \dots{} in math mode anyway, because it confuses the macros of amsmath. – egreg Jul 9 '14 at 9:41
• I can't see any difference in the vertical alignment of \dots with and without amsmath. – Ian Thompson Jul 9 '14 at 9:44
• Inside of math you shouldn't use the {} after \dots, you must let them decide the spacing a + \dots + b. By the way, this may interest you: tex.stackexchange.com/q/168383/21930 and tex.stackexchange.com/q/179336/21930. – Manuel Jul 9 '14 at 9:55
• @egreg -- huh? shouldn't use \dots in math? or were you just referring to the {} after \dots? the amsmath documentation specifically recommends using \dots unless a final reading shows that some of them have gotten misaligned. (the {} is almost always wrong though.) – barbara beeton Jul 9 '14 at 12:39
• @barbarabeeton Sorry, I wasn't clear: {} shouldn't be used after \dots in math mode. – egreg Jul 9 '14 at 12:49

The ellipsis package does

\AtBeginDocument{%
\DeclareRobustCommand{\dots}{%
\ifmmode\mathellipsis\else\expandafter\textellipsis\fi}%
}


which is wrong, because it reinstates the LaTeX kernel definition without taking into account that other package might have redefined it. The package author's aim is ensuring that in text mode the redefined \textellipsis is used. Alas, this breaks the amsmath mechanism.

Solution: reinstate the correct definition given by amsmath that has \textellipsis for text mode.

\documentclass[a4paper]{book}

\usepackage{letltxmacro} % for saving and reinstating the correct macro
\usepackage{amsmath}
% save the definition of \dots by amsmath
\LetLtxMacro{\amsmathdots}{\dots}

\usepackage{ellipsis}

% this must go after \usepackage{ellipsis}
\AtBeginDocument{\LetLtxMacro{\dots}{\amsmathdots}}

\begin{document}

a \dots{} b

a\dots{}b
$a + \dots + b$

\end{document}


This is a solution I used some time ago. It adds \ellipsisbeforegap and \ellipsisaftergap just because I needed it. You can delete it.

\documentclass{scrartcl}

\usepackage{mathtools}
\usepackage{ellipsis}

\makeatletter
\renewcommand*{\mathellipsis}{%
\mathinner{%
\kern\ellipsisbeforegap%
{\ldotp}\kern\ellipsisgap%
{\ldotp}\kern\ellipsisgap%
{\ldotp}\kern\ellipsisaftergap%
}%
}
\renewcommand*{\dotsb@}{%
\mathinner{%
\kern\ellipsisbeforegap%
{\cdotp}\kern\ellipsisgap%
{\cdotp}\kern\ellipsisgap%
{\cdotp}\kern\ellipsisaftergap%
}%
}
\renewcommand*{\@cdots}{%
\mathinner{%
\kern\ellipsisbeforegap%
{\cdotp}\kern\ellipsisgap%
{\cdotp}\kern\ellipsisgap%
{\cdotp}\kern\ellipsisaftergap%
}%
}
\renewcommand*{\ellipsis@default}{%
\ellipsis@before
\kern\ellipsisbeforegap
.\kern\ellipsisgap
.\kern\ellipsisgap
.\kern\ellipsisgap
\ellipsis@after\relax}
\renewcommand*{\ellipsis@centered}{%
\ellipsis@before
\kern\ellipsisbeforegap
.\kern\ellipsisgap
.\kern\ellipsisgap
.\kern\ellipsisaftergap
\ellipsis@after\relax}
\AtBeginDocument{%
\DeclareRobustCommand*{\dots}{%
\ifmmode\@xp\mdots@\else\@xp\textellipsis\fi}}
\def\ellipsisgap{.1em}
\def\ellipsisbeforegap{.05em}
\def\ellipsisaftergap{.05em}
\makeatother

\begin{document}

a \dots\ b

a\dots b

$a + \dots + b$

\end{document}


The relevant part to your question (although my code is more complete) is

\AtBeginDocument{%
\DeclareRobustCommand*{\dots}{%
\ifmmode\@xp\mdots@\else\@xp\textellipsis\fi}}