MDOC.SAMPLES

Section: Environments, Tables, and Troff Macros (7)
Index Return to Main Contents

BSD mandoc
 

NAME

mdoc.sample - writing manual pages with -mdoc macro package  

SYNOPSIS

man mdoc.sample  

DESCRIPTION

A tutorial sampler for writing BSD manual pages with the -mdoc macro package, a content -based formatting package for troff(1). Its predecessor, the -man7 package, addressed page structure leaving the manipulation of fonts and other typesetting details to the individual author. The -mdoc package allows the author to ignore font considerations by using macros to label pieces of text according to content. In the context of manual pages, examples of content are a command name, a file pathname or a cross reference to another manual page; these items have value for both the author and the future user of the manual page. It is hoped the consistency gained across the manual set will provide easier translation to future documentation tools.

Through out the UNIX manual pages, a manual entry is simply referred to as a man page, regardless of actual length and without sexist intention.  

TROFF IDIOSYNCRASIES

The -mdoc package attempts to simplify the process of writing a man page. Theoretically, one should not have to learn the dirty details of troff(1) to use -mdoc however, there are a few limitations which are unavoidable and best gotten out of the way. And, too, be forewarned, this package is not fast.  

Macro Usage

As in troff(1), a macro is called by placing a `.' (dot character) at the beginning of a line followed by the two character name for the macro. Arguments may follow the macro separated by spaces. It is the dot character at the beginning of the line which causes troff(1) to interpret the next two characters as a macro name. To place a `.' (dot character) at the beginning of a line in some context other than a macro macro, precede the `.' (dot) with a `\&'

In general, troff(1) macros accept up to nine arguments, any extra arguments are ignored. Most macros in -mdoc accept nine arguments and, in limited cases, arguments may be continued or extended on the next line (See Sx Extensions - macro `. ' and `. ' A few macros handle quoted aguments (see Sx Passing Space Characters in an Argument below). Many -mdoc macros may be given the name of another macro as an argument. In this case the argument, although the name of a macro, is not preceded by a `.' (dot), and is called when the argument is processed. It is in this manner that some macros are nested; for example the option macro, `.[,] ' may call the flag and argument macros, `.- ' and `.file ... ' to specify an optional flag with an argument:

[-s bytes ]
is produced by .[-s bytes ]

To prevent a two character string from being interpreted as a macro name, precede the string with the escape sequence `\&' :

[-s bytes ]
is produced by .[\&-s \&bytes ]

Here the strings `- ' and `file ... ' were not interpreted as macros. Details on callable macros are presented in the sections Sx CONTENT MACROS and Sx PAGE LAYOUT MACROS.  

Passing Space Characters in an Argument

Sometimes it is desirable to give as one argument a string containing one or more blank space characters. This may be necessary to defeat the nine argument limit or to specify arguments to macros which expect particular arrangement of items in the argument list. For example, the function macro `.Fn expects ' the first argument to be the name of a function and any remaining arguments to be function parameters. As ANSI C stipulates the declaration of function parameters in the parenthesized parameter list, each parameter is guaranteed to be at minimum a two word string. For example, Fa int foo . There are two possible ways to pass an argument which contains an imbedded space. Unfortunately, the most convient way of passing such a space between quotes was too expensive to implement for all the macros. It is however, implemented for the following macros which need it the most:

Configuration declaration (section 4 SYNOPSIS)

Begin list (for the width specifier).
Emphasized text.
Fn Functions (sections two and four).
List items.
Literal text.
Symbolic text.
%B
Book titles.
%J
Journal names.
%O
Optional notes for a reference.
%R
Report title (in a reference).
%T
Title of article in a book or journal.

One way of passing a string containing blank spaces is to use the hard or unpaddable space character `\
 ,' that is, a blank space preceeded by the escape character `\' This method may be used with any macro but has the side effect of interfering with the adjustment of text over the length of a line. Troff sees the hard space as if it were any other printable character and cannot split the string into blank or newline separated pieces as one would expect. The method is useful for strings which are not expected to overlap a line boundary. For example:

Fn fetch char *str
is created by `.Fn fetch ' char\ *str
Fn fetch char *str
can also be created by `.Fn fetch ' \*q*char *str\*q

If the `\' or quotes were omitted, `.Fn would ' see three arguments and the result would be:

Fn fetch char *str

For an example of what happens when the parameter list overlaps a newline boundary, see the Sx BUGS section.

 

Trailing Blank Space Characters

Troff can be confused by blank space characters at the end of a line. It is wise preventative measure to globally remove all blank spaces from <blank-space><end-of-line> character sequences. Should the need arise to force a blank character at the end of a line, it may be forced with an unpaddable space and the `\&' escape character. For example, `string\\& .'  

Escaping Special Characters

