paulgorman.org/technical

troff, groff, etc.

troff is a typesetting system and markup language written by Brian Kernighan at Bell Labs in 1979. GNU implements it as “groff”.

Building blocks of troff:

nroff sends output to a terminal instead of formatting it for printing. Format a file of troff primitives:

$ nroff -c myfile | less

troff produces (semi-)device-independent output that must be processed for a particular printer.

$ troff myfile | hplj | lpr -hP printer

A sample file:

.ft bi
text filling and margin adjustments
.ft p

by default, troff fills lines to produce fully justified output with consistent right margins.
however, the `.nf` primitive tells troff to leave a ragged right margin.

.nf
this bit of
text will not be joined
together
to fill a line.

.fi
`.fi` is a primitive command that restores filling of lines.

blank lines separate blocks of text.
the `.br` primitive can be used to
.br
insert manual breaks.

.ad l
the primitive `.ad` adjusts the margins of filled text.
the "l" argumnet, like `.ad l`, sets the text to left justified, as opposed to the fully justified default.
this paragraph should be left justified, and look different from the first paragraph.

.ad r
the primitive `.ad r` sets the text to right justified.

.ad c
adjust the margin to center the text with `.ad c`.

.ad b
the `.ad b` primitive returns the text to default fully-justified block margins.

.nf
.ce 5
if we turn off filling of lines
with `.nf`, we can
turn on
centering with `.ce`, but we must
specify the number of lines as an argument, like `.ce 5`.

.ft bi
vertical spacing
.ft p

Mom

Mom is macro package that ships with GNU Troff/groff aimed at ease of use and PDF output. http://www.schaffter.ca/mom/momdoc/toc.html

Generate output like:

$ groff -mom filename.mom > filename.ps

or, preferably:

$ pdfmom -K utf-8 filename.mom > filename.pdf

Example:

.PRINTSTYLE TYPESET
.PAGELENGTH 8.5i
.PAGEWIDTH 5.5i
.L_MARGIN 33.45p
.R_MARGIN 33.45p
.T_MARGIN 33.87p
.B_MARGIN 33.87p
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

Here’s my take on a screenplay format using Mom:

\" Use Groff Mom and a few custom macros for approximate screenplay formatting.
\" $ pdfmom -K utf-8 screenplay.mom > screenplay.pdf
.PRINTSTYLE TYPESET
.PAPER LETTER
.L_MARGIN 1.5i
.R_MARGIN 1.0i
.T_MARGIN 1.0i
.B_MARGIN 1.0i
.FOOTER_MARGIN 0
.FOOTERS OFF
.HEADERS OFF
.PAGENUM_FONT C
.PAGENUM_POS TOP RIGHT
.PAGENUM_STYLE DIGIT
.PAGENUM_ON_FIRST_PAGE OFF
.PAGENUM_HYPHENS OFF
.FAMILY C
.PT_SIZE 12

.DOCHEADER_ADVANCE 0

 \" Character name/dialog cue:
 .de C
 .IBX CLEAR
 .IL 2.2i
 \\$*
 .IQ CLEAR
 ..

 \" Parenthetical dialog direction
 .de P
 .IBX CLEAR
 .IL 1.5i
 .IR 2.0i
 \\$*
 .IQ CLEAR
 ..

 \" Dialog
 .de D
 .IBX CLEAR
 .IL 1.0i
 .IR 1.5i
 \\$*
 .IQ CLEAR
 ..

 \" Transition
 .de T
 .rj
 \\$*
 ..

 .START
 .ad l

 INT. OBSERVATORY GANGWAY — DAY

 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

 .C ELIZABETH
 .P (while spitting up mouthfuls of blood)
 .D Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 

 .C JOHN (O.S.)
 .D Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

 .T CUT TO:

 .C FREDDIE
 .D Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
 .P (into phone)
 .D Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

 EXT. BATTLEMENT (DENMARK) — NIGHT

 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.