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