1.\" $OpenBSD: mandoc.1,v 1.45 2011/05/31 22:44:48 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 31 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 pdf 183Produce PDF output. 184See 185.Sx PDF Output . 186.It Fl T Ns Cm ps 187Produce PostScript output. 188See 189.Sx PostScript Output . 190.It Fl T Ns Cm tree 191Produce an indented parse tree. 192.It Fl T Ns Cm xhtml 193Produce strict CSS1/XHTML-1.0 output. 194See 195.Sx XHTML Output . 196.El 197.Pp 198If multiple input files are specified, these will be processed by the 199corresponding filter in-order. 200.Ss UTF\-8 Output 201Use 202.Fl T Ns Cm utf8 203to force a UTF\-8 locale. 204See 205.Sx Locale Output 206for details and options. 207.Ss Locale Output 208Locale-depending output encoding is triggered with 209.Fl T Ns Cm locale . 210This option is not available on all systems: systems without locale 211support, or those whose internal representation is not natively UCS-4, 212will fall back to 213.Fl T Ns Cm ascii . 214See 215.Sx ASCII Output 216for font style specification and available command-line arguments. 217.Ss ASCII Output 218Output produced by 219.Fl T Ns Cm ascii , 220which is the default, is rendered in standard 7-bit ASCII documented in 221.Xr ascii 7 . 222.Pp 223Font styles are applied by using back-spaced encoding such that an 224underlined character 225.Sq c 226is rendered as 227.Sq _ Ns \e[bs] Ns c , 228where 229.Sq \e[bs] 230is the back-space character number 8. 231Emboldened characters are rendered as 232.Sq c Ns \e[bs] Ns c . 233.Pp 234The special characters documented in 235.Xr mandoc_char 7 236are rendered best-effort in an ASCII equivalent. 237If no equivalent is found, 238.Sq \&? 239is used instead. 240.Pp 241Output width is limited to 78 visible columns unless literal input lines 242exceed this limit. 243.Pp 244The following 245.Fl O 246arguments are accepted: 247.Bl -tag -width Ds 248.It Cm width Ns = Ns Ar width 249The output width is set to 250.Ar width , 251which will normalise to \(>=60. 252.El 253.Ss HTML Output 254Output produced by 255.Fl T Ns Cm html 256conforms to HTML-4.01 strict. 257.Pp 258The 259.Pa example.style.css 260file documents style-sheet classes available for customising output. 261If a style-sheet is not specified with 262.Fl O Ns Ar style , 263.Fl T Ns Cm html 264defaults to simple output readable in any graphical or text-based web 265browser. 266.Pp 267Special characters are rendered in decimal-encoded UTF\-8. 268.Pp 269The following 270.Fl O 271arguments are accepted: 272.Bl -tag -width Ds 273.It Cm includes Ns = Ns Ar fmt 274The string 275.Ar fmt , 276for example, 277.Ar ../src/%I.html , 278is used as a template for linked header files (usually via the 279.Sq \&In 280macro). 281Instances of 282.Sq \&%I 283are replaced with the include filename. 284The default is not to present a 285hyperlink. 286.It Cm man Ns = Ns Ar fmt 287The string 288.Ar fmt , 289for example, 290.Ar ../html%S/%N.%S.html , 291is used as a template for linked manuals (usually via the 292.Sq \&Xr 293macro). 294Instances of 295.Sq \&%N 296and 297.Sq %S 298are replaced with the linked manual's name and section, respectively. 299If no section is included, section 1 is assumed. 300The default is not to 301present a hyperlink. 302.It Cm style Ns = Ns Ar style.css 303The file 304.Ar style.css 305is used for an external style-sheet. 306This must be a valid absolute or 307relative URI. 308.El 309.Ss PostScript Output 310PostScript 311.Qq Adobe-3.0 312Level-2 pages may be generated by 313.Fl T Ns Cm ps . 314Output pages default to letter sized and are rendered in the Times font 315family, 11-point. 316Margins are calculated as 1/9 the page length and width. 317Line-height is 1.4m. 318.Pp 319Special characters are rendered as in 320.Sx ASCII Output . 321.Pp 322The following 323.Fl O 324arguments are accepted: 325.Bl -tag -width Ds 326.It Cm paper Ns = Ns Ar name 327The paper size 328.Ar name 329may be one of 330.Ar a3 , 331.Ar a4 , 332.Ar a5 , 333.Ar legal , 334or 335.Ar letter . 336You may also manually specify dimensions as 337.Ar NNxNN , 338width by height in millimetres. 339If an unknown value is encountered, 340.Ar letter 341is used. 342.El 343.Ss PDF Output 344PDF-1.1 output may be generated by 345.Fl T Ns Cm pdf . 346See 347.Sx PostScript Output 348for 349.Fl O 350arguments and defaults. 351.Ss XHTML Output 352Output produced by 353.Fl T Ns Cm xhtml 354conforms to XHTML-1.0 strict. 355.Pp 356See 357.Sx HTML Output 358for details; beyond generating XHTML tags instead of HTML tags, these 359output modes are identical. 360.Sh EXIT STATUS 361The 362.Nm 363utility exits with one of the following values, controlled by the message 364.Ar level 365associated with the 366.Fl W 367option: 368.Pp 369.Bl -tag -width Ds -compact 370.It 0 371No warnings or errors occurred, or those that did were ignored because 372they were lower than the requested 373.Ar level . 374.It 2 375At least one warning occurred, but no error, and 376.Fl W Ns Cm warning 377was specified. 378.It 3 379At least one parsing error occurred, but no fatal error, and 380.Fl W Ns Cm error 381or 382.Fl W Ns Cm warning 383was specified. 384.It 4 385A fatal parsing error occurred. 386.It 5 387Invalid command line arguments were specified. 388No input files have been read. 389.It 6 390An operating system error occurred, for example memory exhaustion or an 391error accessing input files. 392Such errors cause 393.Nm 394to exit at once, possibly in the middle of parsing or formatting a file. 395.El 396.Pp 397Note that selecting 398.Fl T Ns Cm lint 399output mode implies 400.Fl W Ns Cm warning . 401.Sh EXAMPLES 402To page manuals to the terminal: 403.Pp 404.Dl $ mandoc \-Wall,stop mandoc.1 2\*(Gt&1 | less 405.Dl $ mandoc mandoc.1 mdoc.3 mdoc.7 | less 406.Pp 407To produce HTML manuals with 408.Ar style.css 409as the style-sheet: 410.Pp 411.Dl $ mandoc \-Thtml -Ostyle=style.css mdoc.7 \*(Gt mdoc.7.html 412.Pp 413To check over a large set of manuals: 414.Pp 415.Dl $ mandoc \-Tlint `find /usr/src -name \e*\e.[1-9]` 416.Pp 417To produce a series of PostScript manuals for A4 paper: 418.Pp 419.Dl $ mandoc \-Tps \-Opaper=a4 mdoc.7 man.7 \*(Gt manuals.ps 420.Sh DIAGNOSTICS 421Standard error messages reporting parsing errors are prefixed by 422.Pp 423.Sm off 424.D1 Ar file : line : column : \ level : 425.Sm on 426.Pp 427where the fields have the following meanings: 428.Bl -tag -width "column" 429.It Ar file 430The name of the input file causing the message. 431.It Ar line 432The line number in that input file. 433Line numbering starts at 1. 434.It Ar column 435The column number in that input file. 436Column numbering starts at 1. 437If the issue is caused by a word, the column number usually 438points to the first character of the word. 439.It Ar level 440The message level, printed in capital letters. 441.El 442.Pp 443Message levels have the following meanings: 444.Bl -tag -width "warning" 445.It Cm fatal 446The parser is unable to parse a given input file at all. 447No formatted output is produced from that input file. 448.It Cm error 449An input file contains syntax that cannot be safely interpreted, 450either because it is invalid or because 451.Nm 452does not implement it yet. 453By discarding part of the input or inserting missing tokens, 454the parser is able to continue, and the error does not prevent 455generation of formatted output, but typically, preparing that 456output involves information loss, broken document structure 457or unintended formatting. 458.It Cm warning 459An input file uses obsolete, discouraged or non-portable syntax. 460All the same, the meaning of the input is unambiguous and a correct 461rendering can be produced. 462Documents causing warnings may render poorly when using other 463formatting tools instead of 464.Nm . 465.El 466.Pp 467Messages of the 468.Cm warning 469and 470.Cm error 471levels are hidden unless their level, or a lower level, is requested using a 472.Fl W 473option or 474.Fl T Ns Cm lint 475output mode. 476.Pp 477The 478.Nm 479utility may also print messages related to invalid command line arguments 480or operating system errors, for example when memory is exhausted or 481input files cannot be read. 482Such messages do not carry the prefix described above. 483.Sh COMPATIBILITY 484This section summarises 485.Nm 486compatibility with GNU troff. 487Each input and output format is separately noted. 488.Ss ASCII Compatibility 489.Bl -bullet -compact 490.It 491Unrenderable unicode codepoints specified with 492.Sq \e[uNNNN] 493escapes are printed as 494.Sq \&? 495in mandoc. 496In GNU troff, these raise an error. 497.It 498The 499.Sq \&Bd \-literal 500and 501.Sq \&Bd \-unfilled 502macros of 503.Xr mdoc 7 504in 505.Fl T Ns Cm ascii 506are synonyms, as are \-filled and \-ragged. 507.It 508In historic GNU troff, the 509.Sq \&Pa 510.Xr mdoc 7 511macro does not underline when scoped under an 512.Sq \&It 513in the FILES section. 514This behaves correctly in 515.Nm . 516.It 517A list or display following the 518.Sq \&Ss 519.Xr mdoc 7 520macro in 521.Fl T Ns Cm ascii 522does not assert a prior vertical break, just as it doesn't with 523.Sq \&Sh . 524.It 525The 526.Sq \&na 527.Xr man 7 528macro in 529.Fl T Ns Cm ascii 530has no effect. 531.It 532Words aren't hyphenated. 533.El 534.Ss HTML/XHTML Compatibility 535.Bl -bullet -compact 536.It 537The 538.Sq \efP 539escape will revert the font to the previous 540.Sq \ef 541escape, not to the last rendered decoration, which is now dictated by 542CSS instead of hard-coded. 543It also will not span past the current scope, 544for the same reason. 545Note that in 546.Sx ASCII Output 547mode, this will work fine. 548.It 549The 550.Xr mdoc 7 551.Sq \&Bl \-hang 552and 553.Sq \&Bl \-tag 554list types render similarly (no break following overreached left-hand 555side) due to the expressive constraints of HTML. 556.It 557The 558.Xr man 7 559.Sq IP 560and 561.Sq TP 562lists render similarly. 563.El 564.Sh SEE ALSO 565.Xr man 7 , 566.Xr mandoc_char 7 , 567.Xr mdoc 7 , 568.Xr roff 7 , 569.Xr tbl 7 570.Sh AUTHORS 571The 572.Nm 573utility was written by 574.An Kristaps Dzonsons Aq kristaps@bsd.lv . 575.Sh CAVEATS 576In 577.Fl T Ns Cm html 578and 579.Fl T Ns Cm xhtml , 580the maximum size of an element attribute is determined by 581.Dv BUFSIZ , 582which is usually 1024 bytes. 583Be aware of this when setting long link 584formats such as 585.Fl O Ns Cm style Ns = Ns Ar really/long/link . 586.Pp 587Nesting elements within next-line element scopes of 588.Fl m Ns Cm an , 589such as 590.Sq br 591within an empty 592.Sq B , 593will confuse 594.Fl T Ns Cm html 595and 596.Fl T Ns Cm xhtml 597and cause them to forget the formatting of the prior next-line scope. 598.Pp 599The 600.Sq \(aq 601control character is an alias for the standard macro control character 602and does not emit a line-break as stipulated in GNU troff. 603