Special characters like the newline character `\n' , are handled by replacing the `\' with `\e' (e.g. `\en' ) to preserve the backslash.  

THE ANATOMY OF A MAN PAGE (Getting Started)

There are three basic groups of macros: specific header macros called only once at the very beginning of each manual page, page layout or structure macros which may be called many times, and content macros which also may be called many times. The body of a man page is easily constructed from a basic template found in the file:
.\" /usr/share/misc/man.tempate :
.\" The following six lines are required.
.Dt DOCUMENT_TITLE [section number] [volume]
.Os OPERATING_SYSTEM [version/release]
.Dd Month day, year
.Sh NAME
.Sh SYNOPSIS
.Sh DESCRIPTION
.\" The following requests should be uncommented and
.\" used where appropriate.  This next request is
.\" for sections 2 and 3 function return values only.
.\" .Sh RETURN VALUES
.\" This next request is for sections 1, 6, 7 & 8 only
.\" .Sh ENVIRONMENT
.\" .Sh FILES
.\" .Sh EXAMPLES
.\" This next request is for sections 1, 6, 7 & 8 only
.\"     (command return values (to shell) and
.\"       fprintf/stderr type diagnostics)
.\" .Sh DIAGNOSTICS
.\" The next request is for sections 2 and 3 error
.\" and signal handling only.
.\" .Sh ERRORS
.\" .Sh SEE ALSO
.\" .Sh STANDARDS
.\" .Sh HISTORY
.\" .Sh AUTHORS
.\" .Sh BUGS

The first items in the template are the macros (. ) the document or man page title (in upper case ) the section of the manual the page belongs to, the (document) date, and the operating system the man page is derived from. These macros identify the page, and are discussed below in Sx TITLE MACROS .

The remaining items in the template are section headers (. 

;

) of which NAME, SYNOPSIS and DESCRIPTION are mandatory. The headers are discussed in Sx PAGE LAYOUT MACROS, after presentation of Sx CONTENT MACROS . Several content macros are used to demonstrate page layout macros; reading about content macros before page layout macros is recommended.  

TITLE MACROS

Three header macros designate the document title or manual page title, the operating system, and the date of authorship. These macros are one called once at the very beginning of the document and are used to construct the headers and footers only.

.
The document title is the subject of the man page and must be in CAPITALS due to troff limitations. The section number may be 1, ..., 8, and if it is specified, the volume title may be omitted. A volume title may be arbitrary or one of the following:

AMD    UNIX Ancestral Manual Documents
SMM    UNIX System Manager's Manual
URM       UNIX Reference Manual
PRMUNIX Programmers's Manual

.operating_system release#
The name of the operating system
should be the common acronym, e.g. BSD or ATT. The release should be the standard release nomenclature for the system specified, e.g. 4.3, 4.3+Tahoe, V.3, V.4. Unrecognized arguments are displayed as given in the page footer. For instance, for the footer on this page, the 4.4 Berkeley Distribution was produced by:

.BSD 4.4
.month day, year
The date should be written formally:

January 25, 1989

 

CONTENT MACROS

 

What's in a name...

Content macro names are derived from the day to day informal language used to describe commands, subroutines and related files. Slightly different variations of this language are used to describe the three different aspects of writing a man page. First, there is the description of -mdoc macro request usage. Second is the description of a UNIX command with -mdoc macros and third, the description a command to a user in the verbal sense; that is, discussion of a command in the text of a man page.

In the first case, troff(1) macros are themselves a type of command; the general syntax for a troff command is:

.Va argument1 argument2 ... argument9

The `.is ' a macro command or request, and anything following it is an argument to be processed. In the second case, the description of a UNIX command using the content macros is a bit more involved; a typical SYNOPSIS command line might be displayed as:

filter [-flag ] infile outfile

Here, filter is the command name and the bracketed string -flag is a flag argument designated as optional by the option brackets. In -mdoc terms, infile and outfile are called arguments The macros which formatted the above example:

.Nm filter
.Op Fl flag
.Ar infile outfile

In the third case, discussion of commands and command syntax includes both examples above, but may add more detail. The arguments infile and outfile from the example above might be refered to as operands or file arguments Some command line argument lists are quite long:

make
[-eiknqrstv ] [-D variable ] [-d flags ] [-f makefile ] [-I directory ] [-j max_jobs ] [variable=value ]
[target ... ]

Here one might talk about the command make and qualify the argument makefile as an argument to the flag, -f or discuss the optional file operand target In the verbal context, such detail can prevent confusion, however the -mdoc package does not have a macro for an argument to a flag. Instead the `file ... ' argument macro is used for an operand or file argument like target as well as an argument to a flag like variable

.Nm make
.Op Fl eiknqrstv
.Op Fl D Ar variable
.Op Fl d Ar flags
.Op Fl f Ar makefile
.Op Fl I Ar directory
.Op Fl j Ar max_jobs
.Op Ar variable=value
.Op Ar target ...
 

General Syntax

All content macros share a similar syntax with a few minor deviations: `.file ... ' `.- ' `.man mdoc.sample ' and `.differ ' only when called without arguments; `.Fn and ' `.impose ' an order on their argument lists and the enclosure and quoting macros have nesting limitations. All content macros are capable of handling punctuation. Any argument which may be tested for punctuation and contains a member of the mathematical, logical or quotation set:
{+,-,/,*,%,<,>,<=,>=,=,==,&,`,',"}
should have the character escaped with `\&' Typical syntax is shown in the first content macro displayed below, `., ' and the syntax for enclosure/quoting macros is shown in Sx Enclosure and Quoting Macros .  

Address Macro

The address macro constructs an address of the form addr1[,addr2[,addr3]].

Usage: .address ...

.addr1
addr1
.addr1
addr1
.addr1 , file2
addr1 , file2
.f1 , f2 , f3:
f1 , f2 , f3
.addr ) ),
addr ) )

