4

I wish to have a space between and after my em-dashes as I do not like the english tradition to collate them to the nearest words. xspace permits to leave spaces for macros but does not handle well the --- via its exception rules. There is an illustration on page 3 of its PDF http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/required/tools/xspace.pdf to manage the -, but I cannot get it right for ---. \xspaceremoveexception{--(-)} does not seem to work because, evidently, I wish the en-dash -- to remain as it is: no space after the macro \mymacro--sometext, since by definition, these -- are used to indicate a range. Here is a MWE to illustrate with the hack commented from the PDF:

 %\RequirePackage{fix-cm}
\documentclass[twoside, a4paper, 11pt]{article}

\usepackage[T1]{fontenc}
\usepackage{xspace}

%\xspaceremoveexception{-}
%\makeatletter
%\renewcommand*\@xspace@hook{%
%\ifx\@let@token--%
%\expandafter\@xspace@dash@iii
%\fi
%}
%\def\@xspace@dash@i-{\futurelet\@let@token\@xspace@dash@ii}
%\def\@xspace@dash@ii{%
%\ifx\@let@token-%
%\else
%\unskip
%\fi
%-%
%}
%\makeatother




%\xspaceremoveexception{--}

\newcommand{\bla}{January}

\newcommand{\blaa}{{January}\xspace}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%é


\begin{document}


without xspace:\\
 \bla --- ouoiuoiuou --- \bla ; \bla (\bla)

with xspace: the parenthesis improves, not the --- :\\
 \blaa --- ouoiuoiuou --- \blaa ; \blaa (\blaa)

\blaa --December   \blaa--December

\blaa -December
\end{document}




%\xspaceremoveexception{-}
%\makeatletter
%\renewcommand*\@xspace@hook{%
%\ifx\@let@token-%
%\expandafter\@xspace@dash@i
%\fi
%}
%\def\@xspace@dash@i-{\futurelet\@let@token\@xspace@dash@ii}
%\def\@xspace@dash@ii{%
%\ifx\@let@token-%
%\else
%\unskip
%\fi
%-%
%}
%\makeatother
2
  • Knuth defined somewhere a \dash macro which I have used in the past. Commented Sep 9, 2013 at 3:49
  • 1
    This question seems to have a better answer elsewhere, based on microtype: tex.stackexchange.com/a/109188/1340. You still write --- for an em-dash, and use microtype to give it extra kerning. Commented Jun 28, 2017 at 17:41

1 Answer 1

2

As a "hacky solution", what I do is to create a command \newcommand{\emdash}{\,---\,} and then \renewcommand{\emdash}{---} for documents where I don't want enclosing spaces.

1
  • 3
    Possibly adding \unskip at the front and \ignorespaces at the end to be on the safe side.
    – egreg
    Commented Sep 9, 2013 at 8:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .