The mandoc utility formats manual pages for display.
By default, mandoc reads mdoc(7) or man(7) text from stdin and produces -T
The options are as follows:
If the standard output is a terminal device and -c is not specified, use less(1) to paginate the output, just like man(1) would.
Copy the formatted manual pages to the standard output without using less(1) to paginate them. This is the default. It can be specified to override -a.
- -I os=name
Override the default operating system name for the mdoc(7)
Osand for the man(7)
- -K encoding
Specify the input encoding. The supported encoding arguments are
utf-8. If not specified, autodetection uses the first match in the following list:
If the first three bytes of the input file are the UTF-8 byte order mark (BOM, 0xefbbbf), input is interpreted as
If the first or second line of the input file matches the emacs mode line format
.\" -*- [...;] coding: encoding; -*-
then input is interpreted according to encoding.
If the first non-ASCII byte in the file introduces a valid UTF-8 sequence, input is interpreted as
Otherwise, input is interpreted as
- -mdoc | -man
With -mdoc, all input files are interpreted as mdoc(7). With -man, all input files are interpreted as man(7). By default, the input language is automatically detected for each file: if the first macro is
Dt, the mdoc(7) parser is used; otherwise, the man(7) parser is used. With other arguments,
-mis silently ignored.
- -O options
Comma-separated output options. See the descriptions of the individual output formats for supported options.
- -T output
Select the output format. Supported values for the output argument are
html, the default of
The special -T
lintmode only parses the input and produces no output. It implies -W
alland redirects parser messages, which usually appear on standard error output, to standard output.
- -W level
Specify the minimum message level to be reported on the standard error output and to affect the exit status. The level can be
baselevel automatically derives the operating system from the contents of the
Osmacro, from the
-Ioscommand line option, or from the uname(3) return value. The levels
netbsdare variants of
basethat bypass autodetection and request validation of base system conventions for a particular operating system. The level
allis an alias for
base. By default, mandoc is silent. See Exit Status and Diagnostics for details.
The special option -W
stoptells mandoc to exit after parsing a file that causes warnings or errors of at least the requested level. No formatted output will be produced from that file. If both a level and
stopare requested, they can be joined with a comma, for example -W
Read from the given input file. If multiple files are specified, they are processed in the given order. If unspecified, mandoc reads from standard input.
-fhklw are also supported and are documented in man(1). In
-k mode, mandoc also supports the options
-CMmOSs described in the apropos(1) manual. The options
-fkl are mutually exclusive and override each other.
ascii to force text output in 7-bit ASCII character encoding documented in the ascii(7) manual page, ignoring the locale(1) set in the environment.
Font styles are applied by using back-spaced encoding such that an underlined character ‘c’ is rendered as ‘_\[bs]c’, where ‘\[bs]’ is the back-space character number 8. Emboldened characters are rendered as ‘c\[bs]c’. This markup is typically converted to appropriate terminal sequences by the pager or ul(1). To remove the markup, pipe the output to col(1)
The special characters documented in mandoc_char(7) are rendered best-effort in an ASCII equivalent. In particular, opening and closing ‘single quotes’ are represented as characters number 0x60 and 0x27, respectively, which agrees with all ASCII standards from 1965 to the latest revision (2012) and which matches the traditional way in which roff(7) formatters represent single quotes in ASCII output. This correct ASCII rendering may look strange with modern Unicode-compatible fonts because contrary to ASCII, Unicode uses the code point U+0060 for the grave accent only, never for an opening quote.
The following -O arguments are accepted:
The left margin for normal text is set to indent blank characters instead of the default of five for mdoc(7) and seven for man(7). Increasing this is not recommended; it may result in degraded formatting, for example overfull lines or ugly line breaks. When output is to a pager on a terminal that is less than 66 columns wide, the default is reduced to three columns.
Format man(7) input files in mdoc(7) output style. This prints the operating system name rather than the page title on the right side of the footer line, and it implies -O
indent=5. One useful application is for checking that -T
manoutput formats in the same way as the mdoc(7) source it was generated from.
If the formatted manual page is opened in a pager, go to the definition of the term rather than showing the manual page from the beginning. If no term is specified, reuse the first command line argument that is not a section number. If that argument is in apropos(1) key=val format, only the val is used rather than the argument as a whole. This is useful for commands like ‘
man -akO tag Ic=ulimit’ to search for a keyword and jump right to its definition in the matching manual pages.
The output width is set to width instead of the default of 78. When output is to a pager on a terminal that is less than 79 columns wide, the default is reduced to one less than the terminal width. In any case, lines that are output in literal mode are never wrapped and may exceed the output width.
Output produced by -T
html conforms to HTML5 using optional self-closing tags. Default styles use only CSS1. Equations rendered from eqn(7) blocks use MathML.
/usr/share/misc/mandoc.css documents style-sheet classes available for customising output. If a style-sheet is not specified with -O
html defaults to simple output (via an embedded style-sheet) readable in any graphical or text-based web browser.
Non-ASCII characters are rendered as hexadecimal Unicode character references.
The following -O arguments are accepted:
Omit the <!DOCTYPE> declaration and the <html>, <head>, and <body> elements and only emit the subtree below the <body> element. The
styleargument will be ignored. This is useful when embedding manual content within existing documents.
The string fmt, for example, ../src/%I.html, is used as a template for linked header files (usually via the
Inmacro). Instances of ‘%I’ are replaced with the include filename. The default is not to present a hyperlink.
The string fmt, for example, ../html%S/%N.%S.html, is used as a template for linked manuals (usually via the
Xrmacro). Instances of ‘%N’ and ‘%S’ are replaced with the linked manual's name and section, respectively. If no section is included, section 1 is assumed. The default is not to present a hyperlink. If two formats are given and a file %N.%S exists in the current directory, the first format is used; otherwise, the second format is used.
The file style.css is used for an external style-sheet. This must be a valid absolute or relative URI.
Same syntax and semantics as for ASCII Output. This is implemented by passing a
file://URI ending in a fragment identifier to the pager rather than passing merely a file name. When using this argument, use a pager supporting such URIs, for example
MANPAGER='lynx -force_html' man -T html -O tag=MANPAGER man MANPAGER='w3m -T text/html' man -T html -O tag=toc mandoc
Consequently, for HTML output, this argument does not work with more(1) or less(1). For example, ‘
MANPAGER=less man -T html -O tag=toc mandoc’ does not work because less(1) does not support
If an input file contains at least two non-standard sections, print a table of contents near the beginning of the output.
By default, mandoc automatically selects UTF-8 or ASCII output according to the current locale(1). If any of the environment variables
LANG are set and the first one that is set selects the UTF-8 character encoding, it produces UTF-8 Output; otherwise, it falls back to ASCII Output. This output mode can also be selected explicitly with -T
man to translate mdoc(7) input into man(7) output format. This is useful for distributing manual sources to legacy systems lacking mdoc(7) formatters. Embedded eqn(7) and tbl(7) code is not supported.
If the input format of a file is man(7), the input is copied to the output. The parser is also run, and as usual, the -W level controls which Diagnostics are displayed before copying the input to the output.
markdown to translate mdoc(7) input to the markdown format conforming to John Gruber's 2004 specification. The output also almost conforms to the CommonMark specification.
The character set used for the markdown output is ASCII. Non-ASCII characters are encoded as HTML entities. Since that is not possible in literal font contexts, because these are rendered as code spans and code blocks in the markdown output, non-ASCII characters are transliterated to ASCII approximations in these contexts.
Markdown is a very weak markup language, so all semantic markup is lost, and even part of the presentational markup may be lost. Do not use this as an intermediate step in converting to HTML; instead, use -T
The man(7), tbl(7), and eqn(7) input languages are not supported by -T
markdown output mode.
PDF-1.1 output may be generated by -T
PostScript "Adobe-3.0" Level-2 pages may be generated by -T
ps. Output pages default to letter sized and are rendered in the Times font family, 11-point. Margins are calculated as 1/9 the page length and width. Line-height is 1.4m.
Special characters are rendered as in ASCII Output.
The following -O arguments are accepted:
The paper size name may be one of a3, a4, a5, legal, or letter. You may also manually specify dimensions as NNxNN, width by height in millimetres. If an unknown value is encountered, letter is used.
utf8 to force text output in UTF-8 multi-byte character encoding, ignoring the locale(1) settings in the environment. See ASCII Output regarding font styles and -O arguments.
On operating systems lacking locale or wide character support, and on those where the internal character representation is not UCS-4, mandoc always falls back to ASCII Output.
Syntax tree output
tree to show a human readable representation of the syntax tree. It is useful for debugging the source code of manual pages. The exact format is subject to change, so don't write parsers for it.
The first paragraph shows meta data found in the mdoc(7) prologue, on the man(7)
TH line, or the fallbacks used.
In the tree dump, each output line shows one syntax tree node. Child nodes are indented with respect to their parent node. The columns are:
For macro nodes, the macro name; for text and tbl(7) nodes, the content. There is a special format for eqn(7) nodes.
Node type (text, elem, block, head, body, body-end, tail, tbl, eqn).
An opening parenthesis if the node is an opening delimiter.
An asterisk if the node starts a new input line.
The input line number (starting at one).
The input column number (starting at one).
A closing parenthesis if the node is a closing delimiter.
A full stop if the node ends a sentence.
BROKEN if the node is a block broken by another block.
NOSRC if the node is not in the input file, but automatically generated from macros.
NOPRT if the node is not supposed to generate output for any output format.
The following -O argument is accepted:
Skip validation and show the unvalidated syntax tree. This can help to find out whether a given behaviour is caused by the parser or by the validator. Meta data is not available in this case.
The character encoding locale(1). When Locale Output is selected, it decides whether to use ASCII or UTF-8 output format. It never affects the interpretation of input files.
Any non-empty value of the environment variable
MANPAGERis used instead of the standard pagination program, less(1); see man(1) for details. Only used if -a or
Specifies the pagination program to use when
MANPAGERis not defined. If neither PAGER nor MANPAGER is defined, less(1) is used. Only used if -a or
The mandoc utility exits with one of the following values, controlled by the message level associated with the -W option:
No base system convention violations, style suggestions, warnings, or errors occurred, or those that did were ignored because they were lower than the requested level.
At least one base system convention violation or style suggestion occurred, but no warning or error, and -W
At least one warning occurred, but no error, and -W
warningor a lower level was requested.
At least one parsing error occurred, but no unsupported feature was encountered, and -W
erroror a lower level was requested.
At least one unsupported feature was encountered, and -W
unsuppor a lower level was requested.
Invalid command line arguments were specified. No input files have been read.
An operating system error occurred, for example exhaustion of memory, file descriptors, or process table entries. Such errors may cause mandoc to exit at once, possibly in the middle of parsing or formatting a file.
Note that selecting -T
lint output mode implies -W
To page manuals to the terminal:
$ mandoc -l mandoc.1 man.1 apropos.1 makewhatis.8
To produce HTML manuals with
/usr/share/misc/mandoc.css as the style-sheet:
$ mandoc -T html -O style=/usr/share/misc/mandoc.css mdoc.7 > mdoc.7.html
To check over a large set of manuals:
$ mandoc -T lint `find /usr/src -name \*\.[1-9]`
To produce a series of PostScript manuals for A4 paper:
$ mandoc -T ps -O paper=a4 mdoc.7 man.7 > manuals.ps
Convert a modern mdoc(7) manual to the older man(7) format, for use on systems lacking an mdoc(7) parser:
$ mandoc -T man foo.mdoc > foo.man
Messages displayed by mandoc follow this format:
mandoc: file:line:column: level: message: macro arguments (os)
The first three fields identify the file name, line number, and column number of the input file where the message was triggered. The line and column numbers start at 1. Both are omitted for messages referring to an input file as a whole. All level and message strings are explained below. The name of the macro triggering the message and its arguments are omitted where meaningless. The os operating system specifier is omitted for messages that are relevant for all operating systems. Fatal messages about invalid command line arguments or operating system errors, for example when memory is exhausted, may also omit the file and level fields.
Message levels have the following meanings:
An operating system error occurred. There isn't necessarily anything wrong with the input files. Output may all the same be missing or incomplete.
Invalid command line arguments were specified. No input files have been read and no output is produced.
An input file uses unsupported low-level roff(7) features. The output may be incomplete and/or misformatted, so using GNU troff instead of mandoc to process the file may be preferable.
Indicates a risk of information loss or severe misformatting, in most cases caused by serious syntax errors.
Indicates a risk that the information shown or its formatting may mismatch the author's intent in minor ways. Additionally, syntax errors are classified at least as warnings, even if they do not usually cause misformatting.
An input file uses dubious or discouraged style. This is not a complaint about the syntax, and probably neither formatting nor portability are in danger. While great care is taken to avoid false positives on the higher message levels, the
stylelevel tries to reduce the probability that issues go unnoticed, so it may occasionally issue bogus suggestions. Please use your good judgement to decide whether any particular
stylesuggestion really justifies a change to the input file.
A convention used in the base system of a specific operating system is not adhered to. These are not markup mistakes, and neither the quality of formatting nor portability are in danger. Messages of the
baselevel are printed with the more intuitive
Messages of the
unsupp levels are hidden unless their level, or a lower level, is requested using a -W option or -T
lint output mode.
As indicated below, all
base and some
style checks are only performed if a specific operating system name occurs in the arguments of the -W command line option, of the
Os macro, of the
-Ios command line option, or, if neither are present, in the return value of the uname(3) function.
Conventions for base system manuals
- Mdocdate found
(mdoc, NetBSD) The
Ddmacro uses CVS
Mdocdatekeyword substitution, which is not supported by the NetBSD base system. Consider using the conventional “Month dd, yyyy” format instead.
- Mdocdate missing
(mdoc, OpenBSD) The
Ddmacro does not use CVS
Mdocdatekeyword substitution, but using it is conventionally expected in the OpenBSD base system.
- unknown architecture
(mdoc, OpenBSD, NetBSD) The third argument of the
Dtmacro does not match any of the architectures this operating system is running on.
- operating system explicitly specified
(mdoc, OpenBSD, NetBSD) The
Osmacro has an argument. In the base system, it is conventionally left blank.
- RCS id missing
(OpenBSD, NetBSD) The manual page lacks the comment line with the RCS identifier generated by CVS
NetBSDkeyword substitution as conventionally used in these operating systems.
- legacy man(7) date format
Ddmacro uses the legacy man(7) date format “yyyy-dd-mm”. Consider using the conventional mdoc(7) date format “Month dd, yyyy” instead.
- normalizing date format to: ...
(mdoc, man) The
THmacro provides an abbreviated month name or a day number with a leading zero. In the formatted output, the month name is written out in full and the leading zero is omitted.
- lower case character in document title
(mdoc, man) The title is still used as given in the
- duplicate RCS id
A single manual page contains two copies of the RCS identifier for the same operating system. Consider deleting the later instance and moving the first one up to the top of the page.
- possible typo in section name
(mdoc) Fuzzy string matching revealed that the argument of an
Shmacro is similar, but not identical to a standard section name.
- unterminated quoted argument
(roff) Macro arguments can be enclosed in double quote characters such that space characters and macro names contained in the quoted argument need not be escaped. The closing quote of the last argument of a macro can be omitted. However, omitting it is not recommended because it makes the code harder to read.
- useless macro
Udmacro was found. Simply delete it: it serves no useful purpose.
- consider using OS macro
(mdoc) A string was found in plain text or in a
Bxmacro that could be represented using
- errnos out of order
(mdoc, NetBSD) The
Eritems in a
Bllist are not in alphabetical order.
- duplicate errno
(mdoc, NetBSD) A
Bllist contains two consecutive
Itentries describing the same
- referenced manual not found
Xrmacro references a manual page that was not found. When running with -W
base, the search is restricted to the base system, by default to
/usr/X11R6/man. This path can be configured at compile time using the
MANPATH_BASEpreprocessor macro. When running with -W
style, the search is done along the full search path as described in the man(1) manual page, respecting the
-Mcommand line options, the
MANPATHenvironment variable, the man.conf(5) file and falling back to the default of
/usr/local/man, also configurable at compile time using the
- trailing delimiter
(mdoc) The last argument of an
Sxmacro ends with a trailing delimiter. This is usually bad style and often indicates typos. Most likely, the delimiter can be removed.
- no blank before trailing delimiter
(mdoc) The last argument of a macro that supports trailing delimiter arguments is longer than one byte and ends with a trailing delimiter. Consider inserting a blank such that the delimiter becomes a separate argument, thus moving it out of the scope of the macro.
- fill mode already enabled, skipping
firequest occurs even though the document is still in fill mode, or already switched back to fill mode. It has no effect.
- fill mode already disabled, skipping
nfrequest occurs even though the document already switched to no-fill mode and did not switch back to fill mode yet. It has no effect.
- input text line longer than 80 bytes
Consider breaking the input text line at one of the blank characters before column 80.
- verbatim "--", maybe consider using \(em
(mdoc) Even though the ASCII output device renders an em-dash as "--", that is not a good way to write it in an input file because it renders poorly on all other output devices.
- function name without markup
(mdoc) A word followed by an empty pair of parentheses occurs on a text line. Consider using an
- whitespace at end of input line
(mdoc, man, roff) Whitespace at the end of input lines is almost never semantically significant — but in the odd case where it might be, it is extremely confusing when reviewing and maintaining documents.
- bad comment style
(roff) Comment lines start with a dot, a backslash, and a double-quote character. The mandoc utility treats the line as a comment line even without the backslash, but leaving out the backslash might not be portable.
Warnings regarding document structure
- .so is fragile, better use ln(1)
(roff) Including files only works when the parser program runs with the correct current working directory.
- no document body
(mdoc, man) The document body contains neither text nor macros. An empty document is shown, consisting only of a header and a footer line.
- content before first section header
(mdoc, man) Some macros or text precede the first
SHsection header. The offending macros and text are parsed and added to the top level of the syntax tree, outside any section block.
- first section is not NAME
(mdoc) The argument of the first
Shmacro is not ‘NAME’. This may confuse makewhatis(8) and apropos(1).
- NAME section without Nm before Nd
(mdoc) The NAME section does not contain any
Nmchild macro before the first
- NAME section without description
(mdoc) The NAME section lacks the mandatory
- description not at the end of NAME
(mdoc) The NAME section does contain an
Ndchild macro, but other content follows it.
- bad NAME section content
(mdoc) The NAME section contains plain text or macros other than
- missing comma before name
(mdoc) The NAME section contains an
Nmmacro that is neither the first one nor preceded by a comma.
- missing description line, using ""
Ndmacro lacks the required argument. The title line of the manual will end after the dash.
- description line outside NAME section
Ndmacro appears outside the NAME section. The arguments are printed anyway and the following text is used for apropos(1), but none of that behaviour is portable.
- sections out of conventional order
(mdoc) A standard section occurs after another section it usually precedes. All section titles are used as given, and the order of sections is not changed.
- duplicate section title
(mdoc) The same standard section title occurs more than once.
- unexpected section
(mdoc) A standard section header occurs in a section of the manual where it normally isn't useful.
- cross reference to self
Xrmacro refers to a name and section matching the section of the present manual page and a name mentioned in an
Nmmacro in the NAME or Synopsis section, or in an
Fomacro in the Synopsis. Consider using
- unusual Xr order
(mdoc) In the See Also section, an
Xrmacro with a lower section number follows one with a higher number, or two
Xrmacros referring to the same section are out of alphabetical order.
- unusual Xr punctuation
(mdoc) In the See Also section, punctuation between two
Xrmacros differs from a single comma, or there is trailing punctuation after the last
- AUTHORS section without An macro
(mdoc) An Authors sections contains no
Anmacros, or only empty ones. Probably, there are author names lacking markup.
- input too large
(mdoc, man) Currently, mandoc cannot handle input files larger than its arbitrary size limit of 2^31 bytes (2 Gigabytes). Since useful manuals are always small, this is not a problem in practice. Parsing is aborted as soon as the condition is detected.
- unsupported control character
(roff) An ASCII control character supported by other roff(7) implementations but not by mandoc was found in an input file. It is replaced by a question mark.
- unsupported escape sequence
(roff) An input file contains an escape sequence supported by GNU troff or Heirloom troff but not by mandoc, and it is likely that this will cause information loss or considerable misformatting.
- unsupported roff request
(roff) An input file contains a roff(7) request supported by GNU troff or Heirloom troff but not by mandoc, and it is likely that this will cause information loss or considerable misformatting.
- eqn delim option in tbl
(eqn, tbl) The options line of a table defines equation delimiters. Any equation source code contained in the table will be printed unformatted.
- unsupported table layout modifier
(tbl) A table layout specification contains an ‘
m’ modifier. The modifier is discarded.
- ignoring macro in table
(tbl, mdoc, man) A table contains an invocation of an mdoc(7) or man(7) macro or of an undefined macro. The macro is ignored, and its arguments are handled as if they were a text line.
- skipping tbl in -Tman mode
(mdoc, tbl) An input file contains the
TSmacro. This message is only generated in -T
manoutput mode, where tbl(7) input is not supported.
- skipping eqn in -Tman mode
(mdoc, eqn) An input file contains the
EQmacro. This message is only generated in -T
manoutput mode, where eqn(7) input is not supported.
Bad command line arguments
- bad command line argument
The argument following one of the
-IKMmOTWcommand line options is invalid, or a file given as a command line argument cannot be opened.
- duplicate command line argument
The -I command line option was specified twice.
- option has a superfluous value
An argument to the -O option has a value but does not accept one.
- missing option value
An argument to the -O option has no argument but requires one.
- bad option value
An argument to the -O
widthoption has an invalid value.
- duplicate option value
The same -O option is specified more than once.
- no such tag
tagoption was specified but the tag was not found in any of the displayed manual pages.
- -Tmarkdown unsupported for man(7) input
(man) The -T
markdownoption was specified but an input file uses the man(7) language. No output is produced for that input file.
apropos(1), man(1), eqn(7), man(7), mandoc_char(7), mdoc(7), roff(7), tbl(7)
The mandoc utility first appeared in OpenBSD 4.8. The option -I appeared in OpenBSD 5.2, and
-aCcfhKklMSsw in OpenBSD 5.7.
The mandoc utility was written by Kristaps Dzonsons <firstname.lastname@example.org> and is maintained by Ingo Schwarze <email@example.com>.
apropos.mandoc(1), demandoc(1), eqn.mandoc(7), mandoc(3), mandoc_char(7), mandoc.conf(5), mandoc_escape(3), mandoc_malloc(3), man.mandoc(1), man.mandoc(7), mchars_alloc(3), mdoc(7), roff.mandoc(7), soelim.mandoc(1), tbl(3), tbl.mandoc(7).