It is an error to call .without arguments. .is callable by other macros and may call other macros.  

Argument Macro

The .file ... argument macro may be used whenever a command line argument is referenced.

Usage: .argument ...

.file ...
file ...
.file1
file1
.file1
file1
.file1 file2
file1 file2
.f1 f2 f3:
f1 f2 f3
.file ) ),
file ) )

If .file ... is called without arguments `file ... ' is assumed. The .file ... macro may call other macros, and may be called by other macros.  

Angle Bracket Quote/Enclosure

Encloses a string or strings in between angle brackets. The macro `.Aq encloses ' the remaining arguments on the macro command line, and the `.Ao (angle ' open) and `.Ac (angle ' close) macros may be used across one or more lines.

Usage: .Aq string ...

.Aq Aq
.Aq string.
Aq string.
.Aq string
Aq string .
.Aq stdio.h
Aq stdio.h
.Aq ctype.h ),
Aq Ar ctype.h ) ,

See Sx Enclosure Macros for discussion and Sx Options for examples of the open and close macros `.Ac and ' `.Ao ' `.Aq is ' callable by other macros and may call other macros.  

Bracket Quotes/Enclosure

Bracket quotes should be used when the string being bracketed is not an option string. The brackets for an option may be different than the default brackets. The macro `.Bq encloses ' the remaining arguments on a macro command line and the macros `.Bo and ' `.Bc may ' be used across one or more lines.

Usage: .Bq string ...

The .Bq macro exists for statements which use other macros: Bq Em Greek , French . This was done with:

.Bq Greek , French .

It also could have been done using the prefix macro:

.[ Greek , French ] .

See Sx Enclosure Macros for discussion and Sx Options for examples of the open and close macros `.Bc and ' `.Bo ' The `.Bq macro ' is callable and may call other macros.  

Configuration Declaration (section four only)

The `.macro ' is used to demonstrate a config(8) declaration for a device interface in a section four manual. This macro accepts quoted arguments (double quotes only).

device le0 at scode?
produced by: `.device ' le0 at scode? .

 

Command Modifier

The command modifier is identical to the `.- ' (flag) command with the exception the `.macro ' does not assert a dash in front of every argument. Traditionally flags are marked by the preceding dash, some commands or subsets of commands do not use them. Command modifiers may also be specified in conjunction with interactive commands such as editor commands. See Sx Flags .  

Double Quote macro/Enclosure

The `.``double'' ' quote encloses any remaining strings on the command line with double quotes. Punctuation is placed after the end quote. The macros `.Do and ' `.Dc may ' be used across one or more lines.

Usage: .``string ... ''

.````
.``string.''
'' ''
``string.''
.``string abc .''
``string abc''
.``'^[A-Z]'''
``'^[A-Z]'''
.``pattern ) ), ''
``pattern ) ''

If `.``is'' ' called with no arguments ``is assumed. The'' `.``macro'' ' may call or be called by other macros. See Sx Enclosure Macros for discussion of `.Dc and ' `.Do macro ' types.  

Defined Variables

A variable which is defined in an include file is specified by the macro `. '

Usage: .defined_variable ...

.MAXHOSTNAMELEN
MAXHOSTNAMELEN
.TIOCGPGRP )
TIOCGPGRP

It is an error to call `.without ' arguments. `.may ' call other macros and may be called by other macros.  

Emphasis Macro

Text may be stressed or emphasized with the `.macro. '
 The usual font for emphasis is italic.

Usage: .argument ...

.does not
does not
.exceed 1024 .
exceed 1024
.vide infra ) ) ,
vide infra ) )

The emphasis can be forced across several lines of text by using the `.Bf macro ' discussed in Sx Modes under Sx PAGE LAYOUT .

The `.macro ' is callable and may call other macros. It is an error to call `.without ' arguments.  

Enclosure and Quoting Macros

The concept of enclosure is similar to quoting. The object is to enclose a string or more between a pair of characters like quotes or parentheses. The terms quoting and enclosure are used interchangeably throughout this document. Many of the one line enclosure macros end end in small letter `q' to give a hint of quoting, but there are a few exceptions (the macros `.En , ' `.Fn and ' `.[are] ' also enclosure macros). For each enclosure macro there is also a pair of open and close macros which end in small letters `o' and `c' respectively. These can be used across one or more lines of text and while they cannot be nested, the one line quote macros can be used inside of them. For a good example of one these macros, see Sx Options .

quote         close   open   function        result .Aq,   .Ac,    .Ao     Angle Bracket Enclosure<string>
.Bq,    .Bc,    .Bo     Bracket Enclosure       [string]
.Dq,    .Dc,    .Do     Double Quote    ``string''
        .Ec,    .Eo     Enclose String (in XX)  XXstringXX
