Using groff with the -ms Macro Package

1. Introduction
1.1. Basic information
2. General structure of an -ms document
3. Document control registers
4. Cover page macros
5. Body text
5.1. Paragraphs
5.2. Headings
5.3. Highlighting
5.4. Lists
5.5. Displays and keeps
5.6. Tables, figures, equations, and references
5.6.1. An example multi-page table
5.7. Footnotes
6. Page layout
6.1. Headers and footers
6.2. Margins
6.3. Multiple columns
6.4. Creating a table of contents
7. Differences from AT&T -ms
7.1. troff macros not appearing in groff
7.2. groff macros not appearing in AT&T troff
8. Acknowledgements

Larry Kollar
kollar@alltel.net

This document describes the GNU re-implementation of the popular groff -ms macro package.

The -ms macros are suitable for reports, letters, books, user manuals, and so forth. The package provides macros for cover pages, section headings, paragraphs, lists, footnotes, pagination, and a table of contents.

This document provides both tutorial and reference material. It also discusses differences from the AT&T -ms macros, both omissions and additions.

1. Introduction

The original -ms macros were included with AT&T troff as well as the -man macros. While the -man package is intended for brief documents that can be read on-line as well as printed, the -ms macros are suitable for longer documents that are meant to be printed rather than read on-line.

The -ms macro package included with -groff is a complete, bottom-up re-implementation. Several macros (specific to AT&T or Berkeley) are not included, while several new commands are. See Differences from AT&T -ms, later in this document, for more information.

1.1. Basic information

Most number registers have a default unit of measurement. Specifying a unit explicitly does not cause any problems, and can avoid problems in complex situations. The following are typical units:

Unit Description iinchesccentimetersppoints (about 1/72")vline heightnwidth of a letter ‘‘n’in the current fontmwidth of a letter ‘‘M’in the current fontPpica (1/6")

You set number registers by using the .nr request; for example:

.nr PS 12

2 v0.1, April 2001

2. General structure of an -ms document

The -ms macro package expects a certain amount of structure, but not as much as packages such as -man or -mdoc.

The simplest documents can begin with a paragraph macro (such as .LP or .PP), and consist of text separated by paragraph macros or even blank lines. Longer documents have a structure as follows:

Document type

If you invoke the .RP (report) macro on the first line of the document, groff prints the cover page information on its own page; otherwise it prints the information on the first page with your document text immediately following. Other document formats found in AT&T troff are specific to AT&T or Berkeley, and are not supported in groff.

Format and layout

By setting number registers, you can change your document’s type (font and size), margins, spacing, headers and footers, and footnotes. See Document control registers below for more details.

Cover page

A cover page consists of a title, the author’s name and institution, an abstract, and the date. 1

Actually, only the title is required.

See Cover page macros below for more details.

Body

Following the cover page is your document. You can use the -ms macros to write reports, letters, books, and so forth. The package is designed for structured documents, consisting of paragraphs interspersed with headings and augmented by lists, footnotes, tables, and other common constructs. See Body text below for more details.

Table of contents

Longer documents include a table of contents, which you can invoke by placing the .TC macro at the end of your document. 2

The -ms macros have minimal indexing facilities, consisting of the .IX macro, which prints an entry on standard error.

Printing the table of contents at the end is necessary since groff is a single-pass text formatter, thus it cannot determine the page number of each section until that section has actually been set and printed. Since -ms output was intended for hardcopy, the standard procedure was to manually relocate the pages containing the table of contents between the cover page and the body text.

Using groff with the -ms macros 3

3. Document control registers

The following table lists the document control number registers. For the sake of consistency, set registers related to margins at the beginning of your document, or just after the .RP macro. You can set other registers later in your document, but you should keep them together at the beginning to make them easy to find and edit as necessary.

Type RegisterDefinition Effective Default POPage offset (left margin) next page1iLLLine lengthnext ¶6iLTHeader/footer (title) lengthnext ¶6iHMTop (header) margin next page1iFMBottom (footer) margin next page1iMargins PSPoint sizenext ¶10pVSLine spacing (leading)next ¶12pTe xt PIInitial indentnext ¶5nPDSpace between paragraphsnext ¶0.3vQIQuoted paragraph indentnext ¶5nParagraphs FLFootnote lengthnext footnoteLL*5/6FIFootnote indentnext footnote2nFFFootnote formatnext footnote0Footnotes OtherMINGWMinimum width between columnsnext page2n

