roff

Mar 15, 2019
4 minute read

As the first text formatting program built for UNIX in 1970 running on a PDP-7, roff was a port of the BCPL program RUNOFF.

Over the years roff has evolved into troff and the excellent GNU version groff. Similar to other formatting systems, such as LaTeX, groff features a macro system, targetted at authoring certain types of text documents. In spite of its old age, roff is still in wide spread use today, for producing text such as UNIX manual pages, software books, system documentation and standards documents.

Compared to other text formatting systems, such as TeX, groff has a much smaller footprint (a complete LaTeX install can require several GB’s), and my favourite feature is that plain-text output is treated as a first class citizen (such as a man pages). Also just like TeX, groff can do looseless output formats such as postscript and PDF.

Installation

Depending on your distro, there’s a good chance a working groff system is already setup. On this Ubuntu 18 box I needed a:

sudo apt install groff groff-base

A tidy looking document (the ms macro set)

To get started, will take the ms macro set for a spin. Create a new text file test.ms:

.TL
My first groff document
.AU
Ben Simmonds
.AI
University of NSW
.AB \"abstract start
This is an abstract.
.AE \"abstract end
.NH
Introduction
.PP
This is a paragraph.
.PP
And another paragraph.
.NH
Background
.NH 2
The why
.PP
Some more text, this is
.B "bold"
ta da, and this
.I "italic"
boom.

The document has a title (TL), author (AU), institution (AI) and paragraph (PP).

This could be redirected into a ps file, or alternatively groff can just produce a PDF with the -T option:

$ groff -ms groff.ms -T pdf > groff.pdf

Sample document in a PDF viewer:

A humble man page (the man macro set)

While there is some similarity to using the ms macro as in the document example above, the man macro set does introduce some specific character sequences. Check man groff_man to get an awesome cheat sheet.