O nás     Inzerce     KontaktSpolehlivé informace o IT již od roku 2011
Nepřehlédněte: 2. kolo: Pozoruhodné IT produkty 2020
Správa dokumentů
Digitální transformace
Informační systémy
Hlavní rubriky: Informační systémy, Mobilní technologie, Datová centra, Sítě, IT bezpečnost, Software, Hardware, Zkušenosti a názory, Speciály

Pozoruhodné IT produkty 2020
E-knihy o IT zdarma
Odborné IT konference BusinessIT
Manuál Linux
[Linux manuál]

mdoc.samples : tutorial sampler pro psaní BSD příruček s -mdoc

Originální popis anglicky: mdoc.samplestutorial sampler for writing BSD manuals with -mdoc

Návod, kniha: Miscellaneous Information Manual


man mdoc.samples


A tutorial sampler for writing BSD manual pages with the -mdoc macro package, a content-based and domain-based formatting package for troff(1). Its predecessor, the -man(7) package, addressed page layout leaving the manipulation of fonts and other typesetting details to the individual author. In -mdoc, page layout macros make up the page structure domain which consists of macros for titles, section headers, displays and lists. Essentially items which affect the physical position of text on a formatted page. In addition to the page structure domain, there are two more domains, the manual domain and the general text domain. The general text domain is defined as macros which perform tasks such as quoting or emphasizing pieces of text. The manual domain is defined as macros that are a subset of the day to day informal language used to describe commands, routines and related BSD files. Macros in the manual domain handle command names, command line arguments and options, function names, function parameters, pathnames, variables, cross references to other manual pages, and so on. These domain 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.
Throughout the UNIX manual pages, a manual entry is simply referred to as a man page, regardless of actual length and without sexist intention.


Since a tutorial document is normally read when a person desires to use the material immediately, the assumption has been made that the user of this document may be impatient. The material presented in the remained of this document is outlined as follows:
    Macro Usage.
    Passing Space Characters in an Argument.
    Trailing Blank Space Characters (a warning).
    Escaping Special Characters.
    A manual page template.
    What's in a name....
    General Syntax.
    Author name.
    Configuration Declarations (section four only).
    Command Modifier.
    Defined Variables.
    Errno's (Section two only).
    Environment Variables.
    Function Argument.
    Function Declaration.
    Functions (library routines).
    Function Types.
    Interactive Commands.
    Cross References.
    AT&T Macro.
    BSD Macro.
    FreeBSD Macro.
    UNIX Macro.
    Enclosure/Quoting Macros
    Angle Bracket Quote/Enclosure.
    Bracket Quotes/Enclosure.
    Double Quote macro/Enclosure.
    Parenthesis Quote/Enclosure.
    Single Quotes/Enclosure.
    Prefix Macro.
    No-Op or Normal Text Macro.
    No Space Macro.
    Section Cross References.
    References and Citations.
    Return Values (sections two and three only)
    Trade Names (Acronyms and Type Names).
    Extended Arguments.
    Section Headers.
    Paragraphs and Line Spacing.
    Font Modes (Emphasis, Literal, and Symbolic).
    Lists and Columns.
  11. BUGS


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 invocation, precede the ‘.’ (dot) with the ‘\&’ escape sequence. The ‘\&’ translates literally to a zero width space, and is never displayed in the output.
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 Extensions). A few macros handle quoted arguments (see Passing Space Characters in an Argument below).
Most of the -mdoc general text domain and manual domain macros are special in that their argument lists are parsed for callable macro names. This means an argument on the argument list which matches a general text or manual domain macro name and is determined to be callable will be executed or called when it is processed. In this case the argument, although the name of a macro, is not preceded by a ‘.’ (dot). It is in this manner that many macros are nested; for example the option macro, ‘.Op’, may call the flag and argument macros, ‘Fl’ and ‘Ar’, to specify an optional flag with an argument:
[-s bytes]
is produced by .Op Fl s Ar bytes
To prevent a two character string from being interpreted as a macro name, precede the string with the escape sequence ‘\&’:
[Fl s Ar bytes]
is produced by .Op \&Fl s \&Ar bytes
Here the strings ‘Fl’ and ‘Ar’ are not interpreted as macros. Macros whose argument lists are parsed for callable arguments are referred to as parsed and macros which may be called from an argument list are referred to as callable throughout this document and in the companion quick reference manual mdoc(7). This is a technical faux pas as almost all of the macros in -mdoc are parsed, but as it was cumbersome to constantly refer to macros as being callable and being able to call other macros, the term parsed has been used.

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, int foo.
There are two possible ways to pass an argument which contains an embedded space. Implementation note: Unfortunately, the most convenient way of passing spaces in between quotes by reassigning individual arguments before parsing was fairly expensive speed wise and space wise to implement in all the macros for AT&T troff. It is not expensive for groff but for the sake of portability, has been limited to the following macros which need it the most:
Configuration declaration (section 4 STRUČNĚ)
Begin list (for the width specifier).
Emphasized text.
Functions (sections two and four).
List items.
Literal text.
Symbolic text.
Book titles.
Journal names.
Optional notes for a reference.
Report title (in a reference).
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 preceded 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:
fetch(char *str)
is created by ‘.Fn fetch char\ *str
fetch(char *str)
can also be created by ‘.Fn fetch \*qchar *str\*q
If the ‘\’ or quotes were omitted, ‘.Fn’ would see three arguments and the result would be:
fetch(char, *str)
For an example of what happens when the parameter list overlaps a newline boundary, see the BUGS section.

