语义换行符和破折号周围的空格

语义换行符和破折号周围的空格

我想使用语义换行在我的文档的源代码中,但我不确定如何处理破折号:---

每行一句,无破折号空格:

The food---which was delicious---reminded me of home.
The food, which was delicious, reminded me of home.

每行子句,不一致的破折号空格:

The food
---which was delicious---
reminded me of home.
The food,
which was delicious,
reminded me of home.

我希望两个来源呈现相同的效果,但是每行子句版本在破折号之前或之后引入了一个空格。

我可以用

每行一个句子,用破折号分隔符:

The food --- which was delicious --- reminded me of home.

每行一个子句,使用破折号空格:

The food
--- which was delicious ---
reminded me of home.

它们彼此呈现相同,并使破折号间距情况与逗号情况一致。

我想推迟破折号周围空间大小的样式选择,并且能够尝试不同的选择,而无需修改整个源代码。

我更愿意继续使用三重 ASCII 破折号---,也可以考虑使用 Unicode 字符,但我不想使用任何反斜杠\来调用命令。

有关的: 语义换行和脚注标记前的空格问题

答案1

这个答案直接取自我在根据字典自动突出显示文本,使用相同的技术:通过扫描仪运行环境的标记以搜索,在本例中为-标记。如果发现它们以三个为一组出现,则在执行标记列表之前,将标记前面加上\unskip,并在后面加上。\ignorespaces

要启动环境,请调用\def\currentword{}\tokencyclexpress;要关闭环境,请调用\endtokencyclexpress。此操作可在文档的开始和结束时执行一次。

\documentclass{article}
\usepackage{tokcycle,listofitems,xcolor}
\setsepchar{-}
\newcommand\testdict{%
  \if\relax\detokenize\expandafter{\currentword}\relax\else
    {\ignoreemptyitems
      \greadlist\dictcompA{\currentword}}%
    \ifnum\listlen\dictcompA[]=0\relax
      \addcytoks[1]{\autohighlightStyleA}%
      \addcytoks[1]{\expandafter{\currentword}}
    \else
      \addcytoks[1]{\currentword}%
    \fi
  \fi
  \gdef\currentword{}%
}
\makeatletter
\Characterdirective{\tctestifx 
  {-#1}{\g@addto@macro\currentword{#1}}
  {\testdict\addcytoks{#1}}}
\stripgroupingtrue
\Groupdirective{\testdict\groupedcytoks{\processtoks{#1}\testdict}}
\Macrodirective{\g@addto@macro\currentword{#1}}
\Spacedirective{\testdict\addcytoks{#1}}
\makeatother
\newcommand\autohighlightStyleA{\zz}
\def\emdashref{---}
\newcommand\zz[1]{\def\tmp{#1}\ifx\emdashref\tmp
  \unskip#1\ignorespaces\else#1\fi}
\begin{document}
\def\currentword{}\tokencyclexpress
The food---which was delicious---reminded me of home.
The food, which was delicious, reminded me of home. - . -- .

The food
---which was delicious---
reminded me of home.
The food,
which was delicious,
reminded me of home. - . -- .
\endtokencyclexpress
\end{document}

在此处输入图片描述

答案2

您可以%在行尾添加以抑制空格:

The food%
---which was delicious---%
reminded me of home.
The food,
which was delicious,
reminded me of home.

相关内容