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