.Fn,    .Fc,    .Fo     Function Enclosure      function(string)
.Op,    .Oc,    .Oo     Option Enclosure        [string]
.Pq,    .Pc,    .Po     Parenthesis Enclosure   (string)
.Qq,    .Qc,    .Qo     Straight Double Quote   "string"
.Sq,    .Sc,    .So     Single Quote    `string'
        .Xc,    .Xo     Extend Argument  --

The macros `.Eo and ' `.Ec allow ' a user to specify an open and close with the first argument as the opening or closing string respectively.  

Errno's (Section two only)

The `.Er errno ' macro specifies the error return value for section two library routines. The second example below shows `.Er used ' with the `.Bq macro, ' as it would be used in a section two manual page.

Usage: .Er ERRNOTYPE ...

.Er ENOENT
Er ENOENT
.Er ENOENT );
Er ENOENT ) ;
.Bq Er ENOTDIR
Bq Er ENOTDIR

It is an error to call `.Er without ' arguments. The `.Er macro ' is callable and may call other macros.  

Environment Variables

The `.macro ' specifies a environment variable.

Usage: .argument ...

.DISPLAY
DISPLAY
.PATH
PATH
.PRINTER ) ),
PRINTER ) )

It is an error to call `.without ' arguments. The `.macro ' is callable by other macros and may call other macros.  

Function Argument

The `.Fa macro ' is used to refer to function arguments (parameters) outside of the SYNOPSIS section of the manual or inside the SYNOPSIS section should a parameter list be too long for the `.Fn macro ' and the enclosure macros `.Fo and ' `.Fc must ' be used. `.Fa may ' also be used to refer to structure members.

Usage: .Fa function_argument ...

.Fa d_namlen ) ),
Fa d_namlen ) ) ,
.Fa iov_len
Fa iov_len

It is an error to call `.Fa without ' arguments. `.Fa is ' callable by other macros and may call other macros.  

Function Declaration

The `.Fd macro ' is used in the SYNOPSIS section with section two or three functions. The `.Fd macro ' does not call other macros and is not callable by other macros.

Usage: .Fd include_file (or defined variable)

In the SYNOPSIS section a `.Fd request ' causes a line break if a function has already been presented and a break has not occurred. This leaves a nice vertical space in between the previous function call and the declaration for the next function.  

Flags

The `.- ' macro handles command line flags. It prepends a dash, `-' , to the flag. For interactive command flags, which are not prepended with a dash, the `.(command ' modifier) macro is identical, but with out the dash.

Usage: .-argument ...

.-
-
.-cfv
-cfv
.-cfv
-cfv
.-s v t
-s v t
.--,
--
.-xyz ),
-xyz )

The `.- ' macro without any arguments results in a dash representing stdin/stdout. Note that giving `.- ' a single dash, will result in two dashes. The `.- ' macro is callable and may call other macros.  

Functions (library routines)

The .Fn macro is modeled on ANSI C conventions.
Usage: .Fn [type] function [[type] params ... ]

.Fn getchar
Fn getchar
.Fn strlen ) ,
Fn strlen ) ,
.Fn \*qint align\*q \*qconst * char *sptrs\*q
Fn int align const * char *sptrs ,

It is an error to call `.Fn without ' any arguments. The `.Fn macro ' is callable by other macros and may call other macros, but note that any call to another macro signals the end of the `.Fn call ' (it will close-paren at that point).

In the SYNOPSIS section, the function will always begin at the beginning of line. If there is more than one function presented in the SYNOPSIS section and a function type has not been given, a line break will occur, leaving a nice vertical space between the current function name and the one prior. At the moment, `.Fn does ' not check its word boundaries against troff line lengths and may split across a newline ungracefully. This will be fixed in the near future.  

Function Type

This macro is intended for the SYNOPSIS section. It may be used anywhere else in the manpage without problems, but its main purpose is to present the function type in kernel normal form for the SYNOPSIS of sections two and three (it causes a page break allowing the function name to appear on the next line).

Usage: .Ft type ...

.Ft struct stat
Ft struct stat

The `.Ft request ' is not callable by other macros.  

Interactive Commands

The `.macro ' designates an interactive or internal command.

Usage: .argument ...

.:wq
:wq
.do while {...}
do while {...}
.setenv , unsetenv
setenv , unsetenv

It is an error to call `.without ' arguments. The `.macro ' may call other macros and is callable.  

Literals

The `.literal ' macro may be used for special characters, variable constants, anything which should be displayed as it would be typed.

Usage: .argument ...

.\en
\n
.M1 M2 M3;
M1 M2 M3
.cntrl-D ),
cntrl-D )
.1024 ...
1024 ...

The `.macro ' is callable by other macros and may call other macros.  

Name Macro

The `.man mdoc.sample ' macro is used for the document title or subject name. It has the peculiarity of remembering the first argument it was called with, which should always be the subject name of the page. When called without arguments, `.man mdoc.sample ' regurgitates this initial name for the sole purpose of making less work for the author. Note: a section two or three document function name is addressed with the `.man mdoc.sample ' in the NAME section, and with `.Fn in ' the SYNOPSIS and remaining sections. For interactive commands, such as the `while' command keyword in csh(1), the `.macro ' should be used. While the `.is ' nearly identical to `.man mdoc.sample ' it can not recall the first argument it was invoked with.

