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