标题问题很明显——有没有更简单的方法可以做到这一点(或者至少实际上作品?
在处理长破折号 (—) 时,我读到,在破折号和它分隔的文本之间保留少量空格很重要。我猜是单词间跳过的一半,无论它是什么。(我可能会根据情况将其更改为 2/3,但这与核心问题无关。)
单词间距理想的情况下,建议这样做(虽然我不记得了在哪里)这个间距应该是\thinspace
。(尝试this---separation
与this --- separation
——看起来都不太好。)但是,正如您从下面(夸张的)屏幕截图中看到的那样,这可能会导致视觉不一致(在第二段的第一行尤其明显)。(我认识到这也受到所用字体的影响。)
我尝试修复此问题:
\documentclass{article}
\newlength\halfinterwordspace
\newsavebox\interwordspace
\newcommand\Dash{%
\savebox\interwordspace{\ }
\setlength\halfinterwordspace{.5\wd\interwordspace}
\typeout{\the\halfinterwordspace}
%
\unskip % remove all previous skips
\hspace* \halfinterwordspace % unbreakable half-interword space
\textemdash % dash, equivalent to "---"
\hspace \halfinterwordspace % breakable half-interword space
% ^ also plays nice with microtype protrusion; see q/163116
}
% Uncomment to see the problem I am ultimately trying to fix.
% \def\Dash{\unskip\thinspace\textemdash\thinspace}
\sloppy
\hyphenpenalty=10000
\begin{document}
Lorem ipsum dolor sit amet \Dash consectetur adipiscing elit. Fusce
pharetra velit in sem congue \Dash quis malesuada lectus
vulputate. Quisque eu scelerisque nunc. Nam at dui eget metus
ullamcorper rutrum quis et tellus. Interdum et malesuada fames ac
ante ipsum primis in faucibus. Donec vitae augue vel nisi sollicitudin
tempus. Nam neque sapien \Dash ullamcorper vitae sapien at \Dash
volutpat cursus nisi. Nullam lorem ante \Dash fermentum sit amet
fermentum et \Dash rhoncus id ligula. Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas.
Integer congue \Dash sem eu tincidunt pharetra \Dash mi nunc accumsan
neque \Dash in auctor elit eros eget eros. Vestibulum quis varius
lectus.
Curabitur faucibus \Dash feugiat porttitor. Lorem ipsum dolor sit
amet \Dash consectetur adipiscing elit. Vestibulum elementum ipsum id
nisl accumsan \Dash sed rutrum sapien tincidunt. Cras sodales
sagittis neque vitae sollicitudin. Mauris at viverra quam. In nec
interdum diam \Dash ut ultrices velit. Nulla dapibus vulputate
luctus. Etiam vel faucibus augue \Dash ut aliquet massa. Vivamus eu
nunc at velit varius volutpat at eget eros. Nulla at justo quis quam
sagittis aliquam eget in tellus. Nunc est sem \Dash congue et tempus
a \Dash aliquet et nibh. Sed malesuada \Dash nisi eu placerat porta
\Dash orci augue pellentesque ante \Dash ac sollicitudin urna nunc sit
amet tellus. Curabitur hendrerit et enim non vehicula. Donec in nibh
fringilla \Dash sodales arcu eu \Dash hendrerit massa.
\end{document}
结果:
答案1
当前字体的正常字间间距为
\fontdimen2\font
您错误地认为\hspace*
它是“不间断空间”:它是一个“不消失的空间”。
这里有两个非常相似的定义\Dash
:
\documentclass{article}
\newcommand\Dash{%
\leavevmode
\unskip\nobreak\hspace{.5\fontdimen2\font}%
\textemdash
\hspace{.5\fontdimen2\font}%
}
\sloppy
\hyphenpenalty=10000
\begin{document}
Lorem ipsum dolor sit amet \Dash consectetur adipiscing elit. Fusce
pharetra velit in sem congue \Dash quis malesuada lectus
vulputate. Quisque eu scelerisque nunc. Nam at dui eget metus
ullamcorper rutrum quis et tellus. Interdum et malesuada fames ac
ante ipsum primis in faucibus. Donec vitae augue vel nisi sollicitudin
tempus. Nam neque sapien \Dash ullamcorper vitae sapien at \Dash
volutpat cursus nisi. Nullam lorem ante \Dash fermentum sit amet
fermentum et \Dash rhoncus id ligula. Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas.
Integer congue \Dash sem eu tincidunt pharetra \Dash mi nunc accumsan
neque \Dash in auctor elit eros eget eros. Vestibulum quis varius
lectus.
\renewcommand\Dash{%
\leavevmode\unskip
\thinspace\textemdash
\allowbreak\thinspace}
Lorem ipsum dolor sit amet \Dash consectetur adipiscing elit. Fusce
pharetra velit in sem congue \Dash quis malesuada lectus
vulputate. Quisque eu scelerisque nunc. Nam at dui eget metus
ullamcorper rutrum quis et tellus. Interdum et malesuada fames ac
ante ipsum primis in faucibus. Donec vitae augue vel nisi sollicitudin
tempus. Nam neque sapien \Dash ullamcorper vitae sapien at \Dash
volutpat cursus nisi. Nullam lorem ante \Dash fermentum sit amet
fermentum et \Dash rhoncus id ligula. Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas.
Integer congue \Dash sem eu tincidunt pharetra \Dash mi nunc accumsan
neque \Dash in auctor elit eros eget eros. Vestibulum quis varius
lectus.
\end{document}
注意事项:
我们
\nobreak\hspace{...}
设置了一个不间断的空格字距 (kern) 和 字符间距 (and)
\thinspace
都是一,不能用作换行点,除非它后面跟着粘连符;惩罚将是一个可行的换行点,并且\allowbreak
只会添加零惩罚。10pt 大小的 Computer Modern 字体的正常字间距为 3.33pt;细间距为 .16667em,而 em 为 10pt,因此最后细间距(至少在此字体设置下)与半间距相同。
如果你想为破折号周围的空间增加灵活性,那么
\newcommand\Dash{%
\leavevmode\unskip\nobreak
\hspace{\halfspace}%
\textemdash
\hspace{\halfspace}%
}
\newcommand{\halfspace}{%
.5\fontdimen2\font plus .5\fontdimen3\font minus .5\fontdimen4\font
}
\fontdimen3
我们利用和\fontdimen4
包含词间空间默认的可拉伸性和可收缩性的事实。
看不同的 \fontdimen<num> 代表什么意思了解参数含义的列表\fontdimen
。