Usage: .argument ...

.mdoc.sample
mdoc.sample
.-mdoc
-mdoc
.foo ) ),
foo ) )
.man mdoc.sample
man mdoc.sample

The `.man mdoc.sample ' macro is callable by other macros and may call other macros.  

No-[or Normal Text Macro]

The macro .is a hack for words in a macro command line which should not be formatted and follows the conventional syntax for content macros.  

Space Macro

The `.macro ' eliminates unwanted spaces in between macro requests. It is useful for old style argument lists where there is no space between the flag and argument:

.[-I directory ]
produces [-I directory ]

Note: the `.macro ' always invokes the `.macro ' after eliminating the space unless another macro name follows it. The macro `.is ' callable and may call other macros.  

Options

The `.[macro] ' places option brackets around the any remaining arguments on the command line, and places any trailing punctuation outside the brackets. The macros `.] ' and `.[may ' be used across one or more lines.

Usage: .[options ... ]

.[[
.[-k ]
] ]
[-k ]
.[-k ) . ]
[-k ]
.[-k kookfile ]
[-k kookfile ]
.[-k kookfile , ]
[-k kookfile ]
.[objfil [corfil ] ]
[objfil [corfil ] ]
.[-c objfil [corfil , ] ]
[-c objfil [corfil ] ]
.[word1 word2]
[word1 word2]

The `.] ' and `.[macros: '

.Oo
.Op Fl k Ar kilobytes
.Op Fl i Ar interval
.Op Fl c Ar count
.Oc

Produce: [[-k kilobytes ] [-i interval ] [-c count ] ]

The macros `.[,] ' `.] ' and `.[are ' callable and may call other macros.  

Parenthesis Quote/Enclosure

Macros .(, .Pc and ) .Po follow the conventions for a typical quoting macros, see Sx Enclosure Macros and Sx Options above.  

Pathnames

The `.macro ' formats path or file names.

Usage: .pathname

./usr/share
/usr/share
./tmp/fooXXXXX )
/tmp/fooXXXXX )

The `.macro ' is callable by other macros and may call other macros.  

Single Quotes/Enclosure

See Sx Enclosure Macros . See Sx Double Quote/Enclosure above. The single quoting macro `.`works' ' in the identical manner as `.Dq.'  

Prefix Macro

The `.macro ' is a short cut for combining two strings together, the first of which is in the default font, and the second a content specified string.

.( Fa name2
becomes ( Fa name2

The `.macro ' is not callable, but may call other macros. The `.macro ' performs the analogus suffix function.  

Section Cross References

The `.Sx macro ' designates a reference to a section header within the same document. It is callable by other macros and may call other macros.

.Sx FILES
Sx FILES

 

References and Citations

The following macros make a modest attempt to handle references. At best, the macros make it convientent to manually drop in a subset of refer style references.

.Rs
Reference Start. Causes a line break and begins collection of reference information until the reference end macro is read.
.Re
Reference End. The reference is printed.
.%A
Reference author name, one name per invocation.
.%B
Book title.
.%J
Journal title.
.%N
Issue number.
.%O
Optional information.
.%R
Report name.
.%T
Title of article.
.%V
Volume(s).

The macros begining with `%' are not callable, but may call only the trade name macro which returns to its caller. The purpose is to allow trade names to be pretty printed in troff/ditroff output. WARNING: this has very few trade names defined at the moment and will print unknown trade names in the default font.  

Symbolic

The symbolic emphasis macro is generally a boldface macro in either the symbolic sense or the traditional English usage.

Usage: .symbol ...

.Important Notice
Important Notice

The `.macro ' is callable by other macros and may call other macros, except in the second form. Arguments to `.may ' be quoted.  

Variables

Generic variable reference:

Usage: .variable ...

.count
count
.settimer
settimer
.int *prt ):
int *prt )
.char s ] ) ),
char s ] ) )

It is an error to call `.without ' any arguments. The `.macro ' is callable by other macros and may call other macros.  

Cross References

The `.macro ' expects the first argument to be a manual page name, and the second argument, if it exists, to be either a section page number or punctuation. Any remaining arguments are assumed to be punctuation.

Usage: .manpage[1,...,8]

.mdoc
mdoc
.mdoc
mdoc,
.mdoc(7)
mdoc(7)
.mdoc(7)))
mdoc(7))),

The `.macro ' is callable by other macros and may call other macros. It is an error to call `.without ' any arguments.  

Extended Arguments

The . and . maxros allow one to extend an argument list on a macro boundary. Argument lists cannot be extended within a macro which expects all of its arguments on one line such as `.[] '  

PAGE LAYOUT MACROS

 

Section Headers

The first three `. 

section

' header macros list below are required in every man page. The remaining section headers are recommended at the disgression of the author writing the manual page. The `. 

macro

' can take up to nine arguments. It may call other macros, but it may not be called by other macros.

.
 

NAME

