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