如何乾淨/有效率地插入字間跳過的*一半*?

如何乾淨/有效率地插入字間跳過的*一半*?

標題問題很明顯地提出了——是否有一種更簡單的方法來做到這一點(或至少是一種實際上可以實現的方法)作品

在處理長破折號 (—) 時,我了解到在破折號與其分隔的文字之間保留少量空格非常重要。我猜有一半的詞間跳躍,不管是什麼。 (我可能會將其更改為 2/3,具體取決於,但這與核心問題無關。)

建議使用理想的字間距(雖然我不記得了)在哪裡) 該間距為\thinspace. (嘗試this---separationthis --- 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}

注意事項:

  1. 我們\nobreak\hspace{...}設定了一個不間斷的空格

  2. 緊排\thinspace是一個,不能用作換行點,除非緊接在後的是黏合;懲罰將是一個可行的斷線點,並且\allowbreak只添加零懲罰。

  3. 10pt 大小的 Computer Modern 字體的正常字間距為 3.33pt;細空格為 0.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

相關內容