Back to Table of Contents | Next: The typesetting macros |
As explained in the section What is mom?, mom can be used in two ways: for straight typesetting or for document processing. The difference between the two is that in straight typesetting, every macro is a literal typesetting instruction that determines precisely how text following it will look. Document processing, on the other hand, uses markup tags (e.g. .PP for paragraphs, .HEAD for heads, .FOOTNOTE for footnotes, etc.) that make a lot of typesetting decisions automatically.
You tell mom that you want to use the document processing macros with the START macro, explained below. After START, mom determines the appearance of text following the markup tags automatically, although you, the user, can easily change how mom interprets the tags. This gives you nearly complete control over document design. In addition, the typesetting macros, in combination with document processing, let you meet all sorts of typesetting needs that just can’t be covered by “one macro fits all“ markup tags.
Regardless of which way you use mom, the following apply:
Tip:
It’s important that formatted documents be easy to
read/interpret when you’re looking at them in a text editor.
One way to achieve this is to group macros that serve a similar
purpose together, and separate them from other groups of macros
with a blank comment line. In groff, that’s done with
\# on a line by itself. Consider the
following, which is a template for starting the chapter of a book.
.TITLE "My Pulitzer Novel"
.AUTHOR "Joe Blow"
.CHAPTER 1
\#
.DOCTYPE CHAPTER
.PRINTSTYLE TYPESET
\#
.FAM P
.PT_SIZE 10
.LS 12
\#
.START
Other than printing out hard copy, there are two well-established methods for previewing your work. Both assume you have a working X server.
Groff itself comes with a quick and dirty previewer called
gxditview. Invoke it with:
groff -X -mom <filename>
It’s not particularly pretty, doesn’t have many
navigation options, requires a lot of work if you want to use
other than the standard groff PostScript fonts, and occasionally has
difficulty accurately reproducing some of mom’s macro effects
(smartquotes
and
leaders
come to mind). What it does have going for it is that it’s
fast and doesn’t gobble up system resources.
A surer way to preview documents is with gv (ghostview). This
involves processing documents with groff and directing the default
PostScript output to a file, like this:
groff -mom <filename> > <filename>.ps
You can then then open the ps file in gv.
Tip:
I’ve set up my editor (vi[m]) to do seamless, automatic
previewing. Whenever I’m working on a document that
needs previewing/checking, I fire up gv with the “Watch
File“ option turned on. The first time I want to look at
the file, I tell vim (via a keymapping) to process it with groff
and send it to a PostScript file:
groff -mom <filename> > <filename>.ps
I then open the file inside gv. Ever after, when I want to look at
any changes I make, I simply tell vim to work its magic again.
The Watch File option in gv registers that the PostScript file has
changed, and automatically loads the new version. VoilĂ !—instant
previewing.
By default, groff dumps its PostScript output to stdout (your
terminal screen) so you have to say where you want it to go if you
want to save it to a file. The most straightforward way to do
this is:
groff -mom <filename> > <filename>.ps
which drops the output in a PostScript file. Alternatively, you
might prefer to save it as a pdf file, in which case you'd do:
groff -mom <filename> | ps2pdf - <filename>.pdf
You can process and print documents from the command line without saving them to .ps or .pdf files first. Here are two common ways to do it: groff -mom -l <filename> groff -mom <filename> | lpr
In the first, the -l option tells groff
to send the output to your printer. In the second, you’re
doing the same thing, except you’re telling groff to
pipe the output to your printer spooler. Basically,
they’re the same thing. The advantage to the second is that
you can pass additional options to lpr, for example to send
the output to a particular printer, like this:
groff -mom <filename> | lpr -P <printer_name>
Back to Table of Contents | Top | Next: The typesetting macros |