如何转义手册页中的新行

How to escape new line in man pages

我重构了一个手册页的段落,使每个句子都独占一行。使用 man ./somefile.3 渲染时输出略有不同。

举个例子:

This is line 1. This is line 2.

对比

This is line 1.
This is line 2.

正在渲染:

第一个:

This is line 1. This is line 2.

第二个:

This is line 1.  This is line 2.

句子之间多了一个space。请注意,我已经确保没有多余的白色space。我对 Latex、asciidoc 和 markdown 有更多的经验,我可以在那里控制它,troff/groff 有可能吗?如果可能的话,我想避免这种情况。我 认为 它不应该存在。

所以下面的方法可行,但我希望有更好的选择。

This is line 1. \
This is line 2.

呈现为

This is line 1. This is line 2.

troff输入标准是每句末尾换行,让排字机填空。 (虽然我怀疑这是故意的,但它确实使它在源代码管理中发挥得更好。)因此,它认为句子结束是在以句点(或 ?!,并可选择后跟 '"*]) 或 †)。它还认为句子之间应该有两个空格。这几乎可以肯定源自当时贝尔实验室的排版标准;奇怪的是,这种行为不能通过任何填充模式设置。

groff 确实提供了一种设置 "inter-sentence" 间距的方法,扩展 .ss request:

.ss word_space_size [sentence_space_size]

Change the size of a space between words. It takes its units as one twelfth of the space width parameter for the current font. Initially both the word_space_size and sentence_space_size are 12. In fill mode, the values specify the minimum distance.

If two arguments are given to the ss request, the second argument sets the sentence space size. If the second argument is not given, sentence space size is set to word_space_size. The sentence space size is used in two circumstances: If the end of a sentence occurs at the end of a line in fill mode, then both an inter-word space and a sentence space are added; if two spaces follow the end of a sentence in the middle of a line, then the second space is a sentence space. If a second argument is never given to the ss request, the behaviour of UNIX troff is the same as that exhibited by GNU troff. In GNU troff, as in UNIX troff, a sentence should always be followed by either a newline or two spaces.

因此您可以通过发出请求

来指定 "sentence space" 应该是零宽度
.ss 12 0

据我所知,这是一个 groff 扩展; heirloom troff 支持它,但旧的 dwb 派生版本可能不支持。

示例:

This is line 1. This is line 2.

This is line 1.  This is line 2.

This is line 1.
This is line 2.

SET SENTENCE SPACING

.ss 12 0
This is line 1. This is line 2.

This is line 1.  This is line 2.

This is line 1.
This is line 2.

结果:

$ groff -T ascii spaces.tr  |sed -n -e/./p
This is line 1. This is line 2.
This is line 1.  This is line 2.
This is line 1.  This is line 2.
SET SENTENCE SPACING
This is line 1. This is line 2.
This is line 1. This is line 2.
This is line 1. This is line 2.