The `. 

NAME

' macro is mandatory. If not specified, the headers, footers and page layout defaults will not be set and things will be rather unpleasant. The NAME section consists of at least three items. The first is the `.man mdoc.sample ' name macro naming the subject of the man page. The second is the Name Description macro, `. - , ' which separates the subject name from the third item, which is the description. The description should be the most terse and lucid possible, as the space available is small. .Sh SYNOPSIS The SYNOPSIS section describes the typical usage of the subject of a man page. The macros required are either `.Nm' , `.Cd' , or `.Fn' (and possibly `.Fd' , `.Ft' macros). The function name macro `.Fn' is required for manual page sections 2 and 3, the command and general name macro `.man mdoc.sample ' is required for sections 1, 5, 6, 7, 8. Section 4 manuals require a `.Nm' , .Fd or a `.Cd' configuration device usage macro. Several other macros may be necessary to produce the synopsis line as shown below:

cat [-benstuv ] [- ] file ...

The following macros were used:

.cat
.[-benstuv ]
.[- ]
.file ...
.Sh DESCRIPTION In most cases the first text in the DESCRIPTION section is a brief paragraph on the command, function or file, followed by a lexical list of options and respective explanations. To create such a list, the `.

' begin-list, `.

list-item
' and `.

' end-list macros are used (see Sx Lists and Columns below).

The following `. 

section

' headers are part of the preferred manual page layout and must be used appropriately to maintain consistency. They are listed in the order in which they would be used.

.
 

ENVIRONMENT

The ENVIRONMENT section should reveal any related environment variables and clues to their behaviour and/or usage. .Sh EXAMPLES There are several ways to create examples. See the EXAMPLES section below for details. .Sh FILES Files which are used or created by the man page subject should be listed via the `.macro ' in the FILES section. .Sh SEE ALSO References to other material on the man page topic and cross references to other relevant man pages should be placed in the SEE ALSO section. Cross references are specified using the `.macro. '
 At this time refer(1) style references are not accommodated. .Sh STANDARDS If the command, library function or file adheres to a specific implementation such as POSIX 1003.1 or ANSI C X3.159-1989 this should be noted here. If the command does not adhere to any standard, its history should be noted in the HISTORY section. .Sh HISTORY Any command which does not adhere to any specific standards should be outlined historically in this section. .Sh AUTHORS Credits, if need be, should be placed here. .Sh DIAGNOSTICS Diagnostics from a command should be placed in this section. .Sh ERRORS Specific error handling, especially from library functions (man page sections 2 and 3) should go here. The `.Er macro ' is used to specify an errno. .Sh BUGS Blatant problems with the topic go here...

User specified `. 

sections

' may be added, for example, this section was set with:
.Sh PAGE LAYOUT MACROS
 

Paragraphs and Line Spacing.

.

The .Pp paragraph command may be used to specify a line space where necessary. The macro is not necessary after a `.
 

or

' `. 

macro

' or before a `.

' macro. (The `.

' macro asserts a vertical distance unless the -compact flag is given).

 

Examples and Displays

There are five types of displays, a quickie one line indented display `.D1' , a quickie one line literal display `.
,
' a block literal, block filled and block ragged which use the `. ' begin-display and `. ' end-display macros.

.D1
(D-one) Display one line of indented text. Arguments are checked to see if they are callable.
.D1 -ldghfstru

produces:

-ldghfstru
.
(D-ell)
Display one line of indented literal text. The `.
example
' macro has been used throughout this file. It allows the indent (display) of one line of text. Its default font is set to constant width (literal) however `.
does
' check arguments to see it they are callable. Macros called from .
should be content macros; calling macros from
the page layout section is redundant and may cause unpredictable errors.
.
% ls -ldg /usr/local/bin

produces:

% ls -ldg /usr/local/bin
.
Begin-display. The `. ' display must be ended with the `. ' macro. Displays may be nested within displays and lists. `. ' has the following syntax:

".

The display-type must be one of the following four types and may have an offset specifier for indentation: `. '

-ragged
Display a block of text as typed, right (and left) margin edges are left ragged.
-filled
Display a filled (formatted) block. The block of text is formatted (the edges are filled - not left ragged).
-literal
Display a literal block, useful for source code or simple tabbed or spaced text.
-file file_name
The file name following the -file flag is read and displayed. Literal mode is asserted and tabs are set at 8 constant width character intervals, however any troff/NsNm-mdoc commands in file will be processed.
-offset string
If -offset is specified with one of the following strings, the string is interpreted to indicate the level of indentation for the forthcoming block of text:

left
Align block on the current left margin, this is the default mode of `. '
center
Supposedly center the block. At this time unfortunately, the block merely gets left aligned about an imaginary center margin.
indent
Indents by one default indent value or tab. The default indent value is also used for the `.D1' display so one can be garanteed of the two types of displays lining up. This indent is nornally set to 6n or about two thirds of an inch (six constant width characters).
indent-two
Indents two times the default indent value.
right
This left aligns the block about two inches from the right side of the page. This macro also needs work and perhaps may never be right in troff.

".Ed"
End-display.

 

Tagged Lists and Columns

There are several types of lists which may be initiated with the `.Bl' begin-list macro. Items within the list are specified with the `.It' item macro and each list must end with the `.El' macro. Lists may be nested within themselves and within displays. Columns may be used inside of lists, but lists are unproven inside of columns.

In addition, several list attributes may be specified such as the width of a tag, the list offset, and compactness specified (blank lines between items allowed or disallowed). The following list types are accepted by `.Bl:'

-bullet
-item
-enum
These three are the simplest types of lists. Once the `.Bl' macro has been given, items in the list are merely indicated by a line consisting solely of the `.It' macro. For example, the source text for a simple enumerated list would look like:
.Bl -enum -compact
.It
Item one goes here.
.It
And item two here.
.It
Lastly item three goes here.
.El

The results:

  1. Item one goes here.
  2. And item two here.
  3. Lastly item three goes here.

A simple bullet list construction:

.Bl -bullet -compact
.It
Bullet one goes here.
.It
Bullet two here.
.El

Produces:

  • Bullet one goes here.
  • Bullet two here.

-tag
-diag
-hang
-ohang
-inset
These list-types collect arguments specified with the `.
macro
' and create a label which may be inset into the forth coming text, hanged (exdented) from the forth coming text, overhanged set above the forth coming paragraph or tagged (exdented and offset). This list was constructed with the `-ohang ' list-type. The `.
macro
' may call any callable macros for the inset, hang and tag list-types, but will not call macros for the diag type. Here is an example of inset labels:

Tag
The tagged list (also called a tagged paragraph) is the most common type of list used in the Berkeley manuals.
Diag
Diag lists create section four diagnostic lists and are similar to inset lists except callable macros are ignored.
Hang
Hanged labels are a matter of taste.
Ohang
Over hanging labels are nice when space is constrained.
Inset
Inset labels are useful for controlling blocks of paragraphs and are valuable for converting -mdoc manuals to other formats.

Here is the source text which produced the above example:

.Bl -inset -offset indent
.It Em Tag
The tagged list (also called a tagged paragraph) is the
most common type of list used in the Berkeley manuals.
.It Em Diag
Diag lists create section four diagnostic lists
and are similar to inset lists except callable
macros are ignored.
.It Em Hang
Hanged labels are a matter of taste.
.It Em Ohang
Over hanging labels are nice when space is constrained.
.It Em Inset
Inset labels are useful for controlling blocks of
paragraphs and are valuable for converting
.Nm -mdoc
manuals to other formats.
.El

Here is a hanged list with just one item:

Hanged
labels appear similar to tagged lists when the label is smaller than the label width.
Longer hanged list labels
blend in to the paragraph unlike tagged paragraph labels.

And the unfomatted text which created it:

.Bl -hang -offset indent
.It Em Hanged
labels appear similar to tagged lists when the
label is smaller than the label width.
.It Em Longer hanged list labels
blend in to the paragraph unlike
tagged paragraph labels.
.El

The tagged list which follows uses an optional width specifier to controll the width of the tag.

SL 10
sleep time of the process (seconds blocked)
PAGEIN 10
number of disk i/o's resulting from references by the process to pages not loaded in core.
UID 10
numerical user-id of process owner
PPID 10
numerical id of parent of process process priority (non-positive when in non-interruptible wait)

The raw text:

.Bl -tag -width "PAGEIN 10" -compact -offset indent
.It SL 10
sleep time of the process (seconds blocked)
.It PAGEIN 10
number of disk i/o's resulting from references
by the process to pages not loaded in core.
.It UID 10
numerical user-id of process owner
.It PPID 10
numerical id of parent of process process priority
(non-positive when in non-interruptible wait)
.El

Acceptable width specifiers:

-width Fl
sets the width to the default width for a flag. All callable macros have a default width value. The `.- ' value is presently set to ten constant width characters or about five sixth of an inch.
-width 24n
sets the width to 24 constant width characters or about two inches. The `n' is absolutely necessary for the scaling to work correctly.
-width ENAMETOOLONG
sets width to the constant width length of the string given.
-width \*qint mkfifo\*q
again, the width is set to the constant width of the string given.

If a width is not specified for the tag list type, the first time `.

is
' invoked, an attempt is made to determine an appropriate width. If the first argument to `.It' is a callable macro, the default width for that macro will be used as if the macro name had been supplied as the width. However, if another item in the list is given with a different callable macro name, a new and nested list is assumed. Here is an involved example of a self nesting list:
 

DIAGNOSTICS

The debugging facilities for -mdoc are limited, but can help detect subtle errors such as the collision of an argument name with an internal register or macro name. (A what?) A register is an arithmetic storage class for troff with a one or two character name. All registers internal to -mdoc for troff and ditroff are two characters and of the form <uppercase><lowercase> such as `file ... ' <lowercase><uppercase> as `aR' or <upper or lower letter><digit> as `C1' And adding to the muddle, troff has its own internal registers all of which are either two lowercase characters or a dot plus a letter or meta-character character. In one of the introduction examples, it was shown how to prevent the interpretation of a macro name with the escape sequence `\&' This is sufficient for the internal register names also.

If a non-escaped register name is given in the argument list of a request unpredictable behaviour will occur. In general, anytime huge portions of text do not appear where expected in the output, or small strings such as list tags disappear, chances are there is a misunderstanding about an argument type in the argument list. Your mother never intended for you to remember this evil stuff - so here is a way to find out whether or not your arguments are valid: The `.Db (debug) ' macro displays the interpretation of the argument list for most macros. Macros such as the `.

' (paragraph) macro do not contain debugging information. All of the callable macros do, and it is strongly advised whenever in doubt, turn on the `.Db macro. '

Usage: .Db [on | off]

An example of a portion of text with the debug macro placed above and below an artificially created problem (a flag argument `aC' which should be `\&aC' in order to work):

.Db on
.Op Fl aC Ar file )
.Db off

The resulting output:

DEBUGGING ON
DEBUG(argv) MACRO: `.Op'  Line #: 2
        Argc: 1  Argv: `Fl'  Length: 2
        Space: `'  Class: Executable
        Argc: 2  Argv: `aC'  Length: 2
        Space: `'  Class: Executable
        Argc: 3  Argv: `Ar'  Length: 2
        Space: `'  Class: Executable
        Argc: 4  Argv: `file'  Length: 4
        Space: ` '  Class: String
        Argc: 5  Argv: `)'  Length: 1
        Space: ` '  Class: Closing Punctuation or suffix
        MACRO REQUEST: .Op Fl aC Ar file )
DEBUGGING OFF

The first line of information tells the name of the calling macro, here `.[,] ' and the line number it appears on. If one or more files are involved (especially if text from another file is included) the line number may be bogus. If there is only one file, it should be accurate. The second line gives the argument count, the argument (`- ' ) and its length. If the length of an argument is two characters, the argument is tested to see if it is executable (unfortunately, any register which contains a non-zero value appears executable). The third line gives the space allotted for a class, and the class type. The problem here is the argument aC should not be executable. The four types of classes are string, executable, closing punctuation and opening punctuation. The last line shows the entire argument list as it was read. In this next example, the offending `aC' is escaped:

.Db on
.Em An escaped \&aC
.Db off
DEBUGGING ON
DEBUG(fargv) MACRO: `.Em'  Line #: 2
        Argc: 1  Argv: `An'  Length: 2
        Space: ` '  Class: String
        Argc: 2  Argv: `escaped'  Length: 7
        Space: ` '  Class: String
        Argc: 3  Argv: `aC'  Length: 2
        Space: ` '  Class: String
        MACRO REQUEST: .Em An escaped &aC
