我希望在破折号之间和之后有一个空格,因为我不喜欢按照英语传统将它们与最接近的单词进行排序。
xspace
允许为宏留出空间,但不能很好地处理---
例外规则。其 PDF 第 3 页上有一张插图
http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/required/tools/xspace.pdf
来管理-
,但我无法正确处理---
。
\xspaceremoveexception{--(-)}
似乎不起作用,因为显然我希望 en-dash--
保持原样:宏\mymacro--
sometext 后没有空格,因为根据定义,它们--
用于指示范围。以下是 MWE,使用 PDF 中注释的 hack 进行说明:
%\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
答案1
作为一种“黑客解决方案”,我所做的是创建一个命令\newcommand{\emdash}{\,---\,}
,然后\renewcommand{\emdash}{---}
针对我不想包含空格的文档创建一个命令。