Trailing Blank Space Characters

Troff can be confused by blank space characters at the end of a line. It is a wise preventive 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 body of a man page is easily constructed from a basic template found in the file /usr/share/misc/mdoc.template. Several example man pages can also be found in /usr/share/examples/mdoc.

A manual page template

.\" The following requests are required for all man pages. 
.Dd Month day, year 
.Os OPERATING_SYSTEM [version/release] 
.Dt DOCUMENT_TITLE [section number] [volume] 
.Nm name 
.Nd one line description of name 
.\" The following requests should be uncommented and 
.\" used where appropriate.  This next request is 
.\" for sections 2 and 3 function return values only. 
.\" This next request is for sections 1, 6, 7 & 8 only 
.\" .Sh FILES 
.\" This next request is for sections 1, 6, 7 & 8 only 
.\"     (command return values (to shell) and 
.\"	  fprintf/stderr type diagnostics) 
.\" The next request is for sections 2 and 3 error 
.\" and signal handling only. 
.\" .Sh ERRORS 
.\" .Sh SEE ALSO 
.\" .Sh HISTORY 
.\" .Sh AUTHORS 
.\" .Sh BUGS
The first items in the template are the macros (.Dd, .Os, .Dt); the document date, the operating system the man page or subject source is developed or modified for, and the man page title (in upper case) along with the section of the manual the page belongs in. These macros identify the page, and are discussed below in TITLE MACROS.
The remaining items in the template are section headers (.Sh); of which mdoc.samples : tutorial sampler pro psaní BSD příruček s -mdoc , STRUČNĚ and POPIS / INSTRUKCE are mandatory. The headers are discussed in PAGE STRUCTURE DOMAIN, after presentation of MANUAL DOMAIN. Several content macros are used to demonstrate page layout macros; reading about content macros before page layout macros is recommended.


The title macros are the first portion of the page structure domain, but are presented first and separate for someone who wishes to start writing a man page yesterday. 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.
.Dt DOCUMENT_TITLE section# [volume]
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
PRM UNIX Programmer's Manual
The default volume labeling is URM for sections 1, 6, and 7; SMM for section 8; PRM for sections 2, 3, 4, and 5.
.Os operating_system release#
The name of the operating system should be the common acronym, e.g. BSD or FreeBSD 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, a typical footer might be:
.Os BSD 4.3
.Os FreeBSD 2.2
or for a locally produced set
.Os CS Department
The Berkeley default, ‘.Os’ without an argument, has been defined as BSD in the site specific file /usr/share/tmac/mdoc/doc-common. It really should default to LOCAL. Note, if the ‘.Os’ macro is not present, the bottom left corner of the page will be ugly.
.Dd month day, year
The date should be written formally:
January 25, 1989


