groff/troff macros: ms, mm, me or mom
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
groff/troff macros: ms, mm, me or mom
Photos Projects Writings groff/troff macros: ms, mm, me or mom This is a brief explanation of how to choose which macro package to use with the Unix typesetting system troff (or groff). I assume you are familiar with Linux or Unix. The short answer is: use ms, unless you’re writing a novel (then use mom) or a structured document (then use mm—and find a good reference book for it).
照片、项目、写作:groff/troff 宏包:ms、mm、me 或 mom。这是一篇关于如何为 Unix 排版系统 troff(或 groff)选择宏包的简要说明。我假设你熟悉 Linux 或 Unix。简短的回答是:使用 ms,除非你在写小说(那就用 mom)或者结构化文档(那就用 mm——并找一本好的参考书)。
What are troff and groff? Troff is the original Unix typesetting software. Troff is not like a modern word processor, where the pages of your document appear on-screen just as they will appear on paper and you edit them with a mouse. With troff, your document is a plain-text file mixing text with embedded formatting commands. To see what your document looks like, you process the plain-text file with troff to generate a PDF file, then open the PDF and check to see if you got what you wanted.
什么是 troff 和 groff?Troff 是最初的 Unix 排版软件。Troff 不像现代文字处理器那样,文档页面在屏幕上的显示效果与打印在纸上完全一致,且可以通过鼠标进行编辑。使用 troff 时,你的文档是一个混合了文本和嵌入式格式化命令的纯文本文件。要查看文档的效果,你需要用 troff 处理该纯文本文件以生成 PDF 文件,然后打开 PDF 查看是否达到了预期的效果。
An example of a troff formatting command is “.ce”, which centers the next line of text. These simple commands are called “requests.” The other kind of formatting command is called a “macro,” which is essentially a bundle of formatting commands. You could bundle together commands for indenting text, making the font bold and printing sequential numbers, all into a single macro. Then you could use this macro to automatically number and format the headings in your document.
一个 troff 格式化命令的例子是“.ce”,它会将下一行文本居中。这些简单的命令被称为“请求”(requests)。另一种格式化命令被称为“宏”(macro),本质上是一组格式化命令的集合。你可以将缩进文本、加粗字体和打印序列号的命令捆绑在一起,形成一个单一的宏。然后,你可以使用这个宏来自动编号并格式化文档中的标题。
Macros help you separate formatting from text, which can make it easier to change the formatting or the text. If you decide that instead of indenting your headings, you want to center them, you could simply change the “heading” macro instead of manually changing the formatting of each heading in your document. Macros also mean that you can easily copy text from one troff document into another. In a word processor, on the other hand, copied text will carry along formatting from the original document, and unless the two documents have exactly the same styles, you’ll probably need to reformat the copied text from scratch.
宏可以帮助你将格式与文本分离,从而更容易更改格式或文本。如果你决定将标题改为居中而不是缩进,只需修改“标题”宏,而不必手动更改文档中每个标题的格式。宏还意味着你可以轻松地将文本从一个 troff 文档复制到另一个文档中。而在文字处理器中,复制的文本会携带原始文档的格式,除非两个文档的样式完全相同,否则你可能需要从头开始重新格式化复制的文本。
One of the greatest Unix programmers, W. Richard Stevens, used troff to typeset all of his books. But even he agreed that troff is not easy to use, saying, “Troff is an industrial strength package that I have spent years of my life learning.” But despite its difficulty, troff can be more efficient to use than a word processor. Technical writing can be faster because the entire troff document is written in plain text, including the commands to make tables, diagrams, math equations etc.
最伟大的 Unix 程序员之一 W. Richard Stevens 用 troff 排版了他所有的书。但即使是他也承认 troff 不易使用,他说:“Troff 是一个工业级的软件包,我花了数年时间才学会。”尽管有难度,但 troff 在使用上可能比文字处理器更高效。技术写作可以更快,因为整个 troff 文档都是用纯文本编写的,包括制作表格、图表、数学公式等的命令。
In a word processor, it might be necessary to manually construct diagrams and math equations using a mouse or to create them in a separate program altogether, which takes more time. This was W. Richard Stevens’ reason for using troff. Reformatting a document is faster because it only requires changing a few macros. An author writing a book for publication will need to reformat the book several times, which can take an enormous amount of time in a word processor. This was the reason for Peter Schaffter, who created the macro package mom.
在文字处理器中,可能需要使用鼠标手动构建图表和数学公式,或者在单独的程序中创建它们,这会花费更多时间。这就是 W. Richard Stevens 使用 troff 的原因。重新格式化文档更快,因为它只需要更改几个宏。作者在撰写出版书籍时需要多次重新格式化书籍,这在文字处理器中可能需要花费大量时间。这就是创建了 mom 宏包的 Peter Schaffter 的理由。
Having the entire troff document in plain text makes it easy to parameterize in software. For example, it is easy to use troff to create a batch of letters in PDF format for multiple people. Or, if you have written a computer program, you might use troff to enable your program to print, without having to directly generate PDF files or rely on non-standard APIs.
将整个 troff 文档以纯文本形式保存,使其易于在软件中进行参数化。例如,使用 troff 为多人批量创建 PDF 格式的信件非常容易。或者,如果你编写了一个计算机程序,你可以使用 troff 使你的程序具备打印功能,而不必直接生成 PDF 文件或依赖非标准 API。
Troff was created by Bell Labs in the early 1970’s and came with AT&T Unix for decades. But AT&T Unix is now almost completely obsolete, so you are not likely to find a copy of troff. Instead you are likely to find groff, which is a clone of troff published by the GNU Project. Just about everything above also applies to groff and from here I will only refer to groff unless the distinction is important.
Troff 由贝尔实验室在 20 世纪 70 年代初创建,并随 AT&T Unix 附带了数十年。但 AT&T Unix 现在几乎完全过时了,所以你不太可能找到 troff 的副本。相反,你更有可能找到 groff,它是 GNU 项目发布的 troff 克隆版。以上几乎所有内容也适用于 groff,从这里开始,除非有必要区分,否则我将只提到 groff。
What are ms, mm, me and mom? You can, if you want, write a groff document entirely from scratch. This would mean defining your own macros for headings, footnotes, bullet lists, and so on. But there is an easier way. There are standard macro packages, each with dozens of useful macros. Four of them are called ms, mm, me and mom.
什么是 ms、mm、me 和 mom?如果你愿意,可以完全从零开始编写 groff 文档。这意味着你需要为标题、脚注、项目符号列表等定义自己的宏。但有一种更简单的方法。有一些标准的宏包,每个宏包都有几十个有用的宏。其中四个被称为 ms、mm、me 和 mom。
Bell Labs made the first macro package, ms, for internal use, writing technical papers and reports. It’s pretty easy to use and doesn’t have many weird surprises. You can mix up groff requests and ms macros, which is helpful if you have a clear vision for how you want your document to look. W. Richard Stevens used a customized version of ms for the books he wrote. But ms is more limited than mm or mom, so you need to use groff requests for even basic formatting such as numbered lists. The online documentation for ms is adequate but not great.
贝尔实验室制作了第一个宏包 ms,用于内部编写技术论文和报告。它非常易于使用,且没有太多奇怪的意外。你可以混合使用 groff 请求和 ms 宏,如果你对文档的外观有清晰的构想,这会很有帮助。W. Richard Stevens 在他编写的书籍中使用了 ms 的定制版本。但 ms 比 mm 或 mom 更受限,因此即使是编号列表等基本格式,你也需要使用 groff 请求。ms 的在线文档尚可,但并不出色。
At one time, Unix was the most advanced typesetting system in the world, using the mm macro package. This macro package is a lot more full-featured than ms. For example, it has numbered lists (in arabic numerals, roman numerals or letters) built-in. It also supports cross-references, which are essential for structured documents such as technical books. Unfortunately, mm is a little less intuitive than ms and the documentation on the Internet for mm is abysmal. However, there are excellent books on mm from the glory days of Unix typesetting, which you can buy used for cheap.
曾经,Unix 是世界上最先进的排版系统,使用的是 mm 宏包。这个宏包比 ms 功能丰富得多。例如,它内置了编号列表(阿拉伯数字、罗马数字或字母)。它还支持交叉引用,这对于技术书籍等结构化文档至关重要。不幸的是,mm 比 ms 稍微不直观一些,而且互联网上关于 mm 的文档非常糟糕。然而,在 Unix 排版的黄金时代,有一些关于 mm 的优秀书籍,你可以廉价买到二手书。
A developer at the University of California, Berkeley wrote the me macro package in the 1980s. It is more complete than ms, but me’s creator has not worked on it for decades and the documentation is limited to two short papers written by its creator. I do not recommend using me.
加州大学伯克利分校的一位开发人员在 20 世纪 80 年代编写了 me 宏包。它比 ms 更完整,但 me 的创建者已经几十年没有维护它了,文档也仅限于其创建者写的两篇短文。我不建议使用 me。
The most modern of the four is mom, created by a novelist. It has advanced typographical features and is about as powerful as mm. It is designed for ease-of-use and has excellent online documentation. For many users, mom is the right choice. However for some uses, it may be practically impossible to use mom, and it lacks a few specific features that mm has. There is also man, which you do not want to use for creating ordinary documents. It is used by the man command to d
这四个宏包中最现代的是 mom,由一位小说家创建。它具有先进的排版功能,功能与 mm 相当。它专为易用性而设计,并拥有出色的在线文档。对于许多用户来说,mom 是正确的选择。然而,对于某些用途,使用 mom 可能实际上是不可能的,而且它缺少 mm 所具备的一些特定功能。此外还有 man,你不应该用它来创建普通文档。它被 man 命令用于 d