4 v0.1, April 2001

4. Cover page macros

Use the following macros to create a cover page for your document in the order shown.

MacroDescription .RP [no]Specifies the report format for your document. The report format creates a sepa-rate cover page. The default action (no .RP macro) is to print a subset of thecover page on page 1 of your document.If you use the optional no argument, groff prints a title page but does not repeatany of the title page information (title, author, abstract, etc.) on page 1 of thedocument. .DA [xxx](optional) Print the current date, or the arguments to the macro if any, on the titlepage (if specified) and in the footers. This is the default for nroff . .ND xxx [xxx](optional) Print the current date, or the arguments to the macro if any, on the titlepage (if specified) but not in the footers. This is the default for troff . .TLSpecifies the document title. groff collects text following the .TL macro into thetitle, until reaching the author name or abstract. .AUSpecifies the author’s name, which appears on the line (or lines) immediately fol-lowing. You can specify multiple authors as follows:.AUJohn Doe.AIUniversity of West Bumblefuzz.AUMartha Buck.AIMonolithic Corporation... .AISpecifies the author’s institution. You can specify multiple institutions in thesame way that you specify multiple authors. .AB [no]Begins the abstract. The default is to print the wordABSTRACT, centered and initalics, above the text of the abstract. The option no suppresses this heading. .AEEnd the abstract.

The following is example mark-up for a title page.

.RP.TLThe Inevitability of Code Bloatin Commercial and Free Software.AUJ. Random Luser.AIUniversity of West Bumblefuzz.ABThis report examines the long-term growthof the code bases in two large, popular softwarepackages; the free Emacs and the commercialMicrosoft Word.While differences appear in the type or orderof features added, due to the differentmethodologies used, the results are the samein the end..PPThe free software approach is shown to besuperior in that while free software canbecome as bloated as commercial offerings,free software tends to have fewer seriousbugs and the added features are in line withuser demand..AE... the rest of the paper follows ...

Using groff with the -ms macros 5

5. Body text

This section describes macros used to mark up the body of your document. Examples include paragraphs, sections, and other groups.

5.1. Paragraphs

Use the .PP macro to create indented paragraphs (like the next paragraph), and the .LP macro to create paragraphs with no initial indent (like this one).

The .QP macro indents its text at both left and right margins. The effect is identical to the HTML <BLOCKQUOTE> element. The next paragraph or heading returns margins to normal.

The following markup uses all three paragraph macros.

.NH 2Cases used in the study.LPThe following software and versions wereconsidered for this report..PPFor commercial software, we chose.B "Microsoft Word for Windows" ,starting with version 1.0 through thecurrent version (Word 2000)..PPFor free software, we chose.B Emacs ,from its first appearance as a standaloneeditor through the current version (v20)..QPFranklin’s Law applied to software:software expands to outgrow bothRAM and disk space over time.

5.2. Headings

Use headings to create a hierarchical structure for your document. The -ms macros print headings in bold, using the same font family and point size as the body text.

The following table describes the heading macros:

   

MacroDescription .NH xxNumbered heading. The argument xx is either a numeric argument to indicatethe level of the heading, or S xx xx... to set the heading level explicitly. The sec-tion headings in this document use the .NH macro to show the level of each sec-tion.If you specify heading levels out of sequence, such as invoking .NH 3 after.NH 1, groff prints a warning on standard error. .SHUnnumbered subheading.

5.3. Highlighting

The -ms macros provide a variety of methods to highlight or emphasize text:

