xref: /openbsd-src/share/man/man7/roff.7 (revision be38755c412cc72cb8d40f51ea70c9893196afff)
1.\"	$OpenBSD: roff.7,v 1.14 2011/09/18 15:54:48 schwarze Exp $
2.\"
3.\" Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4.\" Copyright (c) 2010 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: September 18 2011 $
19.Dt ROFF 7
20.Os
21.Sh NAME
22.Nm roff
23.Nd roff language reference for mandoc
24.Sh DESCRIPTION
25The
26.Nm roff
27language is a general purpose text formatting language.
28In particular, it serves as the basis for the
29.Xr mdoc 7
30and
31.Xr man 7
32manual formatting macro languages.
33This manual describes the subset of the
34.Nm
35language accepted by the
36.Xr mandoc 1
37utility.
38.Pp
39Input lines beginning with the control characters
40.Sq \&.
41or
42.Sq \(aq
43are parsed for requests and macros.
44These define the document structure, change the processing state
45and manipulate the formatting.
46Some requests and macros also produce formatted output,
47while others do not.
48.Pp
49All other input lines provide free-form text to be printed;
50the formatting of free-form text depends on the respective
51processing context.
52.Sh LANGUAGE SYNTAX
53.Nm
54documents may contain only graphable 7-bit ASCII characters, the space
55character, and, in certain circumstances, the tab character.
56To produce other characters in the output, use the escape sequences
57documented in the
58.Xr mandoc_char 7
59manual.
60.Sh REQUEST SYNTAX
61A request or macro line consists of:
62.Pp
63.Bl -enum -compact
64.It
65the control character
66.Sq \&.
67or
68.Sq \(aq
69at the beginning of the line,
70.It
71optionally an arbitrary amount of whitespace,
72.It
73the name of the request or the macro, which is one word of arbitrary
74length, terminated by whitespace,
75.It
76and zero or more arguments delimited by whitespace.
77.El
78.Pp
79Thus, the following request lines are all equivalent:
80.Bd -literal -offset indent
81\&.ig end
82\&.ig    end
83\&.   ig end
84.Ed
85.Sh MACRO SYNTAX
86Macros can be defined by the
87.Sx \&de
88request.
89When called, they follow the same syntax as requests, except that
90macro arguments may optionally be quoted by enclosing them
91in double quote characters
92.Pq Sq \(dq .
93To be recognised as the beginning of a quoted argument, the opening
94quote character must be preceded by a space character.
95.Pp
96A quoted argument may contain whitespace, and pairs of double quote
97characters
98.Pq Sq Qq
99resolve to single double quote characters.
100A quoted argument extends to the next double quote character that is not
101part of a pair, or to the end of the input line, whichever comes earlier.
102Leaving out the terminating double quote character at the end of the line
103is discouraged.
104For clarity, if more arguments follow on the same input line,
105it is recommended to follow the terminating double quote character
106by a space character; in case the next character after the terminating
107double quote character is anything else, it is regarded as the beginning
108of the next, unquoted argument.
109.Pp
110Both in quoted and unquoted arguments, pairs of backslashes
111.Pq Sq \e\e
112resolve to single backslashes.
113In unquoted arguments, space characters can alternatively be included
114by preceding them with a backslash
115.Pq Sq \e\~ ,
116but quoting is usually better for clarity.
117.Sh REQUEST REFERENCE
118The
119.Xr mandoc 1
120.Nm
121parser recognises the following requests.
122Note that the
123.Nm
124language defines many more requests not implemented in
125.Xr mandoc 1 .
126.Ss \&ad
127Set line adjustment mode.
128This line-scoped request is intended to have one argument to select
129normal, left, right, or centre adjustment for subsequent text.
130Currently, it is ignored including its arguments,
131and the number of arguments is not checked.
132.Ss \&am
133Append to a macro definition.
134The syntax of this request is the same as that of
135.Sx \&de .
136It is currently ignored by
137.Xr mandoc 1 ,
138as are its children.
139.Ss \&ami
140Append to a macro definition, specifying the macro name indirectly.
141The syntax of this request is the same as that of
142.Sx \&dei .
143It is currently ignored by
144.Xr mandoc 1 ,
145as are its children.
146.Ss \&am1
147Append to a macro definition, switching roff compatibility mode off
148during macro execution.
149The syntax of this request is the same as that of
150.Sx \&de1 .
151It is currently ignored by
152.Xr mandoc 1 ,
153as are its children.
154.Ss \&de
155Define a
156.Nm
157macro.
158Its syntax can be either
159.Bd -literal -offset indent
160.Pf . Cm \&de Ar name
161.Ar macro definition
162\&..
163.Ed
164.Pp
165or
166.Bd -literal -offset indent
167.Pf . Cm \&de Ar name Ar end
168.Ar macro definition
169.Pf . Ar end
170.Ed
171.Pp
172Both forms define or redefine the macro
173.Ar name
174to represent the
175.Ar macro definition ,
176which may consist of one or more input lines, including the newline
177characters terminating each line, optionally containing calls to
178.Nm
179requests,
180.Nm
181macros or high-level macros like
182.Xr man 7
183or
184.Xr mdoc 7
185macros, whichever applies to the document in question.
186.Pp
187Specifying a custom
188.Ar end
189macro works in the same way as for
190.Sx \&ig ;
191namely, the call to
192.Sq Pf . Ar end
193first ends the
194.Ar macro definition ,
195and after that, it is also evaluated as a
196.Nm
197request or
198.Nm
199macro, but not as a high-level macro.
200.Pp
201The macro can be invoked later using the syntax
202.Pp
203.D1 Pf . Ar name Op Ar argument Op Ar argument ...
204.Pp
205Regarding argument parsing, see
206.Sx MACRO SYNTAX
207above.
208.Pp
209The line invoking the macro will be replaced
210in the input stream by the
211.Ar macro definition ,
212replacing all occurrences of
213.No \e\e$ Ns Ar N ,
214where
215.Ar N
216is a digit, by the
217.Ar N Ns th Ar argument .
218For example,
219.Bd -literal -offset indent
220\&.de ZN
221\efI\e^\e\e$1\e^\efP\e\e$2
222\&..
223\&.ZN XtFree .
224.Ed
225.Pp
226produces
227.Pp
228.D1 \efI\e^XtFree\e^\efP.
229.Pp
230in the input stream, and thus in the output: \fI\^XtFree\^\fP.
231.Pp
232Since macros and user-defined strings share a common string table,
233defining a macro
234.Ar name
235clobbers the user-defined string
236.Ar name ,
237and the
238.Ar macro definition
239can also be printed using the
240.Sq \e*
241string interpolation syntax described below
242.Sx ds ,
243but this is rarely useful because every macro definition contains at least
244one explicit newline character.
245.Pp
246In order to prevent endless recursion, both groff and
247.Xr mandoc 1
248limit the stack depth for expanding macros and strings
249to a large, but finite number.
250Do not rely on the exact value of this limit.
251.Ss \&dei
252Define a
253.Nm
254macro, specifying the macro name indirectly.
255The syntax of this request is the same as that of
256.Sx \&de .
257It is currently ignored by
258.Xr mandoc 1 ,
259as are its children.
260.Ss \&de1
261Define a
262.Nm
263macro that will be executed with
264.Nm
265compatibility mode switched off during macro execution.
266This is a GNU extension not available in traditional
267.Nm
268implementations and not even in older versions of groff.
269Since
270.Xr mandoc 1
271does not implement
272.Nm
273compatibility mode at all, it handles this request as an alias for
274.Sx \&de .
275.Ss \&ds
276Define a user-defined string.
277Its syntax is as follows:
278.Pp
279.D1 Pf . Cm \&ds Ar name Oo \(dq Oc Ns Ar string
280.Pp
281The
282.Ar name
283and
284.Ar string
285arguments are space-separated.
286If the
287.Ar string
288begins with a double-quote character, that character will not be part
289of the string.
290All remaining characters on the input line form the
291.Ar string ,
292including whitespace and double-quote characters, even trailing ones.
293.Pp
294The
295.Ar string
296can be interpolated into subsequent text by using
297.No \e* Ns Bq Ar name
298for a
299.Ar name
300of arbitrary length, or \e*(NN or \e*N if the length of
301.Ar name
302is two or one characters, respectively.
303Interpolation can be prevented by escaping the leading backslash;
304that is, an asterisk preceded by an even number of backslashes
305does not trigger string interpolation.
306.Pp
307Since user-defined strings and macros share a common string table,
308defining a string
309.Ar name
310clobbers the macro
311.Ar name ,
312and the
313.Ar name
314used for defining a string can also be invoked as a macro,
315in which case the following input line will be appended to the
316.Ar string ,
317forming a new input line passed to the
318.Nm
319parser.
320For example,
321.Bd -literal -offset indent
322\&.ds badidea .S
323\&.badidea
324H SYNOPSIS
325.Ed
326.Pp
327invokes the
328.Cm SH
329macro when used in a
330.Xr man 7
331document.
332Such abuse is of course strongly discouraged.
333.Ss \&el
334The
335.Qq else
336half of an if/else conditional.
337Pops a result off the stack of conditional evaluations pushed by
338.Sx \&ie
339and uses it as its conditional.
340If no stack entries are present (e.g., due to no prior
341.Sx \&ie
342calls)
343then false is assumed.
344The syntax of this request is similar to
345.Sx \&if
346except that the conditional is missing.
347.Ss \&EN
348End an equation block.
349See
350.Sx \&EQ .
351.Ss \&EQ
352Begin an equation block.
353See
354.Xr eqn 7
355for a description of the equation language.
356.Ss \&ft
357Change the font.
358Its syntax is as follows:
359.Pp
360.D1 Pf . Cm \&ft Op Ar font
361.Pp
362The following
363.Ar font
364arguments are supported:
365.Bl -tag -width 4n -offset indent
366.It Cm B , BI , 3 , 4
367switches to
368.Sy bold
369font
370.It Cm I , 2
371switches to
372.Em underlined
373font
374.It Cm R , CW , 1
375switches to normal font
376.It Cm P No "or no argument"
377switches back to the previous font
378.El
379.Pp
380This request takes effect only locally, may be overridden by macros
381and escape sequences, and is only supported in
382.Xr man 7
383for now.
384.Ss \&hy
385Set automatic hyphenation mode.
386This line-scoped request is currently ignored.
387.Ss \&ie
388The
389.Qq if
390half of an if/else conditional.
391The result of the conditional is pushed into a stack used by subsequent
392invocations of
393.Sx \&el ,
394which may be separated by any intervening input (or not exist at all).
395Its syntax is equivalent to
396.Sx \&if .
397.Ss \&if
398Begins a conditional.
399Right now, the conditional evaluates to true
400if and only if it starts with the letter
401.Sy n ,
402indicating processing in nroff style as opposed to troff style.
403If a conditional is false, its children are not processed, but are
404syntactically interpreted to preserve the integrity of the input
405document.
406Thus,
407.Pp
408.D1 \&.if t .ig
409.Pp
410will discard the
411.Sq \&.ig ,
412which may lead to interesting results, but
413.Pp
414.D1 \&.if t .if t \e{\e
415.Pp
416will continue to syntactically interpret to the block close of the final
417conditional.
418Sub-conditionals, in this case, obviously inherit the truth value of
419the parent.
420This request has the following syntax:
421.Bd -literal -offset indent
422\&.if COND \e{\e
423BODY...
424\&.\e}
425.Ed
426.Bd -literal -offset indent
427\&.if COND \e{ BODY
428BODY... \e}
429.Ed
430.Bd -literal -offset indent
431\&.if COND \e{ BODY
432BODY...
433\&.\e}
434.Ed
435.Bd -literal -offset indent
436\&.if COND \e
437BODY
438.Ed
439.Pp
440COND is a conditional statement.
441roff allows for complicated conditionals; mandoc is much simpler.
442At this time, mandoc supports only
443.Sq n ,
444evaluating to true;
445and
446.Sq t ,
447.Sq e ,
448and
449.Sq o ,
450evaluating to false.
451All other invocations are read up to the next end of line or space and
452evaluate as false.
453.Pp
454If the BODY section is begun by an escaped brace
455.Sq \e{ ,
456scope continues until a closing-brace escape sequence
457.Sq \.\e} .
458If the BODY is not enclosed in braces, scope continues until
459the end of the line.
460If the COND is followed by a BODY on the same line, whether after a
461brace or not, then requests and macros
462.Em must
463begin with a control character.
464It is generally more intuitive, in this case, to write
465.Bd -literal -offset indent
466\&.if COND \e{\e
467\&.foo
468bar
469\&.\e}
470.Ed
471.Pp
472than having the request or macro follow as
473.Pp
474.D1 \&.if COND \e{ .foo
475.Pp
476The scope of a conditional is always parsed, but only executed if the
477conditional evaluates to true.
478.Pp
479Note that the
480.Sq \e}
481is converted into a zero-width escape sequence if not passed as a
482standalone macro
483.Sq \&.\e} .
484For example,
485.Pp
486.D1 \&.Fl a \e} b
487.Pp
488will result in
489.Sq \e}
490being considered an argument of the
491.Sq \&Fl
492macro.
493.Ss \&ig
494Ignore input.
495Its syntax can be either
496.Bd -literal -offset indent
497.Pf . Cm \&ig
498.Ar ignored text
499\&..
500.Ed
501.Pp
502or
503.Bd -literal -offset indent
504.Pf . Cm \&ig Ar end
505.Ar ignored text
506.Pf . Ar end
507.Ed
508.Pp
509In the first case, input is ignored until a
510.Sq \&..
511request is encountered on its own line.
512In the second case, input is ignored until the specified
513.Sq Pf . Ar end
514macro is encountered.
515Do not use the escape character
516.Sq \e
517anywhere in the definition of
518.Ar end ;
519it would cause very strange behaviour.
520.Pp
521When the
522.Ar end
523macro is a roff request or a roff macro, like in
524.Pp
525.D1 \&.ig if
526.Pp
527the subsequent invocation of
528.Sx \&if
529will first terminate the
530.Ar ignored text ,
531then be invoked as usual.
532Otherwise, it only terminates the
533.Ar ignored text ,
534and arguments following it or the
535.Sq \&..
536request are discarded.
537.Ss \&ne
538Declare the need for the specified minimum vertical space
539before the next trap or the bottom of the page.
540This line-scoped request is currently ignored.
541.Ss \&nh
542Turn off automatic hyphenation mode.
543This line-scoped request is currently ignored.
544.Ss \&rm
545Remove a request, macro or string.
546This request is intended to have one argument,
547the name of the request, macro or string to be undefined.
548Currently, it is ignored including its arguments,
549and the number of arguments is not checked.
550.Ss \&nr
551Define a register.
552A register is an arbitrary string value that defines some sort of state,
553which influences parsing and/or formatting.
554Its syntax is as follows:
555.Pp
556.D1 Pf \. Cm \&nr Ar name Ar value
557.Pp
558The
559.Ar value
560may, at the moment, only be an integer.
561So far, only the following register
562.Ar name
563is recognised:
564.Bl -tag -width Ds
565.It Cm nS
566If set to a positive integer value, certain
567.Xr mdoc 7
568macros will behave in the same way as in the
569.Em SYNOPSIS
570section.
571If set to 0, these macros will behave in the same way as outside the
572.Em SYNOPSIS
573section, even when called within the
574.Em SYNOPSIS
575section itself.
576Note that starting a new
577.Xr mdoc 7
578section with the
579.Cm \&Sh
580macro will reset this register.
581.El
582.Ss \&ns
583Turn on no-space mode.
584This line-scoped request is intended to take no arguments.
585Currently, it is ignored including its arguments,
586and the number of arguments is not checked.
587.Ss \&ps
588Change point size.
589This line-scoped request is intended to take one numerical argument.
590Currently, it is ignored including its arguments,
591and the number of arguments is not checked.
592.Ss \&so
593Include a source file.
594Its syntax is as follows:
595.Pp
596.D1 Pf \. Cm \&so Ar file
597.Pp
598The
599.Ar file
600will be read and its contents processed as input in place of the
601.Sq \&.so
602request line.
603To avoid inadvertent inclusion of unrelated files,
604.Xr mandoc 1
605only accepts relative paths not containing the strings
606.Qq ../
607and
608.Qq /.. .
609.Ss \&ta
610Set tab stops.
611This line-scoped request can take an arbitrary number of arguments.
612Currently, it is ignored including its arguments.
613.Ss \&tr
614Output character translation.
615Its syntax is as follows:
616.Pp
617.D1 Pf \. Cm \&tr Ar [ab]+
618.Pp
619Pairs of
620.Ar ab
621characters are replaced
622.Ar ( a
623for
624.Ar b ) .
625Replacement (or origin) characters may also be character escapes; thus,
626.Pp
627.Dl tr \e(xx\e(yy
628.Pp
629replaces all invocations of \e(xx with \e(yy.
630.Ss \&T&
631Re-start a table layout, retaining the options of the prior table
632invocation.
633See
634.Sx \&TS .
635.Ss \&TE
636End a table context.
637See
638.Sx \&TS .
639.Ss \&TS
640Begin a table, which formats input in aligned rows and columns.
641See
642.Xr tbl 7
643for a description of the tbl language.
644.Sh COMPATIBILITY
645This section documents compatibility between mandoc and other other
646.Nm
647implementations, at this time limited to GNU troff
648.Pq Qq groff .
649The term
650.Qq historic groff
651refers to groff version 1.15.
652.Pp
653.Bl -dash -compact
654.It
655In mandoc, the
656.Sx \&EQ ,
657.Sx \&TE ,
658.Sx \&TS ,
659and
660.Sx \&T& ,
661macros are considered regular macros.
662In all other
663.Nm
664implementations, these are special macros that must be specified without
665spacing between the control character (which must be a period) and the
666macro name.
667.It
668The
669.Cm nS
670register is only compatible with OpenBSD's groff-1.15.
671.It
672Historic groff did not accept white-space before a custom
673.Ar end
674macro for the
675.Sx \&ig
676request.
677.It
678The
679.Sx \&if
680and family would print funny white-spaces with historic groff when
681using the next-line syntax.
682.El
683.Sh SEE ALSO
684.Xr mandoc 1 ,
685.Xr eqn 7 ,
686.Xr man 7 ,
687.Xr mandoc_char 7 ,
688.Xr mdoc 7 ,
689.Xr tbl 7
690.Rs
691.%A Joseph F. Ossanna
692.%A Brian W. Kernighan
693.%I AT&T Bell Laboratories
694.%T Troff User's Manual
695.%R Computing Science Technical Report
696.%N 54
697.%C Murray Hill, New Jersey
698.%D 1976 and 1992
699.%U http://www.kohala.com/start/troff/cstr54.ps
700.Re
701.Rs
702.%A Joseph F. Ossanna
703.%A Brian W. Kernighan
704.%A Gunnar Ritter
705.%T Heirloom Documentation Tools Nroff/Troff User's Manual
706.%D September 17, 2007
707.%U http://heirloom.sourceforge.net/doctools/troff.pdf
708.Re
709.Sh HISTORY
710The RUNOFF typesetting system was written in PL/1 for the CTSS
711operating system by Jerome ("Jerry") E. Saltzer in 1961.
712It was first used as the main documentation tool by Multics since 1963.
713Robert ("Bob") H. Morris ported it to the GE-635 and called it
714.Nm ,
715Doug McIlroy rewrote it in BCPL in 1969,
716Joseph F. Ossanna rewrote it in PDP-11 assembly in 1973,
717and Brian W. Kernighan rewrote it in C in 1975.
718.Sh AUTHORS
719.An -nosplit
720This
721.Nm
722reference was written by
723.An Kristaps Dzonsons ,
724.Mt kristaps@bsd.lv ;
725and
726.An Ingo Schwarze ,
727.Mt schwarze@openbsd.org .
728