xref: /openbsd-src/usr.bin/mandoc/mandoc.1 (revision e5157e49389faebcb42b7237d55fbf096d9c2523)
1.\"	$OpenBSD: mandoc.1,v 1.66 2014/11/11 02:43:11 schwarze Exp $
2.\"
3.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4.\" Copyright (c) 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
5.\"
6.\" Permission to use, copy, modify, and distribute this software for any
7.\" purpose with or without fee is hereby granted, provided that the above
8.\" copyright notice and this permission notice appear in all copies.
9.\"
10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17.\"
18.Dd $Mdocdate: November 11 2014 $
19.Dt MANDOC 1
20.Os
21.Sh NAME
22.Nm mandoc
23.Nd format and display UNIX manuals
24.Sh SYNOPSIS
25.Nm mandoc
26.Op Fl acfhklV
27.Sm off
28.Op Fl I Cm os Li = Ar name
29.Sm on
30.Op Fl K Ns Ar encoding
31.Op Fl m Ns Ar format
32.Op Fl O Ns Ar option
33.Op Fl T Ns Ar output
34.Op Fl W Ns Ar level
35.Op Ar
36.Sh DESCRIPTION
37The
38.Nm
39utility formats
40.Ux
41manual pages for display.
42.Pp
43By default,
44.Nm
45reads
46.Xr mdoc 7
47or
48.Xr man 7
49text from stdin, implying
50.Fl m Ns Cm andoc ,
51and produces
52.Fl T Ns Cm ascii
53output.
54.Pp
55The options are as follows:
56.Bl -tag -width Ds
57.It Fl a
58If the standard output is a terminal device and
59.Fl c
60is not specified, use
61.Xr more 1
62to paginate the output, just like
63.Xr man 1
64would.
65.It Fl c
66Copy the formatted manual pages to the standard output without using
67.Xr more 1
68to paginate them.
69This is the default.
70It can be specified to override
71.Fl a .
72.It Fl f
73A synonym for
74.Xr whatis 1 .
75This overrides any earlier
76.Fl k
77and
78.Fl l
79options.
80.Sm off
81.It Fl I Cm os Li = Ar name
82.Sm on
83Override the default operating system
84.Ar name
85for the
86.Xr mdoc 7
87.Sq \&Os
88macro.
89.It Fl h
90Display only the SYNOPSIS lines.
91Implies
92.Fl c .
93.It Fl K Ns Ar encoding
94Specify the input encoding.
95The supported
96.Ar encoding
97arguments are
98.Cm us-ascii ,
99.Cm iso-8859-1 ,
100and
101.Cm utf-8 .
102If not specified, autodetection uses the first match:
103.Bl -tag -width iso-8859-1
104.It Cm utf-8
105if the first three bytes of the input file
106are the UTF-8 byte order mark (BOM, 0xefbbbf)
107.It Ar encoding
108if the first or second line of the input file matches the
109.Sy emacs
110mode line format
111.Pp
112.D1 .\e" -*- Oo ...; Oc coding: Ar encoding ; No -*-
113.It Cm utf-8
114if the first non-ASCII byte in the file introduces a valid UTF-8 sequence
115.It Cm iso-8859-1
116otherwise
117.El
118.It Fl k
119A synonym for
120.Xr apropos 1 .
121This overrides any earlier
122.Fl f
123and
124.Fl l
125options.
126.It Fl l
127A synonym for
128.Fl a .
129Also reverts any earlier
130.Fl f
131and
132.Fl k
133options.
134.It Fl m Ns Ar format
135Input format.
136See
137.Sx Input Formats
138for available formats.
139Defaults to
140.Fl m Ns Cm andoc .
141.It Fl O Ns Ar option
142Comma-separated output options.
143.It Fl T Ns Ar output
144Output format.
145See
146.Sx Output Formats
147for available formats.
148Defaults to
149.Fl T Ns Cm ascii .
150.It Fl V
151Print version and exit.
152.It Fl W Ns Ar level
153Specify the minimum message
154.Ar level
155to be reported on the standard error output and to affect the exit status.
156The
157.Ar level
158can be
159.Cm warning ,
160.Cm error ,
161or
162.Cm fatal .
163The default is
164.Fl W Ns Cm fatal ;
165.Fl W Ns Cm all
166is an alias for
167.Fl W Ns Cm warning .
168See
169.Sx EXIT STATUS
170and
171.Sx DIAGNOSTICS
172for details.
173.Pp
174The special option
175.Fl W Ns Cm stop
176tells
177.Nm
178to exit after parsing a file that causes warnings or errors of at least
179the requested level.
180No formatted output will be produced from that file.
181If both a
182.Ar level
183and
184.Cm stop
185are requested, they can be joined with a comma, for example
186.Fl W Ns Cm error , Ns Cm stop .
187.It Ar file
188Read input from zero or more files.
189If unspecified, reads from stdin.
190If multiple files are specified,
191.Nm
192will halt with the first failed parse.
193.El
194.Pp
195In
196.Fl f
197and
198.Fl k
199mode,
200.Nm
201also supports the options
202.Fl CMmOSsw
203described in the
204.Xr apropos 1
205manual.
206.Ss Input Formats
207The
208.Nm
209utility accepts
210.Xr mdoc 7
211and
212.Xr man 7
213input with
214.Fl m Ns Cm doc
215and
216.Fl m Ns Cm an ,
217respectively.
218The
219.Xr mdoc 7
220format is
221.Em strongly
222recommended;
223.Xr man 7
224should only be used for legacy manuals.
225.Pp
226A third option,
227.Fl m Ns Cm andoc ,
228which is also the default, determines encoding on-the-fly: if the first
229non-comment macro is
230.Sq \&Dd
231or
232.Sq \&Dt ,
233the
234.Xr mdoc 7
235parser is used; otherwise, the
236.Xr man 7
237parser is used.
238.Pp
239If multiple
240files are specified with
241.Fl m Ns Cm andoc ,
242each has its file-type determined this way.
243If multiple files are
244specified and
245.Fl m Ns Cm doc
246or
247.Fl m Ns Cm an
248is specified, then this format is used exclusively.
249.Ss Output Formats
250The
251.Nm
252utility accepts the following
253.Fl T
254arguments, which correspond to output modes:
255.Bl -tag -width "-Tlocale"
256.It Fl T Ns Cm ascii
257Produce 7-bit ASCII output.
258This is the default.
259See
260.Sx ASCII Output .
261.It Fl T Ns Cm html
262Produce CSS1/HTML5 output.
263See
264.Sx HTML Output .
265.It Fl T Ns Cm lint
266Parse only: produce no output.
267Implies
268.Fl W Ns Cm warning .
269.It Fl T Ns Cm locale
270Encode output using the current locale.
271See
272.Sx Locale Output .
273.It Fl T Ns Cm man
274Produce
275.Xr man 7
276format output.
277See
278.Sx Man Output .
279.It Fl T Ns Cm pdf
280Produce PDF output.
281See
282.Sx PDF Output .
283.It Fl T Ns Cm ps
284Produce PostScript output.
285See
286.Sx PostScript Output .
287.It Fl T Ns Cm tree
288Produce an indented parse tree.
289.It Fl T Ns Cm utf8
290Encode output in the UTF\-8 multi-byte format.
291See
292.Sx UTF\-8 Output .
293.It Fl T Ns Cm xhtml
294This is a synonym for
295.Fl T Ns Cm html .
296.El
297.Pp
298If multiple input files are specified, these will be processed by the
299corresponding filter in-order.
300.Ss ASCII Output
301Output produced by
302.Fl T Ns Cm ascii ,
303which is the default, is rendered in standard 7-bit ASCII documented in
304.Xr ascii 7 .
305.Pp
306Font styles are applied by using back-spaced encoding such that an
307underlined character
308.Sq c
309is rendered as
310.Sq _ Ns \e[bs] Ns c ,
311where
312.Sq \e[bs]
313is the back-space character number 8.
314Emboldened characters are rendered as
315.Sq c Ns \e[bs] Ns c .
316.Pp
317The special characters documented in
318.Xr mandoc_char 7
319are rendered best-effort in an ASCII equivalent.
320If no equivalent is found,
321.Sq \&?
322is used instead.
323.Pp
324Output width is limited to 78 visible columns unless literal input lines
325exceed this limit.
326.Pp
327The following
328.Fl O
329arguments are accepted:
330.Bl -tag -width Ds
331.It Cm indent Ns = Ns Ar indent
332The left margin for normal text is set to
333.Ar indent
334blank characters instead of the default of five for
335.Xr mdoc 7
336and seven for
337.Xr man 7 .
338Increasing this is not recommended; it may result in degraded formatting,
339for example overfull lines or ugly line breaks.
340.It Cm width Ns = Ns Ar width
341The output width is set to
342.Ar width ,
343which will normalise to \(>=60.
344.El
345.Ss HTML Output
346Output produced by
347.Fl T Ns Cm html
348conforms to HTML5 using optional self-closing tags.
349.Pp
350The
351.Pa example.style.css
352file documents style-sheet classes available for customising output.
353If a style-sheet is not specified with
354.Fl O Ns Ar style ,
355.Fl T Ns Cm html
356defaults to simple output (via an embedded style-sheet)
357readable in any graphical or text-based web
358browser.
359.Pp
360Special characters are rendered in decimal-encoded UTF\-8.
361.Pp
362The following
363.Fl O
364arguments are accepted:
365.Bl -tag -width Ds
366.It Cm fragment
367Omit the
368.Aq !DOCTYPE
369declaration and the
370.Aq html ,
371.Aq head ,
372and
373.Aq body
374elements and only emit the subtree below the
375.Aq body
376element.
377The
378.Cm style
379argument will be ignored.
380This is useful when embedding manual content within existing documents.
381.It Cm includes Ns = Ns Ar fmt
382The string
383.Ar fmt ,
384for example,
385.Ar ../src/%I.html ,
386is used as a template for linked header files (usually via the
387.Sq \&In
388macro).
389Instances of
390.Sq \&%I
391are replaced with the include filename.
392The default is not to present a
393hyperlink.
394.It Cm man Ns = Ns Ar fmt
395The string
396.Ar fmt ,
397for example,
398.Ar ../html%S/%N.%S.html ,
399is used as a template for linked manuals (usually via the
400.Sq \&Xr
401macro).
402Instances of
403.Sq \&%N
404and
405.Sq %S
406are replaced with the linked manual's name and section, respectively.
407If no section is included, section 1 is assumed.
408The default is not to
409present a hyperlink.
410.It Cm style Ns = Ns Ar style.css
411The file
412.Ar style.css
413is used for an external style-sheet.
414This must be a valid absolute or
415relative URI.
416.El
417.Ss Locale Output
418Locale-depending output encoding is triggered with
419.Fl T Ns Cm locale .
420This option is not available on all systems: systems without locale
421support, or those whose internal representation is not natively UCS-4,
422will fall back to
423.Fl T Ns Cm ascii .
424See
425.Sx ASCII Output
426for font style specification and available command-line arguments.
427.Ss Man Output
428Translate input format into
429.Xr man 7
430output format.
431This is useful for distributing manual sources to legacy systems
432lacking
433.Xr mdoc 7
434formatters.
435.Pp
436If
437.Xr mdoc 7
438is passed as input, it is translated into
439.Xr man 7 .
440If the input format is
441.Xr man 7 ,
442the input is copied to the output, expanding any
443.Xr roff 7
444.Sq so
445requests.
446The parser is also run, and as usual, the
447.Fl W
448level controls which
449.Sx DIAGNOSTICS
450are displayed before copying the input to the output.
451.Ss PDF Output
452PDF-1.1 output may be generated by
453.Fl T Ns Cm pdf .
454See
455.Sx PostScript Output
456for
457.Fl O
458arguments and defaults.
459.Ss PostScript Output
460PostScript
461.Qq Adobe-3.0
462Level-2 pages may be generated by
463.Fl T Ns Cm ps .
464Output pages default to letter sized and are rendered in the Times font
465family, 11-point.
466Margins are calculated as 1/9 the page length and width.
467Line-height is 1.4m.
468.Pp
469Special characters are rendered as in
470.Sx ASCII Output .
471.Pp
472The following
473.Fl O
474arguments are accepted:
475.Bl -tag -width Ds
476.It Cm paper Ns = Ns Ar name
477The paper size
478.Ar name
479may be one of
480.Ar a3 ,
481.Ar a4 ,
482.Ar a5 ,
483.Ar legal ,
484or
485.Ar letter .
486You may also manually specify dimensions as
487.Ar NNxNN ,
488width by height in millimetres.
489If an unknown value is encountered,
490.Ar letter
491is used.
492.El
493.Ss UTF\-8 Output
494Use
495.Fl T Ns Cm utf8
496to force a UTF\-8 locale.
497See
498.Sx Locale Output
499for details and options.
500.Sh ENVIRONMENT
501.Bl -tag -width MANPAGER
502.It Ev MANPAGER
503Any non-empty value of the environment variable
504.Ev MANPAGER
505will be used instead of the standard pagination program,
506.Xr more 1 .
507.It Ev PAGER
508Specifies the pagination program to use when
509.Ev MANPAGER
510is not defined.
511If neither PAGER nor MANPAGER is defined,
512.Pa /usr/bin/more Fl s
513will be used.
514.El
515.Sh EXIT STATUS
516The
517.Nm
518utility exits with one of the following values, controlled by the message
519.Ar level
520associated with the
521.Fl W
522option:
523.Pp
524.Bl -tag -width Ds -compact
525.It 0
526No warnings or errors occurred, or those that did were ignored because
527they were lower than the requested
528.Ar level .
529.It 2
530At least one warning occurred, but no error, and
531.Fl W Ns Cm warning
532was specified.
533.It 3
534At least one parsing error occurred, but no fatal error, and
535.Fl W Ns Cm error
536or
537.Fl W Ns Cm warning
538was specified.
539.It 4
540A fatal parsing error occurred.
541.It 5
542Invalid command line arguments were specified.
543No input files have been read.
544.It 6
545An operating system error occurred, for example memory exhaustion or an
546error accessing input files.
547Such errors cause
548.Nm
549to exit at once, possibly in the middle of parsing or formatting a file.
550.El
551.Pp
552Note that selecting
553.Fl T Ns Cm lint
554output mode implies
555.Fl W Ns Cm warning .
556.Sh EXAMPLES
557To page manuals to the terminal:
558.Pp
559.Dl $ mandoc \-Wall,stop mandoc.1 2\*(Gt&1 | less
560.Dl $ mandoc mandoc.1 mdoc.3 mdoc.7 | less
561.Pp
562To produce HTML manuals with
563.Ar style.css
564as the style-sheet:
565.Pp
566.Dl $ mandoc \-Thtml -Ostyle=style.css mdoc.7 \*(Gt mdoc.7.html
567.Pp
568To check over a large set of manuals:
569.Pp
570.Dl $ mandoc \-Tlint `find /usr/src -name \e*\e.[1-9]`
571.Pp
572To produce a series of PostScript manuals for A4 paper:
573.Pp
574.Dl $ mandoc \-Tps \-Opaper=a4 mdoc.7 man.7 \*(Gt manuals.ps
575.Pp
576Convert a modern
577.Xr mdoc 7
578manual to the older
579.Xr man 7
580format, for use on systems lacking an
581.Xr mdoc 7
582parser:
583.Pp
584.Dl $ mandoc \-Tman foo.mdoc \*(Gt foo.man
585.Sh DIAGNOSTICS
586Messages displayed by
587.Nm
588follow this format:
589.Pp
590.D1 Nm Ns : Ar file : Ns Ar line : Ns Ar column : level : message : macro args
591.Pp
592Line and column numbers start at 1.
593Both are omitted for messages referring to an input file as a whole.
594Macro names and arguments are omitted where meaningless.
595Fatal messages about invalid command line arguments
596or operating system errors, for example when memory is exhausted,
597may also omit the
598.Ar file
599and
600.Ar level
601fields.
602.Pp
603Message levels have the following meanings:
604.Bl -tag -width "warning"
605.It Cm syserr
606Opening or reading an input file failed, so the parser cannot
607even be started and no output is produced from that input file.
608.It Cm fatal
609The parser is unable to parse a given input file at all.
610No formatted output is produced from that input file.
611.It Cm error
612An input file contains syntax that cannot be safely interpreted,
613either because it is invalid or because
614.Nm
615does not implement it yet.
616By discarding part of the input or inserting missing tokens,
617the parser is able to continue, and the error does not prevent
618generation of formatted output, but typically, preparing that
619output involves information loss, broken document structure
620or unintended formatting.
621.It Cm warning
622An input file uses obsolete, discouraged or non-portable syntax.
623All the same, the meaning of the input is unambiguous and a correct
624rendering can be produced.
625Documents causing warnings may render poorly when using other
626formatting tools instead of
627.Nm .
628.El
629.Pp
630Messages of the
631.Cm warning
632and
633.Cm error
634levels are hidden unless their level, or a lower level, is requested using a
635.Fl W
636option or
637.Fl T Ns Cm lint
638output mode.
639.Sh COMPATIBILITY
640This section summarises
641.Nm
642compatibility with GNU troff.
643Each input and output format is separately noted.
644.Ss ASCII Compatibility
645.Bl -bullet -compact
646.It
647Unrenderable unicode codepoints specified with
648.Sq \e[uNNNN]
649escapes are printed as
650.Sq \&?
651in mandoc.
652In GNU troff, these raise an error.
653.It
654The
655.Sq \&Bd \-literal
656and
657.Sq \&Bd \-unfilled
658macros of
659.Xr mdoc 7
660in
661.Fl T Ns Cm ascii
662are synonyms, as are \-filled and \-ragged.
663.It
664In historic GNU troff, the
665.Sq \&Pa
666.Xr mdoc 7
667macro does not underline when scoped under an
668.Sq \&It
669in the FILES section.
670This behaves correctly in
671.Nm .
672.It
673A list or display following the
674.Sq \&Ss
675.Xr mdoc 7
676macro in
677.Fl T Ns Cm ascii
678does not assert a prior vertical break, just as it doesn't with
679.Sq \&Sh .
680.It
681The
682.Sq \&na
683.Xr man 7
684macro in
685.Fl T Ns Cm ascii
686has no effect.
687.It
688Words aren't hyphenated.
689.El
690.Ss HTML Compatibility
691.Bl -bullet -compact
692.It
693The
694.Sq \efP
695escape will revert the font to the previous
696.Sq \ef
697escape, not to the last rendered decoration, which is now dictated by
698CSS instead of hard-coded.
699It also will not span past the current scope,
700for the same reason.
701Note that in
702.Sx ASCII Output
703mode, this will work fine.
704.It
705The
706.Xr mdoc 7
707.Sq \&Bl \-hang
708and
709.Sq \&Bl \-tag
710list types render similarly (no break following overreached left-hand
711side) due to the expressive constraints of HTML.
712.It
713The
714.Xr man 7
715.Sq IP
716and
717.Sq TP
718lists render similarly.
719.El
720.Sh SEE ALSO
721.Xr eqn 7 ,
722.Xr man 7 ,
723.Xr mandoc_char 7 ,
724.Xr mdoc 7 ,
725.Xr roff 7 ,
726.Xr tbl 7
727.Sh AUTHORS
728The
729.Nm
730utility was written by
731.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
732.Sh CAVEATS
733In
734.Fl T Ns Cm html
735and
736.Fl T Ns Cm xhtml ,
737the maximum size of an element attribute is determined by
738.Dv BUFSIZ ,
739which is usually 1024 bytes.
740Be aware of this when setting long link
741formats such as
742.Fl O Ns Cm style Ns = Ns Ar really/long/link .
743.Pp
744Nesting elements within next-line element scopes of
745.Fl m Ns Cm an ,
746such as
747.Sq br
748within an empty
749.Sq B ,
750will confuse
751.Fl T Ns Cm html
752and
753.Fl T Ns Cm xhtml
754and cause them to forget the formatting of the prior next-line scope.
755.Pp
756The
757.Sq \(aq
758control character is an alias for the standard macro control character
759and does not emit a line-break as stipulated in GNU troff.
760