如何使 LaTeX 正确地对前面或后面带有三重破折号的单词进行连字符连接?

如何使 LaTeX 正确地对前面或后面带有三重破折号的单词进行连字符连接?

我正在使用回忆录类来写一本小说。众所周知,小说人物对话中的作者评论通常用长破折号括起来,而长破折号在 LaTeX 中则写成三重破折号。然而,当这些长破折号(总是在单词后面或前面,中间没有空格)靠近换行符时,我遇到了麻烦:大多数情况下,断词没有连字符,因此行超出了换行符边距。如何解决这个问题?

答案1

通常,硬连字符 ( -) 不允许在单词的其他地方使用连字符,但您可以用\textemdash它来代替连字符---

\documentclass{article}

% only to show the margins
\usepackage[showframe]{geometry,xcolor} 
\makeatletter
\def\Gm@hrule{}%
\def\Gm@vrule{\color{gray!30}\vrule width 1pt height\textheight depth\z@}%
\def\Gm@hruled{}%
\makeatother


\begin{document}

Something something something something something something something something 
---something--- something something something something something something something something somethin something

Something something something something something something something something 
\textemdash something\textemdash something something something something something something something something somethin something

\end{document}

但实际上,最简单的解决方案是在需要时添加软连字符:---some\-thing---

答案2

在和单词之间添加一个不可见的空格---可以使 LaTeX 正确地对单词进行连字符连接。

\documentclass[draft]{article}

\begin{document}
\noindent
something something something something something something some
---something % no hyphenation resulting in overfull box
something something something something something something something something

\noindent
something something something something something something some
---\hspace{0pt}something
something something something something something something something something
\end{document}

因此,为了获得一个好的解决方案,我建议您编写一个宏来插入正确的间距等,如下所示

\newcommand{\dialogue}[1]{---\hspace{0pt}#1\hspace{0pt}---}

或者无论您遵循什么格式。

相关内容