[Tex/LaTex] Configurable spacing after \dots

ellipsiskerningspacingsymbols

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

Best Answer

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.

Related Question