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