MDOC(7)

๐Ÿ“ฆ
version 1.14.6 ยท 5 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

โœจ NAME โœจ

mdoc โ€” semantic markup language for formatting manual pages ๐Ÿ’–

bestie quick vibe check: this is the mdoc page, from section 7 of the Miscellaneous Information Manual, and it's literally the glow-up guide for writing manual pages โœจ

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

okay so first things first: the mdoc language lets you author manual pages for the man(1) utility, and the way it does that is by letting you slap semantic annotations on words, phrases, page sections, and even entire manual pages. it's giving "labels for everything" energy and honestly? iconic. ๐Ÿท๏ธโœจ

and the way that those annotations get used is by formatting tools โ€” they read them so that every single manual written in mdoc comes out looking uniform and consistent across the board ๐Ÿซถ. plus they support hyperlinking when the output medium supports it, which is lowkey the best part. ๐Ÿ”—

this reference document is here to walk you through the structure of manual pages and the syntax and usage of the mdoc language. and if you're wondering who the main character implementation is: that's mandoc(1), the reference implementation of a parsing and formatting tool. the โ€œCOMPATIBILITYโ€ section further down spills all the tea about how it plays with other implementations. ๐Ÿ‘‘


๐ŸŒธ macro lines vs text lines ๐ŸŒธ

so inside an mdoc document, the drama splits into two categories, and you have to know which one you're in:

  • lines that begin with the control character โ€˜.โ€™ are called โ€œmacro linesโ€. the first word on the line is the macro name, and it's made of two or three letters. most macro names start with a capital letter (not all, but most โ€” don't come for me). want the full roster of available macros? go look at โ€œMACRO OVERVIEWโ€. and the words that come after the macro name are the macro's arguments, which can optionally include the names of other, callable macros โ€” โ€œMACRO SYNTAXโ€ has the deets on all of that. ๐Ÿ’…
  • lines that don't start with the control character are called โ€œtext linesโ€. these are the free-form text that actually gets printed, and how it gets formatted depends on whatever processing context you're currently in. it's giving "we're all just vibing in the current state" ๐Ÿ˜Œ

here's the vibe illustrated, no cap:

.Sh Macro lines change control state.
Text lines are interpreted within the current state.

๐Ÿฆ‹ the roff(7) of it all ๐Ÿฆ‹

ngl, a lot of the basic syntax of the mdoc language is straight-up based on the roff(7) language ๐Ÿซถ. so if you want the full lore, go check out the LANGUAGE SYNTAX and MACRO SYNTAX sections in the roff(7) manual โ€” especially if you care about comments, escape sequences, whitespace, and quoting. all of it lives there. ๐Ÿ“š

โš ๏ธ but here's the thing bestie โ€” using roff(7) requests inside mdoc documents is discouraged. like, please don't. ๐Ÿ™ˆ mandoc(1) only supports some of them, and it does that merely for backward compatibility. so it's not a feature, it's a fossil. ๐Ÿฆ•

๐Ÿ—๏ธ MANUAL STRUCTURE ๐Ÿ—๏ธ

okay so a well-formed mdoc document is literally just two things, bestie: a document prologue, and then one or more sections. that's the whole vibe. ๐Ÿซถ

The prologue is made of the Dd, Dt, and Os macros โ€” and not me being dramatic, they have to be in that exact order. this is required for every document, no exceptions, periodt. ๐Ÿ’…

The first section (sections get denoted by Sh) must be the NAME section, and it has to have at least one Nm followed by an Nd. like, that's the bare minimum, that's the entry fee. โœจ

After that, convention says you should specify at least SYNOPSIS and DESCRIPTION sections โ€” though lowkey this varies between manual sections, so iykyk. ๐Ÿ˜Œ

The following is a well-formed skeleton mdoc file for a utility "progname":

.Dd $Mdocdate$
.Dt PROGNAME section
.Os
.Sh NAME
.Nm progname
.Nd one line about what it does
.\" .Sh LIBRARY
.\" For sections 2, 3, and 9 only.
.\" Not used in OpenBSD.
.Sh SYNOPSIS
.Nm progname
.Op Fl options
.Ar
.Sh DESCRIPTION
The
.Nm
utility processes files ...
.\" .Sh CONTEXT
.\" For section 9 functions only.
.\" .Sh IMPLEMENTATION NOTES
.\" Not used in OpenBSD.
.\" .Sh RETURN VALUES
.\" For sections 2, 3, and 9 function return values only.
.\" .Sh ENVIRONMENT
.\" For sections 1, 6, 7, and 8 only.
.\" .Sh FILES
.\" .Sh EXIT STATUS
.\" For sections 1, 6, and 8 only.
.\" .Sh EXAMPLES
.\" .Sh DIAGNOSTICS
.\" For sections 1, 4, 6, 7, 8, and 9 printf/stderr messages only.
.\" .Sh ERRORS
.\" For sections 2, 3, 4, and 9 errno settings only.
.\" .Sh SEE ALSO
.\" .Xr foobar 1
.\" .Sh STANDARDS
.\" .Sh HISTORY
.\" .Sh AUTHORS
.\" .Sh CAVEATS
.\" .Sh BUGS
.\" .Sh SECURITY CONSIDERATIONS
.\" Not used in OpenBSD.

The sections in an mdoc document are conventionally ordered as they appear above. And sections should be composed like this, bestie: ๐Ÿ‘‡

๐Ÿ“› NAME ๐Ÿ“›

The name(s) plus a one line description of the documented material. The syntax for this is as follows:

.Nm name0 ,
.Nm name1 ,
.Nm name2
.Nd a one line description

Multiple โ€˜Nmโ€™ names should be separated by commas. ๐Ÿ“

The Nm macro(s) must precede the Nd macro. like, order matters, no cap.

See Nm and Nd.


๐Ÿ“š LIBRARY ๐Ÿ“š

The name of the library containing the documented material โ€” which is assumed to be a function in a section 2, 3, or 9 manual. The syntax for this is as follows:

.Lb libarm

See Lb.


๐ŸŽฌ SYNOPSIS ๐ŸŽฌ

This one documents the utility invocation syntax, function call syntax, or device configuration. three whole vibes, one section. โœจ

For the first โ€” utilities (sections 1, 6, and 8): this is generally structured as follows:

.Nm bar
.Op Fl v
.Op Fl o Ar file
.Op Ar
.Nm foo
.Op Fl v
.Op Fl o Ar file
.Op Ar

Commands should be ordered alphabetically. ๐Ÿ”ค

For the second โ€” function calls (sections 2, 3, 9):

.In header.h
.Vt extern const char *global;
.Ft "char *"
.Fn foo "const char *src"
.Ft "char *"
.Fn bar "const char *src"

Ordering of In, Vt, Fn, and Fo macros should follow C header-file conventions. ๐Ÿ’€ yes really.

And for the third โ€” configurations (section 4):

.Cd "it* at isa? port 0x2e"
.Cd "it* at isa? port 0x4e"

Manuals not in these sections generally don't need a SYNOPSIS. lucky them. ๐Ÿ™ˆ

Some macros are displayed differently in the SYNOPSIS section โ€” particularly Nm, Cd, Fd, Fn, Fo, In, Vt, and Ft. All of these macros are output on their own line. If two such dissimilar macros are pairwise invoked (except for Ft before Fo or Fn), they are separated by a vertical space โ€” unless we're talking Fo, Fn, and Ft, which are always separated by vertical space. no negotiation. ๐Ÿ‘‘

When text and macros following an Nm macro starting an input line span multiple output lines, all output lines but the first will be indented to align with the text immediately following the Nm macro, up to the next Nm, Sh, or Ss macro or the end of an enclosing block, whichever comes first. (yes this is very specific. yes it matters. the way that indentation aligns... iconic.) ๐Ÿ’…


๐Ÿ“ DESCRIPTION ๐Ÿ“

This begins with an expansion of the brief, one line description in NAME:

The
.Nm
utility does this, that, and the other.

It usually follows with a breakdown of the options (if you're documenting a command), such as:

The options are as follows:
.Bl -tag -width Ds
.It Fl v
Print verbose information.
.El

List the options in alphabetical order, uppercase before lowercase for each letter, and with no regard to whether an option takes an argument. Put digits in ascending order before all letter options. ๐Ÿ”ข

Manuals not documenting a command won't include the above fragment. ๐ŸŽ€

Since the DESCRIPTION section usually contains most of the text of a manual, longer manuals often use the Ss macro to form subsections. In very long manuals, the DESCRIPTION may be split into multiple sections, each started by an Sh macro followed by a non-standard section name, and each having several subsections โ€” like in the present mdoc manual. (yes, this one. we're being meta, it's giving main character energy.) ๐Ÿฆ‹


๐ŸŒ CONTEXT ๐ŸŒ

This section lists the contexts in which functions can be called in section 9. The contexts are autoconf, process, or interrupt.


๐Ÿ”ง IMPLEMENTATION NOTES ๐Ÿ”ง

Implementation-specific notes should be kept here. This is useful when implementing standard functions that may have side effects or notable algorithmic implications.


โ†ฉ๏ธ RETURN VALUES โ†ฉ๏ธ

This section documents the return values of functions in sections 2, 3, and 9.

See Rv.


๐ŸŒฑ ENVIRONMENT ๐ŸŒฑ

Lists the environment variables used by the utility, and explains the syntax and semantics of their values. The environ(7) manual provides examples of typical content and formatting.

See Ev.


๐Ÿ“ FILES ๐Ÿ“

Documents files used. It's helpful to document both the file name and a short description of how the file is used (created, modified, etc.).

See Pa.


๐Ÿšช EXIT STATUS ๐Ÿšช

This section documents the command exit status for section 1, 6, and 8 utilities. Historically, this information was described in DIAGNOSTICS โ€” a practise that is now discouraged. ๐Ÿ‘€

See Ex.


๐Ÿงช EXAMPLES ๐Ÿงช

Example usages. This often contains snippets of well-formed, well-tested invocations. Make sure that examples work properly! like, actually test them bestie, don't just vibe and hope. ๐Ÿ˜ญ


๐Ÿฉบ DIAGNOSTICS ๐Ÿฉบ

Documents error messages. In section 4 and 9 manuals, these are usually messages printed by the kernel to the console and to the kernel log. In section 1, 6, 7, and 8, these are usually messages printed by userland programs to the standard error output.

Historically, this section was used in place of EXIT STATUS for manuals in sections 1, 6, and 8; however, this practise is discouraged.

See Bl -diag.


๐Ÿšจ ERRORS ๐Ÿšจ

Documents errno(2) settings in sections 2, 3, 4, and 9.

See Er.


๐Ÿ”— SEE ALSO ๐Ÿ”—

References other manuals with related topics. This section should exist for most manuals. Cross-references should conventionally be ordered first by section, then alphabetically (ignoring case).

References to other documentation concerning the topic of the manual page โ€” for example authoritative books or journal articles โ€” may also be provided in this section.

See Rs and Xr.


๐Ÿ“ STANDARDS ๐Ÿ“

References any standards implemented or used. If not adhering to any standards, the HISTORY section should be used instead.

See St.


๐Ÿบ HISTORY ๐Ÿบ

A brief history of the subject, including where it was first implemented, and when it was ported to or reimplemented for the operating system at hand.


๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

Credits to the person or persons who wrote the code and/or documentation. Authors should generally be noted by both name and email address.

See An.


โš ๏ธ CAVEATS โš ๏ธ

Common misuses and misunderstandings should be explained in this section. (we've all been there. this is the section for the "no bestie, don't do that" warnings.) ๐Ÿซถ


๐Ÿ’€ BUGS ๐Ÿ’€

Known bugs, limitations, and work-arounds should be described in this section.


๐Ÿ”’ SECURITY CONSIDERATIONS ๐Ÿ”’

Documents any security precautions that operators should consider.

โœจ MACRO OVERVIEW โœจ

ok so this overview is sorted so that macros that do similar stuff are grouped together, which is so helpful when you're trying to find the best macro for whatever you're doing. Deprecated macros are not in this overview bestie โ€” those are hiding down below in the alphabetical โ€œMACRO REFERENCEโ€ ๐Ÿ“š


๐ŸŽ€ Document preamble and NAME section macros ๐ŸŽ€

  • Dd โ€” document date: $Mdocdate$ | month day, year
  • Dt โ€” document title: TITLE section [arch]
  • Os โ€” operating system version: [system [version]]
  • Nm โ€” document name (one argument)
  • Nd โ€” document description (one line)

๐Ÿฆ‹ Sections and cross references ๐Ÿฆ‹

  • Sh โ€” section header (one line)
  • Ss โ€” subsection header (one line)
  • Sx โ€” internal cross reference to a section or subsection
  • Xr โ€” cross reference to another manual page: name section
  • Tg โ€” tag the definition of a term (<= 1 arguments)
  • Pp โ€” start a text paragraph (no arguments)

๐ŸŒธ Displays and lists ๐ŸŒธ

  • Bd, Ed โ€” display block: -type [-offset width] [-compact]
  • D1 โ€” indented display (one line)
  • Dl โ€” indented literal display (one line)
  • Ql โ€” in-line literal display: โ€˜textโ€™
  • Bl, El โ€” list block: -type [-width val] [-offset val] [-compact]
  • It โ€” list item (syntax depends on -type)
  • Ta โ€” table cell separator in Bl -column lists
  • Rs, %*, Re โ€” bibliographic block (references)

๐Ÿ’… Spacing control ๐Ÿ’…

  • Pf โ€” prefix, no following horizontal space (one argument)
  • Ns โ€” roman font, no preceding horizontal space (no arguments)
  • Ap โ€” apostrophe without surrounding whitespace (no arguments)
  • Sm โ€” switch horizontal spacing mode: [on | off]
  • Bk, Ek โ€” keep block: -words

๐Ÿ’ป Semantic markup for command line utilities ๐Ÿ’ป

  • Nm โ€” start a SYNOPSIS block with the name of a utility
  • Fl โ€” command line options (flags) (>=0 arguments)
  • Cm โ€” command modifier (>0 arguments)
  • Ar โ€” command arguments (>=0 arguments)
  • Op, Oo, Oc โ€” optional syntax elements (enclosure)
  • Ic โ€” internal or interactive command (>0 arguments)
  • Ev โ€” environmental variable (>0 arguments)
  • Pa โ€” file system path (>=0 arguments)

๐Ÿงš Semantic markup for function libraries ๐Ÿงš

  • Lb โ€” function library (one argument)
  • In โ€” include file (one argument)
  • Fd โ€” other preprocessor directive (>0 arguments)
  • Ft โ€” function type (>0 arguments)
  • Fo, Fc โ€” function block: funcname
  • Fn โ€” function name: funcname [argument ...]
  • Fa โ€” function argument (>0 arguments)
  • Vt โ€” variable type (>0 arguments)
  • Va โ€” variable name (>0 arguments)
  • Dv โ€” defined variable or preprocessor constant (>0 arguments)
  • Er โ€” error constant (>0 arguments)
  • Ev โ€” environmental variable (>0 arguments)

๐Ÿ“ Various semantic markup ๐Ÿ“

  • An โ€” author name (>0 arguments)
  • Lk โ€” hyperlink: uri [display_name]
  • Mt โ€” โ€œmailtoโ€ hyperlink: localpart@domain
  • Cd โ€” kernel configuration declaration (>0 arguments)
  • Ad โ€” memory address (>0 arguments)
  • Ms โ€” mathematical symbol (>0 arguments)

๐Ÿ‘‘ Physical markup ๐Ÿ‘‘

  • Em โ€” italic font or underline (emphasis) (>0 arguments)
  • Sy โ€” boldface font (symbolic) (>0 arguments)
  • No โ€” return to roman font (normal) (>0 arguments)
  • Bf, Ef โ€” font block: -type | Em | Li | Sy

๐ŸŽ€ Physical enclosures ๐ŸŽ€

  • Dq, Do, Dc โ€” enclose in typographic double quotes: โ€œtextโ€
  • Qq, Qo, Qc โ€” enclose in typewriter double quotes: "text"
  • Sq, So, Sc โ€” enclose in single quotes: โ€˜textโ€™
  • Pq, Po, Pc โ€” enclose in parentheses: (text)
  • Bq, Bo, Bc โ€” enclose in square brackets: [text]
  • Brq, Bro, Brc โ€” enclose in curly braces: {text}
  • Aq, Ao, Ac โ€” enclose in angle brackets: โŸจtextโŸฉ
  • Eo, Ec โ€” generic enclosure

๐ŸŒˆ Text production ๐ŸŒˆ

  • Ex -std โ€” standard command exit values: [utility ...]
  • Rv -std โ€” standard function return values: [function ...]
  • St โ€” reference to a standards document (one argument)
  • At โ€” AT&T UNIX
  • Bx โ€” BSD
  • Bsx โ€” BSD/OS
  • Nx โ€” NetBSD
  • Fx โ€” FreeBSD
  • Ox โ€” OpenBSD
  • Dx โ€” DragonFly

๐Ÿ’– MACRO REFERENCE ๐Ÿ’–

this section is the canonical reference of every single macro, sorted alphabetically. if you wanna know the scoping of individual macros, go check โ€œMACRO SYNTAXโ€ bestie ๐Ÿซถ

  • %A first_name ... last_name โ€” Author name of an Rs block. Every author should get their own %A line, no sharing. Names go full or abbreviated forename(s) first, then the full surname. โœ๏ธ
  • %B title โ€” Book title of an Rs block. You can also use this outside of a bibliographic context when you're referring to book titles.
  • %C location โ€” Publication city or location of an Rs block. ๐Ÿ™๏ธ
  • %D [month day,] year โ€” Publication date of an Rs block. Give the full English name of the month and all four digits of the year, no shortcuts.
  • %I name โ€” Publisher or issuer name of an Rs block.
  • %J name โ€” Journal name of an Rs block.
  • %N number โ€” Issue number (usually for journals) of an Rs block.
  • %O line โ€” Optional information of an Rs block.
  • %P number โ€” Book or journal page number of an Rs block. By convention the argument starts with โ€˜p.โ€™ for a single page or โ€˜pp.โ€™ for a range of pages, like:
.%P pp. 42\(en47
  • %Q name โ€” Institutional author (school, government, etc.) of an Rs block. Multiple institutional authors each get their own %Q line.
  • %R name โ€” Technical report name of an Rs block.
  • %T title โ€” Article title of an Rs block. You can also use this in a non-bibliographical context when referring to article titles.
  • %U protocol://path โ€” URI of reference document.
  • %V number โ€” Volume number of an Rs block.
  • Ac โ€” Close an Ao block. Does not have any tail arguments.
  • Ad address โ€” Memory address. Do not use this for postal addresses, bestie, that's not what it's for.

Examples:

.Ad [0,$]
.Ad 0x00000000
  • An -split | -nosplit | first_name ... last_name โ€” Author name. Works both for the authors of the program, function, or driver documented in the manual, and for the authors of the manual itself. Needs either an author name or one of these arguments:
    • -split โ€” Start a new output line before each subsequent invocation of An.
    • -nosplit โ€” The opposite of -split.

The default is -nosplit. The effect of picking either of the -split modes ends at the beginning of the AUTHORS section. Inside the AUTHORS section, the default is -nosplit for the first author listing and -split for all the other author listings. ๐Ÿ‘ฏ

Examples:

.An -nosplit
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
  • Ao block โ€” Begin a block enclosed by angle brackets. Does not have any head arguments.
This macro is almost never useful, fr. See Aq for more details. ๐Ÿ’€
  • Ap โ€” Inserts an apostrophe without any surrounding whitespace. This is generally used as a grammatical device when you're referring to the verb form of a function.

Examples:

.Fn execve Ap d
  • Aq line โ€” Enclose the rest of the input line in angle brackets. The only important use case is for email addresses. See Mt for an example.

Occasionally it's used for names of characters and keys, like:

Press the
.Aq escape
key to ...

For URIs, use Lk instead, and In for โ€œ#includeโ€ directives. Never wrap Ar in Aq.

Since Aq usually renders with non-ASCII characters in non-ASCII output modes, don't use it where the ASCII characters โ€˜<โ€™ and โ€˜>โ€™ are required as syntax elements. Instead, use those characters directly in such cases, combining them with the macros Pf, Ns, or Eo as needed.

See also Ao.

  • Ar [placeholder ...] โ€” Command arguments. If you don't provide an argument, the string โ€œfile ...โ€ is used as a default.

Examples:

.Fl o Ar file
.Ar
.Ar arg1 , arg2 .

The arguments to the Ar macro are names and placeholders for command arguments; for fixed strings to be passed verbatim as arguments, use Fl or Cm.

  • At [version] โ€” Formats an AT&T UNIX version. Accepts one optional argument:
    • v[1-7] | 32v โ€” A version of AT&T UNIX.
    • III โ€” AT&T System III UNIX.
    • V | V.[1-4] โ€” A version of AT&T System V UNIX.

Heads up: these arguments do not begin with a hyphen.

Examples:

.At
.At III
.At V.1

See also Bsx, Bx, Dx, Fx, Nx, and Ox.

  • Bc โ€” Close a Bo block. Does not have any tail arguments.
  • Bd -type [-offset width] [-compact] โ€” Begin a display block. Display blocks let you pick a different indentation and justification than whatever the surrounding text is doing. They can hold both macro lines and text lines. By default, a display block is preceded by a vertical space.

The type has to be one of these:

  • -centered โ€” Produce one output line from each input line, and center-justify each line.
Using this display type is not recommended; many mdoc implementations render it poorly. ๐Ÿ™ˆ
  • -filled โ€” Change the positions of line breaks to fill each line, and left- and right-justify the resulting block.
  • -literal โ€” Produce one output line from each input line, and don't justify the block at all. White space is preserved exactly as it appears in the input. Always uses a constant-width font. Use this for displaying source code. ๐Ÿ’ป
  • -ragged โ€” Change the positions of line breaks to fill each line, and left-justify the resulting block.

๐Ÿ’… Bd โ€” the block display, continued

  • -unfilled โ€” exactly the same as -literal, except it uses the same font as normal text โ€” which is a variable width font if the output device supports it.

Bestie, the type has to come first. Extra arguments can follow after that:

  • -offset width` โ€” indents the display by *width, and width can be any one of these:
    • one of the pre-defined strings: indent (the width of a standard indentation, aka six constant width characters), indent-two (twice indent), left (which literally has no effect), right (which justifies to the right margin), or center (which aligns around an imagined center axis).
    • a macro invocation, which selects a predefined width associated with that macro. The most popular one is the imaginary macro Ds, which resolves to 6n.
    • a scaling width as described in roff(7).
    • an arbitrary string, which indents by the length of that string.
    • when the argument is missing, -offset is just ignored. ghosted. ๐Ÿ’€
  • -compact โ€” do not assert vertical space before the display.

Examples:

.Bd -literal -offset indent -compact
   Hello       world.
.Ed

See also D1 and Dl. ๐Ÿ’–


๐ŸŽ€ Bf -emphasis | -literal | -symbolic | Em | Li | Sy

Change the font mode for a scoped block of text. The -emphasis and Em arguments are equivalent, as are -symbolic and Sy, and -literal and Li. With no argument at all, this macro does nothing. The font mode keeps going until it's broken by a new font mode in a nested scope, or until Ef shows up.

See also Li, Ef, Em, and Sy.


โœจ Bk -words

For each macro, keep its output together on the same output line, until the end of the macro or the end of the input line is reached โ€” whichever comes first. Line breaks in text lines are unaffected.

The -words argument is required; additional arguments are ignored.

This next example will not break within each Op macro line:

.Bk -words
.Op Fl f Ar flags
.Op Fl o Ar output
.Ek
Be careful using over-long lines inside a keep block! Doing that will clobber the right margin. ๐Ÿ˜ญ

๐Ÿ‘‘ Bl -type [-width val] [-offset val] [-compact] [col ...]

Begin a list. Lists consist of items specified using the It macro, containing a head or a body or both.

The list type is mandatory and must be specified first. The -width and -offset arguments accept macro names as described for Bd -offset, scaling widths as described in roff(7), or they use the length of the given string. The -offset is a global indentation for the whole list, affecting both item heads and bodies. For those list types that support it, the -width argument requests an additional indentation of item bodies, to be added to the -offset. Unless the -compact argument is specified, list entries are separated by vertical space.

A list must specify one of the following list types:

  • -bullet โ€” no item heads can be specified, but a bullet gets printed at the head of each item. Item bodies start on the same output line as the bullet and are indented according to the -width argument.
  • -column โ€” a columnated list. The -width argument has no effect; instead, the string length of each argument specifies the width of one column. If the first line of the body of a -column list is not an It macro line, It contexts spanning one input line each are implied until an It macro line is encountered, at which point items start being interpreted as described in the It documentation.
  • -dash โ€” like -bullet, except dashes are used in place of bullets.
  • -diag โ€” like -inset, except item heads are not parsed for macro invocations. Most often used in the DIAGNOSTICS section with error constants in the item heads.
  • -enum โ€” a numbered list. No item heads can be specified. Formatted like -bullet, except cardinal numbers are used in place of bullets, starting at 1.
  • -hang โ€” like -tag, except the first lines of item bodies are not indented, but follow the item heads like in -inset lists.
  • -hyphen โ€” synonym for -dash.
  • -inset โ€” item bodies follow item heads on the same line, using normal inter-word spacing. Bodies are not indented, and the -width argument is ignored.
  • -item โ€” no item heads can be specified, and none are printed. Bodies are not indented, and the -width argument is ignored.
  • -ohang โ€” item bodies start on the line following item heads and are not indented. The -width argument is ignored.
  • -tag โ€” item bodies are indented according to the -width argument. When an item head fits inside the indentation, the item body follows this head on the same output line. Otherwise, the body starts on the output line following the head.

Lists may be nested within lists and displays. Nesting of -column and -enum lists may not be portable. ๐Ÿซ 

See also El and It.


๐ŸŒธ Bo block

Begin a block enclosed by square brackets. Does not have any head arguments.

Examples:

.Bo 1 ,
.Dv BUFSIZ Bc

See also Bq.


๐Ÿฆ‹ Bq line

Encloses its arguments in square brackets.

Examples:

.Bq 1, Dv BUFSIZ

Remarks: this macro is sometimes abused to emulate optional arguments for commands; the correct macros to use for this purpose are Op, Oo, and Oc.

See also Bo.


Brc

Close a Bro block. Does not have any tail arguments.


Bro block

Begin a block enclosed by curly braces. Does not have any head arguments.

Examples:

.Bro 1 , ... ,
.Va n Brc

See also Brq.


Brq line

Encloses its arguments in curly braces.

Examples:

.Brq 1, ..., Va n

See also Bro.


๐Ÿ’œ Bsx [version]

Format the BSD/OS version provided as an argument, or a default value if no argument is provided.

Examples:

.Bsx 1.0
.Bsx

See also At, Bx, Dx, Fx, Nx, and Ox.


Bt

Supported only for compatibility โ€” do not use this in new manuals. Prints โ€œis currently in beta test.โ€


โญ Bx [version [variant]]

Format the BSD version provided as an argument, or a default value if no argument is provided.

Examples:

.Bx 4.3 Tahoe
.Bx 4.4
.Bx

See also At, Bsx, Dx, Fx, Nx, and Ox.


๐Ÿ“ Cd line

Kernel configuration declaration. This denotes strings accepted by config(8). It is most often used in section 4 manual pages.

Examples:

.Cd device le0 at scode?

Remarks: this macro is commonly abused by using quoted literals to retain whitespace and align consecutive Cd declarations. This practise is discouraged. ๐Ÿ™ˆ


๐ŸŒˆ Cm keyword ...

Command modifiers. Typically used for fixed strings passed as arguments to interactive commands, to commands in interpreted scripts, or to configuration file directives โ€” unless Fl is more appropriate.

Examples:

.Nm mt Fl f Ar device Cm rewind
.Nm ps Fl o Cm pid , Ns Cm command
.Nm dd Cm if= Ns Ar file1 Cm of= Ns Ar file2
.Ic set Fl o Cm vi
.Ic lookup Cm file bind
.Ic permit Ar identity Op Cm as Ar target

D1 line

One-line indented display. This is formatted by the default rules and is useful for simple indented statements. It is followed by a newline.

Examples:

.D1 Fl abcdefgh

See also Bd and Dl.


Db

This macro is obsolete. No replacement is needed. It is ignored by mandoc(1) and groff, including its arguments. It was formerly used to toggle a debugging mode. rip bozo ๐Ÿชฆ


Dc

Close a Do block. Does not have any tail arguments.


๐Ÿ‘‘ Dd $Mdocdate$ | month day, year

Document date for display in the page footer โ€” by convention, the date of the last change. This is the mandatory first macro of any mdoc manual.

The month is the full English month name, the day is an integer number, and the year is the full four-digit year.

Other arguments are not portable; the mandoc(1) utility handles them as follows:

  1. To have the date automatically filled in by the OpenBSD version of cvs(1), the special string โ€œ$Mdocdate$โ€ can be given as an argument.
  2. The traditional, purely numeric man(7) format yearโ€“*month*โ€“*day* is accepted, too.
  3. If a date string cannot be parsed, it is used verbatim.
  4. If no date string is given, the current date is used.

Examples:

.Dd $Mdocdate$
.Dd $Mdocdate: July 2 2018$
.Dd July 2, 2018

See also Dt and Os.


Dl line

One-line indented display. This is formatted as literal text and is useful for commands and invocations. It is followed by a newline.

Examples:

.Dl % mandoc mdoc.7 \(ba less

See also Ql, Bd -literal, and D1.


Do block

Begin a block enclosed by double quotes. Does not have any head arguments.

See also Dq.

Dq line

Wraps its args in those fancy โ€œtypographicโ€ double quotes ๐Ÿ’… not the boring straight ones.

Examples:

.Dq April is the cruellest month
\(em T.S. Eliot

See also Qq, Sq, and Do. bestie the quote family is extensive, ok?


Dt TITLE section [arch]

The document title, for showing up in the page header. This is the mandatory second macro of literally any mdoc file โ€” no skipping it, fr fr.

Its arguments go like this:

  • TITLE โ€” the doc's title (the name). If you don't specify it, it defaults to โ€œUNTITLEDโ€. For a uniform look across page headers, convention says make it ALL CAPS.
  • section โ€” the manual section. This can be one of 1 (General Commands), 2 (System Calls), 3 (Library Functions), 3p (Perl Library), 4 (Device Drivers), 5 (File Formats), 6 (Games), 7 (Miscellaneous Information), 8 (System Manager's Manual), or 9 (Kernel Developer's Manual). It should match the manual's filename suffix, and it defaults to the empty string if you leave it out.
  • arch โ€” this says which machine architecture the page applies to, where that matters. Like alpha, amd64, i386, or sparc64. The list of valid architectures is different per operating system, so iykyk check yours.

Examples:

.Dt FOO 1
.Dt FOO 9 i386

See also Dd and Os.


Dv identifier ...

Defined variables โ€” think preprocessor constants, constant symbols, enumeration values, and so on โœจ

Examples:

.Dv NULL
.Dv BUFSIZ
.Dv STDOUT_FILENO

See also Er and Ev for special-purpose constants, Va for variable symbols, and Fd for listing preprocessor variable definitions in the SYNOPSIS.


Dx [version]

Formats the DragonFly version you hand it as an argument, or a default value if you hand it nothing ๐Ÿ‰

Examples:

.Dx 2.4.1
.Dx

See also At, Bsx, Bx, Fx, Nx, and Ox.


Ec [closing_delimiter]

Closes a scope that Eo opened. It's giving matched set energy ๐Ÿซถ

The closing_delimiter argument is the enclosure tail โ€” so like, specifying \(rq will emulate Dc.


Ed

Ends a display context that Bd started. That's it, that's the whole job.


Ef

Ends a font mode context that Bf started.


Ek

Ends a keep context that Bk started.


El

Ends a list context that Bl started. See also It.


Em word ...

Requests an italic font. If the output device can't do italic, it underlines instead. Close enough, slay.

This is most often used for stress emphasis (not to be confused with importance โ€” that's Sy's whole thing). In the rare cases where none of the semantic markup macros fit, it can also be used for technical terms and placeholders โ€” except that for syntax elements, Sy and Ar are preferred, respectively.

Examples:

Selected lines are those
.Em not
matching any of the specified patterns.
Some of the functions use a
.Em hold space
to save the pattern space for subsequent retrieval.

See also No, Ql, and Sy.


En word ...

โš ๏ธ This macro is obsolete. Use Eo or any of the other enclosure macros. Not me using deprecated macros ๐Ÿ’€

It encloses its argument in the delimiters specified by the last Es macro.


Eo [opening_delimiter]

An arbitrary enclosure โœจ The opening_delimiter argument is used as the enclosure head โ€” so like, specifying \(lq will emulate Do.


Er identifier ...

Error constants, for defining the errno libc global variable. Most often seen in section 2 and 3 manual pages.

Examples:

.Er EPERM
.Er ENOENT

See also Dv for general constants.


Es opening_delimiter closing_delimiter

โš ๏ธ Also obsolete, bestie. Use Eo or any of the other enclosure macros.

It takes two arguments, defining the delimiters that subsequent En macros will use.


Ev identifier ...

Environmental variables, like the ones specified in environ(7) ๐ŸŒ

Examples:

.Ev DISPLAY
.Ev PATH

See also Dv for general constants.


Ex -std [utility ...]

Inserts a standard sentence about command exit values: 0 on success and >0 on failure. Most often used in section 1, 6, and 8 manual pages.

If utility isn't specified, the document's name set by Nm gets used. Multiple utility arguments are treated as separate utilities.

See also Rv.


Fa argument ...

A function argument or parameter. Each argument can be a name and a type (recommended for the SYNOPSIS section), a name alone (for function invocations), or a type alone (for function prototypes). If both a type and a name are given, or if the type is multiple words, all the words belonging to the same function argument have to be given in a single argument to the Fa macro. no cap.

This macro is also used to specify the field name of a structure.

Most often, Fa shows up in the SYNOPSIS inside Fo blocks, when documenting multi-line function prototypes. If you invoke it with multiple arguments, the arguments get separated by a comma. And furthermore, if the following macro is another Fa, the last argument will also get a trailing comma. Look at her go.

Examples:

.Fa "const char *p"
.Fa "int a" "int b" "int c"
.Fa "char *" size_t

See also Fo.


Fc

Ends a function context that Fo started.


Fd #directive [argument ...]

Preprocessor directive โ€” especially for listing it in the SYNOPSIS. Historically it was also used to document include files, but that usage has been deprecated in favour of In.

Examples:

.Fd #define sa_handler __sigaction_u.__sa_handler
.Fd #define SIO_MAXNFDS
.Fd #ifdef FS_DEBUG
.Ft void
.Fn dbg_open "const char *"
.Fd #endif

See also โ€œMANUAL STRUCTUREโ€, In, and Dv.


Fl [word ...]

Command-line flag or option ๐Ÿ’… Used when listing arguments to command-line utilities. For each argument, it prints an ASCII hyphen-minus character โ€˜-โ€™, immediately followed by the argument. If you provide no arguments, a hyphen-minus gets printed followed by a space. And if the argument is a macro, a hyphen-minus is prefixed to the subsequent macro output.

Examples:

.Nm du Op Fl H | L | P
.Nm ls Op Fl 1AaCcdFfgHhikLlmnopqRrSsTtux
.Nm route Cm add Fl inet Ar destination gateway
.Nm locate.updatedb Op Fl \-fcodes Ns = Ns Ar dbfile
.Nm aucat Fl o Fl
.Nm kill Fl Ar signal_number

For GNU-sytle long options, escaping the additional hyphen-minus isn't strictly required, but it may be safer with future versions of GNU troff; see mandoc_char(7) for details.

See also Cm.


Fn funcname [argument ...]

A function name.

Function arguments get surrounded in parenthesis and are delimited by commas. If you specify no arguments, blank parenthesis get output. In the SYNOPSIS section, this macro starts a new output line, and a blank line is automatically inserted between function definitions โœจ

Examples:

.Fn "int funcname" "int arg0" "int arg1"
.Fn funcname "int arg0"
.Fn funcname arg0

.Ft functype
.Fn funcname

When you're referring to a function documented in another manual page, use Xr instead. See also โ€œMANUAL STRUCTUREโ€, Fo, and Ft.


Fo funcname

Begins a function block. This is the multi-line version of Fn.

Invocations usually happen in this context:

.Ft functype
.Fo funcname
.Fa "argtype argname"
...
.Fc

A Fo scope gets closed by Fc.

See also โ€œMANUAL STRUCTUREโ€, Fa, Fc, and Ft.


Fr number

โš ๏ธ Obsolete macro, bestie. No replacement markup is needed. We simply don't do this anymore ๐Ÿ™ˆ

It was used to show numerical function return values in an italic font.


Ft functype

A function type.

In the SYNOPSIS section, a new output line starts after this macro.

Examples:

.Ft int
.Ft functype
.Fn funcname

See also โ€œMANUAL STRUCTUREโ€, Fn, and Fo.


Fx [version]

Formats the FreeBSD version you give it as an argument, or a default value if you give it nothing ๐Ÿ˜Œ

Examples:

.Fx 7.1
.Fx

See also At, Bsx, Bx, Dx, Nx, and Ox.


Hf filename

โš ๏ธ Heads up: this macro is not implemented in mandoc(1). It was used to include the contents of a (header) file literally. So likeโ€ฆ don't count on it ๐Ÿซ 

Ic keyword ...

An internal or interactive command, or a configuration instruction in a config file. See also Cm.

Examples:

.Ic :wq
.Ic hash
.Ic alias

Quick note: using Ql, Dl, or Bd -literal is preferred for displaying code samples โ€” Ic is the move when you're referring to an individual command name.


In filename

The name of an include file. Most often used in section 2, 3, and 9 manual pages.

When you invoke it as the first macro on an input line in the SYNOPSIS section, the argument is displayed in angle brackets and preceded by #include, and a blank line gets inserted in front if there's a preceding function declaration. In other sections, it just encloses its argument in angle brackets and causes no line break.

Examples:

.In sys/types.h

See also โ€œMANUAL STRUCTUREโ€.


It [head]

A list item โœจ The syntax of this macro depends on the list type, so let's break it down.

Lists of type -hang, -ohang, -inset, and -diag have this syntax:

.It args

Lists of type -bullet, -dash, -enum, -hyphen and -item have this syntax:

.It

with the subsequent lines interpreted within the scope of the It until either a closing El or another It shows up. iconic.

The -tag list has this syntax:

.It [args]

Subsequent lines are interpreted just like -bullet and family. The line arguments correspond to the list's left-hand side; body arguments correspond to the list's contents.

The -column list is the โœจmain characterโœจ of the whole Bl family โ€” the most complicated one, no cap. Its syntax goes like this:

.It cell [Ta cell ...]
.It cell [<TAB> cell ...]

The arguments are one or more lines of text and macros that represent a complete table line. Cells inside that line get separated by either the special Ta block macro or by literal tab characters. ๐Ÿซถ

Using literal tabs is strongly discouraged, bestie. They're genuinely so hard to get right, and mdoc code that uses them is really hard to read. Specifically: a blank character is syntactically significant before and after the literal tab character. If a word sits before or after that tab with no blank in between, that word is never interpreted as a macro call โ€” it's always output literally. ๐Ÿ˜ญ

Also, the tab cell delimiter only works inside the It line itself. On the lines that follow, only the Ta macro can delimit cells, and portability requires that Ta gets called by other macros โ€” some parsers just don't recognize it when it shows up as the first macro on a line. ๐Ÿ™ˆ

Heads up that quoted strings can span tab-delimited cells on an It line. Like:

.It "col1 , <TAB> col2 ," ;

That one preserves the whitespace before both commas โ€” but not the whitespace before the semicolon. โญ

See also Bl.


  • Lb libname โ€” specify a library. ๐Ÿ’…

The name parameter can be a system library, like z or pam, and then a small library description gets printed right next to the linker invocation; or it can be a custom library, and then the library name is printed in quotes. This is most commonly used in the SYNOPSIS section, as described in โ€œMANUAL STRUCTUREโ€.

Examples:

.Lb libz
.Lb libmandoc
  • Li word ... โ€” request a typewriter (literal) font. Deprecated, because on terminal output devices it's usually indistinguishable from normal text. For literal displays, use Ql (in-line), Dl (single line), or Bd -literal (multi-line) instead. ๐ŸŽ€
  • Lk uri [display_name] โ€” format a hyperlink. ๐Ÿ”ฅ

Examples:

.Lk https://bsd.lv "The BSD.lv Project"
.Lk https://bsd.lv

See also Mt.

  • Lp โ€” deprecated synonym for Pp. (yeah, it's giving "old news", just use Pp.)
  • Ms name โ€” display a mathematical symbol. ๐Ÿงฎโœจ

Examples:

.Ms sigma
.Ms aleph
  • Mt localpart@domain โ€” format a โ€œmailto:โ€ hyperlink. ๐Ÿ’Œ

Examples:

.Mt discuss@manpages.bsd.lv
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
  • Nd line โ€” a one line description of the manual's content. This is the mandatory last macro of the NAME section and it is not appropriate anywhere else. ๐Ÿ‘‘

Examples:

.Nd mdoc language reference
.Nd format and display UNIX manuals

Technically, Nd accepts child macros and terminates when a Sh invocation comes along. But do not assume this behaviour โ€” some whatis(1) database generators are simply not smart enough to parse more than the line arguments, and they'll display macros verbatim. ๐Ÿ’€

See also Nm.

  • Nm [name] โ€” the name of the manual page, or โ€” especially in section 1, 6, and 8 pages โ€” of an additional command or feature documented in the manual page. When you first invoke Nm, it expects a single argument: the name of the manual page. Usually that first invocation happens in the NAME section of the page. The name you gave gets remembered, and it's used every time the macro is called again with no arguments later in the page. ๐ŸŒธ

When Nm is invoked as the first macro on an input line in the SYNOPSIS section, it uses โ€œBlock full-implicitโ€ semantics; otherwise it uses ordinary โ€œIn-lineโ€ semantics.

Examples:

.Sh SYNOPSIS
.Nm cat
.Op Fl benstuv
.Op Ar

In the SYNOPSIS of section 2, 3 and 9 manual pages, use the Fn macro rather than Nm to mark up the name of the manual page. ๐Ÿ“Œ

  • No word ... โ€” normal text. It closes the scope of any preceding in-line macro. When you use it after physical formatting macros like Em or Sy, it switches back to the standard font face and weight. You can also use it to embed plain text strings in macro lines using semantic annotation macros. โœจ

Examples:

.Em italic , Sy bold , No and roman

.Sm off
.Cm :C No / Ar pattern No / Ar replacement No /
.Sm on

See also Em, Ql, and Sy.

  • Ns โ€” suppress a space between the output of the preceding macro and the following text or macro. After you invoke it, input is interpreted as normal text, just like after an No macro. ๐Ÿซถ

It has no effect when invoked at the start of a macro line.

Examples:

.Ar name Ns = Ns Ar value
.Cm :M Ns Ar pattern
.Fl o Ns Ar output

See also No and Sm.

  • Nx [version] โ€” format the NetBSD version you give it as an argument, or a default value if no argument is provided. ๐ŸŸ

Examples:

.Nx 5.01
.Nx

See also At, Bsx, Bx, Dx, Fx, and Ox.

  • Oc โ€” close a multi-line Oo context. (that's it, that's the job ๐Ÿ’…)
  • Oo block โ€” the multi-line version of Op.

Examples:

.Oo
.Op Fl flag Ns Ar value
.Oc
  • Op line โ€” optional part of a command line. It prints the argument(s) in brackets. Most often used in the SYNOPSIS section of section 1 and 8 manual pages. ๐ŸŽ€

Examples:

.Op Fl a Ar b
.Op Ar a | b

See also Oo.

  • Os [system [version]] โ€” operating system version for display in the page footer. This is the mandatory third macro of any mdoc file. ๐Ÿ“Œ

The optional system parameter specifies the relevant operating system or environment. It's suggested that you leave it unspecified โ€” in which case mandoc(1) uses its -Ios argument or, if that isn't specified either, sysname and release as returned by uname(3). ๐ŸŒˆ

Examples:

.Os
.Os KTH/CSC/TCS
.Os BSD 4.3

See also Dd and Dt.

  • Ot functype โ€” this macro is obsolete. Use Ft instead; with mandoc(1), both have the same effect. Historical mdoc packages described it as โ€œold function type (FORTRAN)โ€. ๐Ÿ’€
  • Ox [version] โ€” format the OpenBSD version you give it as an argument, or a default value if no argument is provided. ๐Ÿก

Examples:

.Ox 4.5
.Ox

See also At, Bsx, Bx, Dx, Fx, and Nx.

  • Pa name ... โ€” an absolute or relative file system path, or a file or directory name. If you don't provide an argument, the character โ€˜~โ€™ is used as the default. ๐Ÿ“โœจ

Examples:

.Pa /usr/bin/mandoc
.Pa /usr/share/man/man7/mdoc.7

See also Lk.

  • Pc โ€” close the parenthesised context opened by Po. ๐Ÿ’–
  • Pf prefix macro [argument ...] โ€” removes the space between its argument and the following macro. It's equivalent to:
No \&prefix Ns macro [argument ...]

The prefix argument is not parsed for macro names or delimiters โ€” it's used verbatim, as if it were escaped. ๐Ÿซถ

Examples:

.Pf $ Ar variable_name
.Pf . Ar macro_name
.Pf 0x Ar hex_digits

See also Ns and Sm.

  • Po block โ€” the multi-line version of Pq.
  • Pp โ€” break a paragraph. This asserts vertical space between the prior and subsequent macros and/or text. ๐Ÿ“

You don't need paragraph breaks before or after Sh or Ss macros, or before displays (Bd line) or lists (Bl), unless the -compact flag is given.

  • Pq line โ€” parenthesised enclosure. ๐ŸŒธ

See also Po.

  • Qc โ€” close the quoted context opened by Qo.
  • Ql line โ€” in-line literal display. This one's perfect for complete command invocations and for multi-word code examples when you don't want an indented display. ๐Ÿ’…

See also Dl and Bd -literal.

  • Qo block โ€” the multi-line version of Qq.
  • Qq line โ€” encloses its arguments in "typewriter" double-quotes. Consider using Dq instead. ๐Ÿ‘€

See also Dq, Sq, and Qo.

  • Re โ€” close an Rs block. It does not have any tail arguments. ๐ŸŽ€
  • Rs โ€” begin a bibliographic (โ€œreferenceโ€) block. It does not have any head arguments. This block macro may only contain %A, %B, %C, %D, %I, %J, %N, %O, %P, %Q, %R, %T, %U, and %V child macros โ€” and at least one must be specified. ๐Ÿ“š

Examples:

.Rs
.%A J. E. Hopcroft
.%A J. D. Ullman
.%B Introduction to Automata Theory, Languages, and Computation
.%I Addison-Wesley
.%C Reading, Massachusetts
.%D 1979
.Re

If an Rs block is used inside a SEE ALSO section, a vertical space is asserted before the rendered output; otherwise the block just continues on the current line.

  • Rv -std [function ...] โ€” insert a standard sentence about a function call's return value: 0 on success, -1 on error, with the errno libc global variable set on error. ๐Ÿ”ฅ

If function isn't specified, the document's name set by Nm is used. Multiple function arguments are treated as separate functions.

See also Ex.

  • Sc โ€” close the single-quoted context opened by So. โœจ
  • Sh TITLE LINE โ€” begin a new section. For a list of conventional manual sections, see โ€œMANUAL STRUCTUREโ€. These sections should be used unless it's absolutely necessary that custom sections be used. ๐Ÿ‘‘

Section names should be unique so they can be keyed by Sx. Although this macro is parsed, it should not consist of a child node โ€” otherwise it may not be linked with Sx. โš ๏ธ

See also Pp, Ss, and Sx.

  • Sm [on | off] โ€” switches the spacing mode for output generated from macros. ๐ŸŒˆ

By default, spacing is on. When it's switched off, no white space is inserted between macro arguments or between the output generated from adjacent macros โ€” but text lines still get normal spacing between words and sentences. ๐Ÿ“

When called with no argument, the Sm macro toggles the spacing mode. Using it that way is not recommended, because it makes the code harder to read. ๐Ÿ™ˆ

  • So block โ€” the multi-line version of Sq.
  • Sq line โ€” encloses its arguments in โ€˜typewriterโ€™ single-quotes. ๐ŸŽ€

See also Dq, Qq, and So.

Ss โ€” Title line ๐ŸŽ€

Begin a new subsection, bestie. Unlike with Sh, there is no convention for the naming of subsections. Except DESCRIPTION, the conventional sections described in โ€œMANUAL STRUCTUREโ€ rarely have subsections.

Sub-section names should be unique so that they may be keyed by Sx. And even though this macro is parsed, it should not consist of child node or it may not be linked with Sx. noted ๐Ÿ’…

See also Pp, Sh, and Sx.


St -abbreviation โœจ

Replace an abbreviation for a standard with the full form. The following standards are recognised. Where multiple lines are given without a blank line in between, they all refer to the same standard, and using the first form is recommended.

C language standards ๐Ÿงš

  • -ansiC, -ansiC-89 โ€” ANSI X3.159-1989 (โ€œANSI C89โ€)
  • -isoC, -isoC-90 โ€” ISO/IEC 9899:1990 (โ€œISO C90โ€)
    • The original C standard.
  • -isoC-amd1 โ€” ISO/IEC 9899/AMD1:1995 (โ€œISO C90, Amendment 1โ€)
  • -isoC-tcor1 โ€” ISO/IEC 9899/TCOR1:1994 (โ€œISO C90, Technical Corrigendum 1โ€)
  • -isoC-tcor2 โ€” ISO/IEC 9899/TCOR2:1995 (โ€œISO C90, Technical Corrigendum 2โ€)
  • -isoC-99 โ€” ISO/IEC 9899:1999 (โ€œISO C99โ€)
    • The second major version of the C language standard.
  • -isoC-2011 โ€” ISO/IEC 9899:2011 (โ€œISO C11โ€)
    • The third major version of the C language standard.

POSIX.1 before the Single UNIX Specification ๐Ÿฆ‹

  • -p1003.1-88, -p1003.1 โ€” IEEE Std 1003.1-1988 (โ€œPOSIX.1โ€) / IEEE Std 1003.1 (โ€œPOSIX.1โ€)
    • The original POSIX standard, based on ANSI C.
  • -p1003.1-90, -iso9945-1-90 โ€” ISO/IEC 9945-1:1990 (โ€œPOSIX.1โ€)
    • The first update of POSIX.1.
  • -p1003.1b-93, -p1003.1b โ€” IEEE Std 1003.1b-1993 (โ€œPOSIX.1โ€) / IEEE Std 1003.1b (โ€œPOSIX.1โ€)
    • Real-time extensions.
  • -p1003.1c-95 โ€” IEEE Std 1003.1c-1995 (โ€œPOSIX.1โ€)
    • POSIX thread interfaces.
  • -p1003.1i-95 โ€” IEEE Std 1003.1i-1995 (โ€œPOSIX.1โ€)
    • Technical Corrigendum.
  • -p1003.1-96, -iso9945-1-96 โ€” ISO/IEC 9945-1:1996 (โ€œPOSIX.1โ€)
    • Includes POSIX.1-1990, 1b, 1c, and 1i.
  • -xpg3 โ€” X/Open Portability Guide Issue 3 (โ€œXPG3โ€)
    • An XPG4 precursor, published in 1989.
  • -p1003.2, -p1003.2-92, -iso9945-2-93 โ€” IEEE Std 1003.2 (โ€œPOSIX.2โ€) / IEEE Std 1003.2-1992 (โ€œPOSIX.2โ€) / ISO/IEC 9945-2:1993 (โ€œPOSIX.2โ€)
    • An XCU4 precursor.
  • -p1003.2a-92 โ€” IEEE Std 1003.2a-1992 (โ€œPOSIX.2โ€)
    • Updates to POSIX.2.
  • -xpg4 โ€” X/Open Portability Guide Issue 4 (โ€œXPG4โ€)
    • Based on POSIX.1 and POSIX.2, published in 1992.
  • -susv1, -xpg4.2 โ€” Version 1 of the Single UNIX Specification (โ€œSUSv1โ€) / X/Open Portability Guide Issue 4, Version 2 (โ€œXPG4.2โ€)
    • This standard was published in 1994. It was used as the basis for UNIX 95 certification. The following three refer to parts of it.
  • -xsh4.2 โ€” listed with no description of its own, it's just vibing there
  • -xcurses4.2 โ€” X/Open Curses Issue 4, Version 2 (โ€œXCURSES4.2โ€)
  • -p1003.1g-2000 โ€” IEEE Std 1003.1g-2000 (โ€œPOSIX.1โ€)
    • Networking APIs, including sockets.
  • -svid4 โ€” System V Interface Definition, Fourth Edition (โ€œSVID4โ€),
    • Published in 1995.
  • -susv2 โ€” Version 2 of the Single UNIX Specification (โ€œSUSv2โ€) This Standard was published in 1997 and is also called X/Open Portability Guide version 5. It was used as the basis for UNIX 98 certification. The following refer to parts of it.
  • -xbd5 โ€” X/Open Base Definitions Issue 5 (โ€œXBD5โ€)
  • -xsh5 โ€” X/Open System Interfaces and Headers Issue 5 (โ€œXSH5โ€)
  • -xcu5 โ€” X/Open Commands and Utilities Issue 5 (โ€œXCU5โ€)
  • -xns5, -xns5.2 โ€” X/Open Networking Services Issue 5 (โ€œXNS5โ€) / X/Open Networking Services Issue 5.2 (โ€œXNS5.2โ€)

Single UNIX Specification version 3 โญ

  • -p1003.1-2001, -susv3 โ€” IEEE Std 1003.1-2001 (โ€œPOSIX.1โ€) / Version 3 of the Single UNIX Specification (โ€œSUSv3โ€)
    • This standard is based on C99, SUSv2, POSIX.1-1996, 1d, and 1j. It is also called X/Open Portability Guide version 6. It is used as the basis for UNIX 03 certification.
  • -p1003.1-2004 โ€” IEEE Std 1003.1-2004 (โ€œPOSIX.1โ€)
    • The second and last Technical Corrigendum.

Single UNIX Specification version 4 ๐Ÿ’œ

  • -p1003.1-2008, -susv4 โ€” IEEE Std 1003.1-2008 (โ€œPOSIX.1โ€) / Version 4 of the Single UNIX Specification (โ€œSUSv4โ€)
    • This standard is also called X/Open Portability Guide version 7.

Other standards ๐Ÿ“

  • -ieee754 โ€” IEEE Std 754-1985
    • Floating-point arithmetic.
  • -iso8601 โ€” ISO 8601
    • Representation of dates and times, published in 1988.
  • -iso8802-3 โ€” ISO/IEC 8802-3:1989
    • Ethernet local area networks.
  • -ieee1275-94 โ€” IEEE Std 1275-1994 (โ€œOpen Firmwareโ€)

Sx Title line ๐Ÿ”—

Reference a section or subsection in the same manual page. The referenced section or subsection name must be identical to the enclosed argument, including whitespace. fr fr, whitespace counts.

Examples:

.Sx MANUAL STRUCTURE

See also Sh and Ss.


Sy word ... ๐Ÿ”ฅ

Request a boldface font.

This is most often used to indicate importance or seriousness (not to be confused with stress emphasis, see Em). When none of the semantic macros fit, it is also adequate for syntax elements that have to be given or that appear verbatim.

Examples:

.Sy Warning :
If
.Sy s
appears in the owner permissions, set-user-ID mode is set.
This utility replaces the former
.Sy dumpdir
program.

See also Em, No, and Ql.


Ta ๐Ÿ“Š

Table cell separator in Bl -column lists; can only be used below It. That's it, that's the whole job.


Tg [term] ๐Ÿท๏ธ

Announce that the next input line starts a definition of the term. This macro must appear alone on its own input line. The argument defaults to the first argument of the first macro on the next line. The argument may not contain whitespace characters, not even when it is quoted. This macro is a mandoc(1) extension and is typically ignored by other formatters.

When viewing terminal output with less(1), the interactive :t command can be used to go to the definition of the term as described for the MANPAGER variable in man(1); when producing HTML output, a fragment identifier (id attribute) is generated, to be used for deep linking to this place of the document.

In most cases, adding a Tg macro would be redundant because mandoc(1) is able to automatically tag most definitions. This macro is intended for cases where automatic tagging of a term is unsatisfactory, for example if a definition is not tagged automatically (false negative) or if places are tagged that do not define the term (false positives). When there is at least one Tg macro for a term, no other places are automatically marked as definitions of that term. iykyk ๐Ÿ’…


Tn word ... ๐Ÿ’€

Supported only for compatibility, do not use this in new manuals. Even though the macro name (โ€œtradenameโ€) suggests a semantic function, historic usage is inconsistent, mostly using it as a presentation-level macro to request a small caps font.


Ud ๐Ÿ™ˆ

Supported only for compatibility, do not use this in new manuals. Prints out โ€œcurrently under development.โ€


Ux ๐Ÿ–ฅ๏ธ

Supported only for compatibility, do not use this in new manuals. Prints out โ€œUnixโ€.


Va [type] identifier ... ๐Ÿ“ฆ

A variable name.

Examples:

.Va foo
.Va const char *bar;

For function arguments and parameters, use Fa instead. For declarations of global variables in the SYNOPSIS section, use Vt.


Vt type [identifier] ๐Ÿงฌ

A variable type.

This is also used for indicating global variables in the SYNOPSIS section, in which case a variable name is also specified. Note that it accepts โ€œBlock partial-implicitโ€ syntax when invoked as the first macro on an input line in the SYNOPSIS section, else it accepts ordinary โ€œIn-lineโ€ syntax. In the former case, this macro starts a new output line, and a blank line is inserted in front if there is a preceding function definition or include directive.

Examples:

.Vt unsigned char
.Vt extern const char * const sys_signame[] ;

For parameters in function prototypes, use Fa instead, for function return types Ft, and for variable names outside the SYNOPSIS section Va, even when including a type with the name. See also โ€œMANUAL STRUCTUREโ€.


Xc ๐Ÿ”’

Close a scope opened by Xo.


Xo block ๐Ÿ”“

Extend the header of an It macro or the body of a partial-implicit block macro beyond the end of the input line. This macro originally existed to work around the 9-argument limit of historic roff(7). nine whole arguments, can you imagine ๐Ÿ˜ญ


Xr name section ๐Ÿ“š

Link to another manual ("cross-reference").

Cross reference the name and section number of another man page.

Examples:

.Xr mandoc 1
.Xr mandoc 1 ;
.Xr mandoc 1 Ns s behaviour

๐Ÿ’… MACRO SYNTAX ๐Ÿ’…

okay so here's the tea: the syntax of a macro is fully dependent on its classification, no cap. In this section, bestie:

  • -arg refers to macro arguments, which may be followed by zero or more parm parameters
  • Yo opens the scope of a macro
  • and if specified, Yc closes it out

The Callable column โ€” this is the one that says "yes queen, this macro can also be called by passing its name as an argument to another macro." For example, .Op Fl O Ar file produces [-O file]. Wanna stop a macro call and just render the macro name literally? Escape it by prepending a zero-width space, \&. Like, Op \&Fl O produces [Fl O]. And if a macro is not callable but its name shows up as an argument to another macro, it gets interpreted as opaque text. For example, .Fl Sh produces -Sh.

The Parsed column โ€” this one is asking "can this macro call other macros by receiving their names as arguments?" If a macro is not parsed but the name of another macro appears as an argument, it's interpreted as opaque text. Simple as that ๐Ÿ’…

The Scope column, if applicable, describes closure rules. iykyk.


๐ŸŽ€ Block full-explicit ๐ŸŽ€

Multi-line scope, closed by an explicit closing macro. All macros contain bodies; only Bf and (optionally) Bl contain a head.

.Yo [-arg [parm...]] [head...]
[body...]
.Yc
Macro     Callable     Parsed     Scope
Bd        No           No         closed by Ed
Bf        No           No         closed by Ef
Bk        No           No         closed by Ek
Bl        No           No         closed by El
Ed        No           No         opened by Bd
Ef        No           No         opened by Bf
Ek        No           No         opened by Bk
El        No           No         opened by Bl

๐ŸŒธ Block full-implicit ๐ŸŒธ

Multi-line scope, closed by end-of-file or implicitly by another macro. All macros have bodies; some of them (It -bullet, -hyphen, -dash, -enum, -item) don't have heads; and only one (It in Bl -column) has multiple heads.

.Yo [-arg [parm...]] [head... [Ta head...]]
[body...]
Macro     Callable     Parsed     Scope
It        No           Yes        closed by It, El
Nd        No           No         closed by Sh
Nm        No           Yes        closed by Nm, Sh, Ss
Sh        No           Yes        closed by Sh
Ss        No           Yes        closed by Sh, Ss
heads up: the Nm macro is a "Block full-implicit" macro only when it's invoked as the first macro in a SYNOPSIS section line. Otherwise it's "In-line". it's giving dual citizenship ๐Ÿ’€

โœจ Block partial-explicit โœจ

Like block full-explicit, but it also has single-line scope. Each one has at least a body and, in limited circumstances, a head (Fo, Eo) and/or tail (Ec).

.Yo [-arg [parm...]] [head...]
[body...]
.Yc [tail...]
.Yo [-arg [parm...]] [head...] [body...] Yc [tail...]
Macro     Callable     Parsed     Scope
Ac        Yes          Yes        opened by Ao
Ao        Yes          Yes        closed by Ac
Bc        Yes          Yes        closed by Bo
Bo        Yes          Yes        opened by Bc
Brc       Yes          Yes        opened by Bro
Bro       Yes          Yes        closed by Brc
Dc        Yes          Yes        opened by Do
Do        Yes          Yes        closed by Dc
Ec        Yes          Yes        opened by Eo
Eo        Yes          Yes        closed by Ec
Fc        Yes          Yes        opened by Fo
Fo        No           No         closed by Fc
Oc        Yes          Yes        closed by Oo
Oo        Yes          Yes        opened by Oc
Pc        Yes          Yes        closed by Po
Po        Yes          Yes        opened by Pc
Qc        Yes          Yes        opened by Oo
Qo        Yes          Yes        closed by Oc
Re        No           No         opened by Rs
Rs        No           No         closed by Re
Sc        Yes          Yes        opened by So
So        Yes          Yes        closed by Sc
Xc        Yes          Yes        opened by Xo
Xo        Yes          Yes        closed by Xc

๐Ÿฆ‹ Block partial-implicit ๐Ÿฆ‹

Like block full-implicit, but with single-line scope closed by the end of the line. so basically it wraps up when the line wraps up, iconic behaviour honestly.

.Yo [-arg [val...]] [body...] [res...]
Macro     Callable     Parsed
Aq        Yes          Yes
Bq        Yes          Yes
Brq       Yes          Yes
D1        No           Yes
Dl        No           Yes
Dq        Yes          Yes
En        Yes          Yes
Op        Yes          Yes
Pq        Yes          Yes
Ql        Yes          Yes
Qq        Yes          Yes
Sq        Yes          Yes
Vt        Yes          Yes
another lil note: the Vt macro is a "Block partial-implicit" only when invoked as the first macro in a SYNOPSIS section line. Else it's "In-line". yes this is the same plot twist as Nm. they're matching ๐Ÿซถ

๐Ÿ‘‘ Special block macro ๐Ÿ‘‘

The Ta macro can only be used below It in Bl -column lists. It delimits blocks representing table cells; these blocks have bodies, but no heads. no head, all body, main character energy fr.

Macro     Callable     Parsed     Scope
Ta        Yes          Yes        closed by Ta, It

๐Ÿ’– In-line ๐Ÿ’–

Closed by the end of the line, fixed argument lengths, and/or subsequent macros. In-line macros have only text children. And if a number (or inequality) of arguments is (n), then the macro accepts an arbitrary number of arguments.

.Yo [-arg [val...]] [args...] [res...]
.Yo [-arg [val...]] [args...] Yc...
.Yo [-arg [val...]] arg0 arg1 argN
Macro     Callable     Parsed     Arguments
%A        No           No         >0
%B        No           No         >0
%C        No           No         >0
%D        No           No         >0
%I        No           No         >0
%J        No           No         >0
%N        No           No         >0
%O        No           No         >0
%P        No           No         >0
%Q        No           No         >0
%R        No           No         >0
%T        No           No         >0
%U        No           No         >0
%V        No           No         >0
Ad        Yes          Yes        >0
An        Yes          Yes        >0
Ap        Yes          Yes        0
Ar        Yes          Yes        n
At        Yes          Yes        1
Bsx       Yes          Yes        n
Bt        No           No         0
Bx        Yes          Yes        n
Cd        Yes          Yes        >0
Cm        Yes          Yes        >0
Db        No           No         1
Dd        No           No         n
Dt        No           No         n
Dv        Yes          Yes        >0
Dx        Yes          Yes        n
Em        Yes          Yes        >0
Er        Yes          Yes        >0
Es        Yes          Yes        2
Ev        Yes          Yes        >0
Ex        No           No         n
Fa        Yes          Yes        >0
Fd        No           No         >0
Fl        Yes          Yes        n
Fn        Yes          Yes        >0
Fr        Yes          Yes        >0
Ft        Yes          Yes        >0
Fx        Yes          Yes        n
Hf        No           No         n
Ic        Yes          Yes        >0
In        No           No         1
Lb        No           No         1
Li        Yes          Yes        >0
Lk        Yes          Yes        >0
Lp        No           No         0
Ms        Yes          Yes        >0
Mt        Yes          Yes        >0
Nm        Yes          Yes        n
No        Yes          Yes        >0
Ns        Yes          Yes        0
Nx        Yes          Yes        n
Os        No           No         n
Ot        Yes          Yes        >0
Ox        Yes          Yes        n
Pa        Yes          Yes        n
Pf        Yes          Yes        1
Pp        No           No         0
Rv        No           No         n
Sm        No           No         <2
St        No           Yes        1
Sx        Yes          Yes        >0
Sy        Yes          Yes        >0
Tg        No           No         <2
Tn        Yes          Yes        >0
Ud        No           No         0
Ux        Yes          Yes        n
Va        Yes          Yes        n
Vt        Yes          Yes        >0
Xr        Yes          Yes        2

๐ŸŒˆ Delimiters ๐ŸŒˆ

okay so this is the part where things get โœจspecialโœจ. When a macro argument consists of one single input character that's considered a delimiter, the argument gets special handling. This does not apply when delimiters appear in arguments containing more than one character.

So consequently, if you wanna prevent that special handling and just handle it like any other argument, a delimiter can be escaped by prepending a zero-width space (\&). In text lines though, delimiters never need escaping โ€” you can just use them as normal punctuation, live your life ๐Ÿ’…

For many macros, when the leading arguments are opening delimiters, those delimiters are put before the macro scope, and when the trailing arguments are closing delimiters, those delimiters are put after the macro scope. Spacing is suppressed after opening delimiters and before closing delimiters. For example:

.Aq ( [ word ] ) .

renders as:

([โŸจwordโŸฉ]).

Opening delimiters are:

  • ( โ€” left parenthesis
  • [ โ€” left bracket

Closing delimiters are:

  • . โ€” period
  • , โ€” comma
  • : โ€” colon
  • ; โ€” semicolon
  • ) โ€” right parenthesis
  • ] โ€” right bracket
  • ? โ€” question mark
  • ! โ€” exclamation mark
not me needing to tell you that even a period preceded by a backslash (\.) gets this special handling โ€” use \&. to prevent that. sneaky lil guy fr.

Many in-line macros interrupt their scope when they encounter delimiters, and then resume their scope when more arguments follow that are not delimiters. For example:

.Fl a ( b | c \*(Ba d ) e

renders as:

-a (-b | -c | -d) -e

This applies to both opening and closing delimiters, and also to the middle delimiter, which does not suppress spacing:

...and that's the | vertical bar, obviously. ๐Ÿ‘‘

Now for the little special case: the predefined string \*(Ba is handled and rendered in exactly the same way as a plain | character. But ngl, using that predefined string is not recommended in new manuals. It's giving vintage for no reason, bestie โ€” leave it in the drafts folder. ๐Ÿ’…

Appending a zero-width space (\&) to the end of an input line is also useful โ€” it stops a trailing period, exclamation or question mark from getting read as the end of a sentence. Like when an abbreviation just happens to land at the end of a text or macro input line and you're sitting there like ๐Ÿซ . Slap that \& on and the sentence stays open. Iconic.

Font handling

Okay so in mdoc documents, using semantic markup is the move, because that's how you get the proper fonts automatically selected for you. Only when there's genuinely no fitting semantic markup available should you even consider falling back to the "Physical markup" macros. Semantic first, always. โœจ

And here's the part that eats: whenever any mdoc macro switches the roff(7) font mode, it automatically restores the previous font when it exits its scope. So you don't have to babysit it. ๐Ÿงš

Which means manually switching the font with the roff(7) \f font escape sequences is never required. Not once. Not ever. Put the \f down, bestie. ๐Ÿ™ˆ

๐Ÿ’€ COMPATIBILITY ๐Ÿ’€

This section gives you an incomplete list of compatibility issues between mandoc and GNU troff ("groff"). Not the whole drama, just the highlights. ๐Ÿ‘€

The following problematic behaviour is found in groff:

  • Pa does not format its arguments when used in the FILES section under certain list types.
  • Ta can only be called by other macros โ€” it can't be called at the beginning of a line.
  • \f (font face) and \F (font family face) "Text Decoration" escapes behave irregularly when specified within line-macro scopes.
  • Negative scaling units return to prior lines. Instead, mandoc truncates them to zero.

The following features are unimplemented in mandoc:

  • Bd -file file is unsupported for security reasons. Not a vibe thing, a safety thing. ๐Ÿ”’
  • Bd -filled does not adjust the right margin โ€” it's an alias for Bd -ragged.
  • Bd -literal does not use a literal font โ€” it's an alias for Bd -unfilled.
  • Bd -offset center and -offset right don't work. Groff does not implement centered and flush-right rendering either, but it produces large indentations. So nobody's winning here, we're all just indenting. ๐Ÿ˜ญ

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

The web page extended documentation for the mdoc language: https://mandoc.bsd.lv/mdoc/ โ€” it's got a few tutorial-style pages for beginners, an extensive style guide for advanced authors, and an alphabetic index that helps you choose the best macros for various kinds of content. Basically the group chat archive. ๐Ÿซถ

The manual page groff_mdoc(7): https://man.voidlinux.org/groff_mdoc โ€” it lives in the "groff" package and documents exactly the same language in a somewhat different style. Same lore, different narrator. ๐Ÿ’œ

โญ HISTORY โญ

The mdoc language first appeared as a troff macro package in 4.4BSD. It was later significantly updated by Werner Lemberg and Ruslan Ermilov in groff-1.17. The standalone implementation that is part of the mandoc(1) utility, written by Kristaps Dzonsons, appeared in OpenBSD 4.6. Glow-up timeline, honestly. ๐Ÿ‘‘

๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

The mdoc reference was written by Kristaps Dzonsons <kristaps@bsd.lv>.


And that's a wrap on the whole page, bestie!! ๐ŸŽ€ This one ships with Debian, dated July 29, 2021, and you'll find it filed under MDOC(7). Go forth and mark up your manuals semantically, hydrate, and never use \*(Ba in a new manual. Periodt. ๐Ÿ’–โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from