What's in a name...

The manual domain 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 of 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 ‘.Va’ 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 STRUČNĚ 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 referred to as operands or file arguments. Some command line argument lists are quite long:
[-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 ‘Ar’ argument macro is used for an operand or file argument like target as well as an argument to a flag like variable. The make command line was produced from:
.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 
.Bk -words 
.Op Ar target ... 
The ‘.Bk’ and ‘.Ek’ macros are explained in Keeps.

General Syntax

The manual domain and general text domain macros share a similar syntax with a few minor deviations: ‘.Ar’, ‘.Fl’, ‘.Nm’, and ‘.Pa’ differ only when called without arguments; ‘.Fn’ and ‘.Xr’ impose an order on their argument lists and the ‘.Op’ and ‘.Fn’ macros have nesting limitations. All content macros are capable of recognizing and properly handling punctuation, provided each punctuation character is separated by a leading space. If an request is given:
.Li sptr, ptr),
The result is:
sptr, ptr),
The punctuation is not recognized and all is output in the literal font. If the punctuation is separated by a leading white space:
.Li sptr , ptr ) ,
The result is:
sptr, ptr),
The punctuation is now recognized and is output in the default font distinguishing it from the strings in literal font.
To remove the special meaning from a punctuation character escape it with ‘\&’. Troff is limited as a macro language, and has difficulty when presented with a string containing a member of the mathematical, logical or quotation set:
The problem is that troff may assume it is supposed to actually perform the operation or evaluation suggested by the characters. To prevent the accidental evaluation of these characters, escape them with ‘\&’. Typical syntax is shown in the first content macro displayed below, ‘.Ad’.


Address Macro

The address macro identifies an address construct of the form addr1[,addr2[,addr3]].
Usage: .Ad address ...
.Ad addr1
.Ad addr1 .
.Ad addr1 , file2
addr1, file2
.Ad f1 , f2 , f3 :
f1, f2, f3:
.Ad addr ) ) ,
It is an error to call ‘.Ad’ without arguments. ‘.Ad’ is callable by other macros and is parsed.

Author Name

The ‘.An’ macro is used to specify the name of the author of the item being documented, or the name of the author of the actual manual page. Any remaining arguments after the name information are assumed to be punctuation.
Usage: .An author_name
.An Joe Author
Joe Author
.An Joe Author ,
Joe Author,
.An Joe Author Aq nobody@FreeBSD.ORG
Joe Author ⟨nobody@FreeBSD.ORG⟩
.An Joe Author ) ) ,
Joe Author)),
The ‘.An’ macro is parsed and is callable. It is an error to call ‘.An’ without any arguments.

Argument Macro

The ‘.Ar’ argument macro may be used whenever a command line argument is referenced.
Usage: .Ar argument ...
file ...
.Ar file1
.Ar file1 .
.Ar file1 file2
file1 file2
.Ar f1 f2 f3 :
f1 f2 f3:
.Ar file ) ) ,
If ‘.Ar’ is called without arguments ‘file ...’ is assumed. The ‘.Ar’ macro is parsed and is callable.

Configuration Declaration (section four only)

The ‘.Cd’ 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: ‘.Cd device le0 at scode?’.

Command Modifier

The command modifier is identical to the ‘.Fl’ (flag) command with the exception the ‘.Cm’ 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 Flags.

Defined Variables

A variable which is defined in an include file is specified by the macro ‘.Dv’.
Usage: .Dv defined_variable ...
It is an error to call ‘.Dv’ without arguments. ‘.Dv’ is parsed and is callable.

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’ general text domain macro, as it would be used in a section two manual page.
Usage: .Er ERRNOTYPE ...
.Er ENOENT ) ;
It is an error to call ‘.Er’ without arguments. The ‘.Er’ macro is parsed and is callable.

