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

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.

| improve this answer | |
  • 2
    Possibly adding \unskip at the front and \ignorespaces at the end to be on the safe side. – egreg Sep 9 '13 at 8:36

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.