11

LaTeX adds some space after the ellipsis \textellipsis. This is enhanced by ellipsis package, which only adds space before certain characters (and also gives the option to configure “easily” the spacing between the dots and after):

enter image description here

However the spacing is “wrong”, for instance …!, …: or …? does not need the same amount (see : versus ?). However, I'm lost in the ellipsis.sty and I don't understand half of it.

How can we set a certain amount to each different character?

It would be great to have something like

\SetEllipsisSpacing
  {
    . = .1em,
    ? = .08em,
    ! = .09em,
    : = .1em,
  }
\SetEllipsisSpacing
  {
    { . } { .1em }
    { ? } { .08em }
    { ! } { .09em }
    { : } { .1em }
  }

instead of the current (and only) option \def\ellipsispunctuation{,.:;!?}.

Here is a minimal compilable example.

\documentclass{scrartcl}
\usepackage[LY1,T1]{fontenc}
\usepackage[utf8]{inputenx}
\usepackage{lmodern} % Just here to be an example, I use a different font
\usepackage{ellipsis}

%\def\ellipsisgap{.1em}

%\DeclareTextCommandDefault{\textellipsis}
%  {{\fontencoding{LY1}\selectfont\char133}}

\begin{document}
a…! …: …?
\end{document}

This comes because I discovered that the LY1 encoding has an ellipsis character, so I can define

\DeclareTextCommandDefault{\textellipsis}
  {{\fontencoding{LY1}\selectfont\char133}}

but it needs some adjusting.

enter image description here

  • The spacing is the same, but the question mark is farther right than with the colon or the exclamation mark. – egreg May 20 '14 at 17:13
  • I meant that the spacing is the same while I don't want it to be the same (the reason is that different glyphs might need different space). – Manuel May 20 '14 at 17:31
4

This might get you started:

\documentclass{scrartcl}
\usepackage[LY1,T1]{fontenc}
\usepackage[utf8]{inputenx}
\usepackage{lmodern} % Just here to be an example, I use a different font
\usepackage{xparse,newunicodechar}


\ExplSyntaxOn
\newunicodechar{…}
 {
  {\fontencoding{LY1}\selectfont\char133}
  \manuel_lookup:
 }

\NewDocumentCommand\SetEllipsisSpacing { m }
 {
  \keys_set:nn { manuel/ellipsis } { #1 }
 }

\tl_new:N \g_manuel_list_tl

\keys_define:nn { manuel/ellipsis }
 {
  comma   .code:n = \tl_gput_right:Nx \g_manuel_list_tl { { , } { \kern#1 } },
  unknown .code:n = \tl_gput_right:Nx \g_manuel_list_tl { { \l_keys_key_tl } { \kern#1 } },
 }

\cs_new_protected:Npn \manuel_lookup:
 {
  \peek_catcode:NF \c_space_token { \manuel_decide:n }
 }

\cs_new_protected:Npn \manuel_decide:n #1
 {
  \str_case:nVF { #1 } \g_manuel_list_tl { \skip_horizontal:n { .1em } }
  #1
 }

\cs_generate_variant:Nn \str_case:nnF { nV }
\ExplSyntaxOff

\SetEllipsisSpacing{
   . = .1em,
   ? = -.1em,
   ! = -.02em,
   : = -.02em,
   comma = .1em
}

\begin{document}
…! 
…: 
…? 
…, 
….
… a
…X
\end{document}

enter image description here

Since it's difficult to have a comma as a key, I've added the key comma for it.

  • This is nice, and better because of the \SetEllipsisSpacing command. By the way, I managed to do something similar but with \tl_case:... rather than \str_case:.... Is there a main difference/reason to use one versus the other one? – Manuel May 20 '14 at 23:07
  • @Manuel \tl_case:NnTF requires a set of token list variables, \str_case:nnTF doesn't. – egreg May 20 '14 at 23:17
5

Here I redefine \ldots If the next character is one of the checked-for ones, the redefined macro inserts a custom amount of space before it. REVISED to eliminate optional argument and hopefully get end-of-sentence spacing right.

\documentclass{article}
\let\svldots\ldots
\makeatletter
\renewcommand\ldots{\svldots%
  \@ifnextchar!{\kern10pt}{%
  \@ifnextchar:{\kern8pt}{%
  \@ifnextchar?{\kern6pt}{%
}}}}
\makeatother
\begin{document}
NEW:

Here\ldots are\ldots! some\ldots: test\ldots? cases. Next\ldots

ORIGINAL:

Here\svldots are\svldots! some\svldots: test\svldots? cases. Next\svldots
\end{document}

enter image description here

  • unless my eyes are deceiving me, the spaces after the exclamation and question marks are word spaces, not the usual end-of sentence spaces; i don't see \frenchspacing in the example, so i would expect the latter. – barbara beeton May 20 '14 at 17:59
  • You should use \futurelet and \if, or spaces will be gobbled. – egreg May 20 '14 at 18:01
  • @egreg I see the problem barbara cites, but having extremely limited experience with \futurelet, I'm not exactly sure what you have in mind as the fix. – Steven B. Segletes May 20 '14 at 18:15
  • @Manuel Please see revision... optional argument gone. – Steven B. Segletes May 20 '14 at 18:36
  • @egreg I think this is fixed (without \futurelet), but I have trouble telling a normal space from an end-of-sentence space. – Steven B. Segletes May 20 '14 at 18:36
4

With a little bit of trial and error to find the .09 which seems about right for this font at this size.

text ellipsis

In \Huge size:

text ellipsis huge

\documentclass{scrartcl}
\usepackage[LY1,T1]{fontenc}
\usepackage[utf8]{inputenx}
\usepackage{lmodern} % Just here to be an example, I use a different font

\DeclareTextCommandDefault{\textellipsis}
  {{\fontencoding{LY1}\selectfont\char133}}

\newcommand\ellip [1]{\begingroup
                      \setbox0\hbox{\textellipsis}%
                      \setbox2\hbox{#1}%
                      \textellipsis\kern\dimexpr-.5\wd2+.09\wd0\relax
                                    #1\endgroup}

\begin{document}\thispagestyle{empty}
a…! a…: a…?

a\textellipsis! a\textellipsis: a\textellipsis?

a\ellip! a\ellip: a\ellip?


\end{document}
  • The problem with this is that it swallows every symbol. I would prefer some adjustable options, i.e., a certain kern for each character I define, and nothing for everything else. – Manuel May 20 '14 at 17:22
  • It is not to be used systematically, only when the ellipsis is to be followed without spacing by some punctuation. You could do \def\ellip#1{\csname ellip#1\endcsname}, \expandafter\def\csname ellip!\endcsname {…<whatever you want>!}, etc..., naturally only if a few such characters are concerned, not dozens of them. But I don't see why one would like to do it for letters for example, or digits. Not much left then. (this method would not work if the characters are shorthands for babel, then one needs to replace #1 by \string#1 in the definition) – user4686 May 20 '14 at 17:28
  • That's why this doesn't work (I think), because it doesn't differentiate between letters and other symbols. …a and …! would both change the spacing. – Manuel May 20 '14 at 18:34
  • @Manuel but why would one ever type …a and not … a?? – user4686 May 20 '14 at 19:31
  • Yes, that's a rare case (which doesn't mean that it's okey if it doesn't work). But I would use …» or …— (an em-dash). – Manuel May 20 '14 at 23:00
3

You can use my \ifeqcase macro from the previous question and you can type:

\def\mydots{\dots\futurelet\next\mydotsA}
\def\mydotsA{\kern\ifeqcase\next {%
   ! {5em}
   ? {3em}
   , {1em}
  }{0pt}\relax
}

\mydots ?  \mydots !  \mydots ,

Of course, the spacing needs some correction.

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.