Environment Variables

The ‘.Ev’ macro specifies an environment variable.
Usage: .Ev argument ...
It is an error to call ‘.Ev’ without arguments. The ‘.Ev’ macro is parsed and is callable.

Function Argument

The ‘.Fa’ macro is used to refer to function arguments (parameters) outside of the STRUČNĚ section of the manual or inside the STRUČNĚ 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 iov_len
It is an error to call ‘.Fa’ without arguments. ‘.Fa’ is parsed and is callable.

Function Declaration

The ‘.Fd’ macro is used in the STRUČNĚ 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 STRUČNĚ 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.


The ‘.Fl’ macro handles command line flags. It prepends a dash, ‘-’, to the flag. For interactive command flags, which are not prepended with a dash, the ‘.Cm’ (command modifier) macro is identical, but without the dash.
Usage: .Fl argument ...
The ‘.Fl’ macro without any arguments results in a dash representing stdin/stdout. Note that giving ‘.Fl’ a single dash, will result in two dashes. The ‘.Fl’ macro is parsed and is callable.

Functions (library routines)

The .Fn macro is modeled on ANSI C conventions.
Usage: .Fn [type] function [[type] parameters ... ]
.Fn getchar
.Fn strlen ) ,
.Fn \*qint align\*q \*qconst * char *sptrs\*q,
int align(const * char *sptrs),
It is an error to call ‘.Fn’ without any arguments. The ‘.Fn’ macro is parsed and is callable, note that any call to another macro signals the end of the ‘.Fn’ call (it will close-parenthesis at that point).
For functions that have more than eight parameters (and this is rare), the macros ‘.Fo’ (function open) and ‘.Fc’ (function close) may be used with ‘.Fa’ (function argument) to get around the limitation. For example:
.Fo "int res_mkquery" 
.Fa "int op" 
.Fa "char *dname" 
.Fa "int class" 
.Fa "int type" 
.Fa "char *data" 
.Fa "int datalen" 
.Fa "struct rrec *newrr" 
.Fa "char *buf" 
.Fa "int buflen" 
int res_mkquery(int op, char *dname, int class, int type, char *data, int datalen, struct rrec *newrr, char *buf, int buflen);
The ‘.Fo’ and ‘.Fc’ macros are parsed and are callable. In the STRUČNĚ section, the function will always begin at the beginning of line. If there is more than one function presented in the STRUČNĚ 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 STRUČNĚ section. It may be used anywhere else in the man page without problems, but its main purpose is to present the function type in kernel normal form for the STRUČNĚ of sections two and three (it causes a line break allowing the function name to appear on the next line).
Usage: .Ft type ...
.Ft struct stat
struct stat
The ‘.Ft’ request is not callable by other macros.

Interactive Commands

The ‘.Ic’ macro designates an interactive or internal command.
Usage: .Ic argument ...
It is an error to call ‘.Ic’ without arguments. The ‘.Ic’ macro is parsed and is callable.

Name Macro

The ‘.Nm’ 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, ‘.Nm’ 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 ‘.Nm’ in the mdoc.samples : tutorial sampler pro psaní BSD příruček s -mdoc section, and with ‘.Fn’ in the STRUČNĚ and remaining sections. For interactive commands, such as the ‘while’ command keyword in csh(1), the ‘.Ic’ macro should be used. While the ‘.Ic’ is nearly identical to ‘.Nm’, it can not recall the first argument it was invoked with.
Usage: .Nm argument ...
.Nm mdoc.sample
.Nm \-mdoc
.Nm foo ) ) ,
The ‘.Nm’ macro is parsed and is callable.


The ‘.Op’ macro places option brackets around the any remaining arguments on the command line, and places any trailing punctuation outside the brackets. The macros ‘.Oc’ and ‘.Oo’ may be used across one or more lines.
Usage: .Op options ...