unix - 如何在手册页中转义新行

标签 unix manpage groff troff

我重构了一个手册页的段落,以便每个句子都是它自己的一行。使用 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.

句子之间有一个额外的空格。请注意,我已确保没有多余的空白。我在 Latex、asciidoc 和 Markdown 方面有更多经验,我可以控制,是否可以使用 troff/groff ?如果可能的话,我想避免这种情况。我不认为它应该在那里。

最佳答案

troff输入标准是在每个句子的末尾有一个换行符,并让排字机完成它的工作。 (虽然我怀疑这是意图,但它确实使它在源代码控制中发挥得更好。)因此,它认为句子结尾在以句点结尾的行的末尾(或 ?! ,和可选后跟 '"*]) 或 †)。它还认为句子之间应该有两个空格。这几乎可以肯定来自当时贝尔实验室的排版标准;奇怪的是,这种行为无法通过任何填充模式进行设置。
groff确实提供了一种设置“句间”间距的方法,扩展 .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.



因此,您可以通过发出请求来指定“句子空间”应为零宽度
.ss 12 0

据我所知,这是一个 groff 扩展;传家宝 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.

关于unix - 如何在手册页中转义新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33424291/

相关文章:

java - 在java中创建文本文件并以unix格式保存

linux - 每 2391 字节添加换行符

在我自己的 shell 中创建后台进程

linux - Bash 循环 - 为目录中的每个现有 txt 文件创建一个文件夹

linux - 手册页中斜体和粗体周围的多余空间?

Linux/Unix 手册页语法约定

go - golang 的手册页?

Vim 无法自动识别 groff(联机帮助页)文件

java - 如何将 EOF 发送到 Java 中的进程?