* doc/Makefile (clean): Include more index files.
[s-roff.git] / doc / groff.texinfo
blob53feeb5ac75bcc5664547881d0100a7f96aa7047
1 \input texinfo   @c -*-texinfo-*-
3 @c
4 @c If you use texinfo.tex 1999-09-25.10 or earlier please convert this
5 @c manual with `texi2dvi -e groff.texinfo' due to a bug in expanding
6 @c user-defined macros.
7 @c
9 @c %**start of header (This is for running Texinfo on a region.)
10 @setfilename  groff
11 @settitle The GNU Troff Manual
12 @setchapternewpage odd
13 @footnotestyle separate
14 @c %**end of header (This is for running Texinfo on a region.)
17 @c We use the following indices:
19 @c   cindex: concepts
20 @c   findex: requests, escapes, and functions
21 @c   vindex: registers
22 @c   kindex: commands in font files
23 @c   pindex: programs and files
24 @c   tindex: environment variables
25 @c   maindex: macros and strings
26 @c   glindex: glyph names
27 @c   opindex: operators
29 @c tindex and cindex are merged.
31 @defcodeindex ma
32 @defcodeindex gl
33 @defcodeindex op
34 @syncodeindex tp cp
37 @macro Deffn{category, name, arg}
38 @deffn \category\ @t{\name\} \arg\
39 @end macro
41 @macro end_Deffn
42 @end deffn
43 @end macro
45 @macro Deffnx{category, name, arg}
46 @deffnx \category\ @t{\name\} \arg\
47 @end macro
49 @macro end_Deffnx
50 @end deffnx
51 @end macro
53 @macro Defmac{name, arg}
54 @defmac @t{\name\} \arg\
55 @end macro
57 @macro end_Defmac
58 @end defmac
59 @end macro
61 @macro Defmacx{name, arg}
62 @defmacx @t{\name\} \arg\
63 @end macro
65 @macro end_Defmacx
66 @end defmacx
67 @end macro
70 @c XXX comment all examples
73 @dircategory Miscellaneous
74 @direntry
75 * Groff: (groff).  The GNU troff document formatting system.
76 @end direntry
79 @smallbook
82 @iftex
83 @finalout
84 @end iftex
87 @ifinfo
88 This Info file documents GNU troff version 1.16.
90 Published by the Free Software Foundation
91 59 Temple Place, Suite 330
92 Boston, MA  02111-1307  USA
94 Copyright (C) 1994-2000 Free Software Foundation, Inc.
96 Permission is granted to make and distribute verbatim copies of this
97 manual provided the copyright notice and this permission notice are
98 preserved on all copies.
100 @ignore
101 Permission is granted to process this file through TeX and print the
102 results, provided the printed document carries copying permission notice
103 identical to this one except for the removal of this paragraph (this
104 paragraph not being relevant to the printed manual).
106 @end ignore
107 Permission is granted to copy and distribute modified versions of this
108 manual under the conditions for verbatim copying, provided that the
109 entire resulting derived work is distributed under the terms of a
110 permission notice identical to this one.
112 Permission is granted to copy and distribute translations of this manual
113 into another language, under the above conditions for modified versions,
114 except that this permission notice may be stated in a translation
115 approved by the Foundation.
117 Permission is granted to copy and distribute modified versions of this
118 manual under the conditions for verbatim copying, provided also that the
119 section entitled ``GNU General Public License'' is included exactly as
120 in the original, and provided that the entire resulting derived work is
121 distributed under the terms of a permission notice identical to this
122 one.
124 Permission is granted to copy and distribute translations of this manual
125 into another language, under the above conditions for modified versions,
126 except that the section entitled ``GNU General Public License'' may be
127 included in a translation approved by the Free Software Foundation
128 instead of in the original English.
129 @end ifinfo
132 @titlepage
133 @title groff
134 @subtitle The GNU implementation of @code{troff}
135 @subtitle Edition 1.16
136 @subtitle Spring 2000
137 @author by Trent A.@w{ }Fisher
138 @author and Werner Lemberg
140 @c Include the Distribution inside the titlepage environment so
141 @c that headings are turned off.  Headings on and off do not work.
143 @page
144 @vskip 0pt plus 1filll
145 Copyright @copyright@w{ }1994-2000 Free Software Foundation,@w{ }Inc.
146 @sp 2
147 Version 1.16 of @code{groff}, @*
148 Spring 2000
149 @sp 2
150 Published by the Free Software Foundation @*
151 59 Temple Place, Suite 330 @*
152 Boston, MA  02111-1307  USA
155 Permission is granted to make and distribute verbatim copies of this
156 manual provided the copyright notice and this permission notice are
157 preserved on all copies.
159 Permission is granted to copy and distribute modified versions of this
160 manual under the conditions for verbatim copying, provided also that the
161 section entitled ``GNU General Public License'' is included exactly as
162 in the original, and provided that the entire resulting derived work is
163 distributed under the terms of a permission notice identical to this
164 one.
166 Permission is granted to copy and distribute translations of this manual
167 into another language, under the above conditions for modified versions,
168 except that the section entitled ``GNU General Public License'' may be
169 included in a translation approved by the Free Software Foundation
170 instead of in the original English.
172 Cover art by Etienne Suvasa.
173 @end titlepage
174 @page
178 @node Top, Copying, (dir), (dir)
180 @ifinfo
181 This Info file documents groff version 1.16, the GNU implementation of
182 the troff typesetting system.
184 This is an in-progress document; contributions, comments, or
185 contributions are welcome.  Send them to bug-groff@@gnu.org.
186 @end ifinfo
188 @menu
189 * Copying::                     
190 * Introduction::                
191 * Invoking groff::              
192 * Tutorial for Macro Users::    
193 * Macro Packages::              
194 * Programming Tutorial::        
195 * Preprocessors::               
196 * Output Devices::              
197 * File formats::                
198 * Installation::                
199 * Request and Escape Index::    
200 * Operator Index::              
201 * Register Index::              
202 * Macro and String Index::      
203 * Glyph Name Index::            
204 * Font File Keyword Index::     
205 * Program and File Index::      
206 * Concept Index::               
207 @end menu
211 @node Copying, Introduction, Top, Top
212 @cindex copying
213 @unnumbered GNU GENERAL PUBLIC LICENSE
214 @center Version 2, June 1991
216 @display
217 Copyright @copyright{}@w{ }1989, 1991 Free Software Foundation, Inc.
218 59@w{ }Temple Place, Suite@w{ }330, Boston, MA@w{ }02111, USA
220 Everyone is permitted to copy and distribute verbatim copies of this
221 license document, but changing it is not allowed.
222 @end display
224 @unnumberedsec Preamble
226 The licenses for most software are designed to take away your freedom to
227 share and change it.  By contrast, the GNU General Public License is
228 intended to guarantee your freedom to share and change free software --
229 to make sure the software is free for all its users.  This General
230 Public License applies to most of the Free Software Foundation's
231 software and to any other program whose authors commit to using it.
232 (Some other Free Software Foundation software is covered by the GNU
233 Library General Public License instead.)  You can apply it to your
234 programs, too.
236 When we speak of free software, we are referring to freedom, not price.
237 Our General Public Licenses are designed to make sure that you have the
238 freedom to distribute copies of free software (and charge for this
239 service if you wish), that you receive source code or can get it if you
240 want it, that you can change the software or use pieces of it in new
241 free programs; and that you know you can do these things.
243 To protect your rights, we need to make restrictions that forbid anyone
244 to deny you these rights or to ask you to surrender the rights.  These
245 restrictions translate to certain responsibilities for you if you
246 distribute copies of the software, or if you modify it.
248 For example, if you distribute copies of such a program, whether gratis
249 or for a fee, you must give the recipients all the rights that you have.
250 You must make sure that they, too, receive or can get the source code.
251 And you must show them these terms so they know their rights.
253 We protect your rights with two steps: (1)@w{ }copyright the software,
254 and (2)@w{ }offer you this license which gives you legal permission to
255 copy, distribute and/or modify the software.
257 Also, for each author's protection and ours, we want to make certain
258 that everyone understands that there is no warranty for this free
259 software.  If the software is modified by someone else and passed on, we
260 want its recipients to know that what they have is not the original, so
261 that any problems introduced by others will not reflect on the original
262 authors' reputations.
264 Finally, any free program is threatened constantly by software patents.
265 We wish to avoid the danger that redistributors of a free program will
266 individually obtain patent licenses, in effect making the program
267 proprietary.  To prevent this, we have made it clear that any patent
268 must be licensed for everyone's free use or not licensed at all.
270 The precise terms and conditions for copying, distribution and
271 modification follow.
273 @iftex
274 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
275 @end iftex
276 @ifinfo
277 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
278 @end ifinfo
280 @enumerate 0
281 @item
282 This License applies to any program or other work which contains a
283 notice placed by the copyright holder saying it may be distributed under
284 the terms of this General Public License.  The ``Program'', below,
285 refers to any such program or work, and a ``work based on the Program''
286 means either the Program or any derivative work under copyright law:
287 that is to say, a work containing the Program or a portion of it, either
288 verbatim or with modifications and/or translated into another language.
289 (Hereinafter, translation is included without limitation in the term
290 ``modification''.)  Each licensee is addressed as ``you''.
292 Activities other than copying, distribution and modification are not
293 covered by this License; they are outside its scope.  The act of running
294 the Program is not restricted, and the output from the Program is
295 covered only if its contents constitute a work based on the Program
296 (independent of having been made by running the Program).  Whether that
297 is true depends on what the Program does.
299 @item
300 You may copy and distribute verbatim copies of the Program's source code
301 as you receive it, in any medium, provided that you conspicuously and
302 appropriately publish on each copy an appropriate copyright notice and
303 disclaimer of warranty; keep intact all the notices that refer to this
304 License and to the absence of any warranty; and give any other
305 recipients of the Program a copy of this License along with the Program.
307 You may charge a fee for the physical act of transferring a copy, and
308 you may at your option offer warranty protection in exchange for a fee.
310 @item
311 You may modify your copy or copies of the Program or any portion of it,
312 thus forming a work based on the Program, and copy and distribute such
313 modifications or work under the terms of Section@w{ }1 above, provided
314 that you also meet all of these conditions:
316 @enumerate a
317 @item
318 You must cause the modified files to carry prominent notices stating
319 that you changed the files and the date of any change.
321 @item
322 You must cause any work that you distribute or publish, that in whole or
323 in part contains or is derived from the Program or any part thereof, to
324 be licensed as a whole at no charge to all third parties under the terms
325 of this License.
327 @item
328 If the modified program normally reads commands interactively when run,
329 you must cause it, when started running for such interactive use in the
330 most ordinary way, to print or display an announcement including an
331 appropriate copyright notice and a notice that there is no warranty (or
332 else, saying that you provide a warranty) and that users may
333 redistribute the program under these conditions, and telling the user
334 how to view a copy of this License.  (Exception: if the Program itself
335 is interactive but does not normally print such an announcement, your
336 work based on the Program is not required to print an announcement.)
337 @end enumerate
339 These requirements apply to the modified work as a whole.  If
340 identifiable sections of that work are not derived from the Program, and
341 can be reasonably considered independent and separate works in
342 themselves, then this License, and its terms, do not apply to those
343 sections when you distribute them as separate works.  But when you
344 distribute the same sections as part of a whole which is a work based on
345 the Program, the distribution of the whole must be on the terms of this
346 License, whose permissions for other licensees extend to the entire
347 whole, and thus to each and every part regardless of who wrote it.
349 Thus, it is not the intent of this section to claim rights or contest
350 your rights to work written entirely by you; rather, the intent is to
351 exercise the right to control the distribution of derivative or
352 collective works based on the Program.
354 In addition, mere aggregation of another work not based on the Program
355 with the Program (or with a work based on the Program) on a volume of a
356 storage or distribution medium does not bring the other work under the
357 scope of this License.
359 @item
360 You may copy and distribute the Program (or a work based on it, under
361 Section@w{ }2) in object code or executable form under the terms of
362 Sections@w{ }1 and@w{ }2 above provided that you also do one of the
363 following:
365 @enumerate a
366 @item
367 Accompany it with the complete corresponding machine-readable source
368 code, which must be distributed under the terms of Sections@w{ }1 and@w{
369 }2 above on a medium customarily used for software interchange; or,
371 @item
372 Accompany it with a written offer, valid for at least three years, to
373 give any third party, for a charge no more than your cost of physically
374 performing source distribution, a complete machine-readable copy of the
375 corresponding source code, to be distributed under the terms of
376 Sections@w{ }1 and@w{ }2 above on a medium customarily used for software
377 interchange; or,
379 @item
380 Accompany it with the information you received as to the offer to
381 distribute corresponding source code.  (This alternative is allowed only
382 for noncommercial distribution and only if you received the program in
383 object code or executable form with such an offer, in accord with
384 Subsection@w{ }b above.)
385 @end enumerate
387 The source code for a work means the preferred form of the work for
388 making modifications to it.  For an executable work, complete source
389 code means all the source code for all modules it contains, plus any
390 associated interface definition files, plus the scripts used to control
391 compilation and installation of the executable.  However, as a special
392 exception, the source code distributed need not include anything that is
393 normally distributed (in either source or binary form) with the major
394 components (compiler, kernel, and so on) of the operating system on
395 which the executable runs, unless that component itself accompanies the
396 executable.
398 If distribution of executable or object code is made by offering access
399 to copy from a designated place, then offering equivalent access to copy
400 the source code from the same place counts as distribution of the source
401 code, even though third parties are not compelled to copy the source
402 along with the object code.
404 @item
405 You may not copy, modify, sublicense, or distribute the Program except
406 as expressly provided under this License.  Any attempt otherwise to
407 copy, modify, sublicense or distribute the Program is void, and will
408 automatically terminate your rights under this License.  However,
409 parties who have received copies, or rights, from you under this License
410 will not have their licenses terminated so long as such parties remain
411 in full compliance.
413 @item
414 You are not required to accept this License, since you have not signed
415 it.  However, nothing else grants you permission to modify or distribute
416 the Program or its derivative works.  These actions are prohibited by
417 law if you do not accept this License.  Therefore, by modifying or
418 distributing the Program (or any work based on the Program), you
419 indicate your acceptance of this License to do so, and all its terms and
420 conditions for copying, distributing or modifying the Program or works
421 based on it.
423 @item
424 Each time you redistribute the Program (or any work based on the
425 Program), the recipient automatically receives a license from the
426 original licensor to copy, distribute or modify the Program subject to
427 these terms and conditions.  You may not impose any further restrictions
428 on the recipients' exercise of the rights granted herein.  You are not
429 responsible for enforcing compliance by third parties to this License.
431 @item
432 If, as a consequence of a court judgment or allegation of patent
433 infringement or for any other reason (not limited to patent issues),
434 conditions are imposed on you (whether by court order, agreement or
435 otherwise) that contradict the conditions of this License, they do not
436 excuse you from the conditions of this License.  If you cannot
437 distribute so as to satisfy simultaneously your obligations under this
438 License and any other pertinent obligations, then as a consequence you
439 may not distribute the Program at all.  For example, if a patent license
440 would not permit royalty-free redistribution of the Program by all those
441 who receive copies directly or indirectly through you, then the only way
442 you could satisfy both it and this License would be to refrain entirely
443 from distribution of the Program.
445 If any portion of this section is held invalid or unenforceable under
446 any particular circumstance, the balance of the section is intended to
447 apply and the section as a whole is intended to apply in other
448 circumstances.
450 It is not the purpose of this section to induce you to infringe any
451 patents or other property right claims or to contest validity of any
452 such claims; this section has the sole purpose of protecting the
453 integrity of the free software distribution system, which is implemented
454 by public license practices.  Many people have made generous
455 contributions to the wide range of software distributed through that
456 system in reliance on consistent application of that system; it is up to
457 the author/donor to decide if he or she is willing to distribute
458 software through any other system and a licensee cannot impose that
459 choice.
461 This section is intended to make thoroughly clear what is believed to be
462 a consequence of the rest of this License.
464 @item
465 If the distribution and/or use of the Program is restricted in certain
466 countries either by patents or by copyrighted interfaces, the original
467 copyright holder who places the Program under this License may add an
468 explicit geographical distribution limitation excluding those countries,
469 so that distribution is permitted only in or among countries not thus
470 excluded.  In such case, this License incorporates the limitation as if
471 written in the body of this License.
473 @item
474 The Free Software Foundation may publish revised and/or new versions of
475 the General Public License from time to time.  Such new versions will be
476 similar in spirit to the present version, but may differ in detail to
477 address new problems or concerns.
479 Each version is given a distinguishing version number.  If the Program
480 specifies a version number of this License which applies to it and ``any
481 later version'', you have the option of following the terms and
482 conditions either of that version or of any later version published by
483 the Free Software Foundation.  If the Program does not specify a version
484 number of this License, you may choose any version ever published by the
485 Free Software Foundation.
487 @item
488 If you wish to incorporate parts of the Program into other free programs
489 whose distribution conditions are different, write to the author to ask
490 for permission.  For software which is copyrighted by the Free Software
491 Foundation, write to the Free Software Foundation; we sometimes make
492 exceptions for this.  Our decision will be guided by the two goals of
493 preserving the free status of all derivatives of our free software and
494 of promoting the sharing and reuse of software generally.
496 @iftex
497 @heading NO WARRANTY
498 @end iftex
499 @ifinfo
500 @center NO WARRANTY
501 @end ifinfo
503 @item
504 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
505 THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW@.  EXCEPT WHEN
506 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
507 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER
508 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
509 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE@.
510 THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH
511 YOU@.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
512 NECESSARY SERVICING, REPAIR OR CORRECTION.
514 @item
515 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
516 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
517 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
518 DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
519 DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM
520 (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
521 INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
522 THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR
523 OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
524 @end enumerate
526 @iftex
527 @heading END OF TERMS AND CONDITIONS
528 @end iftex
529 @ifinfo
530 @center END OF TERMS AND CONDITIONS
531 @end ifinfo
534 @page
535 @unnumberedsec How to Apply These Terms to Your New Programs
537 If you develop a new program, and you want it to be of the greatest
538 possible use to the public, the best way to achieve this is to make it
539 free software which everyone can redistribute and change under these
540 terms.
542 To do so, attach the following notices to the program.  It is safest to
543 attach them to the start of each source file to most effectively convey
544 the exclusion of warranty; and each file should have at least the
545 ``copyright'' line and a pointer to where the full notice is found.
547 @smallexample
548 @var{one line to give the program's name and an idea of what it does.}
549 Copyright (C) 19@var{yy} @var{name of author}
551 This program is free software; you can redistribute it and/or modify
552 it under the terms of the GNU General Public License as published by
553 the Free Software Foundation; either version 2 of the License, or (at
554 your option) any later version.
556 This program is distributed in the hope that it will be useful, but
557 WITHOUT ANY WARRANTY; without even the implied warranty of
558 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE@.  See the GNU
559 General Public License for more details.
561 You should have received a copy of the GNU General Public License
562 along with this program; if not, write to the Free Software
563 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
564 @end smallexample
566 Also add information on how to contact you by electronic and paper mail.
568 If the program is interactive, make it output a short notice like this
569 when it starts in an interactive mode:
571 @smallexample
572 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
573 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type
574 `show w'.  This is free software, and you are welcome to redistribute
575 it under certain conditions; type `show c' for details.
576 @end smallexample
578 The hypothetical commands @samp{show@w{ }w} and @samp{show@w{ }c} should
579 show the appropriate parts of the General Public License.  Of course,
580 the commands you use may be called something other than @samp{show@w{
581 }w} and @samp{show@w{ }c}; they could even be mouse-clicks or menu
582 items---whatever suits your program.
584 You should also get your employer (if you work as a programmer) or your
585 school, if any, to sign a ``copyright disclaimer'' for the program, if
586 necessary.  Here is a sample; alter the names:
588 @smallexample
589 @group
590 Yoyodyne, Inc., hereby disclaims all copyright interest
591 in the program `Gnomovision' (which makes passes at compilers)
592 written by James Hacker.
594 @var{signature of Ty Coon}, 1 April 1989
595 Ty Coon, President of Vice
596 @end group
597 @end smallexample
599 This General Public License does not permit incorporating your program
600 into proprietary programs.  If your program is a subroutine library, you
601 may consider it more useful to permit linking proprietary applications
602 with the library.  If this is what you want to do, use the GNU Library
603 General Public License instead of this License.
607 @node Introduction, Invoking groff, Copying, Top
608 @chapter Introduction
609 @cindex introduction
611 GNU @code{troff} (or @code{groff}) is a system for typesetting
612 documents.  @code{troff} is very flexible and has been in existence (and
613 use) for about 3@w{ }decades.  It is quite widespread and firmly
614 entrenched in the @acronym{UNIX} community.
616 @menu
617 * What Is groff?::              
618 * History::                     
619 * groff Capabilities::          
620 * Macro Package Intro::         
621 * Preprocessor Intro::          
622 * Output device intro::         
623 * Credits::                     
624 @end menu
627 @node What Is groff?, History, Introduction, Introduction
628 @section What Is @code{groff}?
629 @cindex what is @code{groff}?
630 @cindex @code{groff} -- what is it?
632 @code{groff} is of an older generation of document preparation systems,
633 which operate more like compilers than the more recent interactive
634 @acronym{WYSIWYG}@footnote{What You See Is What You Get} systems.
635 @code{groff} and its contemporary counterpart, @TeX{}, both work using a
636 @dfn{batch} paradigm: The input (or @dfn{source}) files are normal text
637 files with embedded formatting commands.  These files can then be
638 processed by @code{groff} to produce a typeset document on a variety of
639 devices.
641 Likewise, @code{groff} should not be confused with a @dfn{word
642 processor}, since that term connotes an integrated system which includes
643 an editor and a text formatter.  Also, many word processors follow the
644 @acronym{WYSIWYG} paradigm which was discussed earlier.
646 Although @acronym{WYSIWYG} systems may be easier to use, they have a
647 number of disadvantages compared to @code{troff}:
649 @itemize @bullet{}
650 @item
651 They must be used on a graphics display to do any operations on a
652 document.
653 @item
654 Most of the @acronym{WYSIWYG} systems are either non-free or are not
655 very portable.
656 @item
657 @code{troff} is firmly entrenched in all @acronym{UNIX} systems.
658 @item
659 It is difficult to have a wide range of capabilities available within
660 the confines of a GUI/window system.
661 @item
662 It is more difficult to make global changes to a document.
663 @end itemize
665 @quotation
666 ``GUIs normally make it simple to accomplish simple actions and
667 impossible to accomplish complex actions.''  --Doug Gwyn (22/Jun/91 in
668 @code{comp.unix.wizards})
669 @end quotation
672 @node History, groff Capabilities, What Is groff?, Introduction
673 @section History
674 @cindex history
676 @cindex @code{runoff}
677 @code{troff} can trace its origins back to a formatting program called
678 @code{runoff} which ran on MIT's CTSS system.  This name came from the
679 common phrase of the time ``I'll run off a document.''
681 @cindex @code{roff}
682 The first version of @acronym{UNIX} was developed on a PDP-7 which was
683 sitting around Bell Labs.  In 1971 the developers wanted to get a PDP-11
684 for further work on the operating system.  In order to justify the cost
685 for this system, they proposed that they would implement a document
686 formatting system for the AT&T patents division.  This first formatting
687 program was a reimplementation of @code{runoff}.  In accordance with
688 @acronym{UNIX}'s penchant for abbreviations, it was named @code{roff}
689 (an abbreviation of @code{runoff}).
691 @cindex @code{nroff}
692 When they needed a more flexible language, a new version of @code{roff}
693 called @code{nroff} (Newer @code{roff}) was written.  It had a much more
694 complicated syntax, but provided the basis for all future versions.
695 When they got a Graphic Systems CAT Phototypesetter, J.@w{ }F.@w{
696 }Ossanna wrote a version of @code{nroff} which would drive it.  It was
697 dubbed @code{troff} for typesetter @code{roff}, although many people
698 have speculated that it actually means Times @code{roff} because of the
699 use of the Times font family in @code{troff} by default.  As such, the
700 name @code{troff} is pronounced `@w{t-roff}' rather than `trough'.
702 With @code{troff} came @code{nroff} (they were actually the same program
703 except for some @samp{#ifdefs}), which was for producing output for line
704 printers and character terminals.  It understood everything @code{troff}
705 did, and ignored the commands which were not applicable (e.g.@: font
706 changes).
708 Since there are several things which cannot be done easily in
709 @code{troff}, work on several preprocessors began.  These programs would
710 transform certain parts of a document into @code{troff}, which made a
711 very natural use of pipes in @acronym{UNIX}.
713 The @code{eqn} preprocessor allowed mathematical formul@ae{} to be
714 specified in a much simpler and more intuitive manner.  @code{tbl} is a
715 preprocessor for formatting tables.  The @code{refer} preprocessor (and
716 the similar program, @code{bib}) processes citations in a document
717 according to a bibliographic database.
719 Unfortunately, Ossanna's @code{troff} was written in PDP-11 assembly
720 language and produced output specifically for the CAT phototypesetter.
721 He rewrote it in C, although it was now 7000@w{ }lines of uncommented
722 code and still dependent on the CAT.  As the CAT became less common, and
723 was no longer supported by the manufacturer, the need to make it support
724 other devices became a priority.  However, before this could be done, he
725 was killed in an auto accident.
727 @pindex ditroff
728 @cindex @code{ditroff}
729 So, Brian Kernighan took on the task of rewriting @code{troff}.  The
730 newly rewritten version produced a device independent code which was
731 very easy for postprocessors to read and translate to the appropriate
732 printer codes.  Also, this new version of @code{troff} (called
733 @code{ditroff} for `device independent @code{troff}') had several
734 extensions, which included drawing functions.
736 Due to the additional abilities of the new version of @code{troff},
737 several new preprocessors appeared.  The @code{pic} preprocessor
738 provides a wide range of drawing functions.  Likewise the @code{ideal}
739 preprocessor did the same, although via a much different paradigm.  The
740 @code{grap} preprocessor took specifications for graphs, but, unlike
741 other preprocessors, produced @code{pic} code.
743 James Clark began work on a GNU implementation of @code{ditroff} in
744 early@w{ }1989.  The first version, @code{groff}@w{ }0.3.1, was released
745 June@w{ }1990.  @code{groff} included
747 @itemize @bullet{}
748 @item
749 A replacement for @code{ditroff} with many extensions.
750 @item
751 The @code{soelim}, @code{pic}, @code{tbl}, and @code{eqn} preprocessors.
752 @item
753 Postprocessors for character devices, @sc{PostScript}, @TeX{} DVI, and
754 X@w{ }windows.  GNU @code{troff} also eliminated the need for a separate
755 @code{nroff} program with a postprocessor which would produce
756 @acronym{ASCII} output.
757 @item
758 A version of the @file{me} macros and an implementation of the
759 @file{man} macros.
760 @end itemize
762 Also, a front-end was included which could construct the, sometimes
763 painfully long, pipelines required for all the post- and preprocessors.
765 Development of GNU @code{troff} progressed rapidly, and saw the
766 additions of a replacement for @code{refer}, an implementation of the
767 @file{ms} and @file{mm} macros, and a program to deduce how to format a
768 document (@code{grog}).
770 It was declared a stable (i.e.@: non-beta) package with the release of
771 version@w{ }1.04 around November@w{ }1991.
773 Beginning in@w{ }1999, @code{groff} has new maintainers (the package was
774 an orphan for a few years).  As a result, new features and programs like
775 @code{grn}, a preprocessor for gremlin images, and @code{grohtml}, an
776 output device to produce @acronym{HTML} output, have been added.
779 @node groff Capabilities, Macro Package Intro, History, Introduction
780 @section @code{groff} Capabilities
781 @cindex @code{groff} capabilities
782 @cindex capabilities of @code{groff}
784 So what exactly is @code{groff} capable of doing?  @code{groff} provides
785 a wide range of low-level text formatting operations.  Using these, it
786 is possible to perform a wide range of formatting tasks, such as
787 footnotes, table of contents, multiple columns, etc.
789 @itemize @bullet{}
790 @item
791 Text filling, adjusting, and centering
792 @item
793 Hyphenation
794 @item
795 Page control
796 @item
797 Font and character size control
798 @item
799 Vertical spacing (i.e.@: double spacing)
800 @item
801 Line length and indenting
802 @item
803 Macros, strings, diversions, and traps
804 @item
805 Number registers
806 @item
807 Tabs, leaders, and fields
808 @item
809 Input and output conventions and character translation
810 @item
811 Overstrike, bracket, line drawing, and zero-width functions
812 @item
813 Local horizontal and vertical motions and the width function
814 @item
815 Three-part titles
816 @item
817 Output line numbering
818 @item
819 Conditional acceptance of input
820 @item
821 Environment switching
822 @item
823 Insertions from the standard input
824 @item
825 Input/output file switching
826 @item
827 Output and error messages
828 @end itemize
831 @node Macro Package Intro, Preprocessor Intro, groff Capabilities, Introduction
832 @section Macro Packages
833 @cindex macro packages
835 Since @code{groff} provides such low level facilities, it can be quite
836 difficult to use by itself.  However, @code{groff} provides a
837 @dfn{macro} facility to specify how certain routine operations (e.g.@w{
838 }starting paragraphs, printing headers and footers, etc.)@: should be
839 done.  These macros can be collected together into a @dfn{macro
840 package}.  There are a number of macro packages available; the most
841 common (and the ones described in this manual) are @file{man},
842 @file{mdoc}, @file{me}, @file{ms}, and @file{mm}.
845 @node Preprocessor Intro, Output device intro, Macro Package Intro, Introduction
846 @section Preprocessors
847 @cindex preprocessors
849 Although @code{groff} provides most functions needed to format a
850 document, some operations would be unwieldy (e.g.@: to draw pictures).
851 Therefore, programs called preprocessors were written which understand
852 their own language and produce the necessary @code{groff} operations.
853 These preprocessors are able to differentiate their own input from the
854 rest of the document via markers.
856 To use a preprocessor, @acronym{UNIX} pipes are used to feed the output
857 from the preprocessor into @code{groff}.  Any number of preprocessors
858 may be used on a given document; in this case, the preprocessors are
859 linked together into one pipeline.  However, in @code{groff}, the user
860 does not need to construct the pipe, but only tell @code{groff} what
861 preprocessors to use.
863 @code{groff} currently has preprocessors for producing tables
864 (@code{tbl}), typesetting equations (@code{eqn}), drawing pictures
865 (@code{pic} and @code{grn}), and for processing bibliographies
866 (@code{refer}).  An associated program which is useful when dealing with
867 preprocessors is @code{soelim}.
869 A free implementation of @code{grap}, a preprocessor for drawing graphs,
870 can be obtained as an extra package.
872 There are other preprocessors in existence, but, unfortunately, no free
873 implementations are available.  Among them are preprocessors for drawing
874 mathematical pictures (@code{ideal}) and chemical structures
875 (@code{chem}).
878 @node Output device intro, Credits, Preprocessor Intro, Introduction
879 @section Output Devices
880 @cindex postprocessors
881 @cindex output devices
882 @cindex devices for output
884 @code{groff} actually produces device independent code which may be fed
885 into a postprocessor which will produce output for a particular device.
886 Currently, @code{groff} has postprocessors for @sc{PostScript},
887 character terminals, X@w{ }Windows (for previewing), @TeX{} DVI format,
888 HP LaserJet@w{ }4 and Canon LBP printers, and @acronym{HTML}.
891 @node Credits,  , Output device intro, Introduction
892 @section Credits
893 @cindex credits
895 Large portions of this manual were taken from existing documents, most
896 notably, the manual pages for the @code{groff} package by James Clark,
897 and Eric Allman's papers on the @file{me} macro package.
899 The section on the @file{man} macro package is partly based on Susan@w{
900 }G.@: Kleinmann's @file{groff_man} manual page written for the Debian
901 GNU/Linux system.
905 @node Invoking groff, Tutorial for Macro Users, Introduction, Top
906 @chapter Invoking @code{groff}
907 @cindex invoking @code{groff}
908 @cindex @code{groff} invocation
910 @pindex groff
911 @pindex gtroff
912 This section focuses on how to invoke the @code{groff} front end.  This
913 front end takes care of the details of constructing the pipeline among
914 the preprocessors, @code{gtroff} and the postprocessor.
916 It has become a tradition that GNU programs get the prefix @samp{g} to
917 distinguish it from its original counterparts provided by the host
918 (@pxref{Environment}, for more details).  Thus, for example, @code{geqn}
919 is GNU @code{eqn}.  On operating systems like Linux or the Hurd, which
920 don't contain proprietary software, this prefix is omitted since GNU
921 @code{troff} is the only used incarnation of @code{troff}.  Exception:
922 @code{groff} is never replaced by @code{roff}.
924 @menu
925 * Groff Options::               
926 * Environment::                 
927 * Invocation Examples::         
928 @end menu
931 @node Groff Options, Environment, Invoking groff, Invoking groff
932 @section Options
933 @cindex options
935 @pindex groff
936 @pindex gtroff
937 @pindex gpic
938 @pindex geqn
939 @pindex ggrn
940 @pindex gtbl
941 @pindex grefer
942 @pindex gsoelim
943 @code{groff} normally runs the @code{gtroff} program and a postprocessor
944 appropriate for the selected device.  The default device is @samp{ps}.
945 It can optionally preprocess with any of @code{gpic}, @code{geqn},
946 @code{gtbl}, @code{ggrn}, @code{grefer}, or @code{gsoelim}.
948 This section only documents options to the @code{groff} front end.  Many
949 of the arguments to @code{groff} are passed on to @code{gtroff},
950 therefore those are also included.  Arguments to pre- or postprocessors
951 can be found in @ref{Invoking gpic}, @ref{Invoking geqn}, @ref{Invoking
952 gtbl}, @ref{Invoking ggrn}, @ref{Invoking grefer}, @ref{Invoking
953 gsoelim}, @ref{Invoking grotty}, @ref{Invoking grops}, @ref{Invoking
954 grohtml}, @ref{Invoking grodvi}, @ref{Invoking grolj4}, @ref{Invoking
955 grolbp}, and @ref{Invoking gxditview}.
957 The command line format for @code{groff} is:
959 @example
960 groff [ -abeghilpstvzCENRSUVXZ ] [ -F@var{dir} ] [ -m@var{name} ]
961       [ -T@var{def} ] [ -f@var{fam} ] [ -w@var{name} ] [ -W@var{name} ]
962       [ -M@var{dir} ] [ -d@var{cs} ] [ -r@var{cn} ] [ -n@var{num} ]
963       [ -o@var{list} ] [ -P@var{arg} ] [ -L@var{arg} ] [ -I@var{dir} ]
964       [ @var{files}@dots{} ]
965 @end example
967 The command line format for @code{gtroff} is as follows.  As can be
968 seen, many of the options to @code{groff} are actually passed on to
969 @code{gtroff}.
971 @example
972 gtroff [ -abivzCERU ] [ -w@var{name} ] [ -W@var{name} ] [ -d@var{cs} ]
973        [ -f@var{fam} ] [ -m@var{name} ] [ -n@var{num} ]
974        [ -o@var{list} ] [ -r@var{cn} ] [ -T@var{name} ]
975        [ -F@var{dir} ] [ -M@var{dir} ] [ @var{files}@dots{} ]
976 @end example
978 Options without an argument can be grouped behind a single @option{-}.
979 A filename of @samp{-} denotes the standard input.  It is possible to
980 have whitespace between an option and its parameter.
982 @pindex grog
983 The @code{grog} command can be used to guess the correct @code{groff}
984 command to format a file.
986 @table @samp
987 @item -h
988 Print a help message.
989 @item -e
990 Preprocess with @code{geqn}.
991 @item -t
992 Preprocess with @code{gtbl}.
993 @item -g
994 Preprocess with @code{ggrn}.
995 @item -p
996 Preprocess with @code{gpic}.
997 @item -s
998 Preprocess with @code{gsoelim}.
999 @item -R
1000 Preprocess with @code{grefer}.  No mechanism is provided for passing
1001 arguments to @code{grefer} because most @code{grefer} options have
1002 equivalent commands which can be included in the file.  @xref{grefer},
1003 for more details.
1005 @pindex troffrc
1006 @pindex troffrc-end
1007 Note that @code{gtroff} also accepts a @option{-R} option, which is not
1008 accessible via @code{groff}.  This option prevents the loading of the
1009 @file{troffrc} and @file{troffrc-end} files.
1010 @item -v
1011 Make programs run by @code{groff} print out their version number.
1012 @item -V
1013 Print the pipeline on stdout instead of executing it.
1014 @item -z
1015 Suppress output from @code{gtroff}.  Only error messages will be
1016 printed.
1017 @item -Z
1018 Do not postprocess the output of @code{gtroff}.  Normally @code{groff}
1019 will automatically run the appropriate postprocessor.
1020 @item -P@var{arg}
1021 Pass @var{arg} to the postprocessor.  Each argument should be passed
1022 with a separate @option{-P} option.  Note that @code{groff} does not
1023 prepend @samp{-} to @var{arg} before passing it to the postprocessor.
1024 @item -l
1025 Send the output to a printer.  The command used for this is specified by
1026 the print command in the device description file.
1027 @item -L@var{arg}
1028 Pass @var{arg} to the spooler.  Each argument should be passed with a
1029 separate @option{-L} option.  Note that @code{groff} does not prepend a
1030 @samp{-} to @var{arg} before passing it to the postprocessor.
1031 @item -T@var{dev}
1032 Prepare output for device @var{dev}.  The default device is @samp{ps}.
1033 The following are the output devices currently available:
1034 @table @code
1035 @item ps
1036 For @sc{PostScript} printers and previewers.
1037 @item dvi
1038 For @TeX{} DVI format.
1039 @item X75
1040 For a 75@dmn{dpi} X11 previewer.
1041 @item X100
1042 For a 100@dmn{dpi} X11 previewer.
1043 @item ascii
1044 For typewriter-like devices.
1045 @item latin1
1046 For typewriter-like devices using the @w{ISO Latin-1} (@w{ISO 8859-1})
1047 character set.
1048 @item utf8
1049 For typewriter-like devices which use the Unicode (@w{ISO 10646})
1050 character set with @w{UTF-8} encoding.
1051 @item lj4
1052 For an HP LaserJet4-compatible (or other PCL5-compatible) printer.
1053 @item lbp
1054 For Canon @acronym{CAPSL} printers (@w{LBP-4} and @w{LBP-8} series laser
1055 printers).
1056 @item html
1057 To produce @acronym{HTML} output.
1058 @end table
1060 The postprocessor to be used for a device is specified by the
1061 @code{postpro} command in the device description file.  (@xref{Font
1062 Files}, for more info.)  This can be overridden with the @option{-X}
1063 option.
1064 @item -X
1065 Preview with @code{gxditview} instead of using the usual postprocessor.
1066 This is unlikely to produce good results except with @option{-Tps}.
1068 Note that this is not the same as using @option{-TX75} or
1069 @option{-TX100} to view a document with @code{gxditview}: The former
1070 will us the metrics of the specified device, whereas the latter will use
1071 X-specific fonts and metrics.
1072 @item -N
1073 Don't allow newlines with @code{eqn} delimiters.  This is the same as
1074 the @option{-N} option in @code{geqn}.
1075 @item -S
1076 Safer mode.  Pass the @option{-S} option to @code{gpic} and use the
1077 @option{-msafer} macros with @code{gtroff} (enabled by default).
1078 @item -U
1079 Unsafe mode.  Reverts to the old unsafe behaviour.
1080 @item -a
1081 Generate an @acronym{ASCII} approximation of the typeset output.
1082 @item -b
1083 Print a backtrace with each warning or error message.  This backtrace
1084 should help track down the cause of the error.  The line numbers given
1085 in the backtrace may not always be correct: @code{gtroff} can get
1086 confused by @code{as} or @code{am} requests while counting line numbers.
1087 @item -i
1088 Read the standard input after all the named input files have been
1089 processed.
1090 @item -w@var{name}
1091 Enable warning @var{name}.  Available warnings are described in
1092 @ref{Debugging}.  Multiple @option{-w} options are allowed.
1093 @item -W@var{name}
1094 Inhibit warning @var{name}.  Multiple @option{-W} options are allowed.
1095 @item -E
1096 Inhibit all error messages.
1097 @item -C
1098 Enable compatibility mode.
1099 @item -d@var{cs}
1100 @itemx -d@var{name}=s
1101 Define @var{c} or @var{name} to be a string @var{s}; @var{c} must be a
1102 one-letter @var{name}.
1103 @item -f@var{fam}
1104 Use @var{fam} as the default font family.
1105 @item -m@var{name}
1106 Read in the file @file{tmac.@var{name}}.  Normally this will be searched
1107 for in the library directory of @code{groff}.
1108 @item -n@var{num}
1109 Number the first page @var{num}.
1110 @item -o@var{list}
1111 @vindex .P
1112 Output only pages in @var{list}, which is a comma-separated list of page
1113 ranges; @var{n} means print page @var{n}, @samp{@var{m}-@var{n}} means
1114 print every page between @var{m} and @var{n}, @samp{-@var{n}} means
1115 print every page up to @var{n}, @samp{@var{n}-} means print every page
1116 from @var{n}.  @code{gtroff} will exit after printing the last page in
1117 the list.
1119 Within @code{gtroff}, this information can be extracted with the
1120 @samp{.P} register.  @xref{Built-in Registers}.
1121 @item -r@var{cn}
1122 @itemx -r@var{name}=@var{n}
1123 Set number register @var{c} or @var{name} to @var{n}; @var{c} must be a
1124 one-letter @var{name}; @var{n} can be any @code{gtroff} numeric
1125 expression.
1126 @item -F@var{dir}
1127 Search @var{dir} for subdirectories dev@var{name} (@var{name} is the
1128 name of the device) for the @file{DESC} file and font files before the
1129 normal directory.
1130 @item -M@var{dir}
1131 Search directory @var{dir} for macro files before the normal directory.
1132 @item -I@var{dir}
1133 This option is as described in @ref{gsoelim}.  It implies the
1134 @option{-s} option.
1135 @end table
1138 @node Environment, Invocation Examples, Groff Options, Invoking groff
1139 @section Environment
1140 @cindex environment variables
1141 @cindex variables in environment
1143 There are also several environment variables (of the operating system,
1144 not within @code{gtroff}) which can modify the behavior of @code{groff}.
1146 @table @code
1147 @item GROFF_COMMAND_PREFIX
1148 @tindex GROFF_COMMAND_PREFIX
1149 If this is set to @var{X}, then @code{groff} will run
1150 @var{X}@code{troff} instead of @code{gtroff}.  This also applies to
1151 @code{tbl}, @code{pic}, @code{eqn}, @code{grn}, @code{refer}, and
1152 @code{soelim}.  It does not apply to @code{grops}, @code{grodvi},
1153 @code{grotty}, @code{grohtml}, @code{grolj4}, and @code{gxditview}.
1154 @item GROFF_TMAC_PATH
1155 @tindex GROFF_TMAC_PATH
1156 A colon separated list of directories in which to search for macro
1157 files.
1158 @item GROFF_TYPESETTER
1159 @tindex GROFF_TYPESETTER
1160 The default output device.
1161 @item GROFF_FONT_PATH
1162 @tindex GROFF_FONT_PATH
1163 A colon separated list of directories in which to search for the
1164 @code{dev}@var{name} directory.
1165 @item PATH
1166 @tindex PATH
1167 The search path for commands executed by @code{groff}.
1168 @item GROFF_TMPDIR
1169 @tindex GROFF_TMPDIR
1170 @tindex TMPDIR
1171 The directory in which temporary files will be created.  If this is not
1172 set and @env{TMPDIR} is set, temporary files will be created in that
1173 directory.  Otherwise temporary files will be created in @code{/tmp}.
1174 The @code{grops} and @code{grefer} commands can create temporary files.
1175 @end table
1178 @node Invocation Examples,  , Environment, Invoking groff
1179 @section Invocation Examples
1180 @cindex invocation examples
1181 @cindex examples of invocation
1183 This section will list several common uses of @code{groff} and the
1184 command line which will accomplish it.
1186 @example
1187 groff file
1188 @end example
1190 @noindent
1191 This command processes @var{file} without a macro package or a
1192 preprocessor.  The output device is the default, @var{ps}, and the
1193 output is sent to stdout.
1195 @example
1196 groff -t -mandoc -Tascii file | less
1197 @end example
1199 @noindent
1200 This is basically what a call to the @code{man} program does.  The
1201 manual page @var{file} is processed with the @file{mandoc} macros (which
1202 in turn either calls the @file{man} or the @file{mdoc} macro package),
1203 using the @code{tbl} preprocessor and the @acronym{ASCII} output device.
1204 Finally, the result is displayed with the @code{less} pager.
1206 @example
1207 groff -X -m me file
1208 @end example
1210 @noindent
1211 Preview @var{file} with @code{gxditview}, using the @file{me} macro
1212 package.  Since no @option{-T} option is specified, use the default
1213 device (@samp{ps}).  Note that you can either say @w{@samp{-m me}} or
1214 @w{@samp{-me}}; the latter is an anachronism from the early days of
1215 @acronym{UNIX}.@footnote{The same is true for the other main macro
1216 packages that come with @code{groff}: @file{man}, @file{mdoc},
1217 @file{ms}, @file{mm}, and @file{mandoc}.  This won't work in general;
1218 for example, to load @file{tmac.safer}, either @samp{-msafer} or
1219 @w{@samp{-m safer}} must be used.}
1221 @example
1222 groff -man -rD1 -z file
1223 @end example
1225 @noindent
1226 Check @var{file} with the @file{man} macro package, forcing double-sided
1227 printing---don't produce any output.
1229 @subsection @code{grog}
1231 @code{grog} reads files and guesses which of the @code{groff}
1232 preprocessors and/or macro packages are are required for formatting
1233 them, and prints the @code{groff} command including those options on the
1234 standard output.  The options generated are one of @option{-e},
1235 @option{-man}, @option{-me}, @option{-mm}, @option{-ms}, @option{-p},
1236 @option{-R}, @option{-g}, @option{-s}, and @option{-t}.
1238 A filename of @samp{-} is taken to refer to the standard input.  If no
1239 files are specified the standard input will be read.  Any specified
1240 options will be included in the printed command.  No space is allowed
1241 between options and their arguments.  For example,
1243 @example
1244 grog -Tdvi paper.ms
1245 @end example
1247 @noindent
1248 will guess the appropriate command to print @file{paper.ms} and then
1249 print it to the command line after adding the @option{-Tdvi} option.
1250 For direct execution, enclose the call to @code{grog} in backquotes on
1251 the @acronym{UNIX} shell prompt:
1253 @example
1254 `grog -Tdvi paper.ms` > paper.dvi
1255 @end example
1257 @noindent
1258 As seen in the example, it is still necessary to redirect the output to
1259 something meaningful (i.e.@: either a file or a pager program like
1260 @code{less}).
1264 @node Tutorial for Macro Users, Macro Packages, Invoking groff, Top
1265 @chapter Tutorial for Macro Users
1266 @cindex tutorial for macro users
1267 @cindex macro tutorial for users
1268 @cindex user's tutorial for macros
1269 @cindex user's macro tutorial
1271 Most users tend to use a macro package to format their papers.  This
1272 means that the whole breadth of @code{groff} is not necessary for most
1273 people.  This chapter covers the material needed to efficiently use a
1274 macro package.
1276 @menu
1277 * Basics::                      
1278 * Common Features::             
1279 @end menu
1282 @node Basics, Common Features, Tutorial for Macro Users, Tutorial for Macro Users
1283 @section Basics
1284 @cindex basics
1286 This section covers some of the basic concepts necessary to understand
1287 how to use a macro package.@footnote{This section is derived from
1288 @cite{Writing Papers with nroff using -me} by Eric P.@w{ }Allman.}
1289 References are made throughout to more detailed information, if desired.
1291 @code{gtroff} reads an input file prepared by the user and outputs a
1292 formatted document suitable for publication or framing.  The input
1293 consists of text, or words to be printed, and embedded commands
1294 (@dfn{requests} and @dfn{escapes}), which tell @code{gtroff} how to
1295 format the output.  For more detail on this @pxref{Embedded Commands}.
1297 The word @dfn{argument} is used in this manual to mean a word or number
1298 which appears on the same line as a request which modifies the meaning
1299 of that request.  For example, the request
1301 @example
1303 @end example
1305 @noindent
1306 spaces one line, but
1308 @example
1309 .sp 4
1310 @end example
1312 @noindent
1313 spaces four lines.  The number@w{ }4 is an argument to the @code{sp}
1314 request which says to space four lines instead of one.  Arguments are
1315 separated from the request and from each other by spaces.  More details
1316 on this can be found in @ref{Request Arguments}.
1318 The primary function of @code{gtroff} is to collect words from input
1319 lines, fill output lines with those words, justify the right hand margin
1320 by inserting extra spaces in the line, and output the result.  For
1321 example, the input:
1323 @example
1324 Now is the time
1325 for all good men
1326 to come to the aid
1327 of their party.
1328 Four score and seven
1329 years ago,...
1330 @end example
1332 @noindent
1333 will be read, packed onto output lines, and justified to produce:
1335 @quotation
1336 Now is the time for all good men to come to the aid of their party.
1337 Four score and seven years ago,...
1338 @end quotation
1340 @cindex break
1341 @cindex line break
1342 Sometimes a new output line should be started even though the current
1343 line is not yet full; for example, at the end of a paragraph.  To do
1344 this it is possible to cause a @dfn{break}, which starts a new output
1345 line.  Some requests cause a break automatically, as do blank input
1346 lines and input lines beginning with a space.
1348 Not all input lines are text to be formatted.  Some of the input lines
1349 are requests which describe how to format the text.  Requests always
1350 have a period (@samp{.}) or an apostrophe (@samp{'}) as the first
1351 character of the input line.
1353 The text formatter also does more complex things, such as automatically
1354 numbering pages, skipping over page boundaries, putting footnotes in the
1355 correct place, and so forth.
1357 Here a few hints for preparing text for input to @code{gtroff}.  First,
1358 keep the input lines short.  Short input lines are easier to edit, and
1359 @code{gtroff} will pack words onto longer lines anyhow.  In keeping with
1360 this, it is helpful to begin a new line after every period, comma, or
1361 phrase, since common corrections are to add or delete sentences or
1362 phrases.  Secondly, do not hyphenate words at the end of
1363 lines---@code{gtroff} is smart enough to hyphenate words for the user as
1364 needed, but is not smart enough to take hyphens out and join a word back
1365 together.  Also, words such as ``mother-in-law'' should not be broken
1366 over a line, since then a space can occur where not wanted, such as
1367 ``@w{mother- in}-law''.
1369 @findex ls
1370 @cindex double spacing
1371 @cindex spacing
1372 @code{gtroff} will double space output text automatically if using the
1373 request @w{@samp{.ls 2}}.  Single spaced mode can be reactivated by
1374 typing @w{@samp{.ls 1}}.
1376 A number of requests allow to change the way the output looks, sometimes
1377 called the @dfn{layout} of the output page.  Most of these requests
1378 adjust the placing of @dfn{white space} (blank lines or spaces).
1380 @findex bp
1381 @cindex new page
1382 The @samp{.bp} request starts a new page, causing a line break.
1384 @findex sp
1385 @cindex blank lines
1386 @cindex empty lines
1387 @cindex lines, empty
1388 The request @w{@samp{.sp @var{N}}} leaves @var{N}@w{ }lines of blank
1389 space.  @var{N}@w{ }can be omitted (meaning skip a single line) or can
1390 be of the form @var{N}i (for @var{N}@w{ }inches) or @var{N}c (for
1391 @var{N}@w{ }centimeters).  For example, the input:
1393 @example
1394 .sp 1.5i
1395 My thoughts on the subject
1397 @end example
1399 @noindent
1400 leaves one and a half inches of space, followed by the line ``My
1401 thoughts on the subject'', followed by a single blank line.
1403 @findex ce
1404 @cindex centering lines
1405 @cindex lines, centering
1406 Text lines can be centered by using the @code{ce} request.  The line
1407 after @code{ce} is centered (horizontally) on the page.  To center more
1408 than one line, use @w{@samp{.ce @var{N}}} (where @var{N} is the number
1409 of lines to center), followed by the @var{N}@w{ }lines.  To center many
1410 lines without counting them, type:
1412 @example
1413 .ce 1000
1414 lines to center
1415 .ce 0
1416 @end example
1418 @noindent
1419 The @w{@samp{.ce 0}} request tells @code{groff} to center zero more
1420 lines, in other words, stop centering.
1422 @findex br
1423 @cindex line break
1424 @cindex break
1425 All of these requests cause a break; that is, they always start a new
1426 line.  To start a new line without performing any other action, use
1427 @code{br}.
1430 @node Common Features,  , Basics, Tutorial for Macro Users
1431 @section Common Features
1432 @cindex common features
1433 @cindex features, common
1435 @code{gtroff} provides very low level operations for formatting a
1436 document.  There are many common routine operations which are done in
1437 all documents.  These common operations are written into @dfn{macros}
1438 and collected into a @dfn{macro package}.
1440 All macro packages provide certain common capabilities which fall into
1441 the following categories.
1443 @subsection Paragraphs
1444 @cindex paragraphs
1446 One of the most common and most used capability is starting a paragraph.
1447 There are a number of different types of paragraphs, any of which can be
1448 initiated with macros supplied by the macro package.  Normally,
1449 paragraphs start with a blank line and the first line indented, like the
1450 text in this manual.  There are also block style paragraphs, which omit
1451 the indentation:
1453 @example
1454 Some   men  look   at  constitutions   with  sanctimonious
1455 reverence, and deem them like the ark of the covenant, too
1456 sacred to be touched.
1457 @end example
1459 @noindent
1460 And there are also indented paragraphs which begin with a tag or label
1461 at the margin and the remaining text indented.
1463 @example
1464 one   This is  the first paragraph.  Notice  how the first
1465       line of  the resulting  paragraph lines up  with the
1466       other lines in the paragraph.
1467 longlabel
1468       This  paragraph   had  a  long   label.   The  first
1469       character of text on the first line will not line up
1470       with  the  text  on  second  and  subsequent  lines,
1471       although they will line up with each other.
1472 @end example
1474 A variation of this is a bulleted list.
1475 @c XXX description
1477 @subsection Sections and Chapters
1479 Most macro packages supply some form of section headers.  The simplest
1480 kind is simply the heading on a line by itself in bold type.  Others
1481 supply automatically numbered section heading or different heading
1482 styles at different levels.  Some, more sophisticated, macro packages
1483 supply macros for starting chapters and appendices.
1485 @subsection Headers and Footers
1487 Every macro package gives some way to manipulate the headers and
1488 footers (or @dfn{titles}) on each page.  Some packages will allow for
1489 different ones on the even and odd pages (for material printed in a book
1490 form).
1492 The titles are called three-part titles, that is, there is a
1493 left-justified part, a centered part, and a right-justified part.  An
1494 automatically generated page number may be put in any of these fields
1495 with the @samp{%} character (@pxref{Page Layout} for more details).
1497 @subsection Page Layout
1499 Most macro packages let thte user specify top and bottom margins and
1500 other details about the appearance of the printed pages.
1502 @subsection Displays
1503 @cindex displays
1505 Displays are sections of text to be set off from the body of the paper.
1506 Major quotes, tables, and figures are types of displays, as are all the
1507 examples used in this document.
1509 @cindex quotes, major
1510 @cindex major quotes
1511 @dfn{Major quotes} are quotes which are several lines long, and hence
1512 are set in from the rest of the text without quote marks around them.
1514 @cindex list
1515 A @dfn{list} is an indented, single spaced, unfilled display.  Lists
1516 should be used when the material to be printed should not be filled and
1517 justified like normal text, such as columns of figures or the examples
1518 used in this paper.
1520 @cindex keep
1521 A @dfn{keep} is a display of lines which are kept on a single page if
1522 possible.  An example for a keep might be a diagram.  Keeps differ from
1523 lists in that lists may be broken over a page boundary whereas keeps
1524 will not.
1526 @cindex keep, floating
1527 @cindex floating keep
1528 Floating keeps move relative to the text.  Hence, they are good for
1529 things which will be referred to by name, such as ``See figure@w{ }3''.
1530 A floating keep will appear at the bottom of the current page if it will
1531 fit; otherwise, it will appear at the top of the next page.  Meanwhile,
1532 the surrounding text will `flow' around the keep, thus leaving now blank
1533 areas.
1535 @subsection Footnotes and annotations
1536 @cindex footnotes
1537 @cindex annotations
1539 There are a number of requests to save text for later printing.
1541 @dfn{Footnotes} are printed at the bottom of the current page.
1543 @cindex delayed text
1544 @dfn{Delayed text} is very similar to a footnote except that it is
1545 printed when called for explicitly.  This allows a list of references to
1546 appear (for example) at the end of each chapter, as is the convention in
1547 some disciplines.
1549 Most macro packages which supply this functionality also supply a means
1550 of automatically numbering either type of annotation.
1552 @subsection Table of Contents
1553 @cindex table of contents
1554 @cindex contents, table of
1556 @dfn{Tables of contents} are a type of delayed text having a tag
1557 (usually the page number) attached to each entry after a row of dots.
1558 The table accumulates throughout the paper until printed, usually after
1559 the paper has ended.  Many macro packages will provide the ability to
1560 have several tables of contents (i.e.@: one standard one, one for
1561 tables, etc).
1563 @subsection Indices
1564 @cindex index
1566 While some macro packages will use the term @dfn{index}, none actually
1567 provide that functionality.  The facilities they call indices are
1568 actually more appropriate for tables of contents.
1570 @subsection Paper formats
1571 @cindex paper formats
1573 Some macro packages provide stock formats for various kinds of
1574 documents.  Many of them provide a common format for the title and
1575 opening pages of a technical paper.  The @file{mm} macros in particular
1576 provide formats for letters and memoranda.
1578 @subsection Multiple Columns
1580 Some macro packages (except @file{man}) provide the ability to have two
1581 or more columns on a page.
1583 @subsection Font and Size changes
1585 The built-in font and size functions are not always intuitive, so all
1586 macro packages provide macros to make these operations simpler.
1588 @subsection Predefined Strings
1590 Most macro packages provide various predefined strings for a variety of
1591 uses; examples are sub- and superscripts, printable dates, quotes and
1592 various special characters.
1594 @subsection Preprocessor Support
1596 All macro packages provide support for the various preprocessors.
1598 @subsection Configuration and Customization
1600 Some macro packages provide means of customizing many of details of how
1601 the package behaves.  This ranges from setting the default type size to
1602 changing the appearance of section headers.
1606 @node Macro Packages, Programming Tutorial, Tutorial for Macro Users, Top
1607 @chapter Macro Packages
1608 @cindex macro packages
1609 @cindex packages, macros
1611 This chapter documents the main macro packages that come with
1612 @code{groff}.
1614 @menu
1615 * man::                         
1616 * mdoc::                        
1617 * ms::                          
1618 * me::                          
1619 * mm::                          
1620 @end menu
1623 @node man, mdoc, Macro Packages, Macro Packages
1624 @section @file{man}
1625 @cindex @file{man}
1626 @cindex manual pages
1627 @pindex tmac.an
1628 @pindex tmac.man
1630 This is the most popular and probably the most important macro package
1631 of @code{groff}.  It is easy to use, and a vast majority of manual pages
1632 are based on it.
1634 @menu
1635 * Man options::                 
1636 * Man usage::                   
1637 * Man font macros::             
1638 * Miscellaneous man stuff::     
1639 @end menu
1641 @node Man options, Man usage, man, man
1642 @subsection Options
1644 The command line format for using the @file{man} macros with
1645 @code{groff} is:
1647 @c XXX document @TMAC_AN_PREFIX@
1649 @example
1650 groff -m man [ -rC1 ] [ -rD1 ] [ -rP @var{nnn} ] [ -rX @var{nnn} ]
1651       [ @var{files}@dots{} ] 
1652 @end example
1654 It is possible to use @samp{-man} instead of @w{@samp{-m man}}.
1656 @table @code
1657 @item -rC1
1658 If more than one manual page is given on the command line, number the
1659 pages continuously, rather than starting each at@w{ }1.
1660 @item -rD1
1661 Double-sided printing.  Footers for even and odd pages are formatted
1662 differently.
1663 @item -rP @var{nnn}
1664 Enumeration of pages will start with @var{nnn} rather than with@w{ }1.
1665 @item -rX @var{nnn}
1666 After page @var{nnn}, number pages as @var{nnn}a, @var{nnn}b,
1667 @var{nnn}c, etc.  For example, the option @option{-rX2} will produce the
1668 following page numbers: 1, 2, 2a, 2b, 2c, etc.
1669 @end table
1671 @node Man usage, Man font macros, Man options, man
1672 @subsection Usage
1674 @pindex man.local
1675 This section describes the available macros for manual pages.  For
1676 further customization, put additional macros and requests into the file
1677 @file{man.local} which will be loaded immediately after @file{tmac.an}.
1679 @maindex TH
1680 @Defmac{TH, title section [@var{extra1}] [@var{extra2}] [@var{extra3}]}
1681 Sets the title of the man page to @var{title} and the section to
1682 @var{section}, which must take on a value between 1 and@w{ }8.  The
1683 value @var{section} may also have a string appended, e.g.@: @samp{.pm},
1684 to indicate a specific subsection of the man pages.
1686 Both @var{title} and @var{section} are positioned at the left and right
1687 in the header line (with @var{section} in parentheses immediately
1688 appended to @var{title}.  @var{extra1} will be positioned in the middle
1689 of the footer line.  @var{extra2} will be positioned at the left in the
1690 footer line (resp.@: at the left on even pages and at the right on odd
1691 pages if double-sided printing is active).  @var{extra3} is centered in
1692 the header line.
1694 For @acronym{HTML} output, headers and footers are completely supressed.
1696 Additionally, this macro starts a new page; the new line number is@w{ }1
1697 again (except if the @option{-rC1} option is given on the command
1698 line)---this feature is intended only for formatting multiple man pages;
1699 a single man page should contain exactly one @code{TH} macro at the
1700 beginning of the file.
1701 @end_Defmac
1703 @maindex SH
1704 @Defmac{SH, [@var{heading}]}
1705 Sets up an unnumbered section heading sticking out to the left.  Prints
1706 out all the text following @code{SH} up to the end of the line (resp.@:
1707 the text in the next line if there is no argument to @code{SH}) in bold
1708 face, at a default size of 9@w{ }point.  Additionally, the left margin
1709 for the following text is reset to its default value.
1710 @end_Defmac
1712 @maindex SS
1713 @Defmac{SS, [@var{heading}]}
1714 Sets up an unnumbered section heading.  Prints out all the text
1715 following @code{SS} up to the end of the line (resp.@: the text in the
1716 next line if there is no argument to @code{SS}) in bold face, at a
1717 default size of 10@w{ }point.  Additionally, the left margin for the
1718 following text is reset to its default value.
1719 @end_Defmac
1721 @maindex TP
1722 @Defmac{TP, [@var{nnn}]}
1723 Sets up an indented paragraph with label.  The indentation is set to
1724 @var{nnn} if that argument is supplied (the default unit is @samp{n} if
1725 omitted), otherwise it is set to the default indentation value.
1727 The first line of text following this macro is interpreted as a string
1728 to be printed flush-left, as it is appropriate for a label.  It is not
1729 interpreted as part of a paragraph, so there is no attempt to fill the
1730 first line with text from the following input lines.  Nevertheless, if
1731 the label is not as wide as the indentation, then the paragraph starts
1732 at the same line (but indented), continuing on the following lines.  If
1733 the label is wider than the indentation, then the descriptive part of
1734 the paragraph begins on the line following the label, entirely indented.
1735 Note that neither font shape nor font size of the label is set to a
1736 default value; on the other hand, the rest of the text will have default
1737 font settings.
1738 @end_Defmac
1740 @maindex LP
1741 @maindex PP
1742 @maindex P
1743 @Defmac{LP}
1744 @Defmacx{PP}
1745 @Defmacx{P}
1746 These macros are mutual aliases.  Any of them causes a line break at the
1747 current position, followed by a vertical space downwards by the amount
1748 specified by the @code{PD} macro.  The font size and shape are reset to
1749 the default value (10@dmn{pt} resp.@: Roman).  Finally, the current left
1750 margin is restored.
1751 @end_Defmac
1753 @maindex IP
1754 @Defmac{IP, [@var{designator}] [@var{nnn}]}
1755 Sets up an indented paragraph, using @var{designator} as a tag to mark
1756 its beginning.  The indentation is set to @var{nnn} if that argument is
1757 supplied (default unit is @samp{n}), otherwise the default indentation
1758 value is used.  Font size and face of the paragraph (but not the
1759 designator) are reset to its default values.  To start an indented
1760 paragraph with a particular indentation but without a designator, use
1761 @samp{""} (two doublequotes) as the first argument of @code{IP}.
1763 For example, to start a paragraph with bullets as the designator and
1764 4@dmn{en} indentation, write
1766 @example
1767 .IP \(bu 4
1768 @end example
1769 @end_Defmac
1771 @maindex HP
1772 @Defmac{HP, [@var{nnn}]}
1773 Sets up a paragraph with hanging left indentation.  The indentation is
1774 set to @var{nnn} if that argument is supplied (default unit is
1775 @samp{n}), otherwise the default indentation value is used.  Font size
1776 and face are reset to its default values.
1777 @end_Defmac
1779 @maindex RS
1780 @Defmac{RS, [@var{nnn}]}
1781 This macro moves the left margin to the right by the value @var{nnn} if
1782 specified (default unit is @samp{n}); otherwise the default indentation
1783 value is used.  Calls to the @code{RS} macro can be nested.
1784 @end_Defmac
1786 @maindex RE
1787 @Defmac{RE, [@var{nnn}]}
1788 This macro moves the left margin back to level @var{nnn}; if no argument
1789 is given, it moves one level back.  The first level (i.e., no call to
1790 @code{RS} yet) has number@w{ }1, and each call to @code{RS} increases
1791 the level by@w{ }1.
1792 @end_Defmac
1794 @maindex SH
1795 @maindex SS
1796 @maindex TP
1797 @maindex LP
1798 @maindex PP
1799 @maindex P
1800 @maindex IP
1801 @maindex HP
1802 To summarize, the following macros cause a line break with the insertion
1803 of vertical space (which amount can be changed with the @code{PD}
1804 macro): @code{SH}, @code{SS}, @code{TP}, @code{LP} (@code{PP},
1805 @code{P}), @code{IP}, and @code{HP}.
1807 @maindex RS
1808 @maindex RE
1809 The macros @code{RS} and @code{RE} also cause a break but no insertion
1810 of vertical space.
1812 @node Man font macros, Miscellaneous man stuff, Man usage, man
1813 @subsection Macros to set fonts
1815 The standard font is Roman; the default text size is 10@w{ }point.
1817 @maindex SM
1818 @Defmac{SM, [@var{text}]}
1819 Causes the text on the same line or the text on the next line to appear
1820 in a font that is one point size smaller than the default font.
1821 @end_Defmac
1823 @maindex SB
1824 @Defmac{SB, [@var{text}]}
1825 Causes the text on the same line or the text on the next line to appear
1826 in boldface font, one point size smaller than the default font.
1827 @end_Defmac
1829 @maindex BI
1830 @Defmac{BI, text}
1831 Causes text on the same line to appear alternately in bold face and
1832 italic.  The text must be on the same line as the macro call.  Thus
1834 @example
1835 .BI this "word and" that
1836 @end example
1838 @noindent
1839 would cause `this' and `that' to appear in bold face, while `word and'
1840 appears in italics.
1841 @end_Defmac
1843 @maindex IB
1844 @Defmac{IB, text}
1845 Causes text to appear alternately in italic and bold face.  The text
1846 must be on the same line as the macro call.
1847 @end_Defmac
1849 @maindex RI
1850 @Defmac{RI, text}
1851 Causes text on the same line to appear alternately in roman and italic.
1852 The text must be on the same line as the macro call.
1853 @end_Defmac
1855 @maindex IR
1856 @Defmac{IR, text}
1857 Causes text on the same line to appear alternately in italic and roman.
1858 The text must be on the same line as the macro call.
1859 @end_Defmac
1861 @maindex BR
1862 @Defmac{BR, text}
1863 Causes text on the same line to appear alternately in bold face and
1864 roman.  The text must be on the same line as the macro call.
1865 @end_Defmac
1867 @maindex RB
1868 @Defmac{RB, text}
1869 Causes text on the same line to appear alternately in roman and bold
1870 face.  The text must be on the same line as the macro call.
1871 @end_Defmac
1873 @maindex R
1874 @Defmac{R, [@var{text}]}
1875 Causes @var{text} to appear in roman font.  If no text is present on the
1876 line where the macro is called, then the text of the next line appears
1877 in roman.  This is the default font to which text is returned at the end
1878 of processing of the other macros.
1879 @end_Defmac
1881 @maindex B
1882 @Defmac{B, [@var{text}]}
1883 Causes @var{text} to appear in bold face.  If no text is present on the
1884 line where the macro is called, then the text of the next line appears
1885 in bold face.
1886 @end_Defmac
1888 @maindex I
1889 @Defmac{I, [@var{text}]}
1890 Causes @var{text} to appear in italic.  If no text is present on the
1891 line where the macro is called, then the text of the next line appears
1892 in italic.
1893 @end_Defmac
1895 @node Miscellaneous man stuff,  , Man font macros, man
1896 @subsection Miscellaneous
1898 @pindex grohtml
1899 @cindex @file{man}, default indentation
1900 @cindex default indentation, @file{man}
1901 The default indentation is 7.2@dmn{n} for all output devices except for
1902 @code{grohtml} which uses 1.2@dmn{i} instead.
1904 @maindex DT
1905 @maindex TH
1906 @Defmac{DT}
1907 Sets tabs every 0.5@w{ }inches.  Since this macro is always called
1908 during a @code{TH} request, it makes sense to call it only if the tab
1909 positions have been changed.
1910 @end_Defmac
1912 @maindex PD
1913 @Defmac{PD, [@var{nnn}]}
1914 Adjusts the empty space before a new paragraph (resp.@: section).  The
1915 optional argument gives the amount of space (default units are
1916 @samp{v}); without parameter, the value is reset to its default value
1917 (1@w{ }line for tty devices, 0.4@dmn{v}@w{ }otherwise).
1918 @end_Defmac
1920 @maindex SH
1921 @maindex SS
1922 @maindex TP
1923 @maindex LP
1924 @maindex PP
1925 @maindex P
1926 @maindex IP
1927 @maindex HP
1928 This affects the macros @code{SH}, @code{SS}, @code{TP}, @code{LP}
1929 (resp.@: @code{PP} and @code{P}), @code{IP}, and @code{HP}.
1931 The following strings are defined:
1933 @maindex \*S
1934 @Defmac{\\*S}
1935 Switch back to the default font size.
1936 @end_Defmac
1938 @maindex \*R
1939 @Defmac{\\*R}
1940 The `registered' sign.
1941 @end_Defmac
1943 @maindex \*(Tm
1944 @Defmac{\\*(Tm}
1945 The `trademark' sign.
1946 @end_Defmac
1948 @maindex \*(lq
1949 @maindex \*(rq
1950 @glindex lq
1951 @glindex rq
1952 @Defmac{\\*(lq}
1953 @Defmacx{\\*(rq}
1954 Left and right quote.
1955 This is equal to @code{\(lq} and @code{\(rq}, respectively.
1956 @end_Defmac
1958 @cindex preprocessor, calling convention
1959 @cindex calling convention of preprocessors
1960 If a preprocessor like @code{gtbl} or @code{geqn} is needed, it has
1961 become usage to make the first line of the man page look like this:
1963 @example
1964 .\" @var{word}
1965 @end example
1967 @pindex geqn
1968 @pindex grefer
1969 @pindex gtbl
1970 @pindex man
1971 Note the single space character after the double quote.  @var{word}
1972 consists of letters for the needed preprocessors: @samp{e} for
1973 @code{geqn}, @samp{r} for @code{grefer}, @samp{t} for @code{gtbl}.
1974 Modern implementations of the @code{man} program read this first line
1975 and automatically call the right preprocessor(s).
1978 @node mdoc, ms, man, Macro Packages
1979 @section @file{mdoc}
1980 @cindex @file{mdoc}
1982 @c XXX documentation
1985 @node ms, me, mdoc, Macro Packages
1986 @section @file{ms}
1987 @cindex @file{ms}
1989 @c XXX documentation
1992 @node me, mm, ms, Macro Packages
1993 @section @file{me}
1994 @cindex @file{me}
1996 @c XXX documentation
1999 @node mm,  , me, Macro Packages
2000 @section @file{mm}
2001 @cindex @file{mm}
2003 @c XXX documentation
2007 @node Programming Tutorial, Preprocessors, Macro Packages, Top
2008 @chapter Programming Tutorial
2009 @cindex programming tutorial
2010 @cindex tutorial for programming
2012 This chapter covers @strong{all} of the facilities of @code{gtroff}.
2013 Users of macro packages may skip it if not interested in details.
2016 @menu
2017 * Text::                        
2018 * Input Conventions::           
2019 * Measurements::                
2020 * Expressions::                 
2021 * Identifiers::                 
2022 * Embedded Commands::           
2023 * Registers::                   
2024 * Manipulating Filling and Adjusting::  
2025 * Manipulating Hyphenation::    
2026 * Manipulating Spacing::        
2027 * Tabs and Fields::             
2028 * Character Translations::      
2029 * Line Layout::                 
2030 * Page Layout::                 
2031 * Page Control::                
2032 * Fonts::                       
2033 * Sizes::                       
2034 * Strings::                     
2035 * Conditionals and Loops::      
2036 * Writing Macros::              
2037 * Page Motions::                
2038 * Drawing Requests::            
2039 * Traps::                       
2040 * Diversions::                  
2041 * Environments::                
2042 * I/O::                         
2043 * Postprocessor Access::        
2044 * Miscellaneous::               
2045 * Debugging::                   
2046 * Implementation Differences::  
2047 * Summary::                     
2048 @end menu
2051 @node Text, Input Conventions, Programming Tutorial, Programming Tutorial
2052 @section Text
2053 @cindex text
2055 @code{gtroff} input files contain text with control commands
2056 interspersed throughout.  But, even without control codes, @code{gtroff}
2057 will still do several things with the input text: filling and adjusting,
2058 adding additional space after sentences, hyphenating and inserting
2059 implicit line breaks.
2061 @menu
2062 * Filling and Adjusting::       
2063 * Hyphenation::                 
2064 * Sentences::                   
2065 * Tab Stops::                   
2066 * Implicit Line Breaks::        
2067 @end menu
2069 @node Filling and Adjusting, Hyphenation, Text, Text
2070 @subsection Filling and Adjusting
2071 @cindex filling and adjusting
2072 @cindex adjusting and filling
2074 When @code{gtroff} reads in text it collects words from input and fits
2075 as many of them together on one output line as it can.  This is known as
2076 @dfn{filling}.
2078 @cindex leading spaces
2079 @cindex spaces, leading
2080 @cindex extra spaces
2081 @cindex spaces, extra
2082 @cindex trailing spaces
2083 @cindex spaces, trailing
2084 Once @code{gtroff} has a @dfn{filled} line it will try to @dfn{adjust}
2085 it.  Which means it will widen the spacing between words until the text
2086 reaches the right margin (in the default adjustment mode).  Extra spaces
2087 between words are preserved, but spaces at the end of lines are ignored.
2088 Spaces at the front of a line will cause a @dfn{break} (breaks will be
2089 explained in @ref{Implicit Line Breaks})
2091 @xref{Manipulating Filling and Adjusting}.
2093 @node Hyphenation, Sentences, Filling and Adjusting, Text
2094 @subsection Hyphenation
2095 @cindex hyphenation
2097 Since the odds of finding a set of words, for every output line, which
2098 will fit nicely on a line without inserting excessive amounts of space
2099 between words is not great, @code{gtroff} will hyphenate words so that
2100 lines can be justified without there being too much space between words.
2101 It uses an internal hyphenation algorithm (a simplified version of the
2102 algorithm used within @TeX{}) to indicate which words can be hyphenated
2103 and how to do so.  When a word is hyphenated the first part of the word
2104 will be added to the current filled line being output (with an attached
2105 hyphen), and the other portion will be added to the next line to be
2106 filled.
2108 @xref{Manipulating Hyphenation}.
2110 @node Sentences, Tab Stops, Hyphenation, Text
2111 @subsection Sentences
2112 @cindex sentences
2114 Although it is often debated, some typesetting rules say there should be
2115 different amounts of space after various punctuation marks.  For
2116 example, the @emph{Chicago typsetting manual} says that a period at the
2117 end of a sentence should have twice as much space following it as would
2118 a comma or a period as part of an abbreviation.
2120 @c XXX exact citation of Chigago manual
2122 @cindex sentence space
2123 @cindex space between sentences
2124 @cindex french-spacing
2125 @code{gtroff} does this by flagging certain characters (normally
2126 @samp{!}, @samp{?} and @samp{.}) as @dfn{end of sentence} characters.
2127 When @code{gtroff} encounters one of these characters at the end of a
2128 line it will append two @dfn{sentence spaces} in the formatted output.
2129 (Thus, one of the conventions mentioned in @ref{Input Conventions}.)
2131 @cindex transparent characters
2132 @cindex character, transparent
2133 @glindex dg
2134 @glindex rq
2135 @cindex "
2136 @cindex '
2137 @cindex )
2138 @cindex ]
2139 @cindex *
2140 In addition, the following characters resp.@: glyphs are treated
2141 transparently while handling end of sentence characters: @samp{"},
2142 @samp{'}, @samp{)}, @samp{]}, @samp{*}, @code{dg}, and @code{rq}.
2144 See the @code{cflags} request in @ref{Using Symbols}, for more details.
2146 @findex \&
2147 To prevent the insertion of extra space after an end of sentence
2148 character (at the end of a line), append @code{\&}.
2151 @node Tab Stops, Implicit Line Breaks, Sentences, Text
2152 @subsection Tab Stops
2153 @cindex tab stops
2154 @cindex stops, tabulator
2155 @cindex tab character
2156 @cindex character, tabulator
2158 @code{gtroff} translates @dfn{tabulator characters}, also called
2159 @dfn{tabs} (normally code point @code{0x09}), in the input into
2160 movements to the next tabulator stop.  These tab stops are initially
2161 located every half inch across the page.  Using this simple tables can
2162 easily be made.  However, it can often be deceptive as the appearance
2163 (and width) of the text on a terminal and the results from @code{gtroff}
2164 can vary greatly.
2166 Also, a possible sticking point is that lines beginning with tab
2167 characters will still be filled, again producing unexpected results.
2168 For example, the following input
2170 @multitable {12345678} {12345678} {12345678} {12345678}
2171 @item
2172 @tab 1 @tab 2 @tab 3
2173 @item
2174 @tab   @tab 4 @tab 5
2175 @end multitable
2177 @noindent
2178 will produce
2180 @multitable {12345678} {12345678} {12345678} {12345678} {12345678} {12345678} {12345678}
2181 @item
2182 @tab 1 @tab 2 @tab 3 @tab   @tab 4 @tab 5
2183 @end multitable
2185 @xref{Tabs and Fields}.
2187 @node Implicit Line Breaks,  , Tab Stops, Text
2188 @subsection Implicit Line Breaks
2189 @cindex implicit line breaks
2190 @cindex line, implicit breaks
2191 @cindex break
2192 @cindex break, implicit
2193 @cindex line break
2195 An important concept in @code{gtroff} is the @dfn{break}.  When a break
2196 occurs, @code{gtroff} will output the partially filled line
2197 (unjustified), and resume collecting and filling text on the next output
2198 line.
2200 @cindex blank line
2201 @cindex empty line
2202 @cindex line, blank
2203 There are several ways to cause a break in @code{gtroff}.  A blank line
2204 will not only cause a break, but it will also cause a one line vertical
2205 space (effectively a blank line) to be output.
2207 A line which begins with a space will cause a break and the space will
2208 be output at the beginning of the next line.  Note that this space isn't
2209 adjusted, even in fill mode.
2211 The end of file will also cause a break---otherwise the last line of the
2212 document may vanish!
2214 Certain requests also cause breaks, implicitly or explicitly.  This will
2215 be discussed in @ref{Manipulating Filling and Adjusting}.
2218 @node Input Conventions, Measurements, Text, Programming Tutorial
2219 @section Input Conventions
2220 @cindex input conventions
2221 @cindex conventions for input
2223 Since @code{gtroff} does filling automatically, it is traditional in
2224 @code{groff} not to try and type things in as nicely formatted
2225 paragraphs.  These are some conventions commonly used when typing
2226 @code{gtroff} text:
2228 @itemize @bullet{}
2229 @item
2230 Break lines after punctuation, particularly at the end of sentences,
2231 and in other logical places.  Keep separate phrases on lines by
2232 themselves, as entire phrases are often added or deleted when editing.
2233 @item
2234 Try to keep lines less than 40-60@w{ }characters, to allow space for
2235 inserting more text.
2236 @item
2237 Do not try to do any formatting in a @acronym{WYSIWYG} manner (i.e.,
2238 don't try and use spaces to get proper indentation).
2239 @end itemize
2242 @node Measurements, Expressions, Input Conventions, Programming Tutorial
2243 @section Measurements
2244 @cindex measurements
2246 @cindex units of measurement
2247 @cindex basic units
2248 @cindex machine units
2249 @cindex measurement units
2250 @cindex @code{u} unit
2251 @cindex unit, @code{u}
2252 @code{gtroff} (like any other programs) requires numeric parameters to
2253 specify various measurements.  Most numeric parameters@footnote{those
2254 that specify vertical or horizontal motion or a type size} may have a
2255 @dfn{measurement unit} attached.  These units are specified as a single
2256 character which immediately follows the number or expression.  Each of
2257 these units are understood, by @code{gtroff}, to be a multiple of its
2258 @dfn{basic unit}.  So, whenever a different measurement unit is
2259 specified @code{gtroff} converts this into its @dfn{basic units}.  This
2260 basic unit, represented by a @samp{u}, is a device dependent measurement
2261 which is quite small, ranging from 1/75th to 1/72000th of an inch.  The
2262 values may be given as fractional numbers---nevertheless, fractional
2263 basic units are always rounded to integers.
2265 Some of the measurement units are completely independent of any of the
2266 current settings (e.g.@: type size) of @code{gtroff}.
2268 @table @code
2269 @item i
2270 @cindex inch
2271 @cindex @code{i} unit
2272 @cindex unit, @code{i}
2273 Inches.  An antiquated measurement unit still in use in certain
2274 backwards countries.  One inch is equal to@w{ }2.54@dmn{cm}.
2275 @item c
2276 @cindex centimeter
2277 @cindex @code{c} unit
2278 @cindex unit, @code{c}
2279 Centimeters.  One centimeter is equal to@w{ }0.3937@dmn{in}.
2280 @item p
2281 @cindex points
2282 @cindex @code{p} unit
2283 @cindex unit, @code{p}
2284 Points.  This is a typesetter's measurement used for measure type size.
2285 It is 72@w{ }points to an inch.
2286 @item P
2287 @cindex pica
2288 @cindex @code{P} unit
2289 @cindex unit, @code{P}
2290 Pica.  Another typesetting measurement.  6@w{ }Picas to an inch (and
2291 12@w{ }points to a pica).
2292 @item s
2293 @itemx z
2294 @cindex @code{s} unit
2295 @cindex unit, @code{s}
2296 @cindex @code{z} unit
2297 @cindex unit, @code{z}
2298 @xref{Fractional Type Sizes}, for a discussion of these units.
2299 @end table
2301 The other measurements understood by @code{gtroff} are dependent on
2302 settings currently in effect in @code{gtroff}.  These are very useful
2303 for specifying measurements which should look proper with any size of
2304 text.
2306 @table @code
2307 @item m
2308 @cindex em unit
2309 @cindex @code{m} unit
2310 @cindex unit, @code{m}
2311 Ems.  This unit is equal to the current font size in points.  So called
2312 because it is @emph{approximately} the width of the letter@w{ }@samp{m}
2313 in the current font.
2314 @item n
2315 @cindex en unit
2316 @cindex @code{n} unit
2317 @cindex unit, @code{n}
2318 Ens.  This is half of an em.
2319 @item v
2320 @cindex vertical space
2321 @cindex space, vertical
2322 @cindex @code{v} unit
2323 @cindex unit, @code{v}
2324 Vertical space.  This is equivalent to the current line spacing.
2325 @xref{Sizes}, for more information about this.
2326 @item M
2327 @cindex @code{M} unit
2328 @cindex unit, @code{M}
2329 100ths of an em.
2330 @end table
2332 @xref{Fractional Type Sizes}.
2334 @menu
2335 * Default Units::               
2336 @end menu
2338 @node Default Units,  , Measurements, Measurements
2339 @subsection Default Units
2340 @cindex default units
2341 @cindex units, default
2343 Many requests take a default unit.  While this can be helpful at times,
2344 it can cause strange errors in some expressions.  For example, the line
2345 length request expects em units.  Here are several attempts to get a
2346 line length of 3.5@w{ }inches and the results:
2348 @example
2349 3.5i      @result{}   3.5i
2350 7/2       @result{}   0i
2351 7/2i      @result{}   0i
2352 7i/2      @result{}   0.1i
2353 7i/2u     @result{}   3.5i
2354 @end example
2356 @noindent
2357 Everything will be converted to basic units first.  In the above example
2358 it is assumed that 1@dmn{i} equals@w{ }240@dmn{u}, and 1@dmn{m}
2359 equals@w{ }10@dmn{p} (thus 1@dmn{m} equals@w{ }33@dmn{u}).  The value
2360 7i/2 will be first handled as 7i/2m, then converted to 1680u/66u which
2361 is 25@dmn{u}, and this is approximately 0.1@dmn{i}.
2363 As a conclusion, the safest way to specify measurements is to always
2364 attach a scaling indicator.  If you want to multiply or divide by a
2365 certain scalar value, use @samp{u} as the unit for that value.
2368 @node Expressions, Identifiers, Measurements, Programming Tutorial
2369 @section Expressions
2370 @cindex expressions
2372 @code{gtroff} has most of operators common to other languages:
2374 @c XXX more details; examples
2376 @itemize @bullet
2377 @item
2378 @cindex arithmetic operators
2379 @cindex operators, arithmetic
2380 @opindex +
2381 @opindex -
2382 @opindex /
2383 @opindex *
2384 @opindex %
2385 Arithmetic: @samp{+} (addition), @samp{-} (subtraction), @samp{/}
2386 (division), @samp{*} (multiplication), @samp{%} (modulo).
2388 @code{gtroff} only provides integer arithmetic.  The internal type used
2389 for computing results is @samp{int}, which is usually a 32@dmn{bit}
2390 signed integer.
2391 @item
2392 @cindex comparison operators
2393 @cindex operators, comparison
2394 @opindex <
2395 @opindex >
2396 @opindex >=
2397 @opindex <=
2398 @opindex =
2399 @opindex ==
2400 Comparison: @samp{<} (less than), @samp{>} (greater than), @samp{<=}
2401 (less than or equal), @samp{>=} (greater than or equal), @samp{=}
2402 (equal), @samp{==} (the same as @samp{=}).
2403 @item
2404 @cindex logical operators
2405 @cindex operators, logical
2406 @opindex &
2407 @opindex :
2408 Logical: @samp{&} (logical and), @samp{:} (logical or).
2409 @item
2410 @cindex unary operators
2411 @cindex operators, unary
2412 @opindex -
2413 @opindex +
2414 @opindex !
2415 @findex if
2416 @findex while
2417 Unary operators: @samp{-} (negating, i.e.@: changing the sign), @samp{+}
2418 (just for completeness; does nothing in expressions), @samp{!} (logical
2419 not; this works only within @code{if} and @code{while} requests).  See
2420 below for the use of unary operators in motion requests.
2421 @item
2422 @cindex extremum operators
2423 @cindex operators, extremum
2424 @opindex >?
2425 @opindex <?
2426 Extrema: @samp{>?} (maximum), @samp{<?} (minimum).  For example,
2427 @samp{5>?3} yields@w{ }@samp{5}.
2428 @c XXX add examples
2429 @item
2430 @cindex scaling operator
2431 @cindex operator, scaling
2432 Scaling: @code{(@var{c};@var{e})}.  Evaluate @var{e} using @var{c} as
2433 the default scaling indicator.  If @var{c} is missing, ignore scaling
2434 indicators in the evaluation of @var{e}.
2435 @end itemize
2437 @cindex parentheses
2438 @cindex order of evaluation in expressions
2439 @cindex expression, order of evaluation
2440 @opindex (
2441 @opindex )
2442 Parentheses may be used as in any other language.  However, in
2443 @code{gtroff} they are necessary to ensure order of evaluation.
2444 @code{gtroff} has no operator precedence; expressions are evaluated left
2445 to right.  This means that @samp{3+5*4} is evaluated as if it were
2446 parenthesized like @samp{(3+5)*4}, not as @samp{3+(5*4)}, as expected.
2448 @opindex +
2449 @opindex -
2450 @opindex |
2451 @cindex motion operators
2452 @cindex operators, motion
2453 For many requests which cause a motion on the page, the unary operators
2454 work differently.  The @samp{+} and @samp{-} operators then indicate a
2455 motion relative to the current position (down or up, respectively), and
2456 the @samp{|} operator indicates an absolute position on the page or
2457 input line.
2458 @c XXX xref
2459 @samp{+} and @samp{-} are also treated differently by the following
2460 requests and escapes: @code{bp}, @code{in}, @code{ll}, @code{lt},
2461 @code{nm}, @code{nr}, @code{pl}, @code{pn}, @code{po}, @code{ps},
2462 @code{rt}, @code{ti}, @code{\R}, and @code{\s}.  Here the plus and minus
2463 signs indicate increments resp.@: decrements.
2465 @c XXX add more xref
2466 @xref{Setting Registers}.
2468 @cindex space characters in expressions
2469 @cindex expressions and space characters
2470 Due to the way arguments are parsed, spaces are not allowed in
2471 expressions, unless the entire expression is surrounded by parentheses.
2473 @xref{Request Arguments}, and @ref{Conditionals and Loops}.
2476 @node Identifiers, Embedded Commands, Expressions, Programming Tutorial
2477 @section Identifiers
2478 @cindex identifiers
2480 Like any other language, @code{gtroff} has rules for properly formed
2481 @dfn{identifiers}.  In @code{gtroff}, an identifier can be made up of
2482 almost any printable character.  The exception are the following
2483 characters:
2485 @itemize @bullet
2486 @cindex whitespace characters
2487 @cindex newline character
2488 @cindex character, whitespace
2489 @item
2490 Whitespace characters (space, tabs, and newlines).
2491 @cindex character, backspace
2492 @cindex backspace character
2493 @item
2494 Backspace (@code{0x08}) and character code @code{0x01}.
2495 @cindex illegal input characters
2496 @cindex input characters, illegal
2497 @cindex characters, illegal input
2498 @cindex unicode
2499 @item
2500 The following input characters are illegal and will be ignored, causing
2501 a warning message: @code{0x00}, @code{0x0B}, @code{0x0D}-@code{0x1F},
2502 @code{0x80}-@code{0x9F}.  Currently, some of these reserved codepoints
2503 are used internally, thus making it non-trivial to extend @code{gtroff}
2504 to cover Unicode or other character sets resp.@: encodings which use
2505 characters of these ranges.
2507 Note that illegal characters will be removed before parsing; an
2508 identifier `foo', followed by an illegal character, followed by `bar'
2509 will be treated as `foobar'.
2510 @end itemize
2512 For example, any of the following is valid.
2514 @example
2518 end-list
2520 @end example
2522 @findex ]
2523 Note that identifiers longer than two characters with a closing bracket
2524 (@samp{]}) in its name can't be accessed with escape sequences which
2525 expect an identifier as a parameter.
2527 @c XXX xref
2529 @Deffn{Escape, \\A, ident}
2530 Whether an identifier @var{ident} is valid in @code{gtroff} can be
2531 tested with the @code{\A} escape.  It expands to the character@w{ }1
2532 or@w{ }0 according to whether its argument (delimited by quotes usually)
2533 is or is not acceptable as the name of a string, macro, diversion,
2534 number register, environment, or font.  It will return@w{ }0 if no
2535 argument is given.  This is useful for looking up user input in some
2536 sort of associative table.
2538 @example
2539 \A'end-list'
2540     @result{} 1
2541 @end example
2542 @end_Deffn
2544 @xref{Escapes}, for details on parameter delimiting characters.
2546 @c XXX add xrefs above
2548 Identifiers in @code{gtroff} can be any length, but, in some contexts,
2549 @code{gtroff} needs to be told where identifiers end and text begins
2550 (and in different ways depending on their length).
2552 @findex (
2553 @findex [
2554 @findex ]
2555 @itemize @bullet{}
2556 @item
2557 Single character.
2558 @item
2559 Two characters.  Must be prefixed with @samp{(} in some situations.
2560 @item
2561 Arbitrary length (@code{gtroff} only).  Must be bracketed with @samp{[}
2562 and@w{ }@samp{]} in some situations.  Any length identifier can be put
2563 in brackets.
2564 @end itemize
2566 @cindex undefined identifiers
2567 @cindex indentifiers, undefined
2568 Unlike many other programming languages, undefined identifiers are
2569 silently ignored or expanded to nothing.
2571 @c XXX add info about -ww command line option.
2573 @xref{Interpolating Registers}, and @ref{Strings}.
2576 @node Embedded Commands, Registers, Identifiers, Programming Tutorial
2577 @section Embedded Commands
2578 @cindex embedded commands
2579 @cindex commands, embedded
2581 Most documents need more functionality beyond filling, adjusting and
2582 implicit line breaking.  In order to gain further functionality,
2583 @code{gtroff} allows commands to be embedded into the text, in two ways.
2585 The first is a @dfn{request} which takes up an entire line, and does
2586 some large scale operation (e.g.@: break lines, start new pages).
2588 The other is an @dfn{escape} which can be embedded anywhere in the text,
2589 or even as an argument to a request.
2590 @c XXX (Not always?)
2591 Escapes generally do more minor operations like sub- and superscripts,
2592 print a symbol, etc.
2594 @menu
2595 * Requests::                    
2596 * Macros::                      
2597 * Escapes::                     
2598 @end menu
2600 @node Requests, Macros, Embedded Commands, Embedded Commands
2601 @subsection Requests
2602 @cindex requests
2604 @cindex control character
2605 @cindex character, control
2606 @findex '
2607 @findex .
2608 A request line begins with a control character, which is either a single
2609 quote (@samp{'}) or a period (@samp{.}).  These can be changed; see
2610 @ref{Character Translations}, for details.  After this there may be
2611 optional tabs or spaces followed by an identifier which is the name of
2612 the request.  This may be followed by any number of space-separated
2613 arguments.
2615 @cindex zero width space character
2616 @cindex character, zero width space
2617 @cindex space character, zero width
2618 @findex \&
2619 To begin a line with a control character without it being interpreted,
2620 precede it with @code{\&}.  This represents a zero width space, which
2621 means it will not affect the output.
2623 In most cases the period is used as a control character.  Several
2624 requests will cause a break; using the single quote control character
2625 will prevent this.
2627 @menu
2628 * Request Arguments::           
2629 @end menu
2631 @node Request Arguments,  , Requests, Requests
2632 @subsubsection Request Arguments
2633 @cindex request arguments
2634 @cindex arguments to requests
2636 Arguments to requests (and macros) are processed much like the shell:
2637 The line is split into arguments according to spaces.  An argument which
2638 is intended to contain spaces can either be enclosed in quotes (single
2639 or double), or have the spaces @dfn{escaped} with backslashes.
2641 @example
2642 .uh The Mouse Problem
2643 .uh "The Mouse Problem"
2644 .uh The\ Mouse\ Problem
2645 @end example
2647 @findex \~
2648 @findex \@key{SP}
2649 @noindent
2650 The first line is the @code{uh} macro being called with 3 arguments,
2651 @samp{The}, @samp{Mouse}, and @samp{Problem}.  The latter two have the
2652 same effect or calling the @code{uh} macro with one argument @samp{The
2653 Mouse Problem}.@footnote{The last solution, i.e., using escaped spaces,
2654 is `classical' in the sense that it can be found in most @code{troff}
2655 documents.  Nevertheless, it is not optimal in all situations since
2656 @w{@samp{\ }} inserts a fixed-width, non-breaking space character which
2657 can't stretch.  @code{gtroff} provides a different command @code{\~} to
2658 insert a stretchable, non-breaking space.}
2660 @findex ds
2661 Note, however, that the @code{ds} request works differently.
2662 @xref{Strings}, for more details.
2664 @node Macros, Escapes, Requests, Embedded Commands
2665 @subsection Macros
2666 @cindex macros
2668 @code{gtroff} has a @dfn{macro} facility for defining a series of lines
2669 which can be invoked by name.  They are called in the same manner as
2670 requests---arguments also may be passed in the same manner.
2672 @xref{Writing Macros}, and @ref{Request Arguments}.
2674 @node Escapes,  , Macros, Embedded Commands
2675 @subsection Escapes
2676 @cindex escapes
2678 Escapes may occur anywhere in the input to @code{gtroff}.  They begin
2679 with a backslash usually and are followed by a single character which
2680 indicates the function to be performed.  The escape character can be
2681 changed; see @ref{Character Translations}.
2683 @findex (
2684 @findex [
2685 @findex ]
2686 Escape sequences which require an identifier as a parameter accept three
2687 possible syntax forms.
2689 @itemize @bullet
2690 @item
2691 The next single character is the identifier.
2692 @item
2693 If this single character is an opening parenthesis, take the following
2694 two characters as the identifier.  Note that there is no closing
2695 parenthesis after the identifier.
2696 @item
2697 If this single character is an opening bracket, take all characters
2698 until a closing bracket as the identifier.
2699 @end itemize
2701 @noindent
2702 Examples:
2704 @example
2706 \n(XX
2707 \*[TeX]
2708 @end example
2710 @findex '
2711 @cindex argument delimiting characters
2712 @cindex characters, argument delimiting
2713 @cindex delimiting characters for arguments
2714 Other escapes may require several arguments and/or some special format.
2715 In such cases the argument is traditionally enclosed in single quotes
2716 (and quotes are always used in this manual for the definitions of escape
2717 sequences).  The enclosed text is then processed according to what that
2718 escape expects.  Example:
2720 @example
2721 \l'1.5i\(bu'
2722 @end example
2724 @findex \o
2725 @findex \b
2726 @findex \X
2727 Note that the quote character can be replaced with any other character
2728 which does not occur in the argument (even a newline or a space
2729 character) in the following escapes: @code{\o}, @code{\b}, and
2730 @code{\X}.  This makes e.g.
2732 @example
2733 A caf
2738 in Paris
2739   @result{} A caf@'e in Paris
2740 @end example
2742 @noindent
2743 possible, but it is better not to use this feature to avoid confusion.
2745 @findex \%
2746 @findex \@key{SP}
2747 @findex \|
2748 @findex \^
2749 @findex \@{
2750 @findex \@}
2751 @findex \'
2752 @findex \`
2753 @findex \-
2754 @findex \_
2755 @findex \!
2756 @findex \?
2757 @findex \@@
2758 @findex \)
2759 @findex \/
2760 @findex \,
2761 @findex \&
2762 @findex \~
2763 @findex \0
2764 @findex \a
2765 @findex \c
2766 @findex \d
2767 @findex \e
2768 @findex \E
2769 @findex \p
2770 @findex \r
2771 @findex \t
2772 @findex \u
2773 The following escapes sequences (which are handled similarly to
2774 characters since they don't take a parameter) are also allowed as
2775 delimiters: @code{\%}, @w{@samp{\ }}, @code{\|}, @code{\^}, @code{\@{},
2776 @code{\@}}, @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!},
2777 @code{\?}, @code{\@@}, @code{\)}, @code{\/}, @code{\,}, @code{\&},
2778 @code{\~}, @code{\0}, @code{\a}, @code{\c}, @code{\d}, @code{\e},
2779 @code{\E}, @code{\p}, @code{\r}, @code{\t}, and @code{\u}.  Again, don't
2780 use these if possible.
2782 @findex \A
2783 @findex \Z
2784 @findex \C
2785 @findex \w
2786 No newline characters as delimiters are allowed in the following
2787 escapes: @code{\A}, @code{\Z}, @code{\C}, and @code{\w}.
2789 @findex \D
2790 @findex \h
2791 @findex \H
2792 @findex \l
2793 @findex \L
2794 @findex \N
2795 @findex \R
2796 @findex \s
2797 @findex \S
2798 @findex \v
2799 @findex \x
2800 Finally, the escapes @code{\D}, @code{\h}, @code{\H}, @code{\l},
2801 @code{\L}, @code{\N}, @code{\R}, @code{\s}, @code{\S}, @code{\v}, and
2802 @code{\x} can't use the following characters as delimiters:
2804 @itemize @bullet
2805 @cindex numbers
2806 @cindex digits
2807 @item
2808 The digits @code{0}-@code{9}.
2809 @cindex operators
2810 @opindex +
2811 @opindex -
2812 @opindex /
2813 @opindex *
2814 @opindex %
2815 @opindex <
2816 @opindex >
2817 @opindex =
2818 @opindex &
2819 @opindex :
2820 @opindex (
2821 @opindex )
2822 @opindex .
2823 @item
2824 The (single character) operators @samp{+-/*%<>=&:().}.
2825 @item
2826 @cindex space character
2827 @cindex character, space
2828 @cindex tab character
2829 @cindex character, tab
2830 @cindex newline character
2831 @cindex character, newline
2832 The space, tab, and newline characters.
2833 @findex \%
2834 @findex \@{
2835 @findex \@}
2836 @findex \'
2837 @findex \`
2838 @findex \-
2839 @findex \_
2840 @findex \!
2841 @findex \@@
2842 @findex \/
2843 @findex \c
2844 @findex \e
2845 @findex \p
2846 @item
2847 All escape sequences except @code{\%}, @code{\@{}, @code{\@}},
2848 @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!}, @code{\@@},
2849 @code{\/}, @code{\c}, @code{\e}, and @code{\p}.
2850 @end itemize
2852 @findex \\
2853 @findex \e
2854 @findex \E
2855 To have a backslash appear in the output several escapes are defined:
2856 @code{\\}, @code{\e} or @code{\E}.  These are very similar, and only
2857 differ with respect to being used in macros or diversions.
2858 @xref{Copy-in Mode}, and @ref{Diversions}, for more information.
2860 @xref{Identifiers}.
2862 @menu
2863 * Comments::                    
2864 @end menu
2866 @node Comments,  , Escapes, Escapes
2867 @subsubsection Comments
2868 @cindex comments
2870 Probably one of the most@footnote{Unfortunately, this is a lie.  But
2871 hopefully future @code{gtroff} hackers will believe it :-)} common forms
2872 of escapes is the comment.
2874 @Deffn{Escape, \\"}
2875 Start a comment.  Everything to the end of the input line is ignored.
2877 This may sound simple, but it can be tricky to keep the comments from
2878 interfering with the appearance of the final output.
2880 @findex ds
2881 If the escape is to the right of some text or a request, that portion of
2882 the line will be ignored, but the space leading up to it will be noticed
2883 by @code{gtroff}.  This only affects the @code{.ds} request.
2884 @c XXX (any others?)
2886 One possibly irritating idiosyncracy is that tabs must not be used to
2887 line up comments.  Tabs are not treated as white space between the
2888 request and macro arguments.
2890 @cindex undefined request
2891 @cindex request, undefined
2892 A comment on a line by itself will be treated as a blank line, because
2893 after eliminating the comment, that is all that remains:
2895 @example
2896 Test
2897 \" comment
2898 Test
2899 @end example
2901 @noindent
2902 will produce
2904 @example
2905 Test
2907 Test
2908 @end example
2910 As a consequence, it is common to start the line with @code{.\"} which
2911 will cause the line to be treated as an undefined request and thus
2912 ignored completely.
2914 @findex '
2915 Another commenting scheme seen sometimes is three consecutive single
2916 quotes (@code{'''}) at the beginning of a line.  This works, but
2917 @code{gtroff} will give a warning about an undefined macro (namely
2918 @code{''}), which is harmless, but irritating.
2919 @end_Deffn
2921 @Deffn{Escape, \\#}
2922 Now to avoid all this @code{gtroff} has a new comment mechanism using
2923 the @code{\#} escape.  This escape works the same as @code{\"} except
2924 that the newline is also ignored:
2926 @example
2927 Test
2928 \# comment
2929 Test
2930 @end example
2932 @noindent
2933 will produce
2935 @example
2936 Test Test
2937 @end example
2939 @noindent
2940 as expected.
2941 @end_Deffn
2943 @findex ig
2944 For large blocks of text, the @code{ig} request may be useful.
2946 @c XXX definition of .ig
2948 @xref{Strings}.
2950 @node Registers, Manipulating Filling and Adjusting, Embedded Commands, Programming Tutorial
2951 @section Registers
2952 @cindex registers
2954 Numeric variables in @code{gtroff} are called @dfn{registers}.  There
2955 are a number of built-in registers, supplying anything from the date to
2956 details of formatting parameters.
2958 @xref{Identifiers}, for details on register identifiers.
2960 @menu
2961 * Setting Registers::           
2962 * Interpolating Registers::     
2963 * Auto-increment::              
2964 * Assigning Formats::           
2965 * Built-in Registers::          
2966 @end menu
2968 @node Setting Registers, Interpolating Registers, Registers, Registers
2969 @subsection Setting Registers
2970 @cindex setting registers
2971 @cindex registers, setting
2973 Registers are defined resp.@: set via the @code{nr} request or the
2974 @code{\R} escape.
2976 @Deffn{Request, nr, ident value}
2977 @Deffnx{Escape, \\R, ident value}
2978 Set number register @var{ident} to @var{value}.  If @var{ident} doesn't
2979 exist, it will be created.
2980 @end_Deffn
2982 For example, the following two lines are equivalent:
2984 @example
2985 .nr a 1
2986 \R'a 1'
2987 @end example
2989 Both @code{nr} and @code{\N} have two additional special forms to
2990 increment resp.@: decrement a register.
2992 @Deffn{Request, nr, ident +value}
2993 @Deffnx{Request, nr, ident -value}
2994 @Deffnx{Escape, \\N, ident +value}
2995 @Deffnx{Escape, \\N, ident -value}
2996 Increment (decrement) register @var{ident} by @var{value}.
2998 @example
2999 .nr a 1
3000 .nr a +1
3002     @result{} 2
3003 @end example
3005 To assign the negated value of a register to another register, some care
3006 must be taken to get the desired result:
3008 @example
3009 .nr a 7
3010 .nr b 3
3011 .nr a -\nb
3013     @result{} 4
3014 .nr a (-\nb)
3016     @result{} -3
3017 @end example
3019 @noindent
3020 The surrounding parentheses prevent the interpretation of the minus sign
3021 as a decrementing operator.
3022 @end_Deffn
3024 @Deffn{Request, rr, ident}
3025 Remove number register @var{ident}.
3026 @end_Deffn
3028 @Deffn{Request, rnn, ident1 ident2}
3029 Rename number register @var{ident1} to @var{ident2}.
3030 @end_Deffn
3032 @Deffn{Request, aln, ident1 ident2}
3033 This request creates an alias @var{ident1} for a number register
3034 @var{ident2}.  The new name and the old name will be exactly equivalent.
3035 If @var{ident1} is undefined, a warning of type @samp{reg} will be
3036 generated, and the request will be ignored.  @xref{Debugging}, for
3037 information about warnings.
3038 @end_Deffn
3040 @node Interpolating Registers, Auto-increment, Setting Registers, Registers
3041 @subsection Interpolating Registers
3042 @cindex interpolating registers
3043 @cindex registers, interpolating
3045 Numeric registers can be accessed via the @code{\n} escape.
3047 @Deffn{Escape, \\n, ident}
3048 @c XXX is the following correct?
3049 Interpolate number register @var{ident}.  This means that the value of
3050 the register is expanded in-place while @code{gtroff} is parsing the
3051 input line.
3053 @example
3054 .nr a 5
3055 .nr as \na+\na
3056 \n(as
3057     @result{} 10
3058 @end example
3059 @end_Deffn
3061 @node Auto-increment, Assigning Formats, Interpolating Registers, Registers
3062 @subsection Auto-increment
3063 @cindex auto-increment
3064 @cindex increment, automatic
3066 Number registers can also be auto-incremented and auto-decremented.  The
3067 increment resp.@: decrement factor can be specified with a third
3068 argument to the @code{nr} request or @code{\N} escape.
3070 @Deffn{Request, nr, ident value incr}
3071 @Deffnx{Escape, \\N, ident value incr}
3072 Set number register @var{ident} to @var{value}; the increment for
3073 auto-incrementing is set to @var{incr}.
3074 @end_Deffn
3076 To activate auto-incrementing, the escape @code{\n} has a special syntax
3077 form.
3079 @Deffn{Escape, \\n, +ident}
3080 @Deffnx{Escape, \\n, -ident}
3081 Before interpolating, increment resp.@: decrement @var{ident} by the
3082 auto-increment value as specified with the @code{nr} request (or the
3083 @code{\N} escape).  If no auto-increment value has been specified, both
3084 syntax forms are identical to @code{\n}.
3085 @end_Deffn
3087 For example,
3089 @example
3090 .nr a 0 1
3091 .nr xx 0 5
3092 .nr foo 0 -2
3093 \n+a, \n+a, \n+a, \n+a, \n+a
3095 \n-(xx, \n-(xx, \n-(xx, \n-(xx, \n-(xx
3097 \n+[foo], \n+[foo], \n+[foo], \n+[foo], \n+[foo]
3098 @end example
3100 @noindent
3101 produces
3103 @example
3104 1, 2, 3, 4, 5
3105 -5, -10, -15, -20, -25
3106 -2, -4, -6, -8, -10
3107 @end example
3109 To change the increment value without changing the value of a register,
3110 the following can be used.
3112 @example
3113 .nr a \na 10
3114 @end example
3116 @node Assigning Formats, Built-in Registers, Auto-increment, Registers
3117 @subsection Assigning Formats
3118 @cindex assigning formats
3119 @cindex formats, assigning
3121 When a register is used in the text of an input file (as opposed to part
3122 of an expression) it is textually replaced (or interpolated) with a
3123 representation of that number.  This output format can be changed to a
3124 variety of formats (numbers, Roman numerals, etc).  This is done using
3125 the @code{af} request.
3127 @Deffn{Request, af, ident format}
3129 Change the output format of a number register.  The first argument
3130 @var{ident} is the name of the number register to be changed, and the
3131 second argument @var{format} is the output format.  The following output
3132 formats are available:
3134 @table @code
3135 @item 1
3136 This is the default format, decimal numbers: 1, 2, 3,@w{ }@dots{}
3137 @item 0@dots{}01
3138 Decimal numbers with as many leading zeros as specified.  So, @samp{01}
3139 would result in 01, 02, 03,@w{ }@dots{}
3140 @item I
3141 @cindex roman numerals
3142 @cindex numerals, Roman
3143 Upper-case Roman numerals: 0, I, II, III, IV,@w{ }@dots{}
3144 @item i
3145 Lower-case Roman numerals: 0, i, ii, iii, iv,@w{ }@dots{}
3146 @item A
3147 Upper-case letters: A, B, C, @dots{},@w{ }Z, AA, AB,@w{ }@dots{}
3148 @item a
3149 Lower-case letters: a, b, c, @dots{},@w{ }z, aa, ab,@w{ }@dots{}
3150 @end table
3152 The following example will produce @samp{10, X, j, 010}:
3154 @example
3155 .nr a 10
3156 .af a 1           \" the default format
3157 \na,
3158 .af a I
3159 \na,
3160 .af a a
3161 \na,
3162 .af a 001
3164 @end example
3165 @end_Deffn
3167 @Deffn{Escape, \\g, ident}
3168 Return the current format of the specified register @var{ident}.  For
3169 example, @samp{\ga} after the previous example would produce the string
3170 @samp{001}.  If the register hasn't been defined yet, nothing is
3171 returned.
3172 @end_Deffn
3174 @node Built-in Registers,  , Assigning Formats, Registers
3175 @subsection Built-in Registers
3176 @cindex built-in registers
3177 @cindex registers, built-in
3179 The following lists some built-in registers which are not described
3180 elsewhere in this manual.  Any register which begin with a @samp{.} is
3181 read-only.  A complete listing of all built-in registers can be found in
3182 @ref{Register Index}.
3184 @table @code
3185 @item .H
3186 @cindex horizontal resolution
3187 @cindex resolution, horizontal
3188 @vindex .H
3189 Horizontal resolution in basic units.
3190 @item .V
3191 @cindex vertical resolution
3192 @cindex resolution, vertical
3193 @vindex .V
3194 Vertical resolution in basic units.
3195 @item dw
3196 @cindex day of the week
3197 @cindex date, day of the week
3198 @vindex dw
3199 Day of the week (1-7).
3200 @item dy
3201 @cindex day of the month
3202 @cindex date, day of the month
3203 @vindex dy
3204 Day of the month (1-31).
3205 @item mo
3206 @cindex month of the year
3207 @cindex date, month of the year
3208 @vindex mo
3209 Current month (1-12).
3210 @item year
3211 @cindex date, year
3212 @cindex year, current
3213 @vindex year
3214 The current year.
3215 @item yr
3216 @vindex yr
3217 The current year minus@w{ }1900.  Unfortunately, the documentation of
3218 @acronym{UNIX} Version@w{ }7's @code{troff} had a year@w{ }2000 bug: It
3219 incorrectly claimed that @code{yr} contains the last two digits of the
3220 year.  That claim has never been true of either traditional @code{troff}
3221 or GNU @code{troff}.  Old @code{troff} input that looks like this:
3223 @example
3224 '\" The following line stopped working after 1999
3225 This document was formatted in 19\n(yr.
3226 @end example
3228 @noindent
3229 can be corrected as follows:
3231 @example
3232 This document was formatted in \n[year].
3233 @end example
3235 @noindent
3236 or, to be portable to older @code{troff} versions, as follows:
3238 @example
3239 .nr y4 1900+\n(yr
3240 This document was formatted in \n(y4.
3241 @end example
3243 @item .c
3244 @vindex .c
3245 @itemx c.
3246 @vindex c.
3247 @cindex input line number
3248 @cindex line number, input
3249 The current @emph{input} line number.  Register @samp{.c} is read-only,
3250 whereas @samp{c.} (a @code{gtroff} extension) is writable also,
3251 affecting both @samp{.c} and @samp{c.}.
3252 @item ln
3253 @vindex ln
3254 @findex nm
3255 @cindex output line number
3256 @cindex line number, output
3257 The current @emph{output} line number after a call to the @code{nm}
3258 request to activate line numbering.
3259 @c XXX xref nm request
3260 @item .x
3261 @vindex .x
3262 @cindex major version number
3263 @cindex version number, major
3264 The major version number.  For example, if the version number is@w{
3265 }1.03 then @code{.x} will contain@w{ }@samp{1}.
3266 @item .y
3267 @vindex .y
3268 @cindex minor version number
3269 @cindex version number, minor
3270 The minor version number.  For example, if the version number is@w{
3271 }1.03 then @code{.y} will contain@w{ }@samp{03}.
3272 @item .Y
3273 @vindex .Y
3274 @cindex revision number
3275 The revision number of @code{groff}.
3276 @item .g
3277 @vindex .g
3278 Always@w{ }1.  Macros should use this to determine whether they are
3279 running under GNU @code{troff}.
3280 @item .A
3281 @vindex .A
3282 If the current output device is @acronym{ASCII}, this is set to@w{ }1,
3283 zero otherwise.
3284 @item .P
3285 @vindex .P
3286 This register indicates whether the current page is actually being
3287 printed, i.e., whether the @option{-o} option is being used to only
3288 print selected pages.  @xref{Groff Options}, for more information.
3289 @end table
3292 @node Manipulating Filling and Adjusting, Manipulating Hyphenation, Registers, Programming Tutorial
3293 @section Manipulating Filling and Adjusting
3294 @cindex manipulating filling and adjusting
3295 @cindex filling and adjusting, manipulating
3296 @cindex adjusting and filling, manipulating
3297 @cindex justifying text
3298 @cindex text, justifying
3300 @cindex break
3301 @cindex line break
3302 @findex bp
3303 @findex ce
3304 @findex cf
3305 @findex fi
3306 @findex fl
3307 @findex in
3308 @findex nf
3309 @findex rj
3310 @findex sp
3311 @findex ti
3312 @findex trf
3313 Various ways of causing @dfn{breaks} were given in @ref{Implicit Line
3314 Breaks}.  The @code{br} request will likewise cause a break.  Several
3315 other requests will also cause breaks, but implicitly.  These are
3316 @code{bp}, @code{ce}, @code{cf}, @code{fi}, @code{fl}, @code{in},
3317 @code{nf}, @code{rj}, @code{sp}, @code{ti}, and @code{trf}.
3319 @Deffn{Request, br, }
3320 Break the current line, i.e., the input collected so far will be emitted
3321 without adjustment.
3322 @end_Deffn
3324 @vindex .u
3325 Initially, @code{gtroff} will fill and adjust text to both margins.
3326 Filling can be disabled via the @code{nf} request and re-enabled with
3327 the @code{fi} request.
3329 @Deffn{Request, fi, }
3330 Activate fill mode (which is the default).  This request implicitly
3331 enables adjusting; it will also cause a break in the text currently
3332 being filled.  The number register @code{.u} is set to@w{ }1.
3333 @end_Deffn
3335 @Deffn{Request, nf, }
3336 Activate no-fill mode.  Input lines are output as-is, retaining line
3337 breaks.  The current line length will be ignored.  This command
3338 implicitly disables adjusting; it also causes a break.  The number
3339 register @code{.u} will be set to@w{ }0.
3340 @end_Deffn
3342 @Deffn{Request, ad, [@var{mode}]}
3343 Enable adjusting.  @var{mode} can have one of the following values:
3345 @table @code
3346 @item l
3347 @cindex ragged-right
3348 Adjust text to the left margin.  This produces what is traditionally
3349 called ragged-right text.
3350 @item r
3351 @cindex ragged-left
3352 Adjust text to the right margin, producing ragged-left text.
3353 @item c
3354 @cindex centered text
3355 Center filled text.
3356 @c XXX difference to .ce?
3357 @item b
3358 @itemx n
3359 Justify to both margins.  This is default of @code{gtroff}.
3360 @end table
3362 With no argument, @code{gtroff} will adjust lines the same way before
3363 adjusting has been deactivated (with a call to @code{na}, for example).
3365 @example
3366 text
3367 .ad r
3368 text
3369 .ad c
3370 text
3372 text
3373 .ad  \" back to centering
3374 text
3375 @end example
3377 @vindex .j
3378 The current adjustment mode is available in the number register
3379 @code{.j}; it can be stored and subsequently used to set adjustment.
3380 @end_Deffn
3382 @Deffn{Request, na, }
3383 Disable adjusting.  This request won't change the current adjustment
3384 mode: A call to @code{ad} afterwards will use the previous adjustment
3385 setting.
3386 @end_Deffn
3388 @findex \p
3389 The escape @code{\p} will cause a break and the remaining text to be
3390 adjusted.
3392 @cindex word space size
3393 @cindex size of word space
3394 @cindex space between words
3395 @cindex sentence space size
3396 @cindex size of sentence space
3397 @cindex space between sentences
3398 @findex ss
3399 The @code{ss} request changes the minimum size of a space between filled
3400 words.  It takes its units as one twelfth of the space width parameter
3401 for the current font.  Initially both the word space size and the
3402 sentence space size are@w{ }12.
3404 If two arguments are given to the @code{ss} request, the second argument
3405 gives the sentence space size.  If the second argument is not given, the
3406 sentence space size will be the same as the word space size.  The
3407 sentence space size is used in two circumstances: If the end of a
3408 sentence occurs at the end of a line in fill mode, then both an
3409 inter-word space and a sentence space will be added; if two spaces
3410 follow the end of a sentence in the middle of a line, then the second
3411 space will be a sentence space.  Note that the behaviour of
3412 @acronym{UNIX} @code{troff} will be exactly that exhibited by GNU
3413 @code{troff} if a second argument is never given to the @code{ss}
3414 request.  In GNU @code{troff}, as in @acronym{UNIX} @code{troff}, a
3415 sentence should always be followed with either a newline or two spaces.
3417 @vindex .ss
3418 @vindex .sss
3419 The number registers @code{.ss} and @code{.sss} are the values of the
3420 parameters set by the first and second arguments of the @code{ss}
3421 request.
3423 @findex ce
3424 @cindex centering lines
3425 @cindex lines, centering
3426 The @code{ce} request will center text.  While the @w{@samp{ad c}}
3427 request will also center text, it has the side effect of filling the
3428 text.  The @code{.ce} request will not fill the text it affects.  This
3429 request causes a break.
3431 With no arguments, @code{ce} will fill the next line of text.  The
3432 single argument @code{ce} takes is a number indicating the number of
3433 lines to be centered.  If the argument is zero, centering is disabled.
3435 A common idiom is to turn on centering for a large number of lines, and
3436 to turn off centering after text to be centered.  This is useful for any
3437 request which takes a number of lines as an argument.
3439 @example
3440 .ce 1000
3441 replace this
3442 with
3443 something
3444 more interesting
3445 @dots{}
3446 .ce 0
3447 @end example
3449 @vindex .ce
3450 The @code{.ce} number register contains the number of lines remaining to
3451 be centered, as set by the @code{ce} request.
3453 @cindex justifying text
3454 @cindex text, justifying
3455 @cindex right-justifying
3456 @findex rj
3457 @vindex .rj
3458 A similar request is @code{rj} request which will justify unfilled text
3459 to the right margin.  Its arguments are identical to the @code{ce}
3460 request.  The @code{.rj} number register is the number of lines to be
3461 right-justified as set by the @code{rj} request.  This request causes a
3462 line break.
3465 @node Manipulating Hyphenation, Manipulating Spacing, Manipulating Filling and Adjusting, Programming Tutorial
3466 @section Manipulating Hyphenation
3467 @cindex manipulating hyphenation
3468 @cindex hyphenation, manipulating
3470 As discussed in @ref{Hyphenation}, @code{gtroff} will hyphenate words.
3471 There are a number of ways to influence how hyphenation is done.
3473 @findex nh
3474 @findex hy
3475 @vindex .hy
3476 Hyphenation can be turned off with the @code{nh} request, and turned
3477 back on with the @code{hy} request.  However, the hyphenation facilities
3478 of @code{gtroff} are far more flexible than this.  The @code{hy} request
3479 can be used to tell @code{gtroff} to restrict hyphenation to certain
3480 cases.  The request takes a single numeric argument.  The current
3481 hyphenation restrictions can be found in the number register @code{.hy}.
3483 @table @samp
3484 @item 1
3485 The default argument, which indicates to hyphenate without restrictions.
3486 @item 2
3487 Do not hyphenate the last word on a page or column.
3488 @item 4
3489 Do not hyphenate the last two characters of a word.
3490 @item 8
3491 Do not hyphenate the first two characters of a word.
3492 @end table
3494 The values in the previous table are additive.  For example, the
3495 value@w{ }12 causes @code{gtroff} to neither hyphenate the last two nor
3496 the first two characters of a word.
3498 @findex hlm
3499 @vindex .hlc
3500 @vindex .hlm
3501 @findex \%
3502 @cindex explicit hyphens
3503 @cindex hyphen, explicit
3504 The @code{hlm} request will set the maximum number of consecutive
3505 hyphenated lines to the value given as the first argument.  If this
3506 number is negative, there is no maximum.  The default value is@w{ }-1.
3507 This value is associated with the current environment.  Only lines
3508 output from an environment count towards the maximum associated with
3509 that environment.  Hyphens resulting from @code{\%} are counted;
3510 explicit hyphens are not.  The current setting of this is available in
3511 the @code{.hlm} register.  Also the number of immediately preceding
3512 consecutive hyphenated lines are available in the number register
3513 @code{.hlc}.
3515 @findex hw
3516 The @code{hw} request specifies how a specific word is to be hyphenated.
3517 It takes only one argument which is the word with hyphens at the
3518 hyphenation points.  For example:
3520 @example
3521 .hw in-sa-lub-rious
3522 @end example
3524 @noindent
3525 This request can be used more than once.
3527 @c XXX
3528 @c In old versions of troff there was a
3529 @c limited amount of space to store such information, fortunately,
3530 @c with groff, this is no longer a restriction.
3532 @findex \%
3533 @cindex hyphenation character
3534 @cindex character, hyphenation
3535 @cindex disabling hyphenation
3536 @cindex hyphenation, disabling
3537 To tell @code{gtroff} how to hyphenate words on the fly, the @code{\%}
3538 escape, also known as the @dfn{hyphenation character}, can be used.
3539 Preceding a word with this character will prevent it from being
3540 hyphenated, putting it in a word will indicate to @code{gtroff} that the
3541 word may be hyphenated at that point.  Note that this mechanism will
3542 only affect one word; to change the hyphenation of a word for the entire
3543 document, use the @code{hw} request.
3545 @findex hc
3546 The @code{hc} request changes the hyphenation character.  The character
3547 specified as an argument will then work the same as the @code{\%}
3548 escape, and, thus, no longer appear in the output.  Without an argument
3549 it will return the hyphenation character to @code{\%}.
3551 @cindex hyphenation patterns
3552 @cindex pattern for hyphenation
3553 @findex hpf
3554 To further customize hyphenation the @code{hpf} request will read in a
3555 file of hyphenation patterns.  This file will be searched for in the
3556 same way that @file{tmac.@var{name}} is searched for when the
3557 @option{-m@var{name}} option is specified.
3559 It should have the same format as the argument to the @code{\patterns}
3560 primitive in @TeX{}; the letters appearing in this file are interpreted
3561 as hyphenation codes.  A @samp{%} character in the patterns file
3562 introduces a comment that continues to the end of the line.
3564 @findex hla
3565 @findex hpf
3566 @pindex troffrc
3567 @pindex troffrc-end
3568 The set of hyphenation patterns is associated with the current language
3569 set by the @code{hla} request.  The @code{hpf} request is usually
3570 invoked by the @file{troffrc} or @file{troffrc-end} file.
3572 @findex hcode
3573 The @code{hcode} request has the following syntax:
3575 @example
3576 .hcode @var{c1 code1 c2 code2...}
3577 @end example
3579 It sets the hyphenation code of character @var{c1} to @var{code1} and
3580 that of @var{c2} to @var{code2}.  A hyphenation code must be a single
3581 input character (not a special character) other than a digit or a space.
3582 Initially each lower-case letter has a hyphenation code, which is
3583 itself, and each upper-case letter has a hyphenation code which is the
3584 lower-case version of itself.
3586 @cindex hyphenation margin
3587 @cindex margin for hyphenation
3588 @findex hym
3589 @vindex .hym
3590 The @code{hym} request will set the hyphenation margin to the value
3591 given as its argument: when the current adjustment mode is not@w{
3592 }@samp{b}, the line will not be hyphenated if the line is no more than
3593 that amount short.  The default hyphenation margin is@w{ }0.  The
3594 default scaling indicator for this request is@w{ }m.  The hyphenation
3595 margin is associated with the current environment.  The current
3596 hyphenation margin is available in the @code{.hym} register.
3598 @cindex hyphenation space
3599 @findex hys
3600 @vindex .hys
3601 The @code{hys} request sets the hyphenation space to the value given as
3602 the first argument: when the current adjustment mode is@w{ }@samp{b},
3603 don't hyphenate the line if the line can be justified by adding no more
3604 than that amount of extra space to each word space.  The default
3605 hyphenation space is@w{ }0.  The default scaling indicator for this
3606 request is@w{ }m.  The hyphenation space is associated with the current
3607 environment.  The current hyphenation space is available in the
3608 @code{.hys} register.
3610 @cindex soft hyphen character
3611 @cindex character, soft hyphen
3612 @findex shc
3613 @glindex hy
3614 The @code{shc} request will set the soft hyphen character to the
3615 character given as an argument.  If the argument is omitted, the soft
3616 hyphen character will be set to the default character @code{\(hy}.  The
3617 soft hyphen character is the character which will be inserted when a
3618 word is hyphenated at a line break.  If the soft hyphen character does
3619 not exist in the font of the character immediately preceding a potential
3620 break point, then the line will not be broken at that point.  Neither
3621 definitions (specified with the @code{char} request) nor translations
3622 (specified with the @code{tr} request) are considered when finding the
3623 soft hyphen character.
3625 @findex hla
3626 @findex hpf
3627 @findex hw
3628 @vindex .hla
3629 @pindex troffrc
3630 @pindex troffrc-end
3631 The @code{hla} request will set the current hyphenation language to that
3632 given by the first argument.  Hyphenation exceptions specified with the
3633 @code{hw} request and hyphenation patterns specified with the @code{hpf}
3634 request are both associated with the current hyphenation language.  The
3635 @code{hla} request is usually invoked by the @file{troffrc} or the
3636 @file{troffrc-end} files.  The current hyphenation language is available
3637 in the number register @code{.hla}.
3640 @node Manipulating Spacing, Tabs and Fields, Manipulating Hyphenation, Programming Tutorial
3641 @section Manipulating Spacing
3642 @cindex manipulating spacing
3643 @cindex spacing, manipulating
3645 @findex sp
3646 The @code{sp} request will cause @code{gtroff} to space downwards the
3647 distance specified as the first argument.  With no argument it will
3648 advance 1@w{ }line.  A negative argument will cause @code{gtroff} to
3649 move up the page the specified distance.  If the argument is preceded by
3650 a @samp{|} @code{gtroff} will move that distance from the top of the
3651 page.  This request causes a line break.
3653 @cindex double-spacing
3654 @findex ls
3655 @vindex .L
3656 For double or triple spaced output use @code{ls}.  This request causes
3657 @code{troff} to output @var{n}-1 blank lines after each line of text,
3658 where @var{n} is the argument given to the @code{ls} request.  With no
3659 argument @code{gtroff} will go back to single spacing.  The number
3660 register @code{.L} contains the current line spacing setting.
3662 @findex \x
3663 @vindex .a
3664 Sometimes, extra vertical spacing is only needed occasionally, i.e.@: to
3665 allow space for a tall construct (like an equation).  The @code{\x}
3666 escape will do this.  The escape is given a numerical argument (like
3667 @samp{\x'3p'}).  If this number is positive extra vertical space will be
3668 inserted below the current line.  A negative number will add space
3669 above.  If this escape is used multiple times on the same line, the
3670 maximum of the values is used.  The @code{.a} number register contains
3671 the most recent (nonnegative) extra vertical line space.
3673 @c XXX
3674 @example
3675 ... example of inline equation ...
3676 @end example
3678 @findex ns
3679 @findex rs
3680 @cindex no-space mode
3681 @cindex mode, no-space
3682 Spacing (either via @code{sp} or via blank lines) can be disabled with
3683 the @code{ns} request.  This will enable @dfn{no-space mode}.  This mode
3684 will end when actual text is output or the @code{rs} request is
3685 encountered.  No-space mode will also prevent requests to advance to the
3686 next page unless they are accompanied by a page number (@pxref{Page
3687 Control}, for more information).
3690 @node Tabs and Fields, Character Translations, Manipulating Spacing, Programming Tutorial
3691 @section Tabs and Fields
3692 @cindex tabs and fields
3693 @cindex fields and tabs
3695 @findex \t
3696 Tab stops are much like those on a typewriter: a tab character (or the
3697 @code{\t} escape) on input will cause horizontal motion to the next tab
3698 stop.
3700 @findex ta
3701 Tab stops can be changed with the @code{ta} request.  This request takes
3702 a series of numbers as arguments which indicate where each tab stop is
3703 to be (overriding any previous settings).  These can be specified
3704 absolutely, i.e.@: as the distance from the left margin.  For example,
3705 the following will set tab stops every one inch.
3707 @example
3708 .ta 1i 2i 3i 4i 5i 6i
3709 @end example
3711 Tab stops can also be specified relatively (using a leading @samp{+})
3712 which means that the specified tab stop will be set that distance from
3713 the previous tab stop.  For example, the following is equivalent to the
3714 previous example.
3716 @example
3717 .ta 1i +1i +1i +1i +1i +1i
3718 @end example
3720 After the specified tab stops repeat values may be set for tabs beyond
3721 the last one specified.  This is most commonly used to specify tabs set
3722 at equal intervals.  The complete syntax for setting tabs is
3724 @example
3725 ta @var{n1} @var{n2} @dots{} @var{nn} T @var{r1} @var{r2} @dots{} @var{rn}
3726 @end example
3728 @noindent
3729 This will set tabs at positions @var{n1}, @var{n2}, @dots{}, @var{nn}
3730 and then set tabs at @var{nn}+@var{r1}, @var{nn}+@var{r2}, @dots{},
3731 @var{nn}+@var{rn} and then at @var{nn}+@var{rn}+@var{r1},
3732 @var{nn}+@var{rn}+@var{r2}, @dots{}, @var{nn}+@var{rn}+@var{rn}, and so
3733 on.  For example the following is, yet again, the same as the previous
3734 examples.
3736 @example
3737 .ta T 1i
3738 @end example
3740 The material in each tab column may be justified to the right or left
3741 or centered in the column.  This is specified by appending an
3742 @samp{R}, @samp{L} or @samp{C} to the number specifying that tab stop.
3743 The default justification is @samp{L}.  Example:
3745 @example
3746 .ta 1i 2iC 2iR
3747 @end example
3749 @vindex .tabs
3750 The number register @code{.tabs} contains a string representation of the
3751 current tab settings suitable for use as an argument to the @code{ta}
3752 request.
3754 @findex tc
3755 Normally @code{gtroff} will fill the space to the next tab stop with
3756 spaces.  This can be change with the @code{tc} request.  With no
3757 argument @code{gtroff} will revert to using spaces.
3759 @subsection Leaders
3760 @cindex leaders
3762 @findex lc
3763 Sometimes it may may be desirable to use the @code{tc} request to fill a
3764 particular tab stop with a given character, but also normal tab stops on
3765 the rest of the line.  For this @code{gtroff} provides an alternate tab
3766 mechanism, called @dfn{leaders} which will do just that.  They are used
3767 exclusively to produce a repeated run of characters to the next tab
3768 stop.
3770 The character that will be repeated can be declared with the @code{lc}
3771 request.  Without an argument, the leaders will act the same as tabs.
3773 @findex \a
3774 Leader are invoked by using the @code{\a} escape while specifying the
3775 @code{ta} request.
3777 @cindex table of contents
3778 @cindex contents, table of
3779 For a table of contents, to name an example, tab stops may be defined so
3780 that the section number is one tab stop, the title is the second with
3781 the remaining space being filled with a line of dots, and then the page
3782 number slightly separated from the dots.
3784 @example
3785 .lc .
3786 .ta .5iR 5i +.25i
3787 1.1\tFoo\a\t12
3788 @end example
3790 @subsection Fields
3791 @cindex fields
3793 @findex fc
3794 Fields are a more general way of laying out tabular data.
3796 @code{fc}
3798 @c XXX add explanation
3800 @node Character Translations, Line Layout, Tabs and Fields, Programming Tutorial
3801 @section Character Translations
3802 @cindex character translations
3803 @cindex translations of characters
3805 @findex cc
3806 @findex c2
3807 @findex .
3808 @findex '
3809 The control character (@samp{.}) and the no-break control character
3810 (@samp{'}) can be changed with the @code{cc} and @code{c2} requests,
3811 respectively.  The single argument is the new character to be used.
3812 With no argument the normal control character is restored.
3814 @findex ec
3815 @findex eo
3816 The @code{eo} request will completely disable the escape mechanism.  The
3817 @code{ec} request can be used to change the escape character from the
3818 default @samp{\} to what is specified as an argument.  It can be also
3819 used to re-enable the escape mechanism after an @code{eo} request.
3821 @findex tr
3822 The @code{tr} request will translate characters.
3824 @c XXX more info
3826 @findex trnt
3827 @findex \!
3828 @code{trnt} is the same as the @code{tr} request except that the
3829 translations do not apply to text that is transparently throughput into
3830 a diversion with @code{\!}.  @xref{Diversions}, for more information.
3831 For example,
3833 @example
3834 .tr ab
3835 .di x
3836 \!.tm a
3839 @end example
3841 @noindent
3842 will print @samp{b}; if @code{trnt} is used instead of @code{tr} it will
3843 print @samp{a}.
3846 @node Line Layout, Page Layout, Character Translations, Programming Tutorial
3847 @section Line Layout
3848 @cindex line layout
3849 @cindex layout, line
3851 @cindex dimensions, line
3852 @cindex line dimensions
3853 The following drawing shows the dimensions which @code{gtroff} uses for
3854 placing a line of output onto the page.  They are labeled with the
3855 request which manipulates that dimension.
3857 @example
3858 @group
3859               | -->| in |<--                   |
3860            -->| po |<-----------ll------------>|
3861               +----+----+----------------------+----+
3862               |    :    :                      :    |
3863               +----+----+----------------------+----+
3864 @end group
3865 @end example
3867 @noindent
3868 These dimensions are:
3870 @ftable @code
3871 @item po
3872 @cindex left margin
3873 @cindex margin, left
3874 @cindex page offset
3875 @cindex offset, page
3876 @vindex .o
3877 @dfn{Page offset}--This is the leftmost position of text on the final
3878 output, defining the @dfn{left margin}.  It can be adjusted with the
3879 @code{po} request, and the current setting can be found in the built-in
3880 number register @code{.o}.  Note that this request does not cause a
3881 break, so changing the page offset in the middle of text being filled
3882 may not yield the expected result.
3883 @item in
3884 @cindex indentation
3885 @cindex line indentation
3886 @findex in
3887 @vindex .i
3888 @dfn{Indentation}--This is the distance from the left margin where text
3889 will be printed.  This can be adjusted with the @code{in} request, and
3890 the current setting can be found in the built-in number register.
3891 @code{.i}.  This request causes a break.
3893 @findex ti
3894 @vindex .in
3895 There is also the request @code{ti} which will cause one output line to
3896 be indented, after which the indentation returns to@w{ }0.  This request
3897 causes a break.  The number register @code{.in} is the indent that
3898 applies to the current output line.
3899 @item ll
3900 @cindex line length
3901 @cindex length of line
3902 @vindex .l
3903 @vindex .ll
3904 @dfn{Line length}--This is the distance from the left margin to right
3905 margin.  This can be adjusted with the @code{ll} request, and the
3906 current setting can be found in the built-in number register @code{.l}
3907 Note, as the figure implies, line length is not affected by the current
3908 indentation.  The number register @code{.ll} is the line length that
3909 applies to the current output line.
3910 @end ftable
3912 @example
3913 .in +.5i
3914 .ll -.5i
3915 A bunch of really boring text which should
3916 be indented from both margins.
3917 Replace me with a better (and more) example!
3918 .in -.5i
3919 .ll +.5i
3920 @end example
3923 @node Page Layout, Page Control, Line Layout, Programming Tutorial
3924 @section Page Layout
3925 @cindex page layout
3926 @cindex layout, page
3928 @code{gtroff} provides some very primitive operations for controlling
3929 page layout.
3931 @cindex page length
3932 @cindex length of page
3933 @findex pl
3934 @vindex .p
3935 The @dfn{page length} can be specified via the @code{pl} request.  This
3936 is the length of the physical output page.  The current setting can be
3937 found in the built-in number register @code{.p}.  Note that this only
3938 specifies the size of the page, not the top and bottom margins.  Those
3939 are not done by groff directly.  @xref{Traps}, for further information
3940 on how to do this.
3942 @cindex headers
3943 @cindex footers
3944 @cindex titles
3945 @code{gtroff} provides several operations which help in setting up top
3946 and bottom titles (or headers and footers)
3948 @cindex title line
3949 @cindex three-part title
3950 @findex tl
3951 @vindex %
3952 The @code{tl} request will print a @dfn{title line}, which consists of
3953 three parts: a left justified portion, a centered portion and a right
3954 justified portion.  The argument to @code{tl} is specified as
3955 @code{'@var{left}'@var{center}'@var{right}'}.  The @samp{%} character is
3956 replaced with the current page number.  This character can be changed
3957 with the @code{pc} request (see below).
3959 @cindex length of title line
3960 @cindex title line, length
3961 @findex lt
3962 @vindex .lt
3963 The title line is printed using its own line length, which is specified
3964 with the @code{lt} request.  The current setting of this is available in
3965 the @code{.lt} number register.
3967 @cindex page number
3968 @cindex number, page
3969 @findex pn
3970 The @code{pn} request will change the page number of the @emph{next}
3971 page.  The only argument is the page number.
3973 @vindex %
3974 @vindex .pn
3975 The current page number is stored in the number register @code{%}.  The
3976 number register @code{.pn} contains the number of the next page: either
3977 the value set by a @code{pn} request, or the number of the current page
3978 plus@w{ }1.
3980 @cindex changing the page number character
3981 @cindex page number character, changing
3982 @findex pc
3983 The @code{pc} request will change the page number character (used by the
3984 @code{tl} request) to a different character.  With no argument, this
3985 mechanism is disabled.
3987 @xref{Traps}.
3990 @node Page Control, Fonts, Page Layout, Programming Tutorial
3991 @section Page Control
3992 @cindex page control
3993 @cindex control, page
3995 @findex bp
3996 @findex pn
3997 To stop processing the current page, and move to the next page, invoke
3998 the @code{bp} request.  This request will also cause a break.  It can
3999 also take an argument of what the next page should be numbered.  The
4000 only difference between @code{bp} and @code{pn} is that @code{pn} does
4001 not cause a break or actually eject a page.
4003 @example
4004 .de newpage
4006 'sp .5i
4007 .tl 'left top'center top'right top'
4008 'sp .3i
4010 @end example
4012 @cindex orphan
4013 @findex ne
4014 It is often necessary to force a certain amount of space before a new
4015 page occurs.  This is most useful to make sure that there is not a
4016 single @dfn{orphan} line left at the bottom of a page.  The @code{ne}
4017 request will ensure that there is a certain distance, specified by the
4018 first argument, before the next page is triggered (@pxref{Traps}, for
4019 further information).  The default unit for @code{ne} is @code{v} and
4020 the default argument is@w{ }1@dmn{v}.
4022 For example, to make sure that no fewer than 2@w{ }lines get orphaned,
4023 do the following before each paragraph:
4025 @example
4026 .ne 2
4027 .ti +5n
4028 text
4029 @end example
4031 @findex sv
4032 @findex os
4033 @findex ne
4034 @code{sv} is similar to the @code{ne} request; it reserves the specified
4035 amount of vertical space.  If the desired amount of space exists before
4036 the next trap (bottom page boundary), the space will be output
4037 immediately.  If there is not enough space, it is stored for later
4038 output via the @code{os} request.  The default argument is@w{ }1@dmn{v}
4039 and the default unit is @code{v}.
4042 @node Fonts, Sizes, Page Control, Programming Tutorial
4043 @section Fonts
4044 @cindex fonts
4046 @findex ft
4047 @findex \f
4048 @code{gtroff} has the ability to switch fonts at any point in the text.
4049 There are two ways to do this, via the @code{ft} request and the
4050 @code{\f} escape.
4052 Fonts are generally specified as upper-case strings, which are usually
4053 1@w{ }to 4 characters representing an abbreviation or acronym of the font
4054 name.
4056 The basic set of fonts are @samp{R}, @samp{I}, @samp{B}, and @samp{BI}.
4057 These are Times Roman, Italic, Bold, and Bold Italic.  There is also at
4058 least one symbol font which contains various special symbols (Greek,
4059 mathematics).  Such symbols fonts cannot be used directly, but should be
4060 used via an escape.
4062 @menu
4063 * Changing Fonts::              
4064 * Font Families::               
4065 * Font Positions::              
4066 * Using Symbols::               
4067 * Artificial Fonts::            
4068 * Ligatures and Kerning::       
4069 @end menu
4071 @node Changing Fonts, Font Families, Fonts, Fonts
4072 @subsection Changing Fonts
4073 @cindex changing fonts
4074 @cindex fonts, changing
4076 @findex ft
4077 @cindex previous font
4078 @cindex font, previous
4079 Font changes can be done either with the @code{ft} request or the
4080 @code{\f} request.  With no arguments it will switch to the previous
4081 font (also known as @samp{P}).
4083 @example
4084 eggs, bacon,
4085 .ft B
4086 spam
4088 and sausage.
4089 @end example
4091 @findex \f
4092 The @code{\f} escape is useful for changing fonts in the middle of
4093 words:
4095 @example
4096 eggs, bacon, \fBspam\fP and sausage.
4097 @end example
4099 @noindent
4100 Both of the above examples will produce the same output.  Note the usage
4101 of @samp{P} to indicate the previous font---using @code{\f} it is not
4102 possible to omit this parameter.
4104 Sometimes when putting letters of different fonts, more or less space at
4105 such boundaries are needed.  There are two escapes to help with this.
4107 @findex \/
4108 @cindex italic correction
4109 @cindex correction, italic
4110 The @code{\/} escape increases the width of the preceding character so
4111 that the spacing between that character and the following character will
4112 be correct if the following character is a Roman character.  For
4113 example, if an italic@w{ }f is immediately followed by a Roman right
4114 parenthesis, then in many fonts the top right portion of the f will
4115 overlap the top left of the right parenthesis.  It is a good idea to use
4116 this escape sequence whenever an italic character is immediately
4117 followed by a Roman character without any intervening space.  This small
4118 amount of space is also called @dfn{italic correction}.
4120 @c XXX example
4121 @c producing @i{f}), which is ugly.  Inserting \/ produces f) and avoids
4122 @c this problem.
4124 @findex \,
4125 @cindex left italic correction
4126 @cindex correction, left italic
4127 The @code{\,} escape modifies the spacing of the following character so
4128 that the spacing between that character and the preceding character will
4129 be correct if the preceding character is a Roman character.  It is a
4130 good idea to use this escape sequence whenever a Roman character is
4131 immediately followed by an italic character without any intervening
4132 space.  In analogy to above, this space could be called @dfn{left italic
4133 correction}, but this term isn't used widely.
4135 @c XXX example
4136 @c For example, inserting \, between the parenthesis and the f changes
4137 @c (f to (f.
4139 @findex ftr
4140 @findex ft
4141 @findex ul
4142 @findex bd
4143 @findex \f
4144 @findex cs
4145 @findex tkf
4146 @findex special
4147 @findex fspecial
4148 @findex fp
4149 @findex code
4150 The @code{ftr} request will translate fonts; its syntax is
4152 @example
4153 .ftr @var{F} @var{G}
4154 @end example
4156 @noindent
4157 which translates font@w{ }@var{F} to font@w{ }@var{G}.  Whenever a font
4158 named @var{F} is referred to in a @code{\f} escape sequence, or in the
4159 @code{ft}, @code{ul}, @code{bd}, @code{cs}, @code{tkf}, @code{special},
4160 @code{fspecial}, @code{fp}, or @code{code} requests, font@w{ }@var{G} will
4161 be used.  If @var{G} is missing, or equal to @var{F} then font@w{
4162 }@var{F} will not be translated.
4164 @node Font Families, Font Positions, Changing Fonts, Fonts
4165 @subsection Font Families
4166 @cindex font families
4167 @cindex families, font
4169 Due to the variety of fonts available, @code{gtroff} has added the
4170 concept of font families.  Each of these families has four styles
4171 (@samp{R}, @samp{I}, @samp{B} and @samp{BI}).
4173 The fonts are specified as the concatenation of the font family and
4174 style.  Specifying a font without the family part will cause
4175 @code{gtroff} to use that style of the current family.  By default,
4176 @code{gtroff} uses the Times family.
4178 This way, it is possible to use the basic four fonts and to select a
4179 different font family on the command line.
4181 @findex fam
4182 @vindex .fam
4183 Font families can be switched with the @code{fam} request.  The current
4184 font family is available in the number register @code{.fam}.  This is a
4185 string-valued register.
4187 @example
4188 spam,
4189 .fam H
4190 spam,
4191 .ft B
4192 spam,
4193 .fam T
4194 spam,
4195 .ft AR
4196 baked beans,
4197 .ft R
4198 and spam.
4199 @end example
4201 @node Font Positions, Using Symbols, Font Families, Fonts
4202 @subsection Font Positions
4203 @cindex font positions
4204 @cindex positions, font
4206 For the sake of old phototypesetters and compatability with old versions
4207 of @code{troff}, @code{gtroff} has the concept of font @dfn{positions},
4208 on which various fonts are mounted.  The last one or two are reserved
4209 for the symbol font(s).
4211 @findex fp
4212 New fonts can be mounted with the @code{fp} request.  These numeric
4213 positions can then be referred to with font changing commands.  When
4214 @code{gtroff} starts it is using font number one.
4216 @example
4217 .fp 1 H
4218 .fp 2 HI
4219 .fp 3 HB
4220 wink, wink,
4221 .ft 2
4222 nudge, nudge,
4224 .ft 3
4225 say no more!
4227 @end example
4229 @noindent
4230 Note that after these font changes have taken place the original font
4231 is restored.
4233 @vindex .f
4234 The current font in use, as a font position, is available in number
4235 register @code{.f}.  This can be useful to remember the current font,
4236 for later recall.
4238 @example
4239 .nr save-font \n(.f
4240 ... lots 'o text ...
4241 .ft \n[save-font]
4242 @end example
4244 @vindex .fp
4245 The number of the next free font position is available in the number
4246 register @code{.fp}.  This is useful when mounting a new font, like so:
4248 @example
4249 .fp \n[.fp] NEATOFONT
4250 @end example
4252 @pindex DESC
4253 Fonts not listed in the @file{DESC} file are automatically mounted on
4254 the next available font position when they are referenced.  If a font is
4255 to be mounted explicitly with the @code{fp} request on an unused font
4256 position, it should be mounted on the first unused font position, which
4257 can be found in the @code{.fp} register.  Although @code{gtroff} does
4258 not enforce this strictly, it will not allow a font to be mounted at a
4259 position whose number is much greater than that of any currently used
4260 position.
4262 @findex fp
4263 The @code{fp} request has an optional third argument.  This argument
4264 gives the external name of the font, which is used for finding the font
4265 description file.  The second argument gives the internal name of the
4266 font which is used to refer to the font in @code{gtroff} after it has
4267 been mounted.  If there is no third argument then the internal name will
4268 be used as the external name.  This feature make it possible to use
4269 fonts with long names in compatibility mode.
4271 @node Using Symbols, Artificial Fonts, Font Positions, Fonts
4272 @subsection Using Symbols
4273 @cindex using symbols
4274 @cindex symbols, using
4276 @findex \(
4277 @findex \[
4278 Symbols can be inserted by using a special escape sequence.  This escape
4279 is simply the escape character (usually a backslash) followed by an
4280 identifier.  The symbol identifiers have to be two or more characters,
4281 since single characters conflict with all the other escapes.  The
4282 identifier can be either preceded by a parenthesis if it is two
4283 characters long, or surrounded by square brackets.  So, the symbol for
4284 the mathematical Greek letter `pi' can be produced either by @code{\(*p}
4285 or @code{\[*p]}.
4287 @example
4288 area = \(*p\fIr\fP\u2\d
4289 @end example
4291 @findex \C
4292 The escape @code{\C'@var{xxx}'} will typeset the character named
4293 @var{xxx}.  Normally it is more convenient to use @code{\[@var{xxx}]}.
4294 But @code{\C} has the advantage that it is compatible with recent
4295 versions of @code{ditroff} and is available in compatibility mode.
4297 @findex \N
4298 @findex char
4299 The escape @code{\N'@var{n}'} will typeset the character with code@w{
4300 }@var{n} in the current font.  @var{n} can be any integer.  Most devices
4301 only have characters with codes between 0 and@w{ }255.  If the current
4302 font does not contain a character with that code, special fonts will
4303 @emph{not} be searched.  The @code{\N} escape sequence can be
4304 conveniently used on conjunction with the @code{char} request:
4306 @example
4307 .char \[phone] \f(ZD\N'37'
4308 @end example
4310 @noindent
4311 @pindex DESC
4312 @cindex unnamed characters
4313 @cindex characters, unnamed
4314 The code of each character is given in the fourth column in the font
4315 description file after the charset command.  It is possible to include
4316 unnamed characters in the font description file by using a name of
4317 @samp{---}; the @code{\N} escape sequence is the only way to use these.
4319 @c XXX should be `glyph', not `character'
4321 @findex cflags
4322 @cindex character properties
4323 @cindex properties of characters
4324 Each character has certain properties associated with it.  These
4325 properties can be modified with the @code{cflags} request.  The first
4326 argument is the the sum of the desired flags and the remaining arguments
4327 are the characters to have those properties.
4329 @table @code
4330 @item 1
4331 @cindex end of sentence characters
4332 @cindex characters, end of sentence
4333 the character ends sentences (initially characters @samp{.?!} have this
4334 property)
4335 @item 2
4336 @cindex hyphenating characters
4337 @cindex characters, hyphenation
4338 lines can be broken before the character (initially no characters have
4339 this property)
4340 @item 4
4341 @glindex hy
4342 @glindex em
4343 lines can be broken after the character (initially the characters
4344 @samp{-\(hy\(em} have this property)
4345 @item 8
4346 @cindex overlapping characters
4347 @cindex characters, overlapping
4348 @glindex ul
4349 @glindex rn
4350 @glindex ru
4351 the character overlaps horizontally (initially the characters
4352 @samp{\(ul\(rn\(ru} have this property)
4353 @item 16
4354 @glindex br
4355 the character overlaps vertically (initially character @samp{\(br} has
4356 this property)
4357 @item 32
4358 @cindex transparent characters
4359 @cindex character, transparent
4360 @cindex '
4361 @cindex "
4362 @cindex ]
4363 @cindex )
4364 @cindex *
4365 @glindex dg
4366 @glindex rq
4367 an end of sentence character followed by any number of characters with
4368 this property will be treated as the end of a sentence if followed by a
4369 newline or two spaces; in other words the character is @dfn{transparent}
4370 for the purposes of end of sentence recognition---this is the same as
4371 having a zero space factor in @TeX{} (initially characters
4372 @samp{"')]*\(dg\(rq} have this property).
4373 @end table
4375 @findex char
4376 @cindex defining characters
4377 @cindex characters, defining
4378 New characters can be created with the @code{char} request.  It is
4379 called as
4381 @example
4382 .char @var{c} @var{string}
4383 @end example
4385 @findex tr
4386 @findex lc
4387 @findex \l
4388 @findex \L
4389 @findex hcode
4390 @noindent
4391 This defines character@w{ }@var{c} to be @var{string}.  Every time
4392 character@w{ }@var{c} needs to be printed, @var{string} will be
4393 processed in a temporary environment and the result will be wrapped up
4394 into a single object.  Compatibility mode will be turned off and the
4395 escape character will be set to @samp{\} while @var{string} is being
4396 processed.  Any emboldening, constant spacing or track kerning will be
4397 applied to this object rather than to individual characters in
4398 @var{string}.  A character defined by this request can be used just like
4399 a normal character provided by the output device.  In particular other
4400 characters can be translated to it with the @code{tr} request; it can be
4401 made the leader character by the @code{lc} request; repeated patterns
4402 can be drawn with the character using the @code{\l} and @code{\L} escape
4403 sequences; words containing the character can be hyphenated correctly,
4404 if the @code{hcode} request is used to give the character a hyphenation
4405 code.  There is a special anti-recursion feature: use of character
4406 within the character's definition will be handled like normal characters
4407 not defined with @code{char}.
4409 @findex rchar
4410 @cindex removing character definition
4411 @cindex character, removing definition
4412 A character definition can be removed with the @code{rchar} request.
4413 Its arguments are the characters to be removed.  This undoes the effect
4414 of a @code{char} request.
4416 @xref{Special Characters}.
4418 @node Artificial Fonts, Ligatures and Kerning, Using Symbols, Fonts
4419 @subsection Artificial Fonts
4420 @cindex artificial fonts
4421 @cindex fonts, artificial
4423 There are a number of requests for artificially creating fonts.  These
4424 are largely vestigial remains from the days when output devices did not
4425 have a wide variety of fonts, and when @code{nroff} and @code{troff}
4426 were separate programs.  These are no longer necessary in GNU
4427 @code{troff}.
4429 @findex ul
4430 @cindex underlining
4431 The @code{ul} request will print subsequent lines in italics on a device
4432 capable of it, or underline the text on an character output device.  The
4433 single argument is the number of lines to be ``underlined,'' with no
4434 argument, the next line will be underlined.
4436 @findex cu
4437 @cindex continuous underlining
4438 @cindex underlining, continuous
4439 The @code{cu} request is similar to @code{ul} ...
4441 @c XXX more info
4443 @findex uf
4444 @cindex underline font
4445 @cindex font for underlining
4446 The @code{uf} request will set the underline font used by @code{ul} and
4447 @code{cu}.
4449 @findex bd
4450 @cindex imitating bold face
4451 @cindex bold face, imitating
4452 The @code{bd} request artificially creates a bold font by printing each
4453 character twice, slightly offset.  The first argument specifies the font
4454 to embolden, and the second is the number of basic units, minus one, by
4455 which the two characters will be offset.  If the second argument is
4456 missing, emboldening will be turned off.
4458 @node Ligatures and Kerning,  , Artificial Fonts, Fonts
4459 @subsection Ligatures and Kerning
4460 @cindex ligatures and kerning
4461 @cindex kerning and ligatures
4463 What are ligatures?
4465 @c XXX more info
4467 @findex lg
4468 @vindex .lg
4469 The ligature mechanism can be switched on or off with the @code{lg}
4470 request; if the parameter is non-zero or missing, ligatures are enabled,
4471 otherwise disabled.  Default is on.  The current ligature mode can be
4472 found in the number register @code{.lg} (set to@w{ }1 if ligatures are
4473 enabled, 0@w{ }otherwise).
4475 What is kerning?
4477 @c XXX more info
4479 @cindex zero width space character
4480 @cindex character, zero width space
4481 @cindex space character, zero width
4482 If the font description file contains pairwise kerning information,
4483 characters from that font will be kerned.  Kerning between two
4484 characters can be inhibited by placing @code{\&} between them.
4486 @findex kern
4487 @vindex .kern
4488 Kerning can be activated with the @code{kern} request.  If the parameter
4489 is non-zero or missing, enable pairwise kerning, otherwise disable it.
4490 The number register @code{.kern} is set to@w{ }1 if pairwise kerning is
4491 enabled, 0@w{ }otherwise.
4493 @findex tkf
4494 @cindex track kerning
4495 @cindex kerning, track
4496 What is track kerning?
4498 @c XXX more info
4500 Track kerning must be used with great care since it is usually
4501 considered bad typography if the reader notices the effect.  The syntax
4502 of the @code{tkf} request is
4504 @example
4505 .tkf @var{f} @var{s1} @var{n1} @var{s2} @var{n2}
4506 @end example
4508 @noindent
4509 Enable track kerning for font@w{ }@var{f}.  If the current font is@w{
4510 }@var{f} the width of every character will be increased by an amount
4511 between @var{n1} and @var{n2}; if the current point size is less than or
4512 equal to @var{s1} the width will be increased by @var{n1}; if it is
4513 greater than or equal to @var{s2} the width will be increased by
4514 @var{n2}; if the point size is greater than or equal to @var{s1} and
4515 less than or equal to @var{s2} the increase in width is a linear
4516 function of the point size.
4519 @node Sizes, Strings, Fonts, Programming Tutorial
4520 @section Sizes
4521 @cindex sizes
4523 @cindex baseline
4524 @cindex type size
4525 @cindex size of type
4526 @cindex vertical spacing
4527 @cindex spacing, vertical
4528 @code{gtroff} uses two dimensions with each line of text, type size and
4529 vertical spacing.  The @dfn{type size} is the height from the text
4530 @dfn{baseline} to the top of the tallest character (descenders may drop
4531 below this baseline).  @dfn{Vertical spacing} is the amount of space
4532 @code{gtroff} allows for a line of text; normally, this is about 20%@w{
4533 }larger than the current type size.  Ratios smaller than this can result
4534 in hard-to-read text; larger that this, it will spread the text out more
4535 vertically (useful for term papers).  By default, @code{gtroff} uses
4536 10@w{ }point type on 12@w{ }point spacing.
4538 @cindex leading
4539 The difference between type size and vertical spacing is known, by
4540 typesetters, as @dfn{leading}.
4542 @menu
4543 * Changing Type Sizes::         
4544 * Fractional Type Sizes::       
4545 @end menu
4547 @node Changing Type Sizes, Fractional Type Sizes, Sizes, Sizes
4548 @subsection Changing Type Sizes
4549 @cindex changing type sizes
4550 @cindex type sizes, changing
4552 @findex ps
4553 @findex vs
4554 @findex \s
4555 @vindex .s
4556 @vindex .v
4557 Using the @code{ps} request and the @code{\s} escape the type size can
4558 be changed.  The @code{vs} request will change the vertical spacing.
4559 The default unit for the @code{ps} and @code{vs} requests are points.
4560 The number registers @code{.s} and @code{.v} contain the current type
4561 size and vertical spacing.
4563 These requests take parameters in units of points.  It is possible to
4564 specify sizes as an absolute size, or as a relative change from the
4565 current size.  The size@w{ }0 means go back to the previous size.  With
4566 no argument it will also revert to the previous size.
4568 @example
4569 snap, snap,
4570 .ps +2
4571 grin, grin,
4572 .ps +2
4573 wink, wink, \s+2nudge, nudge,\s+8 say no more!
4574 .ps 10
4575 @end example
4577 The @code{\s} escape may be called in a variety of ways.  Much like
4578 other escapes there must be a way to determine where the argument ends
4579 and the text begins.  Any of the following forms are valid:
4581 @table @code
4582 @item \s@var{n}
4583 Set the point size to @var{n}@w{ }points.  @var{n}@w{ }must be either 0
4584 or in the range 4 to@w{ }39.
4585 @itemx \s+@var{n}
4586 @itemx \s-@var{n}
4587 Increase resp.@: decrease the point size by @var{n}@w{ }points.
4588 @var{n}@w{ }must be exactly one digit.
4589 @item \s(@var{nn}
4590 Set the point size to @var{nn}@w{ }points.  @var{nn} must be exactly two
4591 digits.
4592 @item \s+(@var{nn}
4593 @itemx \s-(@var{nn}
4594 @itemx \s(+@var{nn}
4595 @itemx \s(-@var{nn}
4596 Increase resp.@: decrease the point size by @var{nn}@w{ }points.
4597 @var{nn} must be exactly two digits.
4598 @end table
4600 @xref{Fractional Type Sizes}, for yet another syntactical form of using
4601 the @code{\s} escape.
4603 Some devices may only have certain permissible sizes, in which case
4604 @code{gtroff} will round to the nearest permissible size.
4606 @c XXX example
4608 @example
4609 ... .sz macro example?? ...
4610 @end example
4612 @node Fractional Type Sizes,  , Changing Type Sizes, Sizes
4613 @subsection Fractional Type Sizes
4614 @cindex fractional type sizes
4615 @cindex type sizes, fractional
4617 @cindex @code{s} unit
4618 @cindex unit, @code{s}
4619 @cindex @code{z} unit
4620 @cindex unit, @code{z}
4621 @findex ps
4622 @findex cs
4623 @findex tkf
4624 @findex \H
4625 @findex \s
4626 A @dfn{scaled point} is equal to 1/@var{sizescale} points, where
4627 @var{sizescale} is specified in the @file{DESC} file (1@w{ }by default.)
4628 There is a new scale indicator @samp{z} which has the effect of
4629 multiplying by @var{sizescale}.  Requests and escape sequences in
4630 @code{gtroff} interpret arguments that represent a point size as being in
4631 units of scaled points, but they evaluate each such argument using a
4632 default scale indicator of @samp{z}.  Arguments treated in this way are
4633 the argument to the @code{ps} request, the third argument to the
4634 @code{cs} request, the second and fourth arguments to the @code{tkf}
4635 request, the argument to the @code{\H} escape sequence, and those
4636 variants of the @code{\s} escape sequence that take a numeric expression
4637 as their argument (see below).
4639 For example, suppose @var{sizescale} is@w{ }1000; then a scaled point
4640 will be equivalent to a millipoint; the request @w{@samp{.ps 10.25}} is
4641 equivalent to @w{@samp{.ps 10.25z}} and thus sets the point size to 10250
4642 scaled points, which is equal to 10.25@w{ }points.
4644 It would make no sense to use the @samp{z} scale indicator in a numeric
4645 expression whose default scale indicator was neither @samp{u} nor
4646 @samp{z}, and so @code{gtroff} disallows this.  Similarly it would make
4647 no sense to use a scaling indicator other than @samp{z} or @samp{u} in a
4648 numeric expression whose default scale indicator was @samp{z}, and so
4649 @code{gtroff} disallows this as well.
4651 There is also new scale indicator @samp{s} which multiplies by the
4652 number of units in a scaled point.  So, for example, @samp{\n[.ps]s} is
4653 equal to @samp{1m}.  Be sure not to confuse the @samp{s} and @samp{z}
4654 scale indicators.
4656 @vindex .s
4657 @vindex .ps
4658 The number register @code{.s} returns the point size in points as decimal
4659 fraction.  There is also a new number register @code{.ps} that returns
4660 the point size in scaled points.
4662 @vindex .psr
4663 @vindex .sr
4664 The last-requested point size in scaled points is contained in the
4665 @code{.psr} number register.  The last requested point size in points as
4666 a decimal fraction can be found in @code{.psr}.  This is a string-valued
4667 register.
4669 @table @code
4670 @item \s[@var{n}]
4671 @itemx \s'@var{n}'
4672 Set the point size to @var{n} scaled points; @var{n}@w{ }is a numeric
4673 expression with a default scale indicator of @samp{z}.
4674 @item \s[+@var{n}]
4675 @itemx \s[-@var{n}]
4676 @itemx \s+[@var{n}]
4677 @itemx \s-[@var{n}]
4678 @itemx \s'+@var{n}'
4679 @itemx \s'-@var{n}'
4680 @itemx \s+'@var{n}'
4681 @itemx \s-'@var{n}'
4682 Increases resp.@: decreases the point size by @var{n} scaled points;
4683 @var{n} is a numeric expression with a default scale indicator of
4684 @samp{z}.
4685 @end table
4687 @xref{Font Files}.
4690 @node Strings, Conditionals and Loops, Sizes, Programming Tutorial
4691 @section Strings
4692 @cindex strings
4694 @findex ds
4695 @code{gtroff} has string variables, which are entirely for user
4696 convenience (i.e.@: there are no built-in strings).  They are defined
4697 via the @code{ds} request.
4699 @example
4700 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d
4701 @end example
4703 @findex \*
4704 @cindex string interpolation
4705 @cindex string expansion
4706 @cindex interpolation of strings
4707 @cindex expansion of strings
4708 They are interpolated, or expanded in-place, via the @code{\*} escape:
4710 @example
4711 The \*(UX Operating System
4712 @end example
4714 If the string named by the @code{\*} does not exist, the escape will be
4715 replaced by nothing.
4717 @cindex comments, with @code{ds}
4718 @strong{Caution:} Unlike other requests, the second argument to the
4719 @code{ds} request takes up the entire line including trailing spaces.
4720 This means that comments on a line with such a request can introduce
4721 unwanted space into a string.
4723 @example
4724 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d \" UNIX trademark
4725 @end example
4727 @noindent
4728 Instead the comment should be put on another line or have the comment
4729 escape adjacent with the end of the string.
4731 @example
4732 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d\"  UNIX trademark
4733 @end example
4735 @cindex trailing quotes
4736 @cindex quotes, trailing
4737 @cindex leading spaces with @code{ds}
4738 @cindex spaces with @code{ds}
4739 To produce leading space the string can be started with a double quote.
4740 No trailing quote is needed; in fact, any trailing quote is included in
4741 your string.
4743 @example
4744 .ds sign "           Yours in a white wine sauce,
4745 @end example
4747 @findex as
4748 @cindex appending to strings
4749 @cindex strings, appending
4750 The @code{as} request will append a string to another string.  It works
4751 similar to the @code{ds} request except that it appends the second
4752 argument onto the string named by the first argument.
4754 @example
4755 .as sign " with shallots, onions and garlic,
4756 @end example
4758 @findex \@key{RET}
4759 @cindex multi-line strings
4760 @cindex strings, multi-line
4761 @cindex newline character, escaping
4762 @cindex escaping newline characters
4763 Strings are not limited to a single line of text.  A string can span
4764 several lines by escaping the newlines with a backslash.  The resulting
4765 string will be stored @emph{without} the newlines.
4767 @example
4768 .ds foo lots and lots \
4769 of text are on these \
4770 next several lines
4771 @end example
4773 @findex substring
4774 @cindex substrings
4775 Rudimentary string manipulation routines are given with the
4776 @code{substring} and @code{length} requests.  The former has the
4777 following syntax:
4779 @example
4780 .substring @var{xx} @var{n1} [@var{n2}]
4781 @end example
4783 @noindent
4784 It replaces the string in register@w{ }@var{xx} with the substring
4785 defined by the indices @var{n1} and@w{ }@var{n2}.  The first character
4786 in the string has index one.  If @var{n2} is omitted, it is taken to be
4787 equal to the string's length.  If the index value @var{n1} or @var{n2}
4788 is negative or zero, it will be counted from the end of the string,
4789 going backwards: The last character has index@w{ }0, the character
4790 before the last character has index@w{ }-1, etc.
4792 @findex length
4793 @cindex length of a string
4794 @cindex string, length of
4795 Here the syntax of the @code{length} request:
4797 @example
4798 .length @var{xx} @var{string}
4799 @end example
4801 @noindent
4802 It computes the length of @var{string} and returns it in the number
4803 register@w{ }@var{xx} (which is not necessarily defined before).
4805 @findex rn
4806 @code{rn}
4808 @c XXX
4810 @findex rm
4811 @code{rm}
4813 @c XXX
4815 @findex als
4816 @code{als}
4818 @c XXX
4820 @findex chop
4821 @code{chop}
4823 @c XXX
4825 @xref{Identifiers}, and @ref{Comments}.
4828 @node Conditionals and Loops, Writing Macros, Strings, Programming Tutorial
4829 @section Conditionals and Loops
4830 @cindex conditionals and loops
4831 @cindex loops and conditionals
4833 @findex if
4834 @findex while
4835 In @code{if} and @code{while} requests, there are several more operators
4836 available:
4838 @table @code
4839 @item e
4840 @itemx o
4841 True if the current page is even or odd numbered (respectively).
4842 @item n
4843 @itemx t
4844 True if the document is being processed by @code{nroff} (or a character
4845 device) resp.@: @code{troff}.
4846 @item '@var{xxx}'@var{yyy}'
4847 True if the string @var{xxx} is equal to the string @var{yyy}.  Other
4848 characters can be used in place of the single quotes.
4849 @c XXX (Which?)
4850 The strings are `formatted' before being compared.
4851 @c XXX (?)
4852 @item r@var{xxx}
4853 True if there is a number register named @var{xxx}.
4854 @item d@var{xxx}
4855 True if there is a string, macro, diversion, or request named @var{xxx}.
4856 @item c@var{ch}
4857 @findex char
4858 True if there is a character @var{ch} available; @var{ch} is either an
4859 @acronym{ASCII} character or a special character (@code{\(@var{ch}} or
4860 @code{\[@var{ch}]}); the condition will also be true if @var{ch} has
4861 been defined by the @code{char} request.
4862 @end table
4864 @menu
4865 * if-else::                     
4866 * while::                       
4867 @end menu
4869 @node if-else, while, Conditionals and Loops, Conditionals and Loops
4870 @subsection if-else
4871 @cindex if-else
4873 @code{gtroff} has if-then-else constructs like other languages, although
4874 the formatting can be painful.
4876 @findex if
4877 The @code{if} request has the following syntax:
4879 @example
4880 .if @var{expr} @var{anything}
4881 @end example
4883 @noindent
4884 where @var{expr} is the expression to be evaluated; @var{anything} (the
4885 remainder of the line) will be executed if @var{expr} evaluates to
4886 non-zero (true).  @var{anything} will be interpreted as though it was on
4887 a line by itself.  @xref{Expressions}, for more info.
4889 Here are some examples:
4891 @example
4892 .if t .ls 2                             \" double spacing in troff
4893 .if 0 .ab how'd this happen?
4894 @end example
4896 @findex ie
4897 @findex el
4898 An if-then-else is written using two requests @code{ie} and @code{el}.
4899 The first request is the `if' part and the latter is the `else' part.
4901 @c XXX example
4903 @example
4906 @end example
4908 @findex \@{
4909 @findex \@}
4910 In many cases more than one request is to be executed as a result of any
4911 of these requests.  This can be done using the @code{\@{} and @code{\@}}
4912 escapes.  The following example shows the possible ways to use these
4913 escapes (note the position of the opening and closing braces).
4915 @example
4916 .ie t \@{\
4917 .    ds lq ``
4918 .    ds rq ''
4919 .\@}
4920 .el \
4921 .\@{\
4922 .    ds lq "
4923 .    ds rq "\@}
4924 .ds qq "
4925 @end example
4927 @xref{Expressions}.
4929 @node while,  , if-else, Conditionals and Loops
4930 @subsection while
4931 @cindex while
4933 @findex while
4934 @code{gtroff} provides a looping construct using the @code{while}
4935 request, which is used much like the @code{if} (and related) requests.
4936 The first argument is an expression which will be evaluated.  The
4937 @code{while} request will interpret the remainder of the line until the
4938 expression evaluates to 0 or false.
4940 @example
4941 .nr a 0 1
4942 .while (\na<9) \&\n+a,
4943 \&\n+a
4944 @end example
4946 @noindent
4947 The preceding example produces:
4949 @example
4950 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
4951 @end example
4953 @cindex zero width space character
4954 @cindex character, zero width space
4955 @cindex space character, zero width
4956 @findex \&
4957 @noindent
4958 Note the usage of the @code{\&} escape to avoid a control character at
4959 the beginning of a line.
4961 @findex break
4962 @findex continue
4963 The @code{break} request will @dfn{break} out of a while loop.  Be sure
4964 not to confuse this with the @code{br} request (causing a line break).
4965 The @code{continue} request will finish the current iteration of a while
4966 loop, immediately restarting the next iteration.
4968 @xref{Expressions}.
4971 @node Writing Macros, Page Motions, Conditionals and Loops, Programming Tutorial
4972 @section Writing Macros
4973 @cindex writing macros
4974 @cindex macros, writing
4976 @findex de
4977 A @dfn{macro} is a collection of text and embedded commands which can be
4978 invoked multiple times.  Macros are used for defining common operations.
4979 Macros are defined using the @code{de} request.  This request takes a
4980 name for the macro as the first argument.  Subsequent lines are copied
4981 into an internal buffer until the line @code{..} is encountered.  The
4982 optional second argument to @code{de} can change this ending token.
4984 Here a small example macro called @samp{P} which will cause a break and
4985 the insertion of some vertical space.  It could be used to separate
4986 paragraphs.
4988 @example
4989 .de P
4991 .sp .8v
4993 @end example
4995 @findex am
4996 The @code{am} request works similarly to @code{de} except it appends
4997 onto the macro named by the first argument.  So, to make the previously
4998 defined @samp{P} macro actually do indented instead of block paragraphs,
4999 is is possible to add the necessary code to the existing macro like
5000 this:
5002 @example
5003 .am P
5004 .ti +5n
5006 @end example
5008 @findex als
5009 @cindex aliases, macro
5010 @cindex macro aliases
5011 Macros can be aliased with the @code{als} request.
5013 @c XXX example
5015 @menu
5016 * Copy-in Mode::                
5017 * Parameters::                  
5018 @end menu
5020 @node Copy-in Mode, Parameters, Writing Macros, Writing Macros
5021 @subsection Copy-in Mode
5022 @cindex copy-in mode
5023 @cindex mode, copy-in
5025 @findex \n
5026 @findex \$
5027 @findex \*
5028 @findex \\
5029 @findex \@key{RET}
5030 When @code{gtroff} reads in the text for a macro or diversion it copies
5031 the text (including request lines, but excluding escapes) into an
5032 internal buffer.  Escapes will be converted into an internal form,
5033 except for @code{\n}, @code{\$}, @code{\*}, @code{\\} and
5034 @code{\@key{RET}} which are evaluated and inserted into the text where
5035 the escape was located.  This is known as @dfn{copy-in} mode.
5037 What this means is that you can specify when these escapes are to be
5038 evaluated (either at copy-in time or at the time of use) by insulating
5039 the escapes with an extra backslash.  Compare this to the @code{\def}
5040 and @code{\edef} commands in @TeX{}.
5042 For example, the following will result in the numbers 20 and@c{ }10
5043 being printed:
5045 @example
5046 .nr x 20
5047 .de y
5048 .nr x 10
5049 \&\nx
5050 \&\\nx
5053 @end example
5055 @node Parameters,  , Copy-in Mode, Writing Macros
5056 @subsection Parameters
5057 @cindex parameters
5059 @findex \$
5060 @vindex .$
5061 The arguments to a macro can be examined using a variety of escapes.
5062 The number of arguments is available in the @code{.$} number register.
5063 Any individual argument can be retrieved with one of the following
5064 escapes:
5066 @cindex copy-in mode
5067 The escapes @code{\$@var{n}}, @code{\$(@var{nn}} and
5068 @code{\$[@var{nnn}]} will result in the @var{n}th, @var{nn}th or
5069 @var{nnn}th argument.  As usual, the first form only accepts a single
5070 number (larger than zero), the second only a two-digit number (larger or
5071 equal to@w{ }10), and the third any positive integer value (larger than
5072 zero).  Macros can have an unlimited number of arguments.  Note that due
5073 to copy-in mode, two backslashes should be used on these in actual use
5074 to prevent interpolation until the macro is actually invoked.
5076 @findex shift
5077 The request @code{shift} will shift the arguments 1@w{ }position, or as
5078 many positions as specified by its argument.  After executing this
5079 request, argument@w{ }@var{i} will become argument @var{i}-@var{n};
5080 arguments 1 to@w{ }@var{n} will no longer be available.  Shifting by
5081 negative amounts is currently undefined.
5083 @findex \$*
5084 @findex \$@@
5085 In some cases it is convenient to use all of the arguments at once (for
5086 example, to pass the arguments along to another macro).  The @code{\$*}
5087 escape is the concatenation of all the arguments separated by spaces.  A
5088 similar escape is @code{\$@@}, which is the concatenation of all the
5089 arguments with each surrounded by double quotes, and separated by
5090 spaces.
5092 @findex \$0
5093 @findex als
5094 The @code{\$0} escape is the name by which the current macro was
5095 invoked.  The @code{als} request can make a macro have more than one
5096 name.
5098 @example
5099 .de vl
5100 .ie \\n(.$=1 .ds Vl Pre-Release Version
5101 .el          .ds Vl Version \\$3, \\$4.
5103 @end example
5105 This would be called as
5107 @example
5108 .vl $Id$
5109 @end example
5111 @xref{Request Arguments}.
5114 @node Page Motions, Drawing Requests, Writing Macros, Programming Tutorial
5115 @section Page Motions
5116 @cindex page motions
5117 @cindex motions, page
5119 @findex sp
5120 Motions up and down the page can be done with the @code{sp} request.
5121 However, this causes a break so that the actual effect is to move to the
5122 left margin and then to the specified location.
5124 @findex mk
5125 @findex rt
5126 The request @code{mk} can be used to mark a location on a page, for
5127 movement to later.  This request takes a register name as an argument in
5128 which to store the current page location.  With no argument it will
5129 store the location in an internal register.  The results of this can be
5130 used later by the @code{rt} or the @code{sp} request.  The @code{rt}
5131 request will return @emph{upwards} to the location given in the register
5132 name given as an argument, with no argument it will return to the
5133 location marked with the @code{mk} request
5135 @c XXX example
5137 @example
5138 ... dual column example ...
5139 @end example
5141 The following escapes give fine control of movements about the page.
5143 @findex \v
5144 @cindex vertical motion
5145 @cindex motion, vertical
5146 The @code{\v'@var{e}'} enables arbitrary vertical motion from the
5147 current location on the page.  The argument@w{ }@var{e} specifies the
5148 distance to move; positive is downwards and negative upwards.  The
5149 default unit for this escape is vertical spaces, @code{v}'s.  Beware,
5150 however, that @code{gtroff} will leave text processing to continue
5151 wherever the motion ends, so to avoid interference with text processing,
5152 motions should be balanced.
5154 There are some special case escapes for vertical motion.
5156 @ftable @code
5157 @item \r
5158 move upwards@w{ }1@dmn{v}.
5159 @item \u
5160 move upwards@w{ }.5@dmn{v}.
5161 @item \d
5162 move down@w{ }.5@dmn{v}.
5163 @end ftable
5165 @findex \h
5166 Horizontal motions can be done via the @code{\h'@var{e}'} escape.  The
5167 expression@w{ }@var{e} indicates how far to move: positive is rightwards
5168 and negative leftwards.
5170 There are a number of special case escapes for horizontal motion:
5172 @ftable @code
5173 @item \@key{SP}
5174 an unbreakable and unpaddable (i.e.@: not expanded during filling)
5175 space.  (Note: It is a backslash followed by a space.)
5176 @item \~
5177 an unbreakable space that stretches like a normal inter-word space when a
5178 line is adjusted.
5179 @item \|
5180 a 1/6th em space.
5181 @item \^
5182 a 1/12th em space.
5183 @item \0
5184 a space the size of a digit.
5185 @cindex zero width space character
5186 @cindex character, zero width space
5187 @cindex space character, zero width
5188 @item \&
5189 A zero width space.
5190 @item \)
5191 Like @code{\&} except that it behaves like a character declared with the
5192 @code{cflags} request to be transparent for the purposes of end of
5193 sentence recognition.
5194 @end ftable
5196 @c XXX example
5198 @example
5199 ... tex logo example ...
5200 @end example
5202 @findex \w
5203 @cindex width escape
5204 @cindex escape, width
5205 A frequent need is to do horizontal movement based on the width of some
5206 arbitrary text (e.g.@: given as an argument to a macro).  For that,
5207 there is the escape @code{\w'@var{text}'} which will interpolate to the
5208 width of the given @var{text} in basic units.
5210 @c XXX example
5212 @example
5213 ... strlen example ...
5214 @end example
5216 Font changes may occur in @var{text} which don't affect current
5217 settings.
5219 After use, @code{\w} sets several registers:
5221 @table @code
5222 @vindex st
5223 @vindex sb
5224 @item st
5225 @itemx sb
5226 The highest and lowest point, respectively, in @var{text}.
5227 @vindex rst
5228 @vindex rsb
5229 @item rst
5230 @itemx rsb
5231 Like the @code{st} and @code{sb} registers, but takes account of the
5232 heights and depths of characters.
5233 @vindex ct
5234 @item ct
5235 is set according to what kinds of characters occur in @var{text}:
5236 @table @asis
5237 @item 0
5238 only short characters, no descenders or tall characters.
5239 @item 1
5240 descender
5241 @item 2
5242 tall character
5243 @item 3
5244 both a descender and a tall character
5245 @end table
5246 @vindex ssc
5247 @item ssc
5248 The amount of horizontal space (possibly negative) that should be added
5249 to the last character before a subscript.
5250 @vindex skw
5251 @item skw
5252 How far to right of the center of the last character in the @code{\w}
5253 argument, the center of an accent from a Roman font should be placed
5254 over that character.
5255 @end table
5257 @findex \k
5258 @vindex .k
5259 @code{\k}
5261 @code{.k}
5263 @c XXX documentation
5266 @node Drawing Requests, Traps, Page Motions, Programming Tutorial
5267 @section Drawing Requests
5268 @cindex drawing requests
5269 @cindex requests for drawing
5271 @code{gtroff} provides a number of ways to draw lines and other figures
5272 on the page.  Used in combination with the page motion commands
5273 (@pxref{Page Motions}, for more info), a wide variety of figures can be
5274 drawn.  However, for complex drawings these operations can be quite
5275 cumbersome, and it may be wise to use graphic preprocessors like
5276 @code{gpic} or @code{ggrn}.  @xref{gpic}, and @ref{ggrn}, for more
5277 information.
5279 All drawing is done via escapes.
5281 @findex \l
5282 @cindex horizontal line
5283 @cindex line, horizontal
5284 The @code{\l} escape will draw a line rightwards from the current
5285 location.  The full syntax for this escape is
5287 @example
5288 \l'@var{l}@var{c}'
5289 @end example
5291 @noindent
5292 where @var{l} is the length of the line to be drawn, starting at the
5293 current location; positive numbers will draw to the right, and negative
5294 will draw towards the left.  This can also be specified absolutely
5295 (i.e.@: with a leading @samp{|}) which will draw back to the beginning
5296 of the line.
5298 @cindex underscore character
5299 @cindex character, underscore
5300 @cindex line drawing character
5301 @cindex character for line drawing
5302 The optional second parameter @var{c} is a character to draw the line
5303 with.  If this second argument is not specified, @code{gtroff} will use
5304 the underscore character.
5306 @cindex zero width space character
5307 @cindex character, zero width space
5308 @cindex space character, zero width
5309 @findex \&
5310 To separate the two arguments (to prevent @code{gtroff} from
5311 interpreting a drawing character as a scaling indicator) use @code{\&}.
5313 Here a small useful example:
5315 @example
5316 .de box
5317 \(br\\$*\(br\l'|0\(rn'\l'|0\(ul'
5319 @end example
5321 @noindent
5322 @opindex |
5323 Note that this works by outputting a box rule (a vertical line), then
5324 the text given as an argument and then another box rule.  Then the line
5325 drawing escapes both draw from the current location to the beginning of
5326 the @emph{input} line.
5328 @findex \L
5329 @cindex vertical line
5330 @cindex line, vertical
5331 @cindex line drawing character
5332 @cindex character for line drawing
5333 @cindex box rule character
5334 @cindex character, box rule
5335 Vertical lines are drawn using the @code{\L} escape.  Its parameters are
5336 specified similar to the @code{\l} escape.  If the length is positive,
5337 the movement will be downwards, and upwards for negative values.  The
5338 default character is the box rule character.  As with the vertical
5339 motion escapes, text processing will blindly continue where the line
5340 ends.
5342 @c XXX example
5344 @example
5345 ...box macro...
5346 @end example
5348 @findex \D
5349 More flexible drawing functions are available via the @code{\D} escape.
5350 While the previous escapes will work on a character device, these
5351 escapes will not.
5353 @table @code
5354 @item \D'l @var{dx} @var{dy}'
5355 Draw a line from the current location to the relative point specified by
5356 (@var{dx},@var{dy}).
5358 @c XXX example
5360 @example
5361 ...revised box macro...
5362 @end example
5364 @item \D'c @var{d}'
5365 @cindex circles
5366 Draw a circle with a diameter of @var{d} with the leftmost point at the
5367 current position.
5368 @item \D'C @var{d}'
5369 Draw a solid circle with the same parameters as an outlined circle.
5370 @item \D'e @var{dx} @var{dy}'
5371 @cindex ellipses
5372 Draw an ellipse with a horizontal diameter of @var{dx} and a vertical
5373 diameter of @var{dy} with the leftmost point at the current position.
5374 @item \D'E @var{dx} @var{dy}'
5375 Draw a solid ellipse with the same parameters as an outlined ellipse.
5376 @item \D'a @var{dx1} @var{dy1} @var{dx2} @var{dy2}'
5377 @cindex arcs
5378 Draw an arc clockwise from the current location through the two
5379 specified locations (@var{dx1},@var{dy1}) and (@var{dx2},@var{dy2}).
5380 @item \D'~ @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
5381 @cindex splines
5382 Draw a spline from the current location to (@var{dx1},@var{dy1}) and
5383 then to (@var{dx2},@var{dy2}), and so on.
5384 @item \D'f @var{n}'
5385 @cindex gray shading
5386 @cindex shading
5387 Set the shade of gray to be used for filling solid objects to@w{
5388 }@var{n}; @var{n}@w{ }must be an integer between 0 and@w{ }1000, where 0
5389 corresponds solid white and 1000 to solid black, and values in between
5390 correspond to intermediate shades of gray.  This applies only to solid
5391 circles, solid ellipses and solid polygons.  By default, a level of@w{
5392 }1000 will be used.
5393 @item \D'p @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
5394 @cindex polygons
5395 Draw a polygon from the current location to (@var{dx1},@var{dy1}) and
5396 then to (@var{dx2},@var{dy2}) and so on.  When the specified data points
5397 are exhausted, a line is drawn back to the starting point.
5399 @c XXX example
5401 @example
5402 ... box example (yes, again)...
5403 @end example
5405 @itemx \D'P @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
5406 Draw a solid polygon with the same parameters as an outlined polygon.
5408 @c XXX example
5410 @example
5411 ... shaded box example ...
5412 @end example
5414 @item \D't @var{n}'
5415 @cindex line thickness
5416 @cindex thickness of lines
5417 Set the current line thickness to @var{n} machine units.  A value of
5418 zero selects the smallest available line thickness.  A negative value
5419 makes the line thickness proportional to the current point size (this is
5420 the default behaviour of @code{ditroff}).
5421 @end table
5423 @findex \b
5424 @cindex pile, character
5425 @cindex character pile
5426 The @code{\b} escape will @dfn{pile} a sequence of characters
5427 vertically, and center it vertically on the current line.  This can be
5428 used to build large brackets and braces.
5430 @example
5431 \b'\(lt\(bv\(lk\(bv\(lb'
5432 @end example
5434 @xref{Drawing Functions}.
5436 @node Traps, Diversions, Drawing Requests, Programming Tutorial
5437 @section Traps
5438 @cindex traps
5440 @dfn{Traps} are locations, which, when reached, will call a specified
5441 macro.  These traps can occur at a given location on the page, at a
5442 given location in the current diversion, after a certain number of input
5443 lines or at the end of input.
5445 @menu
5446 * Page Location Traps::         
5447 * Diversion Traps::             
5448 * Input Line Traps::            
5449 * End-of-input Traps::          
5450 @end menu
5452 @node Page Location Traps, Diversion Traps, Traps, Traps
5453 @subsection Page Location Traps
5454 @cindex page location traps
5455 @cindex traps, page location
5457 @c XXX definition of wh request
5459 @cindex page headers
5460 @cindex page footers
5461 @cindex headers
5462 @cindex footers
5463 Page location traps are frequently used for page headers and footers.
5464 The following is a simple example of this.
5466 @example
5467 .de hd                \" Page header
5468 'sp .5i
5469 .tl 'Title''date'
5470 'sp .3i
5472 .de fo                \" Page footer
5473 'sp 1v
5474 .tl ''%''
5477 .wh 0   hd            \" trap at top of the page
5478 .wh -1i fo            \" trap one inch from bottom
5479 @end example
5481 @vindex .t
5482 @cindex distance to next trap
5483 @cindex trap, distance
5484 The number register @code{.t} is the distance to the next trap.
5486 @findex ch
5487 @cindex changing trap location
5488 @cindex trap, changing location
5489 The location of a trap can be changed later on with the @code{ch}
5490 request.  The first argument is the name of the macro to be invoked at
5491 the trap, and the second argument is the new location for the trap.
5492 This is useful for building up footnotes in a diversion to allow more
5493 space at the bottom of the page for them.
5495 @c XXX
5497 @example
5498 ... (simplified) footnote example ...
5499 @end example
5501 @findex vpt
5502 @findex wh
5503 @findex dt
5504 @vindex .vpt
5505 The @code{vpt} request will enable vertical position traps if the
5506 argument is non-zero, disable them otherwise.  Vertical position traps
5507 are traps set by the @code{wh} or @code{dt} requests.  Traps set by the
5508 @code{it} request are not vertical position traps.  The parameter that
5509 controls whether vertical position traps are enabled is global.
5510 Initially vertical position traps are enabled.  The current setting of
5511 this is available in the number register @code{.vpt}.
5513 @vindex .trunc
5514 @findex ne
5515 The number register @code{.trunc} contains the amount of vertical space
5516 truncated by the most recently sprung vertical position trap, or, if the
5517 trap was sprung by a @code{ne} request, minus the amount of vertical
5518 motion produced by the @code{ne} request.  In other words, at the point
5519 a trap is sprung, it represents the difference of what the vertical
5520 position would have been but for the trap, and what the vertical
5521 position actually is.
5523 @vindex .ne
5524 The number register @code{.ne} contains the amount of space that was
5525 needed in the last @code{ne} request that caused a trap to be sprung.
5526 Useful in conjunction with the @code{.trunc} register.  @xref{Page
5527 Control}, for more information.
5529 @node Diversion Traps, Input Line Traps, Page Location Traps, Traps
5530 @subsection Diversion Traps
5531 @cindex diversion traps
5532 @cindex traps, diversion
5534 @findex dt
5535 @vindex .t
5536 Traps can also be set @emph{within} a diversion using the @code{dt}
5537 request.  Like @code{wh} the first argument is the location of the trap
5538 and the second argument is the name of the macro to be invoked.  The
5539 number register @code{.t} will still work within diversions.
5540 @xref{Diversions}, for more information.
5542 @node Input Line Traps, End-of-input Traps, Diversion Traps, Traps
5543 @subsection Input Line Traps
5544 @cindex input line traps
5545 @cindex traps, input line
5547 @findex it
5548 The @code{it} request will set an input line trap.  The format for
5549 calling this is
5551 @example
5552 .it @var{n} @var{name}
5553 @end example
5555 @noindent
5556 where @var{n} is the number of lines of input which may be read before
5557 @dfn{springing} the trap, @var{name} is the macro to be invoked.
5558 Request lines are not counted as input lines.
5560 For example, one possible use is to have a macro which will print the
5561 next @var{n}@w{ }lines in a bold font.
5563 @example
5564 .de B
5565 .it B-end \\$1
5566 .ft B
5568 .de B-end
5569 .ft R
5571 @end example
5573 @node End-of-input Traps,  , Input Line Traps, Traps
5574 @subsection End-of-input Traps
5575 @cindex end-of-input traps
5576 @cindex traps, end-of-input
5578 @findex em
5579 The @code{em} request will set a trap at the end of input.  The macro
5580 specified as an argument will be executed after the last line of the
5581 input file has been processed.
5583 For example, if the document had to have a section at the bottom of the
5584 last page for someone to approve it, the @code{em} request could be
5585 used.
5587 @example
5588 .de approval
5589 .ne 5v
5590 .sp |(\\n(.t-6v)
5591 .in +4i
5592 .lc _
5594 Approved:\t\a
5596 Date:\t\t\a
5598 .em approval
5599 @end example
5602 @node Diversions, Environments, Traps, Programming Tutorial
5603 @section Diversions
5604 @cindex diversions
5606 In @code{gtroff} it is possible to @dfn{divert} text into a named
5607 storage area.  Due to the similarity to defining macros it is sometimes
5608 said to be stored in a macro.  This is used for saving text for output
5609 at a later time, which is useful for keeping blocks of text on the same
5610 page, footnotes, tables of contents and indices.
5612 @findex di
5613 @findex da
5614 A diversion is initiated by the @code{di} request.  Like the @code{de}
5615 request, it takes an argument of a macro name to divert subsequent text
5616 into.  The @code{da} macro will append to an existing diversion.
5618 @code{di} (resp.@: @code{da}) without an argument ends the diversion.
5620 @c XXX example
5622 @example
5623 ... end-note example ...
5624 @end example
5626 @vindex .z
5627 @vindex .d
5628 @vindex nl
5629 @vindex .h
5630 @cindex nested diversions
5631 @cindex diversion, nested
5632 Diversions may be nested.  The number register @code{.z} contains the
5633 name of the current diversion.  The number register @code{.d} contains
5634 the current vertical place in the diversion.  If not in a diversion it
5635 is the same as the register @code{nl}.
5637 @c XXX more info
5639 @code{.h}
5641 @vindex dn
5642 @vindex dl
5643 After completing a diversion, the built-in number registers @code{dn}
5644 and @code{dl} contain the vertical and horizontal size of the diversion.
5646 @example
5647 .\" Center text both horizontally & vertically
5648 .de (c
5651 .di @@c
5653 .de )c
5656 .nr @@s (((\\n(.tu-\\n(dnu)/2u)-1v)
5657 .sp \\n(@@su
5658 .ce 1000
5662 .ce 0
5663 .sp \\n(@@su
5666 .rr @@s
5668 @end example
5670 @findex \!
5671 @cindex transparent output
5672 @cindex output, transparent
5673 Requests, macros and escapes are interpreted when read into a diversion.
5674 There are two ways to prevent this; either way will take the given text
5675 and @dfn{transparently} embed it into the diversion.  The first method
5676 is to prefix the line with @code{\!}.  This will cause the entire line
5677 to be transparently inserted into the diversion.  This is useful for
5678 macros which shouldn't be invoked until the diverted text is actually
5679 output.
5681 @c XXX anything is read in copy mode. (what about \! ??)
5683 @findex \?
5684 The other way is to surround the text by the @code{\?} escape, i.e.
5686 @example
5687 \?@var{anything}\?
5688 @end example
5690 @noindent
5691 @var{anything} may not contain newlines; use @code{\!}  to embed
5692 newlines in a diversion.  The escape sequence @code{\?} is also
5693 recognized in copy mode and turned into a single internal code; it is
5694 this code that terminates anything.  Thus the following example will
5695 print@w{ }4.
5697 @example
5698 .nr x 1
5700 .di d
5701 \?\\?\\\\?\\\\\\\\nx\\\\?\\?\?
5703 .nr x 2
5704 .di e
5707 .nr x 3
5708 .di f
5711 .nr x 4
5713 @end example
5715 @findex asciify
5716 @cindex unformatting diversions
5717 @cindex diversion, unformatting
5718 The @code{asciify} request only exists in order to make certain gross
5719 hacks work with GNU @code{troff}.  It @dfn{unformats} the diversion
5720 specified as an argument in such a way that @acronym{ASCII} characters
5721 that were formatted and diverted will be treated like ordinary input
5722 characters when the diversion is reread.  For example, the following
5723 will set register @code{n} to@w{ }1.
5725 @example
5726 .tr @@.
5727 .di x
5728 @@nr\ n\ 1
5731 .tr @@@@
5732 .asciify x
5734 @end example
5736 @xref{Copy-in Mode}.
5739 @node Environments, I/O, Diversions, Programming Tutorial
5740 @section Environments
5741 @cindex environments
5743 It happens frequently that some text should be printed in a certain
5744 format regardless of what may be in effect at the time, for example, in
5745 a trap invoked macro to print headers and footers.  To solve this
5746 @code{gtroff} has @dfn{environments} in which text is processed.  An
5747 environment contains most of the parameters that control text
5748 processing.  It is possible to switch amongst these environments; by
5749 default @code{gtroff} processes text in environment@w{ }0.  The
5750 following is the information kept in an environment.
5752 @itemize @bullet{}
5753 @item
5754 type size
5755 @item
5756 font (family and style)
5757 @item
5758 page parameters
5759 @item
5760 fill/adjust mode
5761 @item
5762 tab stops
5763 @item
5764 partially collected lines
5765 @end itemize
5767 These environments may be given arbitrary names (@pxref{Identifiers},
5768 for more info).  Old versions of @code{troff} only had environments
5769 named @samp{0}, @samp{1} and@w{ }@samp{2}.
5771 @findex ev
5772 @vindex .ev
5773 The @code{ev} request will switch among environments.  The single
5774 argument is the name of the environment to switch to.  With no argument
5775 @code{gtroff} will switch back to the previous environment.  There is no
5776 limit on the number of named environments; they will be created the
5777 first time that they are referenced.  The @code{.ev} register contains
5778 the name or number of the current environment.  This is a string-valued
5779 register.
5781 Note that a call to @code{ev} (with argument) will push the previously
5782 active environment onto a stack.  If, say, environments @samp{foo},
5783 @samp{bar}, and @samp{zap} are called (in that order), the first
5784 @code{ev} request without parameter will switch back to environment
5785 @samp{bar} (which will be popped off the stack), and a second call will
5786 switch back to environment @samp{foo}.
5788 @c XXX example
5790 @example
5791 ... page break macro, revised ...
5792 @end example
5794 Here another example:
5796 @example
5797 .ev footnote-env
5798 .fam N
5799 .ps 6
5800 .vs 8
5801 .ll -.5i
5804 .ev footnote-env
5805 \(dg Note the large, friendly letters.
5807 @end example
5809 @findex evc
5810 To copy an environment into the current one, use the @code{evc} request,
5811 which takes the name of the environment to copy from as an argument.
5814 @node I/O, Postprocessor Access, Environments, Programming Tutorial
5815 @section I/O
5816 @cindex i/o
5817 @cindex input and output requests
5818 @cindex requests for input and output
5819 @cindex output and input requests
5821 @findex so
5822 The @code{so} request will read in the file given as an argument and
5823 include it in place of the @code{so} request.  This is quite useful for
5824 large documents, i.e.@: keeping each chapter in a separate file.
5825 @xref{gsoelim}, for more information.
5827 @findex mso
5828 The @code{mso} request is the same as the @code{so} request except that
5829 the file is searched for in the same way that @file{tmac.@var{name}} is
5830 searched for when the @option{-m@var{name}} option is specified.
5832 @findex cf
5833 @cindex transparent output
5834 @cindex output, transparent
5835 The @code{cf} and @code{trf} requests are to include a file.  It will
5836 transparently output the contents of file filename.  Each line is output
5837 as it were preceded by @code{\!}; however, the lines are not subject to
5838 copy-mode interpretation.  If the file does not end with a newline, then
5839 a newline will be added.  For example, to define a macro@w{ }@code{x}
5840 containing the contents of file@w{ }@file{f}, use
5842 @example
5843 .di x
5844 .trf f
5846 @end example
5848 The request @w{@code{.cf @var{filename}}}, when used in a diversion,
5849 will embed in the diversion an object which, when reread, will cause the
5850 contents of @var{filename} to be transparently copied through to the
5851 output.  In @acronym{UNIX} @code{troff}, the contents of @var{filename}
5852 is immediately copied through to the output regardless of whether there
5853 is a current diversion; this behaviour is so anomalous that it must be
5854 considered a bug.  This request causes a line break.
5856 @findex trf
5857 With @code{trf}, unlike @code{cf}, the file cannot contain characters
5858 such as NUL that are not legal @code{gtroff} input characters.  This
5859 request causes a line break.
5861 @c XXX xref to illegal input characters
5863 @findex nx
5864 The @code{nx} request will force @code{gtroff} to continue processing of
5865 the file specified as an argument.
5867 @findex rd
5868 The @code{rd} request will read from standard input, and include what is
5869 read as though it were part of the input file.  Text is read until a
5870 blank line is encountered.
5872 @cindex form letters
5873 @cindex letters, form
5874 Using these two requests it is easy to set up form letters.  The form
5875 letter template is constructed like this:
5877 @example
5879 \*(td
5880 .sp 2
5886 Body of letter.
5888 .nx repeat.let
5889 @end example
5891 @findex ex
5892 @noindent
5893 When this is run, the following file should be redirected in.  Note that
5894 requests included in this file are executed as though they were part of
5895 the form letter.  The last block of input is the @code{ex} requests
5896 which tells groff to stop processing.  If this was not there, groff
5897 would not know when to stop.
5899 @example
5900 Trent A. Fisher
5901 708 NW 19th Av., #202
5902 Portland, OR  97209
5904 Dear Trent,
5906 Len Adollar
5907 4315 Sierra Vista
5908 San Diego, CA  92103
5910 Dear Mr. Adollar,
5913 @end example
5915 @findex pi
5916 @code{pi}
5918 @c XXX documentation
5920 @findex sy
5921 The @code{sy} request will allow arbitrary system commands to be
5922 executed from within a @code{gtroff} document.  The output is not saved
5923 anyplace, so it is up to the user to do so.
5925 @c XXX add info about safer and unsafe mode
5927 For example, the following example will introduce the current time
5928 into a document:
5930 @cindex time, current
5931 @cindex current time
5932 @pindex perl
5933 @example
5934 .sy perl -e 'printf ".nr H %d\\n.nr M %d\\n.nr S %d\\n",\
5935              (localtime(time))[2,1,0]' > /tmp/x\n[$$]
5936 .so /tmp/x\n[$$]
5937 .sy rm /tmp/x\n[$$]
5938 \nH:\nM:\nS
5939 @end example
5941 @noindent
5942 Note that this works by having the @code{perl} script (run by @code{sy})
5943 print out the @code{nr} requests which will set the number registers
5944 @samp{H}, @samp{M} and @samp{S}, and then reads those commands in with
5945 the @code{so} request.
5947 @vindex systat
5948 The @code{systat} number register contains the return value of the
5949 @code{system()} function executed by the last @code{sy} request.
5951 @findex open
5952 The @code{open} request will open a file (specified as the second
5953 argument) for writing and associate the stream (specified as the first
5954 argument) with it.
5956 @findex opena
5957 The @code{opena} is like @code{open}, but if the file exists, append to
5958 it instead of truncating it.
5960 @findex write
5961 @findex ds
5962 @cindex copy-in mode
5963 @cindex mode, copy-in
5964 The @code{write} request will write to the file associated with the
5965 stream specified by the first argument.  The stream must previously have
5966 been the subject of an open request.  The remainder of the line is
5967 interpreted as the @code{ds} request reads its second argument: A
5968 leading @samp{"} will be stripped, and it will be read in copy-in mode.
5970 @findex close
5971 The @code{close} request will close the stream specified by the first
5972 argument; stream will no longer be an acceptable argument to the
5973 @code{write} request.
5975 @c XXX example
5977 @example
5978 ... example of open write &c...
5979 @end example
5981 @findex \V
5982 The @code{\V} escape will interpolate the contents of the specified
5983 environment variable, as returned by @code{getenv()}.  The argument to
5984 @code{\V} is specified as an identifier, i.e.@: @samp{\V@var{x}},
5985 @samp{\V(@var{xx}} or @samp{\V[@var{xxx}]}.  @code{\V} is interpreted in
5986 copy-in mode.
5989 @node Postprocessor Access, Miscellaneous, I/O, Programming Tutorial
5990 @section Postprocessor Access
5991 @cindex postprocessor access
5992 @cindex access of postprocessor
5994 There are two escapes which will allow information to be directly given
5995 to the postprocessor.  This is particularly useful for embedding
5996 @sc{PostScript} into the final document.
5998 @findex \X
5999 The @code{\X} escape will embed its argument into the @code{gtroff}
6000 output preceded with @w{@samp{x X}}.
6002 @findex \Y
6003 The @code{\Y} escape is called with an identifier (i.e.@:
6004 @code{\Y@var{x}}, @code{\Y(@var{xx}} or @code{\Y[@var{xxx}]}).  This is
6005 approximately equivalent to @samp{\X'\*[@var{xxx}]'}.  However, the
6006 contents of the string or macro @var{xxx} are not interpreted; also it
6007 is permitted for @var{xxx} to have been defined as a macro and thus
6008 contain newlines (it is not permitted for the argument to @code{\X} to
6009 contain newlines).  The inclusion of newlines requires an extension to
6010 the @acronym{UNIX} @code{troff} output format, and will confuse drivers
6011 that do not know about this extension.
6013 @xref{Output Devices}.
6016 @node Miscellaneous, Debugging, Postprocessor Access, Programming Tutorial
6017 @section Miscellaneous
6018 @cindex miscellaneous
6020 This section contains parts of @code{gtroff} which cannot (yet) be
6021 categorized elsewhere in this manual.
6023 @findex nm
6024 @cindex line numbers
6025 @cindex numbers, line
6026 Line numbers can be printed in the left margin using the @code{nm}
6027 request.  The first argument is the line number of the @emph{next}
6028 output line; this defaults to@w{ }1.  The second argument indicates on
6029 which lines numbers will be printed, i.e.@: 5 means put line numbers on
6030 every 5@w{ }lines; this defaults to@w{ }1.  The third argument is the
6031 space to be left between the number and the text; this defaults to@w{
6032 }1.  The fourth argument is the indentation of the line numbers.
6033 Without arguments, line numbers are turned off.
6035 @c XXX xref ln register
6037 @findex nn
6038 The @code{nn} request will temporarily turn off line numbering.  The
6039 first argument is the number of lines not to be numbered; this defaults
6040 to@w{ }1.
6042 @c XXX (does this disable incrementing or display?)
6044 @c XXX example
6046 @example
6047 ... line numbering example ...
6048 @end example
6050 @findex mc
6051 @cindex margin characters
6052 @cindex characters for margins
6053 Margin characters can be automatically printed to the right of the text
6054 with the @code{mc} request.  The first argument is the character to be
6055 printed, and the second argument is the distance away from the main body
6056 text.  With no arguments the margin characters are turned off.  If this
6057 occurs before a break, no margin character will be printed.
6059 @pindex nrchbar
6060 @pindex changebar
6061 This is quite useful for indicating text that has changed, and, in fact,
6062 there are programs available for doing this (they are called
6063 @code{nrchbar} and @code{changebar} and can be found in any
6064 @samp{comp.sources.unix} archive.
6066 @c XXX example
6068 @example
6069 ... margin char example ...
6070 @end example
6072 @findex lf
6073 @pindex soelim
6074 @cindex multi-file documents
6075 @cindex documents, multi-file
6076 The primary reason for the existence of @code{lf} is to make debugging
6077 documents which are split into many files, which are then put together
6078 with @code{soelim} and other preprocessors.  The first argument is the
6079 name of the file and the second argument is the input line number in
6080 that file.  This way @code{gtroff} can produce error messages which are
6081 intelligible to the user.
6083 @c XXX example
6085 @example
6086 ... example of soelim'ed doc ...
6087 @end example
6090 @node Debugging, Implementation Differences, Miscellaneous, Programming Tutorial
6091 @section Debugging
6092 @cindex debugging
6094 @code{gtroff} is not easy to debug, but there are some useful features
6095 and strategies for debugging.
6097 @itemize @bullet{}
6098 @item
6099 @findex tm
6100 The @code{tm} request will send output to stderr; this is very useful
6101 for printing debugging output.
6102 @item
6103 When doing something involved it is useful to leave the debugging
6104 statements in the code and have them turned on by a command line flag.
6106 @example
6107 .if \n(DB .tm debugging output
6108 @end example
6110 @noindent
6111 To activate these statements say
6113 @example
6114 groff -rDB=1 file
6115 @end example
6117 @item
6118 @findex ab
6119 @cindex aborting
6120 The @code{ab} request is similar to the @code{tm} request, except that
6121 it will cause @code{gtroff} to stop processing.  With no argument it
6122 will print @samp{User Abort}.
6123 @item
6124 @findex ex
6125 @cindex exiting
6126 The @code{ex} request will also cause @code{gtroff} to stop processing
6127 (if encountered at the topmost level; see also @ref{I/O}.
6128 @item
6129 If it is known in advance that there will be many errors and no useful
6130 output, @code{gtroff} can be forced to suppress formatted output with
6131 the @option{-z} flag.
6132 @item
6133 @findex pm
6134 @cindex dumping symbol table
6135 @cindex symbol table, dumping
6136 The @code{pm} request will dump out the entire symbol table.
6137 @item
6138 @findex pnr
6139 @cindex dumping number registers
6140 @cindex number registers, dumping
6141 The @code{pnr} request will print the names and contents of all
6142 currently defined number registers on stderr.
6143 @item
6144 @findex ptr
6145 @cindex dumping traps
6146 @cindex traps, dumping
6147 The @code{ptr} request will print the names and positions of all traps
6148 (not including input line traps and diversion traps) on stderr.  Empty
6149 slots in the page trap list are printed as well, because they can affect
6150 the priority of subsequently planted traps.
6151 @item
6152 @findex fl
6153 @cindex flush output
6154 @cindex output, flush
6155 @cindex interactive use of @code{gtroff}
6156 @cindex @code{gtroff}, interactive use
6157 The @code{fl} request instructs @code{gtroff} to flush its output
6158 immediately.  The intention is that this be used when using
6159 @code{gtroff} interactively.  There is little other use for it.  This
6160 request causes a line break.
6161 @item
6162 @findex backtrace
6163 @cindex backtrace of input stack
6164 @cindex input stack, backtrace
6165 The @code{backtrace} request will print a backtrace of the input stack
6166 on stderr.
6167 @item
6168 @cindex warnings
6169 @code{gtroff} has command line options for printing out more warnings
6170 (@option{-w}) and for printing backtraces (@option{-b}) when a warning
6171 or an error occurs.  The most verbose level of warnings is @option{-ww}.
6172 @item
6173 @findex warn
6174 @vindex .warn
6175 @cindex level of warnings
6176 @cindex warnings, level
6177 The @code{warn} request controls the level of warnings checked for.  The
6178 only argument is the sum of the numbers associated with each warning
6179 that is to be enabled; all other warnings will be disabled.  The number
6180 associated with each warning is listed below.  For example,
6181 @w{@code{.warn 0}} will disable all warnings, and @w{@code{.warn 1}}
6182 will disable all warnings except that about missing characters.  If an
6183 argument is not given, all warnings will be enabled.  The number
6184 register @code{.warn} contains the current warning level.
6185 @end itemize
6187 @subsection Warnings
6188 @cindex warnings
6190 The warnings that can be given to @code{gtroff} are divided into the
6191 following categories.  The name associated with each warning is used by
6192 the @option{-w} and @option{-W} options; the number is used by the
6193 @code{warn} request and by the @code{.warn} register.
6195 @table @samp
6196 @item char
6197 @itemx 1
6198 Non-existent characters.  This is enabled by default.
6199 @item number
6200 @itemx 2
6201 Invalid numeric expressions.  This is enabled by default.
6202 @xref{Expressions}.
6203 @item break
6204 @itemx 4
6205 In fill mode, lines which could not be broken so that their length was
6206 less than the line length.  This is enabled by default.
6207 @item delim
6208 @itemx 8
6209 Missing or mismatched closing delimiters.
6210 @item el
6211 @itemx 16
6212 @findex ie
6213 @findex el
6214 Use of the @code{el} request with no matching @code{ie} request.
6215 @xref{if-else}.
6216 @item scale
6217 @itemx 32
6218 Meaningless scaling indicators.
6219 @item range
6220 @itemx 64
6221 Out of range arguments.
6222 @item syntax
6223 @itemx 128
6224 Dubious syntax in numeric expressions.
6225 @item di
6226 @itemx 256
6227 @findex di
6228 @findex da
6229 Use of @code{di} or @code{da} without an argument when there is no
6230 current diversion.
6231 @item mac
6232 @itemx 512
6233 @findex de
6234 @c XXX more findex entries
6235 Use of undefined strings, macros and diversions.  When an undefined
6236 string, macro or diversion is used, that string is automatically defined
6237 as empty.  So, in most cases, at most one warning will be given for each
6238 name.
6239 @item  reg
6240 @itemx 1024
6241 @findex nr
6242 @c XXX more findex entries
6243 Use of undefined number registers.  When an undefined number register is
6244 used, that register is automatically defined to have a value of@w{ }0.
6245 A definition is automatically made with a value of@w{ }0.  So, in most
6246 cases, at most one warning will be given for use of a particular name.
6247 @item  tab
6248 @itemx 2048
6249 Use of a tab character where a number was expected.
6250 @item  right-brace
6251 @itemx 4096
6252 @findex \@}
6253 Use of @code{\@}} where a number was expected.
6254 @item  missing
6255 @itemx 8192
6256 Requests that are missing non-optional arguments.
6257 @item  input
6258 @itemx 16384
6259 Illegal input characters.
6260 @item  escape
6261 @itemx 32768
6262 Unrecognized escape sequences.  When an unrecognized escape sequence is
6263 encountered, the escape character is ignored.
6264 @item  space
6265 @itemx 65536
6266 @cindex compatibility mode
6267 Missing space between a request or macro and its argument.  This warning
6268 will be given when an undefined name longer than two characters is
6269 encountered, and the first two characters of the name make a defined
6270 name.  The request or macro will not be invoked.  When this warning is
6271 given, no macro is automatically defined.  This is enabled by default.
6272 This warning will never occur in compatibility mode.
6273 @item  font
6274 @itemx 131072
6275 Non-existent fonts.  This is enabled by default.
6276 @item all
6277 All warnings except @samp{di}, @samp{mac} and @samp{reg}.  It is
6278 intended that this covers all warnings that are useful with traditional
6279 macro packages.
6280 @item w
6281 All warnings.
6282 @end table
6285 @node Implementation Differences, Summary, Debugging, Programming Tutorial
6286 @section Implementation Differences
6287 @cindex implementation differences
6288 @cindex differences in implementation
6289 @cindex compatibility mode
6290 @cindex mode, compatibility
6292 GNU @code{troff} has a number of features which cause incompatibilities
6293 with documents written with old versions of @code{troff}.
6295 @cindex long names
6296 @cindex names, long
6297 Long names cause some incompatibilities.  @acronym{UNIX} @code{troff}
6298 will interpret
6300 @example
6301 .dsabcd
6302 @end example
6304 @findex \*
6305 @findex \n
6306 @findex cp
6307 @vindex .C
6308 @noindent
6309 as defining a string @samp{ab} with contents @samp{cd}.  Normally, GNU
6310 @code{troff} will interpret this as a call of a macro named
6311 @code{dsabcd}.  Also @acronym{UNIX} @code{troff} will interpret
6312 @code{\*[} or @code{\n[} as references to a string or number register
6313 called @samp{[}.  In GNU @code{troff}, however, this will normally be
6314 interpreted as the start of a long name.  In compatibility mode GNU
6315 @code{troff} will interpret these things in the traditional way.  In
6316 compatibility mode, however, long names are not recognized.
6317 Compatibility mode can be turned on with the @option{-C} command line
6318 option, and turned on or off with the @code{cp} request.  The number
6319 register @code{.C} is@w{ }1 if compatibility mode is on, 0@w{
6320 }otherwise.
6322 @findex \A
6323 @findex \|
6324 @findex \^
6325 @findex \&
6326 @findex \@}
6327 @findex \@{
6328 @findex \@key{SP}
6329 @findex \'
6330 @findex \`
6331 @findex \-
6332 @findex \_
6333 @findex \!
6334 @findex \%
6335 @findex \c
6336 GNU @code{troff} does not allow the use of the escape sequences
6337 @code{\|}, @code{\^}, @code{\&}, @code{\@}}, @code{\@{},
6338 @code{\@key{SP}}, @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!},
6339 @code{\%}, and @code{\c} in names of strings, macros, diversions, number
6340 registers, fonts or environments; @acronym{UNIX} @code{troff} does.  The
6341 @code{\A} escape sequence (@pxref{Identifiers}) may be helpful in
6342 avoiding use of these escape sequences in names.
6344 @cindex fractional point sizes
6345 @cindex point sizes, fractional
6346 @findex ps
6347 Fractional point sizes cause one noteworthy incompatibility.  In
6348 @acronym{UNIX} @code{troff} the @code{ps} request ignores scale
6349 indicators and thus
6351 @example
6352 .ps 10u
6353 @end example
6355 @noindent
6356 will set the point size to 10@w{ }points, whereas in GNU @code{troff} it
6357 will set the point size to 10@w{ }scaled points.  @xref{Fractional Type
6358 Sizes}, for more information.
6360 @findex bd
6361 @findex cs
6362 @findex tkf
6363 @findex tr
6364 @findex fp
6365 @cindex input and output characters
6366 @cindex output characters
6367 @cindex characters, input and output
6368 In GNU @code{troff} there is a fundamental difference between
6369 unformatted, input characters, and formatted, output characters.
6370 Everything that affects how an output character will be output is stored
6371 with the character; once an output character has been constructed it is
6372 unaffected by any subsequent requests that are executed, including
6373 @code{bd}, @code{cs}, @code{tkf}, @code{tr}, or @code{fp} requests.
6374 Normally output characters are constructed from input characters at the
6375 moment immediately before the character is added to the current output
6376 line.  Macros, diversions and strings are all, in fact, the same type of
6377 object; they contain lists of input characters and output characters in
6378 any combination.  An output character does not behave like an input
6379 character for the purposes of macro processing; it does not inherit any
6380 of the special properties that the input character from which it was
6381 constructed might have had.  For example,
6383 @example
6384 .di x
6385 \\\\
6389 @end example
6391 @findex \e
6392 @findex \!
6393 @findex \?
6394 @cindex transparent output
6395 @cindex output, transparent
6396 @noindent
6397 will print @samp{\\} in GNU @code{troff}; each pair of input backslashes
6398 is turned into one output backslash and the resulting output backslashes
6399 are not interpreted as escape characters when they are reread.
6400 @acronym{UNIX} @code{troff} would interpret them as escape characters
6401 when they were reread and would end up printing one @samp{\}.  The
6402 correct way to obtain a printable backslash is to use the @code{\e}
6403 escape sequence: This will always print a single instance of the current
6404 escape character, regardless of whether or not it is used in a
6405 diversion; it will also work in both GNU @code{troff} and @acronym{UNIX}
6406 @code{troff}.  To store, for some reason, an escape sequence in a
6407 diversion that will be interpreted when the diversion is reread, either
6408 use the traditional @code{\!} transparent output facility, or, if this
6409 is unsuitable, the new @code{\?} escape sequence.
6411 @xref{Diversions}, for more information.
6414 @node Summary,  , Implementation Differences, Programming Tutorial
6415 @section Summary
6416 @cindex summary
6418 @c XXX documentation
6422 @node Preprocessors, Output Devices, Programming Tutorial, Top
6423 @chapter Preprocessors
6424 @cindex preprocessors
6426 This chapter describes all preprocessors that come with @code{groff} or
6427 which are freely available.
6429 @menu
6430 * geqn::                        
6431 * gtbl::                        
6432 * gpic::                        
6433 * ggrn::                        
6434 * grap::                        
6435 * grefer::                      
6436 * gsoelim::                     
6437 @end menu
6440 @node geqn, gtbl, Preprocessors, Preprocessors
6441 @section @code{geqn}
6442 @cindex @code{eqn}
6443 @cindex @code{geqn}
6445 @c XXX
6447 @menu
6448 * Invoking geqn::               
6449 @end menu
6451 @node Invoking geqn,  , geqn, geqn
6452 @subsection Invoking @code{geqn}
6453 @cindex invoking @code{geqn}
6454 @cindex @code{geqn}, invoking
6456 @c XXX
6459 @node gtbl, gpic, geqn, Preprocessors
6460 @section @code{gtbl}
6461 @cindex @code{tbl}
6462 @cindex @code{gtbl}
6464 @c XXX
6466 @menu
6467 * Invoking gtbl::               
6468 @end menu
6470 @node Invoking gtbl,  , gtbl, gtbl
6471 @subsection Invoking @code{gtbl}
6472 @cindex invoking @code{gtbl}
6473 @cindex @code{gtbl}, invoking
6475 @c XXX
6478 @node gpic, ggrn, gtbl, Preprocessors
6479 @section @code{gpic}
6480 @cindex @code{pic}
6481 @cindex @code{gpic}
6483 @c XXX
6485 @menu
6486 * Invoking gpic::               
6487 @end menu
6489 @node Invoking gpic,  , gpic, gpic
6490 @subsection Invoking @code{gpic}
6491 @cindex invoking @code{gpic}
6492 @cindex @code{gpic}, invoking
6494 @c XXX
6497 @node ggrn, grap, gpic, Preprocessors
6498 @section @code{ggrn}
6499 @cindex @code{grn}
6500 @cindex @code{ggrn}
6502 @c XXX
6504 @menu
6505 * Invoking ggrn::               
6506 @end menu
6508 @node Invoking ggrn,  , ggrn, ggrn
6509 @subsection Invoking @code{ggrn}
6510 @cindex invoking @code{ggrn}
6511 @cindex @code{ggrn}, invoking
6513 @c XXX
6516 @node grap, grefer, ggrn, Preprocessors
6517 @section @code{grap}
6518 @cindex @code{grap}
6520 A freely available implementation of @code{grap}, written by Ted Faber,
6521 is available as an extra package from the following address:
6523 @display
6524 @url{http://www.lunabase.org/~faber/Vault/software/grap/}
6525 @end display
6528 @node grefer, gsoelim, grap, Preprocessors
6529 @section @code{grefer}
6530 @cindex @code{refer}
6531 @cindex @code{grefer}
6533 @c XXX
6535 @menu
6536 * Invoking grefer::             
6537 @end menu
6539 @node Invoking grefer,  , grefer, grefer
6540 @subsection Invoking @code{grefer}
6541 @cindex invoking @code{grefer}
6542 @cindex @code{grefer}, invoking
6544 @c XXX
6547 @node gsoelim,  , grefer, Preprocessors
6548 @section @code{gsoelim}
6549 @cindex @code{soelim}
6550 @cindex @code{gsoelim}
6552 @c XXX
6554 @menu
6555 * Invoking gsoelim::            
6556 @end menu
6558 @node Invoking gsoelim,  , gsoelim, gsoelim
6559 @subsection Invoking @code{gsoelim}
6560 @cindex invoking @code{gsoelim}
6561 @cindex @code{gsoelim}, invoking
6563 @c XXX
6567 @node Output Devices, File formats, Preprocessors, Top
6568 @chapter Output Devices
6569 @cindex output devices
6570 @cindex devices for output
6572 @c XXX
6574 @menu
6575 * Special Characters::          
6576 * grotty::                      
6577 * grops::                       
6578 * grodvi::                      
6579 * grolj4::                      
6580 * grolbp::                      
6581 * grohtml::                     
6582 * gxditview::                   
6583 @end menu
6586 @node Special Characters, grotty, Output Devices, Output Devices
6587 @section Special Characters
6588 @cindex special characters
6589 @cindex characters, special
6591 @c XXX
6593 @xref{Font Files}.
6596 @node grotty, grops, Special Characters, Output Devices
6597 @section @code{grotty}
6598 @cindex @code{grotty}
6600 @c XXX
6602 @menu
6603 * Invoking grotty::             
6604 @end menu
6606 @node Invoking grotty,  , grotty, grotty
6607 @subsection Invoking @code{grotty}
6608 @cindex invoking @code{grotty}
6609 @cindex @code{grotty}, invoking
6611 @c XXX
6614 @node grops, grodvi, grotty, Output Devices
6615 @section @code{grops}
6616 @cindex @code{grops}
6618 @c XXX
6620 @menu
6621 * Invoking grops::              
6622 * Embedding PostScript::        
6623 @end menu
6625 @node Invoking grops, Embedding PostScript, grops, grops
6626 @subsection Invoking @code{grops}
6627 @cindex invoking @code{grops}
6628 @cindex @code{grops}, invoking
6630 @c XXX
6632 @node Embedding PostScript,  , Invoking grops, grops
6633 @subsection Embedding @sc{PostScript}
6634 @cindex embedding postscript
6635 @cindex postscript, embedding
6637 @c XXX
6640 @node grodvi, grolj4, grops, Output Devices
6641 @section @code{grodvi}
6642 @cindex @code{grodvi}
6644 @c XXX
6646 @menu
6647 * Invoking grodvi::             
6648 @end menu
6650 @node Invoking grodvi,  , grodvi, grodvi
6651 @subsection Invoking @code{grodvi}
6652 @cindex invoking @code{grodvi}
6653 @cindex @code{grodvi}, invoking
6655 @c XXX
6658 @node grolj4, grolbp, grodvi, Output Devices
6659 @section @code{grolj4}
6660 @cindex @code{grolj4}
6662 @c XXX
6664 @menu
6665 * Invoking grolj4::             
6666 @end menu
6668 @node Invoking grolj4,  , grolj4, grolj4
6669 @subsection Invoking @code{grolj4}
6670 @cindex invoking @code{grolj4}
6671 @cindex @code{grolj4}, invoking
6673 @c XXX
6676 @node grolbp, grohtml, grolj4, Output Devices
6677 @section @code{grolbp}
6678 @cindex @code{grolbp}
6680 @c XXX
6682 @menu
6683 * Invoking grolbp::             
6684 @end menu
6686 @node Invoking grolbp,  , grolbp, grolbp
6687 @subsection Invoking @code{grolbp}
6688 @cindex invoking @code{grolbp}
6689 @cindex @code{grolbp}, invoking
6691 @c XXX
6694 @node grohtml, gxditview, grolbp, Output Devices
6695 @section @code{grohtml}
6696 @cindex @code{grohtml}
6698 @c XXX
6700 @menu
6701 * Invoking grohtml::            
6702 @end menu
6704 @node Invoking grohtml,  , grohtml, grohtml
6705 @subsection Invoking @code{grohtml}
6706 @cindex invoking @code{grohtml}
6707 @cindex @code{grohtml}, invoking
6709 @c XXX
6712 @node gxditview,  , grohtml, Output Devices
6713 @section @code{gxditview}
6714 @cindex @code{gxditview}
6716 @c XXX
6718 @menu
6719 * Invoking gxditview::          
6720 @end menu
6722 @node Invoking gxditview,  , gxditview, gxditview
6723 @subsection Invoking @code{gxditview}
6724 @cindex invoking @code{gxditview}
6725 @cindex @code{gxditview}, invoking
6727 @c XXX
6728 @c X11's xditview
6732 @node File formats, Installation, Output Devices, Top
6733 @chapter File formats
6734 @cindex file formats
6735 @cindex formats, file
6737 @c XXX
6739 @menu
6740 * gtroff Output::               
6741 * Font Files::                  
6742 @end menu
6745 @node gtroff Output, Font Files, File formats, File formats
6746 @section @code{gtroff} Output
6747 @cindex @code{gtroff} output
6748 @cindex output, @code{gtroff}
6750 This section describes the format output of GNU @code{troff}.  The
6751 output format used by GNU @code{troff} is very similar to that used by
6752 @acronym{UNIX} device-independent @code{troff} (@code{ditroff}).
6754 @menu
6755 * Output Format::               
6756 * Device Control::              
6757 * Drawing Functions::           
6758 * Line Continuation::           
6759 @end menu
6761 @node Output Format, Device Control, gtroff Output, gtroff Output
6762 @subsection Output Format
6763 @cindex output format
6764 @cindex format of output
6766 @cindex 8-bit input
6767 @cindex input, 8-bit
6768 The output format is text based, as opposed to a binary format (like
6769 @TeX{} DVI).  The output format is @w{8-bit} clean, thus single
6770 characters can have the eighth bit set, as can the names of fonts and
6771 special characters.
6773 The output format consists of single command characters with attached
6774 parameters which are separated from subsequent text by whitespace or a
6775 newline.
6777 The names of characters and fonts can be of arbitrary length; drivers
6778 should not assume that they will be only two characters long (as
6779 @code{ditroff} does).
6781 When a character is to be printed, that character will always be in the
6782 current font.  Unlike @code{ditroff}, it is not necessary for drivers to
6783 search special fonts to find a character.
6785 @table @code
6786 @item H@var{n}
6787 @c XXX
6788 @item V@var{n}
6789 @c XXX
6790 @item h@var{n}
6791 @c XXX
6792 @item v@var{n}
6793 @c XXX
6794 @item c@var{n}
6795 @c XXX
6796 @item C@var{n}
6797 @c XXX
6798 @item @var{nn}@var{c}
6799 @c XXX
6800 @item t@var{xxx}
6801 @var{xxx} is any sequence of characters terminated by a space or a
6802 newline; the first character should be printed at the current position,
6803 the the current horizontal position should be increased by the width of
6804 the first character, and so on for each character.  The width of the
6805 character is that given in the font file, appropriately scaled for the
6806 current point size, and rounded so that it is a multiple of the
6807 horizontal resolution.  Special characters cannot be printed using this
6808 command.
6810 @kindex tcommand
6811 @pindex DESC
6812 This command is only allowed if the @samp{tcommand} line is present in
6813 the @file{DESC} file.
6814 @item u@var{n} @var{xxx}
6815 This is same as the @samp{t} command except that after printing each
6816 character, the current horizontal position is increased by the sum of
6817 the width of that character and@w{ }@var{n}.
6819 This command is only allowed if the @samp{tcommand} line is present in
6820 the @file{DESC} file.
6821 @item n@var{a}@var{b}
6822 @c XXX
6823 @item p@var{n}
6824 @c XXX
6825 @item s@var{n}
6826 @kindex sizescale
6827 @pindex DESC
6828 The argument to the @samp{s} command is in scaled points (units of
6829 points/@var{n}, where @var{n} is the argument to the @samp{sizescale}
6830 command in the @file{DESC} file).
6831 @item f@var{n}
6832 @item x @dots{} \n
6833 Device control.
6834 @c XXX more info
6835 @item D@var{c} @var{x}@dots{}\n
6836 @c XXX
6837 @end table
6839 @node Device Control, Drawing Functions, Output Format, gtroff Output
6840 @subsection Device Control
6841 @cindex device control
6842 @cindex control of devices
6844 The @samp{x} command is normally followed by a letter or word indicating
6845 the function to perform, followed by white space separated arguments.
6847 The first argument can be abbreviated to the first letter.
6849 @table @code
6850 @item x init
6851 @c XXX
6852 @item x T
6853 @c XXX
6854 @item x res @var{n} @var{h} @var{v}
6855 @c XXX
6856 @item x H
6857 @c XXX more info
6858 The argument to the @w{@samp{x Height}} command is also in scaled
6859 points.
6860 @end table
6862 The first three output commands are guaranteed to be:
6864 @example
6865 x T device
6866 x res n h v
6867 x init
6868 @end example
6870 @noindent
6871 For example, the input
6873 @example
6874 crunchy \fH\s+2frog\s0\fP!?
6875 @end example
6877 @noindent
6878 will produce
6880 @c XXX example
6882 @example
6883 ... sample output here ...
6884 @end example
6886 @node Drawing Functions, Line Continuation, Device Control, gtroff Output
6887 @subsection Drawing Functions
6888 @cindex drawing functions
6889 @cindex functions for drawing
6891 @pindex gpic
6892 The @samp{D} drawing command has been extended.  These extensions will
6893 only be used by GNU @code{pic} if the @option{-x} option is given.
6895 @xref{Drawing Requests}.
6897 @table @code
6898 @c XXX ...
6899 @item Df @var{n}
6900 Set the shade of gray to be used for filling solid objects to@w{
6901 }@var{n}; @var{n}@w{ }must be an integer between 0 and@w{ }1000, where 0
6902 corresponds solid white and 1000 to solid black, and values in between
6903 correspond to intermediate shades of gray.  This applies only to solid
6904 circles, solid ellipses and solid polygons.  By default, a level of@w{
6905 }1000 will be used.  Whatever color a solid object has, it should
6906 completely obscure everything beneath it.  A value greater than@w{ }1000
6907 or less than@w{ }0 can also be used: this means fill with the shade of
6908 gray that is currently being used for lines and text.  Normally this
6909 will be black, but some drivers may provide a way of changing this.
6910 @item DC @var{d}
6911 Draw a solid circle with a diameter of@w{ }@var{d} with the leftmost
6912 point at the current position.
6913 @item DE @var{dx} @var{dy}
6914 Draw a solid ellipse with a horizontal diameter of@w{ }@var{dx} and a
6915 vertical diameter of@w{ }@var{dy} with the leftmost point at the current
6916 position.
6917 @item Dp @var{dx1} @var{dy1} @var{dx2} @var{dy2} @dots{} @var{dxn} @var{dyn}
6918 Draw a polygon with.  The first vertex is at the current position, the
6919 second vertex at an offset (@var{dx1},@var{dy1}) from the current
6920 position, the second vertex at an offset (@var{dx2},@var{dy2}) from the
6921 first vertex, and so on up to the @var{n}-th vertex.  At the moment, GNU
6922 @code{pic} only uses this command to generate triangles and rectangles.
6923 @item DP @var{dx1} @var{dy1} @var{dx2} @var{dy2} @dots{} @var{dxn} @var{dyn}
6924 Like @code{Dp} but draw a solid rather than outlined polygon.
6925 @item Dt @var{n}
6926 @cindex line thickness
6927 @cindex thickness of lines
6928 Set the current line thickness to @var{n}@w{ }machine units.
6929 Traditionally, @acronym{UNIX} @code{troff} drivers use a line thickness
6930 proportional to the current point size; drivers should continue to do
6931 this if no @code{Dt} command has been given, or if a @code{Dt} command
6932 has been given with a negative value of@w{ }@var{n}.  A zero value of@w{
6933 }@var{n} selects the smallest available line thickness.
6934 @end table
6936 @findex \D
6937 A difficulty arises in how the current position should be changed after
6938 the execution of these commands.  This is not of great importance since
6939 the code generated by GNU @code{pic} does not depend on this.  Given a
6940 drawing command of the form
6942 @example
6943 \D'@var{c} @var{x1} @var{y1} @var{x2} @var{y2} @dots{} @var{xn} @var{yn}'
6944 @end example
6946 @findex \w
6947 @vindex st
6948 @findex sb
6949 @noindent
6950 where @var{c} is not one of @samp{c}, @samp{e}, @samp{l}, @samp{a} or
6951 @samp{~}, @acronym{UNIX} @code{troff} will treat each of the x@w{ }value
6952 as a horizontal quantity, and each of the y@w{ }values as a vertical
6953 quantity and will assume that the width of the drawn object is sum if
6954 all x@w{ }values, and that the height is the sum of all y@w{ }values.
6955 (The assumption about the height can be seen by examining the @code{st}
6956 and @code{sb} registers after using such a @code{D}@w{ }command in a
6957 @code{\w} escape sequence.)  This rule also holds for all the original
6958 drawing commands with the exception of @code{De}.  For the sake of
6959 compatibility GNU @code{troff} also follows this rule, even though it
6960 produces an ugly result in the case of the @code{Df}, @code{Dt}, and, to
6961 a lesser extent, @code{DE}@w{ }commands.  Thus after executing a
6962 @code{D}@w{ }command of the form
6964 @example
6965 D@var{c} @var{x1} @var{y1} @var{x2} @var{y2} @dots{} @var{xn} @var{yn}
6966 @end example
6968 @noindent
6969 the current position should be increased horizontally by the sum of all
6970 x@w{ }values and vertically by the sum of all y@w{ }values.
6972 @node Line Continuation,  , Drawing Functions, gtroff Output
6973 @subsection Line Continuation
6974 @cindex line continuation in output commands
6975 @cindex output commands, line continuation
6977 There is a continuation convention which permits the argument to the
6978 @w{@samp{x X}} command to contain newlines: When outputting the argument
6979 to the @w{@samp{x X}} command, GNU @code{troff} will follow each newline
6980 in the argument with a @samp{+} character (as usual, it will terminate
6981 the entire argument with a newline); thus if the line after the line
6982 containing the @w{@samp{x X}} command starts with @samp{+}, then the
6983 newline ending the line containing the @w{@samp{x X}} command should be
6984 treated as part of the argument to the @w{@samp{x X}} command, the
6985 @samp{+} should be ignored, and the part of the line following the
6986 @samp{+} should be treated like the part of the line following the
6987 @w{@samp{x X}} command.
6990 @node Font Files,  , gtroff Output, File formats
6991 @section Font Files
6992 @cindex font files
6993 @cindex files, font
6995 The @code{gtroff} font format is roughly a superset of the
6996 @code{ditroff} font format.  Unlike the @code{ditroff} font format,
6997 there is no associated binary format; all files are text files.  The
6998 font files for device @var{name} are stored in a directory
6999 @file{dev@var{name}}.  There are two types of file: a device description
7000 file called @file{DESC} and for each font@w{ }@samp{F} a font file
7001 called@w{ }@file{F}.
7003 @menu
7004 * DESC file format::            
7005 * Font file format::            
7006 @end menu
7008 @node DESC file format, Font file format, Font Files, Font Files
7009 @subsection @file{DESC} file format
7010 @cindex @file{DESC} file format
7011 @cindex font description file format
7012 @cindex format of font description file
7013 @pindex DESC
7015 The @file{DESC} file can contain the following types of line:
7017 @table @code
7018 @kindex res
7019 @item res @var{n}
7020 There are @var{n} machine units per inch.
7021 @kindex hor
7022 @item hor @var{n}
7023 The horizontal resolution is @var{n} machine units.
7024 @kindex vert
7025 @item vert @var{n}
7026 The vertical resolution is @var{n} machine units.
7027 @kindex sizescale
7028 @item sizescale @var{n}
7029 The scale factor for point sizes.  By default this has a value of@w{ }1.
7030 One scaled point is equal to one point/@var{n}.  The arguments to the
7031 @code{unitwidth} and @code{sizes} commands are given in scaled points.
7032 @xref{Fractional Type Sizes}, for more information.
7033 @kindex unitwidth
7034 @item unitwidth @var{n}
7035 Quantities in the font files are given in machine units for fonts whose
7036 point size is @var{n}@w{ }scaled points.
7037 @kindex tcommand
7038 @item tcommand
7039 This means that the postprocessor can handle the @samp{t} and @samp{u}
7040 output commands.
7041 @kindex sizes
7042 @item sizes @var{s1} @var{s2} @dots{} @var{sn} 0
7043 This means that the device has fonts at @var{s1}, @var{s2}, @dots{}
7044 @var{sn} scaled points.  The list of sizes must be terminated by a@w{
7045 }0.  Each @var{si} can also be a range of sizes @var{m}-@var{n}.  The
7046 list can extend over more than one line.
7047 @kindex styles
7048 @item styles @var{S1} @var{S2} @dots{} @var{Sm}
7049 The first @var{m}@w{ }font positions will be associated with styles
7050 @var{S1} @dots{} @var{Sm}.
7051 @kindex fonts
7052 @item fonts @var{n} @var{F1} @var{F2} @var{F3} @dots{} @var{Fn}
7053 Fonts @var{F1} @dots{} @var{Fn} will be mounted in the font positions
7054 @var{m}+1, @dots{}, @var{m}+@var{n} where @var{m} is the number of
7055 styles.  This command may extend over more than one line.  A font name
7056 of@var{ }0 will cause no font to be mounted on the corresponding font
7057 position.
7058 @kindex family
7059 @item family @var{fam}
7060 The default font family is @var{fam}.
7061 @kindex charset
7062 @item charset
7063 This line and everything following in the file are ignored.  It is
7064 allowed for the sake of backwards compatibility.
7065 @end table
7067 The @code{res}, @code{unitwidth}, @code{fonts} and @code{sizes} lines
7068 are compulsory.  Other commands are ignored by @code{gtroff} but may be
7069 used by postprocessors to store arbitrary information about the device
7070 in the @file{DESC} file.
7072 @c XXX add other commands resp. xrefs to output devices
7073 @c XXX add obsolete commands
7075 @node Font file format,  , DESC file format, Font Files
7076 @subsection Font file format
7077 @cindex font file format
7078 @cindex format of font files
7080 A font file has two sections.  The first section is a sequence of lines
7081 each containing a sequence of blank delimited words; the first word in
7082 the line is a key, and subsequent words give a value for that key.
7084 @table @code
7085 @kindex name
7086 @item name @var{F}
7087 The name of the font is@w{ }@var{F}.
7088 @kindex spacewidth
7089 @item spacewidth @var{n}
7090 The normal width of a space is@w{ }@var{n}.
7091 @kindex slant
7092 @item slant @var{n}
7093 The characters of the font have a slant of @var{n}@w{ }degrees.
7094 (Positive means forward.)
7095 @kindex ligatures
7096 @item ligatures @var{lig1} @var{lig2} @dots{} @var{lign} [0]
7097 Characters @var{lig1}, @var{lig2}, @dots{}, @var{lign} are ligatures;
7098 possible ligatures are @samp{ff}, @samp{fi}, @samp{fl}, @samp{ffi} and
7099 @samp{ffl}.  For backwards compatibility, the list of ligatures may be
7100 terminated with a@w{ }0.  The list of ligatures may not extend over more
7101 than one line.
7102 @kindex special
7103 @item special
7104 The font is special; this means that when a character is requested that
7105 is not present in the current font, it will be searched for in any
7106 special fonts that are mounted.
7107 @end table
7109 Other commands are ignored by @code{gtroff} but may be used by
7110 postprocessors to store arbitrary information about the font in the font
7111 file.
7113 @cindex comments in font files
7114 @cindex font files, comments
7115 @kindex #
7116 The first section can contain comments which start with the @samp{#}
7117 character and extend to the end of a line.
7119 The second section contains one or two subsections.  It must contain a
7120 @code{charset} subsection and it may also contain a @code{kernpairs}
7121 subsection.  These subsections can appear in any order.  Each
7122 subsection starts with a word on a line by itself.
7124 @kindex charset
7125 The word @code{charset} starts the character set subsection.  The
7126 @code{charset} line is followed by a sequence of lines.  Each line gives
7127 information for one character.  A line comprises a number of fields
7128 separated by blanks or tabs.  The format is
7130 @c XXX fix it for new HTML additions
7132 @example
7133 @var{name} @var{metrics} @var{type} @var{code} @var{comment}
7134 @end example
7136 @cindex 8-bit input
7137 @cindex input, 8-bit
7138 @findex \N
7139 @kindex ---
7140 @noindent
7141 @var{name} identifies the character: If @var{name} is a single
7142 character@w{ }@var{c} then it corresponds to the @code{gtroff} input
7143 character @var{c}; if it is of the form @samp{\@var{c}} where @var{c} is
7144 a single character, then it corresponds to the @code{gtroff} input
7145 character@w{ }\@var{c}; otherwise it corresponds to the groff input
7146 character @samp{\[@var{name}]}.  (If it is exactly two characters
7147 @var{xx} it can be entered as @samp{\(@var{xx}}.)  @code{gtroff}
7148 supports 8-bit characters; however some utilities have difficulties with
7149 eight-bit characters.  For this reason, there is a convention that the
7150 name @samp{char@var{n}} is equivalent to the single character whose code
7151 is@w{ }@var{n}.  For example, @samp{char163} would be equivalent to the
7152 character with code@w{ }163 which is the pounds sterling sign in @w{ISO
7153 Latin-1} character set.  The name @samp{---} is special and indicates
7154 that the character is unnamed; such characters can only be used by means
7155 of the @code{\N} escape sequence in @code{gtroff}.
7157 @c XXX input encodings vs. output encodings
7159 The @var{type} field gives the character type:
7161 @table @code
7162 @item 1
7163 the character has an descender, for example, `p';
7164 @item 2
7165 the character has an ascender, for example, `b';
7166 @item 3
7167 the character has both an ascender and a descender, for example, `('.
7168 @end table
7170 The @var{code} field gives the code which the postprocessor uses to
7171 print the character.  The character can also be input to @code{gtroff}
7172 using this code by means of the @code{\N} escape sequence.  The code can
7173 be any integer.  If it starts with @samp{0} it will be interpreted as
7174 octal; if it starts with @samp{0x} or @samp{0X} it will be interpreted as
7175 hexadecimal.
7177 Anything on the line after the @var{code} field will be ignored.
7179 The @var{metrics} field has the form:
7181 @example
7182 @var{width}[,@var{height}[,@var{depth}[,@var{italic_correction}
7183   [,@var{left_italic_correction}[,@var{subscript_correction}]]]]]
7184 @end example
7186 @noindent
7187 There must not be any spaces between these subfields (it has been split
7188 here into two lines for better legibility only).  Missing subfields are
7189 assumed to be@w{ }0.  The subfields are all decimal integers.  Since
7190 there is no associated binary format, these values are not required to
7191 fit into a variable of type @samp{char} as they are in @code{ditroff}.
7192 The @var{width} subfield gives the width of the character.  The
7193 @var{height} subfield gives the height of the character (upwards is
7194 positive); if a character does not extend above the baseline, it should
7195 be given a zero height, rather than a negative height.  The @var{depth}
7196 subfield gives the depth of the character, that is, the distance below
7197 the lowest point below the baseline to which the character extends
7198 (downwards is positive); if a character does not extend below above the
7199 baseline, it should be given a zero depth, rather than a negative depth.
7200 The @var{italic_correction} subfield gives the amount of space that
7201 should be added after the character when it is immediately to be
7202 followed by a character from a Roman font.  The
7203 @var{left_italic_correction} subfield gives the amount of space that
7204 should be added before the character when it is immediately to be
7205 preceded by a character from a Roman font.  The
7206 @var{subscript_correction} gives the amount of space that should be
7207 added after a character before adding a subscript.  This should be less
7208 than the italic correction.
7210 A line in the @code{charset} section can also have the format
7212 @example
7213 @var{name} "
7214 @end example
7216 @noindent
7217 This indicates that @var{name} is just another name for the character
7218 mentioned in the preceding line.
7220 @kindex kernpairs
7221 The word @code{kernpairs} starts the kernpairs section.  This contains a
7222 sequence of lines of the form:
7224 @example
7225 @var{c1} @var{c2} @var{n}
7226 @end example
7228 This means that when character @var{c1} appears next to character
7229 @var{c2} the space between them should be increased by@w{ }@var{n}.
7230 Most entries in kernpairs section will have a negative value for@w{
7231 }@var{n}.
7235 @node Installation, Request and Escape Index, File formats, Top
7236 @chapter Installation
7237 @cindex installation
7239 @c XXX
7243 @node Request and Escape Index, Operator Index, Installation, Top
7244 @chapter Request and Escape Index
7246 In this index, escapes are listed with a leading backslash (@samp{\}) to
7247 distinguish them from requests which appear without the leading control
7248 character (normally either @samp{.} or @samp{'}).
7250 @printindex fn
7254 @node Operator Index, Register Index, Request and Escape Index, Top
7255 @chapter Operator Index
7257 @printindex op
7261 @node Register Index, Macro and String Index, Operator Index, Top
7262 @chapter Register Index
7264 @printindex vr
7268 @node Macro and String Index, Glyph Name Index, Register Index, Top
7269 @chapter Macro and String Index
7271 In this index, strings are listed with the calling escape sequence
7272 (@samp{\*}) to distinguish them from macros which appear without the
7273 leading control character (normally either @samp{.} or @samp{'}).
7275 @printindex ma
7279 @node Glyph Name Index, Font File Keyword Index, Macro and String Index, Top
7280 @chapter Glyph Name Index
7282 A glyph name @code{xx} consisting of exactly two characters can be
7283 accessed as @samp{\(xx}.  Glyph names @code{xxx} of any length can be
7284 accessed as @samp{\[xxx]}.
7286 @printindex gl
7290 @node Font File Keyword Index, Program and File Index, Glyph Name Index, Top
7291 @chapter Font File Keyword Index
7293 @printindex ky
7297 @node Program and File Index, Concept Index, Font File Keyword Index, Top
7298 @chapter Program  and File Index
7300 @printindex pg
7304 @node Concept Index,  , Program and File Index, Top
7305 @chapter Concept Index
7307 @printindex cp
7311 @summarycontents
7312 @contents
7313 @bye