MacroDescription .B [txt [post [pre]]]Sets its first argument in bold type. If you specify a second argu-ment, groff prints it in the previous font after the bold text, with nointervening space (this allows you to set punctuation after thehighlighted text without highlighting the punctuation). Similarly,it prints the third argument (if any) in the previous font before thefirst argument. For example,.B foo ) (prints (foo).If you give this macro no arguments, groff prints all text followingin bold until the next highlighting, paragraph, or heading macro. .R [txt [post [pre]]]Sets its first argument in roman (or regular) type. It operates simi-larly to the .B macro otherwise. .I [txt [post [pre]]]Sets its first argument in italic type. It operates similarly to the .Bmacro otherwise. .CW [txt [post [pre]]]Sets its first argument in a constant width face. It oper-ates similarly to the .B macro otherwise. .BI [txt [post [pre]]]Sets its first argument in bold italic type. It operates similarly tothe .B macro otherwise. .BX [txt]Prints its argument and draws a box around it. If you want to boxa string that contains spaces, use a digit-width space (\0). .UL [txt [post]]Prints its first argument with an underline . If you specify a secondargument, groff prints it in the previous font after the underlinedtext, with no intervening space. .LGPrints all text following inlarger type(2 points larger than thecurrent point size) until the next font size, highlighting, paragraph,or heading macro. You canspecify this macromultipletimesto enlarge the point size as needed. .SMPrints all text following insmaller type(2 points smaller than thecurrent point size) until the next type size, highlighting, paragraph,or heading macro. You canspecify this macromultiple timesto reduce thepoint size as needed. .NLPrints all text following in the normal point size (that is, the valueof the PS register).

5.4. Lists

The .IP macro handles duties for all lists. Its syntax is as follows:

.IP [marker [width]]

The marker is usually a bullet character (\(bu) for unordered lists, a number (or auto-incrementing number register) for numbered lists, or a word or phrase for indented (glossary-style) lists.

The width specifies the indent for the body of each list item. Once specified, the indent remains the same for all list items in the document until specified again.

The following are examples of each type of list:

Source Result A bulleted list:.IP \(bu 2lawyers.IP \(buguns.IP \(bumoneyA bulleted list:lawyersgunsmoney .nr step 1 1A numbered list:.IP \n[step] 3lawyers.IP \n+[step]guns.IP \n+[step]moneyA numbered list:1. lawyers2. guns3. moneyNote the use of the auto-incrementing numberregister in this example. A glossary-style list:.IP lawyers 0.4iTwo or more attorneys..IP gunsFirearms, preferablylarge-caliber..IP moneyGotta pay for thoselawyers and guns!A glossary-style list:lawyersTw o or more attorneys.guns Firearms, preferably large-caliber.moneyGotta pay for those lawyers and guns!

In the last example, note how the .IP macro places the definition on the same line as the term if it has enough space. This may or may not be the effect you want. The following example shows two possible workarounds:

Code Result A glossary-style list:.IP lawyers 0.4iTwo or more attorneys..IP guns.brFirearms, preferablylarge-caliber..IP moneyGotta pay for thoselawyers and guns!A glossary-style list:lawyersTw o or more attorneys.gunsFirearms, preferably large-caliber.moneyGotta pay for those lawyers and guns! A glossary-style list:.IP lawyers 0.4iTwo or more attorneys..IP guns\h'0.4i'Firearms, preferablylarge-caliber..IP moneyGotta pay for thoselawyers and guns!A glossary-style list:lawyersTw o or more attorneys.gunsFirearms, preferably large-caliber.moneyGotta pay for those lawyers and guns!

The first example uses the .br request to force a break after printing the term or label. The second example uses the \p escape to do the same thing. Note the space following the escape; this is important. If you omit the space, groff prints the first word on the same line as the term or label (if it fits) then breaks the line.

To set nested lists, use the .RS and .RE macros. These macros begin and end a section indented to line up with the body of an .IP macro. For example:

.IP \(bu 2Lawyers:.RS.IP \(buDewey,.IP \(buCheatham,.IP \(buand Howe..RE.IP \(buGuns...Lawyers:Dewey,Cheatham,and Howe.Guns ...

5.5. Displays and keeps

Use displays to show text-based examples or figures (such as code listings). This document shows groff code examples inside displays, for example.

Displays turn off filling, so lines of code can be displayed as-is without inserting .br requests in between each line. Displays can be kept on a single page, or allowed to break across pages. The following table shows the display types available.

Display macroWith keep No keepDescription .DS L.LDLeft-justified display..DS I [indent].IDIndented display (default is the DIregister)..DS B.BDBlock-centered display (left-justi-fied, longest line centered)..DS C.CDCenters all lines in the display..DS R.RDRight-justifies all lines in the display.

Use the .DE macro to end any display type.

On occasion, you may want to keep other text together on a page. For example, you may want to keep two paragraphs together, or a paragraph that refers to a table (or list, or other item) immediately following. The -ms macros provide the .KS and .KE macros for this purpose. The .KS macro begins a block of text to be kept on a single page, and the .KE macro ends the block.

You can specify a floating keep; if the keep cannot fit on the current page, groff holds the contents of the keep and allows text following the keep (in the source file) to fill in the remainder of the current page. When the page breaks, whether by an explicit .bp request or by reaching the end of the page, groff prints the floating keep at the top of the new page. This is useful for printing large graphics or tables that do not need to appear exactly where specified. Use the .KF and .KE macros to specify a floating keep.

You can also use the .ne request to force a page break if there is not enough vertical space remaining on the page.

5.6. Tables, figures, equations, and references

The -ms macros support the standard groff preprocessors: tbl, pic, eqn, and refer. You mark text meant for preprocessors by enclosing it in pairs of tags as follows:

Tag Pair Description .TS [H].TEDenotes a table, to be processed by the tbl preprocessor. The optional Hargument to .TS instructs groff to create a running header with the infor-mation up to the .TH macro. Groff prints the header at the beginning ofthe table; if the table runs onto another page, groff prints the header on thenext page as well. .PS.PEDenotes a graphic, to be processed by the pic preprocessor. You can cre-ate a pic file by hand, using theAT&Tpic manual available on the Web asa reference, or by using a graphics program such as xfig. .EQ [align].ENDenotes an equation, to be processed by the eqn preprocessor. The op-tional align argument can be C, L, or I to center (the default), left-justify,or indent the equation. .[.]Denotes a reference, to be processed by the refer preprocessor. TheGNUrefer(1) manpage provides a comprehensive reference to the preprocessorand the format of the bibliographic database.

5.6.1. An example multi-page table

The following is an example of how to set up a table that may print across two or more pages.

.TS Hallbox expand;cb | cb .Text ...of heading..._.TH.T&l | l .... the rest of the table follows....TE

5.7. Footnotes

The -ms macro package has a flexible footnote system. You can specify a numbered footnote 3

This is a numbered footnote.

by using the \** escape, followed by the text of the footnote enclosed by .FS and .FE macros.

You can specify symbolic footnotes†

†This is a symbolic footnote.

by placing the character (such as \(dg for the dagger character used here), followed by the symbol and the text of the footnote enclosed by .FS and .FE macros.

You can control how groff prints footnote numbers by changing the
value of the FF register as follows:

Value Description 0Prints the footnote number as a superscript; indents the footnote (default).1Prints the number followed by a period (like 1.) and indents the footnote.2Like 1, without an indent.3Like 1, but prints the footnote number as a hanging paragraph.

6. Page layout

The default output from the -ms macros provides a minimalist page layout: it prints a single column, with the page number centered at the top of each page. It prints no footers.

You can change the layout by setting the proper number registers and strings.

6.1. Headers and footers

There are two ways to define headers and footers:

Set the strings LH, CH, and RH, to set the left, center, and right headers; and LF, CF, and RF to set the left, center, and right footers. This works best for documents that do not distinguish between odd and even pages.

Use the .OH and .EH macros to define headers for the odd and even pages; and .OF and .EF macros to define footers for the odd and even pages. This is more flexible than defining the individual strings. The syntax for these macros is as follows:

.OH ’leftcenterright

You can replace the quote (’) marks with any character not appearing in the header or footer text.

6.2. Margins

You control margins using a set of number registers. The following table lists the register names and defaults:

Register Definition Effective Default POPage offset (left margin) next page1iLLLine lengthnext ¶6iLTHeader/footer (title) lengthnext ¶6iHMTop (header) margin next page1iFMBottom (footer) margin next page1i

Note that there is no right margin setting. The combination of page offset and line length provide the information necessary to derive the right margin.

6.3. Multiple columns

The -ms macros can set text in as many columns as will reasonably fit on the page. The following macros are available. All of them force a page break if a multi-column mode is already set. However, if the current mode is single-column, starting a multi-column mode does not force a page break.

MacroDescription .1CSingle-column mode. .2CTw o-column mode. .MC [width [gutter]]Multi-column mode. If you specify no arguments, it is equiva-lent to the .2C macro. Otherwise, width is the width of eachcolumn and gutter is the space between columns. The MINGWnumber register is the default gutter width.

6.4. Creating a table of contents

The facilities in the -ms macro package for creating a table of contents are semi-automated at best. Assuming that you want the table of contents to consist of the document’s headings, you need to repeat those headings wrapped in .XS and .XE macros.

In addition, the .XS macro does not know to indent a heading based on its level. The easiest way to work around this is to add tabs to the table of contents string. The following is an example:

.NH 1Introduction.XSIntroduction.XE....NH 2Methodology.XSMethodology.XE...

The Groff and Friends HOWTO includes a sed script that automatically inserts .XS and .XE entries after each heading in a document.

Altering the .NH macro to automatically build the table of contents is perhaps initially more difficult, but would save a great deal of time in the long run if you use -ms regularly.

7. Differences from AT&T -ms

This section lists the (minor) differences between the groff -ms macros and AT&T troff -ms macros.

7.1. troff macros not appearing in groff

Macros missing from groff -ms are cover page macros specific to Bell Labs. The macros known to be missing are:

.TM

Technical memorandum; a cover sheet style

.IM

Internal memorandum; a cover sheet style

.MR

Memo for record; a cover sheet style

.MF

Memo for file; a cover sheet style

.EG

Engineer’s notes; a cover sheet style

.TR

Computing Science Tech Report; a cover sheet style

.OK

Other keywords

.CS

Cover sheet information

.MH

A cover sheet macro

7.2. groff macros not appearing in AT&T troff

The groff -ms macros have a few minor extensions compared to the AT&T troff -ms macros.

.AM

Improved accent marks.

.DS I

Indented display. The default behavior of AT&T troff -ms was to indent; the groff default prints displays flush left with the body text.

.CW

Print text in constant width (Courier) font.

.IX

Indexing term (printed on standard error).

The MINGW number register specifies a minimum space between columns (for multi-column output); this takes the place of the GW register that was documented but apparently not implemented in AT&T troff. Several new string registers are available as well. You can change these to handle (for example) the local language.

REFERENCES

Contains the string printed at the beginning of the references (bibliography) page.

ABSTRACT

Contains the string printed at the beginning of the abstract.

TOC

Contains the string printed at the beginning of the table of contents.

6 v0.1, April 2001

8. Acknowledgements

Two documents provided essential reference material:

The Groff and Friends HOWTO, by Dean Allen Provins.

Using the -ms Macros with Troff and Nroff, the original AT&T document by M. E. Lesk.

Without these documents close at hand, writing this document would have been a much more difficult task.

Using groff with the -ms macros i

Table of Contents

Introduction

. . . . . . . . . . . . . . . . . . . . . . . . 1

Basic information

. . . . . . . . . . . . . . . . . . . 1

General structure of an -ms document

. . . . . . . . . . . . 2

Document control registers

. . . . . . . . . . . . . . . . . 3

Cover page macros

. . . . . . . . . . . . . . . . . . . . . . 4

Body text

. . . . . . . . . . . . . . . . . . . . . . . . . . 5

Paragraphs

. . . . . . . . . . . . . . . . . . . . . . . 5

Headings

. . . . . . . . . . . . . . . . . . . . . . . . 5

Highlighting

. . . . . . . . . . . . . . . . . . . . . . 5

Lists

. . . . . . . . . . . . . . . . . . . . . . . . . 5

Displays and keeps

. . . . . . . . . . . . . . . . . . . 5

Tables, figures, equations, and references

. . . . . . . 5

An example multi-page table

. . . . . . . . . . . . 5

Footnotes

. . . . . . . . . . . . . . . . . . . . . . . 5

Page layout

. . . . . . . . . . . . . . . . . . . . . . . . . 5

Headers and footers

. . . . . . . . . . . . . . . . . . 5

Margins

. . . . . . . . . . . . . . . . . . . . . . . . 5

Multiple columns

. . . . . . . . . . . . . . . . . . . . 5

Creating a table of contents

. . . . . . . . . . . . . . 5

Differences from AT&T -ms

. . . . . . . . . . . . . . . . . . 5

troff macros not appearing in groff

. . . . . . . . . . 5

groff macros not appearing in AT&T troff

. . . . . . . . 5

Acknowledgements

. . . . . . . . . . . . . . . . . . . . . . 6