DEBUGGING OFF

The argument `\&aC' shows up with the same length of 2 as the `\&' sequence produces a zero width, but a register named `\&aC' was not found and the type classified as string.

Other diagnostics consist of usage statements and are self explanatory.  

FILES

/usr/share/tmac/tmac.doc
manual macro package
/usr/share/man0/template.doc
template for writing a man page

 

HISTORY

4.4 BSD  

SEE ALSO

mdoc(7), man(1), troff(1)  

BUGS

Undesirable hyphenation on the dash of a flag argument is not yet resolved, and causes occasional mishaps in the DESCRIPTION section. (line break on the hyphen).

Predefined strings are not declared in documentation.

Section 3f has not been added to the header routines.

`.man mdoc.sample ' font should be changed in NAME section.

`.Fn needs ' to have a check to prevent splitting up if the line length is too short. Right now it separates the last parenthesis, and sometimes looks ridiculous if a line is in fill mode.

The method used to prevent header and footer page breaks (other than the initial header and footer) when using nroff seems to be putting out a partially filled line at the bottom of the page leaving an unsightly blank space.

The list and display macros to not do any keeps and certainly should be able to.


 

Index

NAME
SYNOPSIS
DESCRIPTION
TROFF IDIOSYNCRASIES
Macro Usage
Passing Space Characters in an Argument
Trailing Blank Space Characters
Escaping Special Characters
THE ANATOMY OF A MAN PAGE (Getting Started)
;
TITLE MACROS
CONTENT MACROS
What's in a name...
General Syntax
Address Macro
Argument Macro
Angle Bracket Quote/Enclosure
Bracket Quotes/Enclosure
Configuration Declaration (section four only)
Command Modifier
Double Quote macro/Enclosure
Defined Variables
Emphasis Macro
Enclosure and Quoting Macros
Errno's (Section two only)
Environment Variables
Function Argument
Function Declaration
Flags
Functions (library routines)
Function Type
Interactive Commands
Literals
Name Macro
No-Op or Normal Text Macro
No Space Macro
Options
Parenthesis Quote/Enclosure
Pathnames
Single Quotes/Enclosure
Prefix Macro
Section Cross References
References and Citations
Symbolic
Variables
Cross References
Extended Arguments
PAGE LAYOUT MACROS
Section Headers
section
macro
NAME
NAME
section
ENVIRONMENT
sections
Paragraphs and Line Spacing.
or
macro
Examples and Displays
Tagged Lists and Columns
DIAGNOSTICS
FILES
HISTORY
SEE ALSO
BUGS

This document was created by man2html, using the manual pages.
Time: 06:48:43 GMT, May 19, 2025