* DviChar.c: Replacing `md' glyph name with `pc' in latin-1 map to
[s-roff.git] / doc / groff.texinfo
blob22605988f42826832605ac08352390fce6de2e45
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 @vindex .T
1061 @maindex \*(.T
1062 The predefined @code{gtroff} string register @code{.T} contains the
1063 current output device; the read-only number register @code{.T} is set
1064 to@w{ }1 if this option is used (which is always true if @code{groff} is
1065 used to call @code{gtroff}).  @xref{Built-in Registers}.
1067 The postprocessor to be used for a device is specified by the
1068 @code{postpro} command in the device description file.  (@xref{Font
1069 Files}, for more info.)  This can be overridden with the @option{-X}
1070 option.
1071 @item -X
1072 Preview with @code{gxditview} instead of using the usual postprocessor.
1073 This is unlikely to produce good results except with @option{-Tps}.
1075 Note that this is not the same as using @option{-TX75} or
1076 @option{-TX100} to view a document with @code{gxditview}: The former
1077 will us the metrics of the specified device, whereas the latter will use
1078 X-specific fonts and metrics.
1079 @item -N
1080 Don't allow newlines with @code{eqn} delimiters.  This is the same as
1081 the @option{-N} option in @code{geqn}.
1082 @item -S
1083 Safer mode.  Pass the @option{-S} option to @code{gpic} and use the
1084 @option{-msafer} macros with @code{gtroff} (enabled by default).
1085 @item -U
1086 Unsafe mode.  Reverts to the old unsafe behaviour.
1087 @item -a
1088 @vindex .A
1089 Generate an @acronym{ASCII} approximation of the typeset output.  The
1090 read-only register @code{.A} is then set to@w{ }1.  @xref{Built-in
1091 Registers}.
1092 @item -b
1093 Print a backtrace with each warning or error message.  This backtrace
1094 should help track down the cause of the error.  The line numbers given
1095 in the backtrace may not always be correct: @code{gtroff} can get
1096 confused by @code{as} or @code{am} requests while counting line numbers.
1097 @item -i
1098 Read the standard input after all the named input files have been
1099 processed.
1100 @item -w@var{name}
1101 Enable warning @var{name}.  Available warnings are described in
1102 @ref{Debugging}.  Multiple @option{-w} options are allowed.
1103 @item -W@var{name}
1104 Inhibit warning @var{name}.  Multiple @option{-W} options are allowed.
1105 @item -E
1106 Inhibit all error messages.
1107 @item -C
1108 Enable compatibility mode.
1109 @item -d@var{cs}
1110 @itemx -d@var{name}=s
1111 Define @var{c} or @var{name} to be a string @var{s}; @var{c} must be a
1112 one-letter @var{name}.
1113 @item -f@var{fam}
1114 Use @var{fam} as the default font family.
1115 @item -m@var{name}
1116 Read in the file @file{tmac.@var{name}}.  Normally this will be searched
1117 for in the library directory of @code{groff}.
1118 @item -n@var{num}
1119 Number the first page @var{num}.
1120 @item -o@var{list}
1121 @vindex .P
1122 Output only pages in @var{list}, which is a comma-separated list of page
1123 ranges; @var{n} means print page @var{n}, @samp{@var{m}-@var{n}} means
1124 print every page between @var{m} and @var{n}, @samp{-@var{n}} means
1125 print every page up to @var{n}, @samp{@var{n}-} means print every page
1126 from @var{n}.  @code{gtroff} will exit after printing the last page in
1127 the list.
1129 Within @code{gtroff}, this information can be extracted with the
1130 @samp{.P} register.  @xref{Built-in Registers}.
1131 @item -r@var{cn}
1132 @itemx -r@var{name}=@var{n}
1133 Set number register @var{c} or @var{name} to @var{n}; @var{c} must be a
1134 one-letter @var{name}; @var{n} can be any @code{gtroff} numeric
1135 expression.
1136 @item -F@var{dir}
1137 Search @var{dir} for subdirectories dev@var{name} (@var{name} is the
1138 name of the device) for the @file{DESC} file and font files before the
1139 normal directory.
1140 @item -M@var{dir}
1141 Search directory @var{dir} for macro files before the normal directory.
1142 @item -I@var{dir}
1143 This option is as described in @ref{gsoelim}.  It implies the
1144 @option{-s} option.
1145 @end table
1148 @node Environment, Invocation Examples, Groff Options, Invoking groff
1149 @section Environment
1150 @cindex environment variables
1151 @cindex variables in environment
1153 There are also several environment variables (of the operating system,
1154 not within @code{gtroff}) which can modify the behavior of @code{groff}.
1156 @table @code
1157 @item GROFF_COMMAND_PREFIX
1158 @tindex GROFF_COMMAND_PREFIX
1159 If this is set to @var{X}, then @code{groff} will run
1160 @var{X}@code{troff} instead of @code{gtroff}.  This also applies to
1161 @code{tbl}, @code{pic}, @code{eqn}, @code{grn}, @code{refer}, and
1162 @code{soelim}.  It does not apply to @code{grops}, @code{grodvi},
1163 @code{grotty}, @code{grohtml}, @code{grolj4}, and @code{gxditview}.
1164 @item GROFF_TMAC_PATH
1165 @tindex GROFF_TMAC_PATH
1166 A colon separated list of directories in which to search for macro
1167 files.
1168 @item GROFF_TYPESETTER
1169 @tindex GROFF_TYPESETTER
1170 The default output device.
1171 @item GROFF_FONT_PATH
1172 @tindex GROFF_FONT_PATH
1173 A colon separated list of directories in which to search for the
1174 @code{dev}@var{name} directory.
1175 @item PATH
1176 @tindex PATH
1177 The search path for commands executed by @code{groff}.
1178 @item GROFF_TMPDIR
1179 @tindex GROFF_TMPDIR
1180 @tindex TMPDIR
1181 The directory in which temporary files will be created.  If this is not
1182 set and @env{TMPDIR} is set, temporary files will be created in that
1183 directory.  Otherwise temporary files will be created in @code{/tmp}.
1184 The @code{grops} and @code{grefer} commands can create temporary files.
1185 @end table
1188 @node Invocation Examples,  , Environment, Invoking groff
1189 @section Invocation Examples
1190 @cindex invocation examples
1191 @cindex examples of invocation
1193 This section will list several common uses of @code{groff} and the
1194 command line which will accomplish it.
1196 @example
1197 groff file
1198 @end example
1200 @noindent
1201 This command processes @var{file} without a macro package or a
1202 preprocessor.  The output device is the default, @var{ps}, and the
1203 output is sent to stdout.
1205 @example
1206 groff -t -mandoc -Tascii file | less
1207 @end example
1209 @noindent
1210 This is basically what a call to the @code{man} program does.  The
1211 manual page @var{file} is processed with the @file{mandoc} macros (which
1212 in turn either calls the @file{man} or the @file{mdoc} macro package),
1213 using the @code{tbl} preprocessor and the @acronym{ASCII} output device.
1214 Finally, the result is displayed with the @code{less} pager.
1216 @example
1217 groff -X -m me file
1218 @end example
1220 @noindent
1221 Preview @var{file} with @code{gxditview}, using the @file{me} macro
1222 package.  Since no @option{-T} option is specified, use the default
1223 device (@samp{ps}).  Note that you can either say @w{@samp{-m me}} or
1224 @w{@samp{-me}}; the latter is an anachronism from the early days of
1225 @acronym{UNIX}.@footnote{The same is true for the other main macro
1226 packages that come with @code{groff}: @file{man}, @file{mdoc},
1227 @file{ms}, @file{mm}, and @file{mandoc}.  This won't work in general;
1228 for example, to load @file{tmac.safer}, either @samp{-msafer} or
1229 @w{@samp{-m safer}} must be used.}
1231 @example
1232 groff -man -rD1 -z file
1233 @end example
1235 @noindent
1236 Check @var{file} with the @file{man} macro package, forcing double-sided
1237 printing---don't produce any output.
1239 @subsection @code{grog}
1241 @code{grog} reads files and guesses which of the @code{groff}
1242 preprocessors and/or macro packages are are required for formatting
1243 them, and prints the @code{groff} command including those options on the
1244 standard output.  The options generated are one of @option{-e},
1245 @option{-man}, @option{-me}, @option{-mm}, @option{-ms}, @option{-p},
1246 @option{-R}, @option{-g}, @option{-s}, and @option{-t}.
1248 A filename of @samp{-} is taken to refer to the standard input.  If no
1249 files are specified the standard input will be read.  Any specified
1250 options will be included in the printed command.  No space is allowed
1251 between options and their arguments.  For example,
1253 @example
1254 grog -Tdvi paper.ms
1255 @end example
1257 @noindent
1258 will guess the appropriate command to print @file{paper.ms} and then
1259 print it to the command line after adding the @option{-Tdvi} option.
1260 For direct execution, enclose the call to @code{grog} in backquotes on
1261 the @acronym{UNIX} shell prompt:
1263 @example
1264 `grog -Tdvi paper.ms` > paper.dvi
1265 @end example
1267 @noindent
1268 As seen in the example, it is still necessary to redirect the output to
1269 something meaningful (i.e.@: either a file or a pager program like
1270 @code{less}).
1274 @node Tutorial for Macro Users, Macro Packages, Invoking groff, Top
1275 @chapter Tutorial for Macro Users
1276 @cindex tutorial for macro users
1277 @cindex macro tutorial for users
1278 @cindex user's tutorial for macros
1279 @cindex user's macro tutorial
1281 Most users tend to use a macro package to format their papers.  This
1282 means that the whole breadth of @code{groff} is not necessary for most
1283 people.  This chapter covers the material needed to efficiently use a
1284 macro package.
1286 @menu
1287 * Basics::                      
1288 * Common Features::             
1289 @end menu
1292 @node Basics, Common Features, Tutorial for Macro Users, Tutorial for Macro Users
1293 @section Basics
1294 @cindex basics
1296 This section covers some of the basic concepts necessary to understand
1297 how to use a macro package.@footnote{This section is derived from
1298 @cite{Writing Papers with nroff using -me} by Eric P.@w{ }Allman.}
1299 References are made throughout to more detailed information, if desired.
1301 @code{gtroff} reads an input file prepared by the user and outputs a
1302 formatted document suitable for publication or framing.  The input
1303 consists of text, or words to be printed, and embedded commands
1304 (@dfn{requests} and @dfn{escapes}), which tell @code{gtroff} how to
1305 format the output.  For more detail on this @pxref{Embedded Commands}.
1307 The word @dfn{argument} is used in this manual to mean a word or number
1308 which appears on the same line as a request which modifies the meaning
1309 of that request.  For example, the request
1311 @example
1313 @end example
1315 @noindent
1316 spaces one line, but
1318 @example
1319 .sp 4
1320 @end example
1322 @noindent
1323 spaces four lines.  The number@w{ }4 is an argument to the @code{sp}
1324 request which says to space four lines instead of one.  Arguments are
1325 separated from the request and from each other by spaces.  More details
1326 on this can be found in @ref{Request Arguments}.
1328 The primary function of @code{gtroff} is to collect words from input
1329 lines, fill output lines with those words, justify the right hand margin
1330 by inserting extra spaces in the line, and output the result.  For
1331 example, the input:
1333 @example
1334 Now is the time
1335 for all good men
1336 to come to the aid
1337 of their party.
1338 Four score and seven
1339 years ago,...
1340 @end example
1342 @noindent
1343 will be read, packed onto output lines, and justified to produce:
1345 @quotation
1346 Now is the time for all good men to come to the aid of their party.
1347 Four score and seven years ago,...
1348 @end quotation
1350 @cindex break
1351 @cindex line break
1352 Sometimes a new output line should be started even though the current
1353 line is not yet full; for example, at the end of a paragraph.  To do
1354 this it is possible to cause a @dfn{break}, which starts a new output
1355 line.  Some requests cause a break automatically, as do blank input
1356 lines and input lines beginning with a space.
1358 Not all input lines are text to be formatted.  Some of the input lines
1359 are requests which describe how to format the text.  Requests always
1360 have a period (@samp{.}) or an apostrophe (@samp{'}) as the first
1361 character of the input line.
1363 The text formatter also does more complex things, such as automatically
1364 numbering pages, skipping over page boundaries, putting footnotes in the
1365 correct place, and so forth.
1367 Here a few hints for preparing text for input to @code{gtroff}.  First,
1368 keep the input lines short.  Short input lines are easier to edit, and
1369 @code{gtroff} will pack words onto longer lines anyhow.  In keeping with
1370 this, it is helpful to begin a new line after every period, comma, or
1371 phrase, since common corrections are to add or delete sentences or
1372 phrases.  Secondly, do not hyphenate words at the end of
1373 lines---@code{gtroff} is smart enough to hyphenate words for the user as
1374 needed, but is not smart enough to take hyphens out and join a word back
1375 together.  Also, words such as ``mother-in-law'' should not be broken
1376 over a line, since then a space can occur where not wanted, such as
1377 ``@w{mother- in}-law''.
1379 @findex ls
1380 @cindex double spacing
1381 @cindex spacing
1382 @code{gtroff} will double space output text automatically if using the
1383 request @w{@samp{.ls 2}}.  Single spaced mode can be reactivated by
1384 typing @w{@samp{.ls 1}}.
1386 A number of requests allow to change the way the output looks, sometimes
1387 called the @dfn{layout} of the output page.  Most of these requests
1388 adjust the placing of @dfn{white space} (blank lines or spaces).
1390 @findex bp
1391 @cindex new page
1392 The @samp{.bp} request starts a new page, causing a line break.
1394 @findex sp
1395 @cindex blank lines
1396 @cindex empty lines
1397 @cindex lines, empty
1398 The request @w{@samp{.sp @var{N}}} leaves @var{N}@w{ }lines of blank
1399 space.  @var{N}@w{ }can be omitted (meaning skip a single line) or can
1400 be of the form @var{N}i (for @var{N}@w{ }inches) or @var{N}c (for
1401 @var{N}@w{ }centimeters).  For example, the input:
1403 @example
1404 .sp 1.5i
1405 My thoughts on the subject
1407 @end example
1409 @noindent
1410 leaves one and a half inches of space, followed by the line ``My
1411 thoughts on the subject'', followed by a single blank line.
1413 @findex ce
1414 @cindex centering lines
1415 @cindex lines, centering
1416 Text lines can be centered by using the @code{ce} request.  The line
1417 after @code{ce} is centered (horizontally) on the page.  To center more
1418 than one line, use @w{@samp{.ce @var{N}}} (where @var{N} is the number
1419 of lines to center), followed by the @var{N}@w{ }lines.  To center many
1420 lines without counting them, type:
1422 @example
1423 .ce 1000
1424 lines to center
1425 .ce 0
1426 @end example
1428 @noindent
1429 The @w{@samp{.ce 0}} request tells @code{groff} to center zero more
1430 lines, in other words, stop centering.
1432 @findex br
1433 @cindex line break
1434 @cindex break
1435 All of these requests cause a break; that is, they always start a new
1436 line.  To start a new line without performing any other action, use
1437 @code{br}.
1440 @node Common Features,  , Basics, Tutorial for Macro Users
1441 @section Common Features
1442 @cindex common features
1443 @cindex features, common
1445 @code{gtroff} provides very low level operations for formatting a
1446 document.  There are many common routine operations which are done in
1447 all documents.  These common operations are written into @dfn{macros}
1448 and collected into a @dfn{macro package}.
1450 All macro packages provide certain common capabilities which fall into
1451 the following categories.
1453 @subsection Paragraphs
1454 @cindex paragraphs
1456 One of the most common and most used capability is starting a paragraph.
1457 There are a number of different types of paragraphs, any of which can be
1458 initiated with macros supplied by the macro package.  Normally,
1459 paragraphs start with a blank line and the first line indented, like the
1460 text in this manual.  There are also block style paragraphs, which omit
1461 the indentation:
1463 @example
1464 Some   men  look   at  constitutions   with  sanctimonious
1465 reverence, and deem them like the ark of the covenant, too
1466 sacred to be touched.
1467 @end example
1469 @noindent
1470 And there are also indented paragraphs which begin with a tag or label
1471 at the margin and the remaining text indented.
1473 @example
1474 one   This is  the first paragraph.  Notice  how the first
1475       line of  the resulting  paragraph lines up  with the
1476       other lines in the paragraph.
1477 longlabel
1478       This  paragraph   had  a  long   label.   The  first
1479       character of text on the first line will not line up
1480       with  the  text  on  second  and  subsequent  lines,
1481       although they will line up with each other.
1482 @end example
1484 A variation of this is a bulleted list.
1485 @c XXX description
1487 @subsection Sections and Chapters
1489 Most macro packages supply some form of section headers.  The simplest
1490 kind is simply the heading on a line by itself in bold type.  Others
1491 supply automatically numbered section heading or different heading
1492 styles at different levels.  Some, more sophisticated, macro packages
1493 supply macros for starting chapters and appendices.
1495 @subsection Headers and Footers
1497 Every macro package gives some way to manipulate the headers and
1498 footers (or @dfn{titles}) on each page.  Some packages will allow for
1499 different ones on the even and odd pages (for material printed in a book
1500 form).
1502 The titles are called three-part titles, that is, there is a
1503 left-justified part, a centered part, and a right-justified part.  An
1504 automatically generated page number may be put in any of these fields
1505 with the @samp{%} character (@pxref{Page Layout} for more details).
1507 @subsection Page Layout
1509 Most macro packages let thte user specify top and bottom margins and
1510 other details about the appearance of the printed pages.
1512 @subsection Displays
1513 @cindex displays
1515 Displays are sections of text to be set off from the body of the paper.
1516 Major quotes, tables, and figures are types of displays, as are all the
1517 examples used in this document.
1519 @cindex quotes, major
1520 @cindex major quotes
1521 @dfn{Major quotes} are quotes which are several lines long, and hence
1522 are set in from the rest of the text without quote marks around them.
1524 @cindex list
1525 A @dfn{list} is an indented, single spaced, unfilled display.  Lists
1526 should be used when the material to be printed should not be filled and
1527 justified like normal text, such as columns of figures or the examples
1528 used in this paper.
1530 @cindex keep
1531 A @dfn{keep} is a display of lines which are kept on a single page if
1532 possible.  An example for a keep might be a diagram.  Keeps differ from
1533 lists in that lists may be broken over a page boundary whereas keeps
1534 will not.
1536 @cindex keep, floating
1537 @cindex floating keep
1538 Floating keeps move relative to the text.  Hence, they are good for
1539 things which will be referred to by name, such as ``See figure@w{ }3''.
1540 A floating keep will appear at the bottom of the current page if it will
1541 fit; otherwise, it will appear at the top of the next page.  Meanwhile,
1542 the surrounding text will `flow' around the keep, thus leaving now blank
1543 areas.
1545 @subsection Footnotes and annotations
1546 @cindex footnotes
1547 @cindex annotations
1549 There are a number of requests to save text for later printing.
1551 @dfn{Footnotes} are printed at the bottom of the current page.
1553 @cindex delayed text
1554 @dfn{Delayed text} is very similar to a footnote except that it is
1555 printed when called for explicitly.  This allows a list of references to
1556 appear (for example) at the end of each chapter, as is the convention in
1557 some disciplines.
1559 Most macro packages which supply this functionality also supply a means
1560 of automatically numbering either type of annotation.
1562 @subsection Table of Contents
1563 @cindex table of contents
1564 @cindex contents, table of
1566 @dfn{Tables of contents} are a type of delayed text having a tag
1567 (usually the page number) attached to each entry after a row of dots.
1568 The table accumulates throughout the paper until printed, usually after
1569 the paper has ended.  Many macro packages will provide the ability to
1570 have several tables of contents (i.e.@: one standard one, one for
1571 tables, etc).
1573 @subsection Indices
1574 @cindex index
1576 While some macro packages will use the term @dfn{index}, none actually
1577 provide that functionality.  The facilities they call indices are
1578 actually more appropriate for tables of contents.
1580 @subsection Paper formats
1581 @cindex paper formats
1583 Some macro packages provide stock formats for various kinds of
1584 documents.  Many of them provide a common format for the title and
1585 opening pages of a technical paper.  The @file{mm} macros in particular
1586 provide formats for letters and memoranda.
1588 @subsection Multiple Columns
1590 Some macro packages (except @file{man}) provide the ability to have two
1591 or more columns on a page.
1593 @subsection Font and Size changes
1595 The built-in font and size functions are not always intuitive, so all
1596 macro packages provide macros to make these operations simpler.
1598 @subsection Predefined Strings
1600 Most macro packages provide various predefined strings for a variety of
1601 uses; examples are sub- and superscripts, printable dates, quotes and
1602 various special characters.
1604 @subsection Preprocessor Support
1606 All macro packages provide support for the various preprocessors.
1608 @subsection Configuration and Customization
1610 Some macro packages provide means of customizing many of details of how
1611 the package behaves.  This ranges from setting the default type size to
1612 changing the appearance of section headers.
1616 @node Macro Packages, Programming Tutorial, Tutorial for Macro Users, Top
1617 @chapter Macro Packages
1618 @cindex macro packages
1619 @cindex packages, macros
1621 This chapter documents the main macro packages that come with
1622 @code{groff}.
1624 @menu
1625 * man::                         
1626 * mdoc::                        
1627 * ms::                          
1628 * me::                          
1629 * mm::                          
1630 @end menu
1633 @node man, mdoc, Macro Packages, Macro Packages
1634 @section @file{man}
1635 @cindex @file{man}
1636 @cindex manual pages
1637 @pindex tmac.an
1638 @pindex tmac.man
1640 This is the most popular and probably the most important macro package
1641 of @code{groff}.  It is easy to use, and a vast majority of manual pages
1642 are based on it.
1644 @menu
1645 * Man options::                 
1646 * Man usage::                   
1647 * Man font macros::             
1648 * Miscellaneous man stuff::     
1649 @end menu
1651 @node Man options, Man usage, man, man
1652 @subsection Options
1654 The command line format for using the @file{man} macros with
1655 @code{groff} is:
1657 @c XXX document @TMAC_AN_PREFIX@
1659 @example
1660 groff -m man [ -rC1 ] [ -rD1 ] [ -rP @var{nnn} ] [ -rX @var{nnn} ]
1661       [ @var{files}@dots{} ] 
1662 @end example
1664 It is possible to use @samp{-man} instead of @w{@samp{-m man}}.
1666 @table @code
1667 @item -rC1
1668 If more than one manual page is given on the command line, number the
1669 pages continuously, rather than starting each at@w{ }1.
1670 @item -rD1
1671 Double-sided printing.  Footers for even and odd pages are formatted
1672 differently.
1673 @item -rP @var{nnn}
1674 Enumeration of pages will start with @var{nnn} rather than with@w{ }1.
1675 @item -rX @var{nnn}
1676 After page @var{nnn}, number pages as @var{nnn}a, @var{nnn}b,
1677 @var{nnn}c, etc.  For example, the option @option{-rX2} will produce the
1678 following page numbers: 1, 2, 2a, 2b, 2c, etc.
1679 @end table
1681 @node Man usage, Man font macros, Man options, man
1682 @subsection Usage
1684 @pindex man.local
1685 This section describes the available macros for manual pages.  For
1686 further customization, put additional macros and requests into the file
1687 @file{man.local} which will be loaded immediately after @file{tmac.an}.
1689 @maindex TH
1690 @Defmac{TH, title section [@var{extra1}] [@var{extra2}] [@var{extra3}]}
1691 Sets the title of the man page to @var{title} and the section to
1692 @var{section}, which must take on a value between 1 and@w{ }8.  The
1693 value @var{section} may also have a string appended, e.g.@: @samp{.pm},
1694 to indicate a specific subsection of the man pages.
1696 Both @var{title} and @var{section} are positioned at the left and right
1697 in the header line (with @var{section} in parentheses immediately
1698 appended to @var{title}.  @var{extra1} will be positioned in the middle
1699 of the footer line.  @var{extra2} will be positioned at the left in the
1700 footer line (resp.@: at the left on even pages and at the right on odd
1701 pages if double-sided printing is active).  @var{extra3} is centered in
1702 the header line.
1704 For @acronym{HTML} output, headers and footers are completely supressed.
1706 Additionally, this macro starts a new page; the new line number is@w{ }1
1707 again (except if the @option{-rC1} option is given on the command
1708 line)---this feature is intended only for formatting multiple man pages;
1709 a single man page should contain exactly one @code{TH} macro at the
1710 beginning of the file.
1711 @end_Defmac
1713 @maindex SH
1714 @Defmac{SH, [@var{heading}]}
1715 Sets up an unnumbered section heading sticking out to the left.  Prints
1716 out all the text following @code{SH} up to the end of the line (resp.@:
1717 the text in the next line if there is no argument to @code{SH}) in bold
1718 face, at a default size of 9@w{ }point.  Additionally, the left margin
1719 for the following text is reset to its default value.
1720 @end_Defmac
1722 @maindex SS
1723 @Defmac{SS, [@var{heading}]}
1724 Sets up an unnumbered section heading.  Prints out all the text
1725 following @code{SS} up to the end of the line (resp.@: the text in the
1726 next line if there is no argument to @code{SS}) in bold face, at a
1727 default size of 10@w{ }point.  Additionally, the left margin for the
1728 following text is reset to its default value.
1729 @end_Defmac
1731 @maindex TP
1732 @Defmac{TP, [@var{nnn}]}
1733 Sets up an indented paragraph with label.  The indentation is set to
1734 @var{nnn} if that argument is supplied (the default unit is @samp{n} if
1735 omitted), otherwise it is set to the default indentation value.
1737 The first line of text following this macro is interpreted as a string
1738 to be printed flush-left, as it is appropriate for a label.  It is not
1739 interpreted as part of a paragraph, so there is no attempt to fill the
1740 first line with text from the following input lines.  Nevertheless, if
1741 the label is not as wide as the indentation, then the paragraph starts
1742 at the same line (but indented), continuing on the following lines.  If
1743 the label is wider than the indentation, then the descriptive part of
1744 the paragraph begins on the line following the label, entirely indented.
1745 Note that neither font shape nor font size of the label is set to a
1746 default value; on the other hand, the rest of the text will have default
1747 font settings.
1748 @end_Defmac
1750 @maindex LP
1751 @maindex PP
1752 @maindex P
1753 @Defmac{LP}
1754 @Defmacx{PP}
1755 @Defmacx{P}
1756 These macros are mutual aliases.  Any of them causes a line break at the
1757 current position, followed by a vertical space downwards by the amount
1758 specified by the @code{PD} macro.  The font size and shape are reset to
1759 the default value (10@dmn{pt} resp.@: Roman).  Finally, the current left
1760 margin is restored.
1761 @end_Defmac
1763 @maindex IP
1764 @Defmac{IP, [@var{designator}] [@var{nnn}]}
1765 Sets up an indented paragraph, using @var{designator} as a tag to mark
1766 its beginning.  The indentation is set to @var{nnn} if that argument is
1767 supplied (default unit is @samp{n}), otherwise the default indentation
1768 value is used.  Font size and face of the paragraph (but not the
1769 designator) are reset to its default values.  To start an indented
1770 paragraph with a particular indentation but without a designator, use
1771 @samp{""} (two doublequotes) as the first argument of @code{IP}.
1773 For example, to start a paragraph with bullets as the designator and
1774 4@dmn{en} indentation, write
1776 @example
1777 .IP \(bu 4
1778 @end example
1779 @end_Defmac
1781 @maindex HP
1782 @Defmac{HP, [@var{nnn}]}
1783 Sets up a paragraph with hanging left indentation.  The indentation is
1784 set to @var{nnn} if that argument is supplied (default unit is
1785 @samp{n}), otherwise the default indentation value is used.  Font size
1786 and face are reset to its default values.
1787 @end_Defmac
1789 @maindex RS
1790 @Defmac{RS, [@var{nnn}]}
1791 This macro moves the left margin to the right by the value @var{nnn} if
1792 specified (default unit is @samp{n}); otherwise the default indentation
1793 value is used.  Calls to the @code{RS} macro can be nested.
1794 @end_Defmac
1796 @maindex RE
1797 @Defmac{RE, [@var{nnn}]}
1798 This macro moves the left margin back to level @var{nnn}; if no argument
1799 is given, it moves one level back.  The first level (i.e., no call to
1800 @code{RS} yet) has number@w{ }1, and each call to @code{RS} increases
1801 the level by@w{ }1.
1802 @end_Defmac
1804 @maindex SH
1805 @maindex SS
1806 @maindex TP
1807 @maindex LP
1808 @maindex PP
1809 @maindex P
1810 @maindex IP
1811 @maindex HP
1812 To summarize, the following macros cause a line break with the insertion
1813 of vertical space (which amount can be changed with the @code{PD}
1814 macro): @code{SH}, @code{SS}, @code{TP}, @code{LP} (@code{PP},
1815 @code{P}), @code{IP}, and @code{HP}.
1817 @maindex RS
1818 @maindex RE
1819 The macros @code{RS} and @code{RE} also cause a break but no insertion
1820 of vertical space.
1822 @node Man font macros, Miscellaneous man stuff, Man usage, man
1823 @subsection Macros to set fonts
1825 The standard font is Roman; the default text size is 10@w{ }point.
1827 @maindex SM
1828 @Defmac{SM, [@var{text}]}
1829 Causes the text on the same line or the text on the next line to appear
1830 in a font that is one point size smaller than the default font.
1831 @end_Defmac
1833 @maindex SB
1834 @Defmac{SB, [@var{text}]}
1835 Causes the text on the same line or the text on the next line to appear
1836 in boldface font, one point size smaller than the default font.
1837 @end_Defmac
1839 @maindex BI
1840 @Defmac{BI, text}
1841 Causes text on the same line to appear alternately in bold face and
1842 italic.  The text must be on the same line as the macro call.  Thus
1844 @example
1845 .BI this "word and" that
1846 @end example
1848 @noindent
1849 would cause `this' and `that' to appear in bold face, while `word and'
1850 appears in italics.
1851 @end_Defmac
1853 @maindex IB
1854 @Defmac{IB, text}
1855 Causes text to appear alternately in italic and bold face.  The text
1856 must be on the same line as the macro call.
1857 @end_Defmac
1859 @maindex RI
1860 @Defmac{RI, text}
1861 Causes text on the same line to appear alternately in roman and italic.
1862 The text must be on the same line as the macro call.
1863 @end_Defmac
1865 @maindex IR
1866 @Defmac{IR, text}
1867 Causes text on the same line to appear alternately in italic and roman.
1868 The text must be on the same line as the macro call.
1869 @end_Defmac
1871 @maindex BR
1872 @Defmac{BR, text}
1873 Causes text on the same line to appear alternately in bold face and
1874 roman.  The text must be on the same line as the macro call.
1875 @end_Defmac
1877 @maindex RB
1878 @Defmac{RB, text}
1879 Causes text on the same line to appear alternately in roman and bold
1880 face.  The text must be on the same line as the macro call.
1881 @end_Defmac
1883 @maindex R
1884 @Defmac{R, [@var{text}]}
1885 Causes @var{text} to appear in roman font.  If no text is present on the
1886 line where the macro is called, then the text of the next line appears
1887 in roman.  This is the default font to which text is returned at the end
1888 of processing of the other macros.
1889 @end_Defmac
1891 @maindex B
1892 @Defmac{B, [@var{text}]}
1893 Causes @var{text} to appear in bold face.  If no text is present on the
1894 line where the macro is called, then the text of the next line appears
1895 in bold face.
1896 @end_Defmac
1898 @maindex I
1899 @Defmac{I, [@var{text}]}
1900 Causes @var{text} to appear in italic.  If no text is present on the
1901 line where the macro is called, then the text of the next line appears
1902 in italic.
1903 @end_Defmac
1905 @node Miscellaneous man stuff,  , Man font macros, man
1906 @subsection Miscellaneous
1908 @pindex grohtml
1909 @cindex @file{man}, default indentation
1910 @cindex default indentation, @file{man}
1911 The default indentation is 7.2@dmn{n} for all output devices except for
1912 @code{grohtml} which uses 1.2@dmn{i} instead.
1914 @maindex DT
1915 @maindex TH
1916 @Defmac{DT}
1917 Sets tabs every 0.5@w{ }inches.  Since this macro is always called
1918 during a @code{TH} request, it makes sense to call it only if the tab
1919 positions have been changed.
1920 @end_Defmac
1922 @maindex PD
1923 @Defmac{PD, [@var{nnn}]}
1924 Adjusts the empty space before a new paragraph (resp.@: section).  The
1925 optional argument gives the amount of space (default units are
1926 @samp{v}); without parameter, the value is reset to its default value
1927 (1@w{ }line for tty devices, 0.4@dmn{v}@w{ }otherwise).
1928 @end_Defmac
1930 @maindex SH
1931 @maindex SS
1932 @maindex TP
1933 @maindex LP
1934 @maindex PP
1935 @maindex P
1936 @maindex IP
1937 @maindex HP
1938 This affects the macros @code{SH}, @code{SS}, @code{TP}, @code{LP}
1939 (resp.@: @code{PP} and @code{P}), @code{IP}, and @code{HP}.
1941 The following strings are defined:
1943 @maindex \*S
1944 @Defmac{\\*S}
1945 Switch back to the default font size.
1946 @end_Defmac
1948 @maindex \*R
1949 @Defmac{\\*R}
1950 The `registered' sign.
1951 @end_Defmac
1953 @maindex \*(Tm
1954 @Defmac{\\*(Tm}
1955 The `trademark' sign.
1956 @end_Defmac
1958 @maindex \*(lq
1959 @maindex \*(rq
1960 @glindex lq
1961 @glindex rq
1962 @Defmac{\\*(lq}
1963 @Defmacx{\\*(rq}
1964 Left and right quote.
1965 This is equal to @code{\(lq} and @code{\(rq}, respectively.
1966 @end_Defmac
1968 @cindex preprocessor, calling convention
1969 @cindex calling convention of preprocessors
1970 If a preprocessor like @code{gtbl} or @code{geqn} is needed, it has
1971 become usage to make the first line of the man page look like this:
1973 @example
1974 .\" @var{word}
1975 @end example
1977 @pindex geqn
1978 @pindex grefer
1979 @pindex gtbl
1980 @pindex man
1981 Note the single space character after the double quote.  @var{word}
1982 consists of letters for the needed preprocessors: @samp{e} for
1983 @code{geqn}, @samp{r} for @code{grefer}, @samp{t} for @code{gtbl}.
1984 Modern implementations of the @code{man} program read this first line
1985 and automatically call the right preprocessor(s).
1988 @node mdoc, ms, man, Macro Packages
1989 @section @file{mdoc}
1990 @cindex @file{mdoc}
1992 @c XXX documentation
1995 @node ms, me, mdoc, Macro Packages
1996 @section @file{ms}
1997 @cindex @file{ms}
1999 @c XXX documentation
2002 @node me, mm, ms, Macro Packages
2003 @section @file{me}
2004 @cindex @file{me}
2006 @c XXX documentation
2009 @node mm,  , me, Macro Packages
2010 @section @file{mm}
2011 @cindex @file{mm}
2013 @c XXX documentation
2017 @node Programming Tutorial, Preprocessors, Macro Packages, Top
2018 @chapter Programming Tutorial
2019 @cindex programming tutorial
2020 @cindex tutorial for programming
2022 This chapter covers @strong{all} of the facilities of @code{gtroff}.
2023 Users of macro packages may skip it if not interested in details.
2026 @menu
2027 * Text::                        
2028 * Input Conventions::           
2029 * Measurements::                
2030 * Expressions::                 
2031 * Identifiers::                 
2032 * Embedded Commands::           
2033 * Registers::                   
2034 * Manipulating Filling and Adjusting::  
2035 * Manipulating Hyphenation::    
2036 * Manipulating Spacing::        
2037 * Tabs and Fields::             
2038 * Character Translations::      
2039 * Line Layout::                 
2040 * Page Layout::                 
2041 * Page Control::                
2042 * Fonts::                       
2043 * Sizes::                       
2044 * Strings::                     
2045 * Conditionals and Loops::      
2046 * Writing Macros::              
2047 * Page Motions::                
2048 * Drawing Requests::            
2049 * Traps::                       
2050 * Diversions::                  
2051 * Environments::                
2052 * I/O::                         
2053 * Postprocessor Access::        
2054 * Miscellaneous::               
2055 * Debugging::                   
2056 * Implementation Differences::  
2057 * Summary::                     
2058 @end menu
2061 @node Text, Input Conventions, Programming Tutorial, Programming Tutorial
2062 @section Text
2063 @cindex text
2065 @code{gtroff} input files contain text with control commands
2066 interspersed throughout.  But, even without control codes, @code{gtroff}
2067 will still do several things with the input text: filling and adjusting,
2068 adding additional space after sentences, hyphenating and inserting
2069 implicit line breaks.
2071 @menu
2072 * Filling and Adjusting::       
2073 * Hyphenation::                 
2074 * Sentences::                   
2075 * Tab Stops::                   
2076 * Implicit Line Breaks::        
2077 @end menu
2079 @node Filling and Adjusting, Hyphenation, Text, Text
2080 @subsection Filling and Adjusting
2081 @cindex filling and adjusting
2082 @cindex adjusting and filling
2084 When @code{gtroff} reads in text it collects words from input and fits
2085 as many of them together on one output line as it can.  This is known as
2086 @dfn{filling}.
2088 @cindex leading spaces
2089 @cindex spaces, leading
2090 @cindex extra spaces
2091 @cindex spaces, extra
2092 @cindex trailing spaces
2093 @cindex spaces, trailing
2094 Once @code{gtroff} has a @dfn{filled} line it will try to @dfn{adjust}
2095 it.  Which means it will widen the spacing between words until the text
2096 reaches the right margin (in the default adjustment mode).  Extra spaces
2097 between words are preserved, but spaces at the end of lines are ignored.
2098 Spaces at the front of a line will cause a @dfn{break} (breaks will be
2099 explained in @ref{Implicit Line Breaks})
2101 @xref{Manipulating Filling and Adjusting}.
2103 @node Hyphenation, Sentences, Filling and Adjusting, Text
2104 @subsection Hyphenation
2105 @cindex hyphenation
2107 Since the odds of finding a set of words, for every output line, which
2108 will fit nicely on a line without inserting excessive amounts of space
2109 between words is not great, @code{gtroff} will hyphenate words so that
2110 lines can be justified without there being too much space between words.
2111 It uses an internal hyphenation algorithm (a simplified version of the
2112 algorithm used within @TeX{}) to indicate which words can be hyphenated
2113 and how to do so.  When a word is hyphenated the first part of the word
2114 will be added to the current filled line being output (with an attached
2115 hyphen), and the other portion will be added to the next line to be
2116 filled.
2118 @xref{Manipulating Hyphenation}.
2120 @node Sentences, Tab Stops, Hyphenation, Text
2121 @subsection Sentences
2122 @cindex sentences
2124 Although it is often debated, some typesetting rules say there should be
2125 different amounts of space after various punctuation marks.  For
2126 example, the @emph{Chicago typsetting manual} says that a period at the
2127 end of a sentence should have twice as much space following it as would
2128 a comma or a period as part of an abbreviation.
2130 @c XXX exact citation of Chigago manual
2132 @cindex sentence space
2133 @cindex space between sentences
2134 @cindex french-spacing
2135 @code{gtroff} does this by flagging certain characters (normally
2136 @samp{!}, @samp{?} and @samp{.}) as @dfn{end of sentence} characters.
2137 When @code{gtroff} encounters one of these characters at the end of a
2138 line it will append two @dfn{sentence spaces} in the formatted output.
2139 (Thus, one of the conventions mentioned in @ref{Input Conventions}.)
2141 @cindex transparent characters
2142 @cindex character, transparent
2143 @glindex dg
2144 @glindex rq
2145 @cindex "
2146 @cindex '
2147 @cindex )
2148 @cindex ]
2149 @cindex *
2150 In addition, the following characters resp.@: glyphs are treated
2151 transparently while handling end of sentence characters: @samp{"},
2152 @samp{'}, @samp{)}, @samp{]}, @samp{*}, @code{dg}, and @code{rq}.
2154 See the @code{cflags} request in @ref{Using Symbols}, for more details.
2156 @findex \&
2157 To prevent the insertion of extra space after an end of sentence
2158 character (at the end of a line), append @code{\&}.
2161 @node Tab Stops, Implicit Line Breaks, Sentences, Text
2162 @subsection Tab Stops
2163 @cindex tab stops
2164 @cindex stops, tabulator
2165 @cindex tab character
2166 @cindex character, tabulator
2168 @code{gtroff} translates @dfn{tabulator characters}, also called
2169 @dfn{tabs} (normally code point @acronym{ASCII} @code{0x09} resp.@:
2170 @acronym{EBCDIC} @code{0x05}), in the input into movements to the next
2171 tabulator stop.  These tab stops are initially located every half inch
2172 across the page.  Using this simple tables can easily be made.  However,
2173 it can often be deceptive as the appearance (and width) of the text on a
2174 terminal and the results from @code{gtroff} can vary greatly.
2176 Also, a possible sticking point is that lines beginning with tab
2177 characters will still be filled, again producing unexpected results.
2178 For example, the following input
2180 @multitable {12345678} {12345678} {12345678} {12345678}
2181 @item
2182 @tab 1 @tab 2 @tab 3
2183 @item
2184 @tab   @tab 4 @tab 5
2185 @end multitable
2187 @noindent
2188 will produce
2190 @multitable {12345678} {12345678} {12345678} {12345678} {12345678} {12345678} {12345678}
2191 @item
2192 @tab 1 @tab 2 @tab 3 @tab   @tab 4 @tab 5
2193 @end multitable
2195 @xref{Tabs and Fields}.
2197 @node Implicit Line Breaks,  , Tab Stops, Text
2198 @subsection Implicit Line Breaks
2199 @cindex implicit line breaks
2200 @cindex line, implicit breaks
2201 @cindex break
2202 @cindex break, implicit
2203 @cindex line break
2205 An important concept in @code{gtroff} is the @dfn{break}.  When a break
2206 occurs, @code{gtroff} will output the partially filled line
2207 (unjustified), and resume collecting and filling text on the next output
2208 line.
2210 @cindex blank line
2211 @cindex empty line
2212 @cindex line, blank
2213 There are several ways to cause a break in @code{gtroff}.  A blank line
2214 will not only cause a break, but it will also cause a one line vertical
2215 space (effectively a blank line) to be output.
2217 A line which begins with a space will cause a break and the space will
2218 be output at the beginning of the next line.  Note that this space isn't
2219 adjusted, even in fill mode.
2221 The end of file will also cause a break---otherwise the last line of the
2222 document may vanish!
2224 Certain requests also cause breaks, implicitly or explicitly.  This will
2225 be discussed in @ref{Manipulating Filling and Adjusting}.
2228 @node Input Conventions, Measurements, Text, Programming Tutorial
2229 @section Input Conventions
2230 @cindex input conventions
2231 @cindex conventions for input
2233 Since @code{gtroff} does filling automatically, it is traditional in
2234 @code{groff} not to try and type things in as nicely formatted
2235 paragraphs.  These are some conventions commonly used when typing
2236 @code{gtroff} text:
2238 @itemize @bullet{}
2239 @item
2240 Break lines after punctuation, particularly at the end of sentences,
2241 and in other logical places.  Keep separate phrases on lines by
2242 themselves, as entire phrases are often added or deleted when editing.
2243 @item
2244 Try to keep lines less than 40-60@w{ }characters, to allow space for
2245 inserting more text.
2246 @item
2247 Do not try to do any formatting in a @acronym{WYSIWYG} manner (i.e.,
2248 don't try and use spaces to get proper indentation).
2249 @end itemize
2252 @node Measurements, Expressions, Input Conventions, Programming Tutorial
2253 @section Measurements
2254 @cindex measurements
2256 @cindex units of measurement
2257 @cindex basic units
2258 @cindex machine units
2259 @cindex measurement units
2260 @cindex @code{u} unit
2261 @cindex unit, @code{u}
2262 @code{gtroff} (like any other programs) requires numeric parameters to
2263 specify various measurements.  Most numeric parameters@footnote{those
2264 that specify vertical or horizontal motion or a type size} may have a
2265 @dfn{measurement unit} attached.  These units are specified as a single
2266 character which immediately follows the number or expression.  Each of
2267 these units are understood, by @code{gtroff}, to be a multiple of its
2268 @dfn{basic unit}.  So, whenever a different measurement unit is
2269 specified @code{gtroff} converts this into its @dfn{basic units}.  This
2270 basic unit, represented by a @samp{u}, is a device dependent measurement
2271 which is quite small, ranging from 1/75th to 1/72000th of an inch.  The
2272 values may be given as fractional numbers---nevertheless, fractional
2273 basic units are always rounded to integers.
2275 Some of the measurement units are completely independent of any of the
2276 current settings (e.g.@: type size) of @code{gtroff}.
2278 @table @code
2279 @item i
2280 @cindex inch
2281 @cindex @code{i} unit
2282 @cindex unit, @code{i}
2283 Inches.  An antiquated measurement unit still in use in certain
2284 backwards countries.  One inch is equal to@w{ }2.54@dmn{cm}.
2285 @item c
2286 @cindex centimeter
2287 @cindex @code{c} unit
2288 @cindex unit, @code{c}
2289 Centimeters.  One centimeter is equal to@w{ }0.3937@dmn{in}.
2290 @item p
2291 @cindex points
2292 @cindex @code{p} unit
2293 @cindex unit, @code{p}
2294 Points.  This is a typesetter's measurement used for measure type size.
2295 It is 72@w{ }points to an inch.
2296 @item P
2297 @cindex pica
2298 @cindex @code{P} unit
2299 @cindex unit, @code{P}
2300 Pica.  Another typesetting measurement.  6@w{ }Picas to an inch (and
2301 12@w{ }points to a pica).
2302 @item s
2303 @itemx z
2304 @cindex @code{s} unit
2305 @cindex unit, @code{s}
2306 @cindex @code{z} unit
2307 @cindex unit, @code{z}
2308 @xref{Fractional Type Sizes}, for a discussion of these units.
2309 @end table
2311 The other measurements understood by @code{gtroff} are dependent on
2312 settings currently in effect in @code{gtroff}.  These are very useful
2313 for specifying measurements which should look proper with any size of
2314 text.
2316 @table @code
2317 @item m
2318 @cindex em unit
2319 @cindex @code{m} unit
2320 @cindex unit, @code{m}
2321 Ems.  This unit is equal to the current font size in points.  So called
2322 because it is @emph{approximately} the width of the letter@w{ }@samp{m}
2323 in the current font.
2324 @item n
2325 @cindex en unit
2326 @cindex @code{n} unit
2327 @cindex unit, @code{n}
2328 Ens.  This is half of an em.
2329 @item v
2330 @cindex vertical space
2331 @cindex space, vertical
2332 @cindex @code{v} unit
2333 @cindex unit, @code{v}
2334 Vertical space.  This is equivalent to the current line spacing.
2335 @xref{Sizes}, for more information about this.
2336 @item M
2337 @cindex @code{M} unit
2338 @cindex unit, @code{M}
2339 100ths of an em.
2340 @end table
2342 @menu
2343 * Default Units::               
2344 @end menu
2346 @node Default Units,  , Measurements, Measurements
2347 @subsection Default Units
2348 @cindex default units
2349 @cindex units, default
2351 Many requests take a default unit.  While this can be helpful at times,
2352 it can cause strange errors in some expressions.  For example, the line
2353 length request expects em units.  Here are several attempts to get a
2354 line length of 3.5@w{ }inches and the results:
2356 @example
2357 3.5i      @result{}   3.5i
2358 7/2       @result{}   0i
2359 7/2i      @result{}   0i
2360 7i/2      @result{}   0.1i
2361 7i/2u     @result{}   3.5i
2362 @end example
2364 @noindent
2365 Everything will be converted to basic units first.  In the above example
2366 it is assumed that 1@dmn{i} equals@w{ }240@dmn{u}, and 1@dmn{m}
2367 equals@w{ }10@dmn{p} (thus 1@dmn{m} equals@w{ }33@dmn{u}).  The value
2368 7i/2 will be first handled as 7i/2m, then converted to 1680u/66u which
2369 is 25@dmn{u}, and this is approximately 0.1@dmn{i}.
2371 As a conclusion, the safest way to specify measurements is to always
2372 attach a scaling indicator.  If you want to multiply or divide by a
2373 certain scalar value, use @samp{u} as the unit for that value.
2376 @node Expressions, Identifiers, Measurements, Programming Tutorial
2377 @section Expressions
2378 @cindex expressions
2380 @code{gtroff} has most of operators common to other languages:
2382 @c XXX more details; examples
2384 @itemize @bullet
2385 @item
2386 @cindex arithmetic operators
2387 @cindex operators, arithmetic
2388 @opindex +
2389 @opindex -
2390 @opindex /
2391 @opindex *
2392 @opindex %
2393 Arithmetic: @samp{+} (addition), @samp{-} (subtraction), @samp{/}
2394 (division), @samp{*} (multiplication), @samp{%} (modulo).
2396 @code{gtroff} only provides integer arithmetic.  The internal type used
2397 for computing results is @samp{int}, which is usually a 32@dmn{bit}
2398 signed integer.
2399 @item
2400 @cindex comparison operators
2401 @cindex operators, comparison
2402 @opindex <
2403 @opindex >
2404 @opindex >=
2405 @opindex <=
2406 @opindex =
2407 @opindex ==
2408 Comparison: @samp{<} (less than), @samp{>} (greater than), @samp{<=}
2409 (less than or equal), @samp{>=} (greater than or equal), @samp{=}
2410 (equal), @samp{==} (the same as @samp{=}).
2411 @item
2412 @cindex logical operators
2413 @cindex operators, logical
2414 @opindex &
2415 @opindex :
2416 Logical: @samp{&} (logical and), @samp{:} (logical or).
2417 @item
2418 @cindex unary operators
2419 @cindex operators, unary
2420 @opindex -
2421 @opindex +
2422 @opindex !
2423 @findex if
2424 @findex while
2425 Unary operators: @samp{-} (negating, i.e.@: changing the sign), @samp{+}
2426 (just for completeness; does nothing in expressions), @samp{!} (logical
2427 not; this works only within @code{if} and @code{while} requests).  See
2428 below for the use of unary operators in motion requests.
2429 @item
2430 @cindex extremum operators
2431 @cindex operators, extremum
2432 @opindex >?
2433 @opindex <?
2434 Extrema: @samp{>?} (maximum), @samp{<?} (minimum).  For example,
2435 @samp{5>?3} yields@w{ }@samp{5}.
2436 @c XXX add examples
2437 @item
2438 @cindex scaling operator
2439 @cindex operator, scaling
2440 Scaling: @code{(@var{c};@var{e})}.  Evaluate @var{e} using @var{c} as
2441 the default scaling indicator.  If @var{c} is missing, ignore scaling
2442 indicators in the evaluation of @var{e}.
2443 @end itemize
2445 @cindex parentheses
2446 @cindex order of evaluation in expressions
2447 @cindex expression, order of evaluation
2448 @opindex (
2449 @opindex )
2450 Parentheses may be used as in any other language.  However, in
2451 @code{gtroff} they are necessary to ensure order of evaluation.
2452 @code{gtroff} has no operator precedence; expressions are evaluated left
2453 to right.  This means that @samp{3+5*4} is evaluated as if it were
2454 parenthesized like @samp{(3+5)*4}, not as @samp{3+(5*4)}, as expected.
2456 @opindex +
2457 @opindex -
2458 @opindex |
2459 @cindex motion operators
2460 @cindex operators, motion
2461 For many requests which cause a motion on the page, the unary operators
2462 work differently.  The @samp{+} and @samp{-} operators then indicate a
2463 motion relative to the current position (down or up, respectively), and
2464 the @samp{|} operator indicates an absolute position on the page or
2465 input line.
2466 @c XXX xref
2467 @samp{+} and @samp{-} are also treated differently by the following
2468 requests and escapes: @code{bp}, @code{in}, @code{ll}, @code{lt},
2469 @code{nm}, @code{nr}, @code{pl}, @code{pn}, @code{po}, @code{ps},
2470 @code{rt}, @code{ti}, @code{\R}, and @code{\s}.  Here the plus and minus
2471 signs indicate increments resp.@: decrements.
2473 @c XXX add more xref
2474 @xref{Setting Registers}.
2476 @cindex space characters in expressions
2477 @cindex expressions and space characters
2478 Due to the way arguments are parsed, spaces are not allowed in
2479 expressions, unless the entire expression is surrounded by parentheses.
2481 @xref{Request Arguments}, and @ref{Conditionals and Loops}.
2484 @node Identifiers, Embedded Commands, Expressions, Programming Tutorial
2485 @section Identifiers
2486 @cindex identifiers
2488 Like any other language, @code{gtroff} has rules for properly formed
2489 @dfn{identifiers}.  In @code{gtroff}, an identifier can be made up of
2490 almost any printable character.  The exception are the following
2491 characters:
2493 @itemize @bullet
2494 @cindex whitespace characters
2495 @cindex newline character
2496 @cindex character, whitespace
2497 @item
2498 Whitespace characters (space, tabs, and newlines).
2499 @cindex character, backspace
2500 @cindex backspace character
2501 @item
2502 Backspace (@acronym{ASCII}@w{ }@code{0x08} resp.@: @acronym{EBCDIC}@w{
2503 }@code{0x16}) and character code @code{0x01}.
2504 @cindex illegal input characters
2505 @cindex input characters, illegal
2506 @cindex characters, illegal input
2507 @cindex unicode
2508 @item
2509 The following input characters are illegal and will be ignored if
2510 @code{groff} runs on a machine based on @acronym{ASCII}, causing a
2511 warning message: @code{0x00}, @code{0x0B}, @code{0x0D}-@code{0x1F},
2512 @code{0x80}-@code{0x9F}.
2514 And here the illegal input characters if @code{groff} runs on an
2515 @acronym{EBCDIC} host: @code{0x00}, @code{0x08}, @code{0x09},
2516 @code{0x0B}, @code{0x0D}-@code{0x14}, @code{0x17}-@code{0x1F},
2517 @code{0x30}-@code{0x3F}.
2519 Currently, some of these reserved codepoints are used internally, thus
2520 making it non-trivial to extend @code{gtroff} to cover Unicode or other
2521 character sets resp.@: encodings which use characters of these ranges.
2523 Note that illegal characters will be removed before parsing; an
2524 identifier `foo', followed by an illegal character, followed by `bar'
2525 will be treated as `foobar'.
2526 @end itemize
2528 For example, any of the following is valid.
2530 @example
2534 end-list
2536 @end example
2538 @findex ]
2539 Note that identifiers longer than two characters with a closing bracket
2540 (@samp{]}) in its name can't be accessed with escape sequences which
2541 expect an identifier as a parameter.  For example, @samp{\[foo]]} will
2542 access the glyph @samp{foo}, followed by @samp{]}, whereas
2543 @samp{\C'foo]'} really asks for glyph @samp{foo]}.
2545 @c XXX xref
2547 @Deffn{Escape, \\A, ident}
2548 Whether an identifier @var{ident} is valid in @code{gtroff} can be
2549 tested with the @code{\A} escape.  It expands to the character@w{ }1
2550 or@w{ }0 according to whether its argument (delimited by quotes usually)
2551 is or is not acceptable as the name of a string, macro, diversion,
2552 number register, environment, or font.  It will return@w{ }0 if no
2553 argument is given.  This is useful for looking up user input in some
2554 sort of associative table.
2556 @example
2557 \A'end-list'
2558     @result{} 1
2559 @end example
2560 @end_Deffn
2562 @xref{Escapes}, for details on parameter delimiting characters.
2564 @c XXX add xrefs above
2566 Identifiers in @code{gtroff} can be any length, but, in some contexts,
2567 @code{gtroff} needs to be told where identifiers end and text begins
2568 (and in different ways depending on their length).
2570 @findex (
2571 @findex [
2572 @findex ]
2573 @itemize @bullet{}
2574 @item
2575 Single character.
2576 @item
2577 Two characters.  Must be prefixed with @samp{(} in some situations.
2578 @item
2579 Arbitrary length (@code{gtroff} only).  Must be bracketed with @samp{[}
2580 and@w{ }@samp{]} in some situations.  Any length identifier can be put
2581 in brackets.
2582 @end itemize
2584 @cindex undefined identifiers
2585 @cindex indentifiers, undefined
2586 Unlike many other programming languages, undefined identifiers are
2587 silently ignored or expanded to nothing.
2589 @c XXX add info about -ww command line option.
2591 @xref{Interpolating Registers}, and @ref{Strings}.
2594 @node Embedded Commands, Registers, Identifiers, Programming Tutorial
2595 @section Embedded Commands
2596 @cindex embedded commands
2597 @cindex commands, embedded
2599 Most documents need more functionality beyond filling, adjusting and
2600 implicit line breaking.  In order to gain further functionality,
2601 @code{gtroff} allows commands to be embedded into the text, in two ways.
2603 The first is a @dfn{request} which takes up an entire line, and does
2604 some large scale operation (e.g.@: break lines, start new pages).
2606 The other is an @dfn{escape} which can be embedded anywhere in the text,
2607 or even as an argument to a request.
2608 @c XXX (Not always?)
2609 Escapes generally do more minor operations like sub- and superscripts,
2610 print a symbol, etc.
2612 @menu
2613 * Requests::                    
2614 * Macros::                      
2615 * Escapes::                     
2616 @end menu
2618 @node Requests, Macros, Embedded Commands, Embedded Commands
2619 @subsection Requests
2620 @cindex requests
2622 @cindex control character
2623 @cindex character, control
2624 @findex '
2625 @findex .
2626 A request line begins with a control character, which is either a single
2627 quote (@samp{'}) or a period (@samp{.}).  These can be changed; see
2628 @ref{Character Translations}, for details.  After this there may be
2629 optional tabs or spaces followed by an identifier which is the name of
2630 the request.  This may be followed by any number of space-separated
2631 arguments.
2633 @cindex zero width space character
2634 @cindex character, zero width space
2635 @cindex space character, zero width
2636 @findex \&
2637 To begin a line with a control character without it being interpreted,
2638 precede it with @code{\&}.  This represents a zero width space, which
2639 means it will not affect the output.
2641 In most cases the period is used as a control character.  Several
2642 requests will cause a break; using the single quote control character
2643 will prevent this.
2645 @menu
2646 * Request Arguments::           
2647 @end menu
2649 @node Request Arguments,  , Requests, Requests
2650 @subsubsection Request Arguments
2651 @cindex request arguments
2652 @cindex arguments to requests
2654 Arguments to requests (and macros) are processed much like the shell:
2655 The line is split into arguments according to spaces.  An argument which
2656 is intended to contain spaces can either be enclosed in quotes (single
2657 or double), or have the spaces @dfn{escaped} with backslashes.
2659 @example
2660 .uh The Mouse Problem
2661 .uh "The Mouse Problem"
2662 .uh The\ Mouse\ Problem
2663 @end example
2665 @findex \~
2666 @findex \@key{SP}
2667 @noindent
2668 The first line is the @code{uh} macro being called with 3 arguments,
2669 @samp{The}, @samp{Mouse}, and @samp{Problem}.  The latter two have the
2670 same effect or calling the @code{uh} macro with one argument @samp{The
2671 Mouse Problem}.@footnote{The last solution, i.e., using escaped spaces,
2672 is `classical' in the sense that it can be found in most @code{troff}
2673 documents.  Nevertheless, it is not optimal in all situations since
2674 @w{@samp{\ }} inserts a fixed-width, non-breaking space character which
2675 can't stretch.  @code{gtroff} provides a different command @code{\~} to
2676 insert a stretchable, non-breaking space.}
2678 @findex ds
2679 Note, however, that the @code{ds} request works differently.
2680 @xref{Strings}, for more details.
2682 @node Macros, Escapes, Requests, Embedded Commands
2683 @subsection Macros
2684 @cindex macros
2686 @code{gtroff} has a @dfn{macro} facility for defining a series of lines
2687 which can be invoked by name.  They are called in the same manner as
2688 requests---arguments also may be passed in the same manner.
2690 @xref{Writing Macros}, and @ref{Request Arguments}.
2692 @node Escapes,  , Macros, Embedded Commands
2693 @subsection Escapes
2694 @cindex escapes
2696 Escapes may occur anywhere in the input to @code{gtroff}.  They begin
2697 with a backslash usually and are followed by a single character which
2698 indicates the function to be performed.  The escape character can be
2699 changed; see @ref{Character Translations}.
2701 @findex (
2702 @findex [
2703 @findex ]
2704 Escape sequences which require an identifier as a parameter accept three
2705 possible syntax forms.
2707 @itemize @bullet
2708 @item
2709 The next single character is the identifier.
2710 @item
2711 If this single character is an opening parenthesis, take the following
2712 two characters as the identifier.  Note that there is no closing
2713 parenthesis after the identifier.
2714 @item
2715 If this single character is an opening bracket, take all characters
2716 until a closing bracket as the identifier.
2717 @end itemize
2719 @noindent
2720 Examples:
2722 @example
2724 \n(XX
2725 \*[TeX]
2726 @end example
2728 @findex '
2729 @cindex argument delimiting characters
2730 @cindex characters, argument delimiting
2731 @cindex delimiting characters for arguments
2732 Other escapes may require several arguments and/or some special format.
2733 In such cases the argument is traditionally enclosed in single quotes
2734 (and quotes are always used in this manual for the definitions of escape
2735 sequences).  The enclosed text is then processed according to what that
2736 escape expects.  Example:
2738 @example
2739 \l'1.5i\(bu'
2740 @end example
2742 @findex \o
2743 @findex \b
2744 @findex \X
2745 Note that the quote character can be replaced with any other character
2746 which does not occur in the argument (even a newline or a space
2747 character) in the following escapes: @code{\o}, @code{\b}, and
2748 @code{\X}.  This makes e.g.
2750 @example
2751 A caf
2756 in Paris
2757   @result{} A caf@'e in Paris
2758 @end example
2760 @noindent
2761 possible, but it is better not to use this feature to avoid confusion.
2763 @findex \%
2764 @findex \@key{SP}
2765 @findex \|
2766 @findex \^
2767 @findex \@{
2768 @findex \@}
2769 @findex \'
2770 @findex \`
2771 @findex \-
2772 @findex \_
2773 @findex \!
2774 @findex \?
2775 @findex \@@
2776 @findex \)
2777 @findex \/
2778 @findex \,
2779 @findex \&
2780 @findex \~
2781 @findex \0
2782 @findex \a
2783 @findex \c
2784 @findex \d
2785 @findex \e
2786 @findex \E
2787 @findex \p
2788 @findex \r
2789 @findex \t
2790 @findex \u
2791 The following escapes sequences (which are handled similarly to
2792 characters since they don't take a parameter) are also allowed as
2793 delimiters: @code{\%}, @w{@samp{\ }}, @code{\|}, @code{\^}, @code{\@{},
2794 @code{\@}}, @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!},
2795 @code{\?}, @code{\@@}, @code{\)}, @code{\/}, @code{\,}, @code{\&},
2796 @code{\~}, @code{\0}, @code{\a}, @code{\c}, @code{\d}, @code{\e},
2797 @code{\E}, @code{\p}, @code{\r}, @code{\t}, and @code{\u}.  Again, don't
2798 use these if possible.
2800 @findex \A
2801 @findex \Z
2802 @findex \C
2803 @findex \w
2804 No newline characters as delimiters are allowed in the following
2805 escapes: @code{\A}, @code{\Z}, @code{\C}, and @code{\w}.
2807 @findex \D
2808 @findex \h
2809 @findex \H
2810 @findex \l
2811 @findex \L
2812 @findex \N
2813 @findex \R
2814 @findex \s
2815 @findex \S
2816 @findex \v
2817 @findex \x
2818 Finally, the escapes @code{\D}, @code{\h}, @code{\H}, @code{\l},
2819 @code{\L}, @code{\N}, @code{\R}, @code{\s}, @code{\S}, @code{\v}, and
2820 @code{\x} can't use the following characters as delimiters:
2822 @itemize @bullet
2823 @cindex numbers
2824 @cindex digits
2825 @item
2826 The digits @code{0}-@code{9}.
2827 @cindex operators
2828 @opindex +
2829 @opindex -
2830 @opindex /
2831 @opindex *
2832 @opindex %
2833 @opindex <
2834 @opindex >
2835 @opindex =
2836 @opindex &
2837 @opindex :
2838 @opindex (
2839 @opindex )
2840 @opindex .
2841 @item
2842 The (single character) operators @samp{+-/*%<>=&:().}.
2843 @item
2844 @cindex space character
2845 @cindex character, space
2846 @cindex tab character
2847 @cindex character, tab
2848 @cindex newline character
2849 @cindex character, newline
2850 The space, tab, and newline characters.
2851 @findex \%
2852 @findex \@{
2853 @findex \@}
2854 @findex \'
2855 @findex \`
2856 @findex \-
2857 @findex \_
2858 @findex \!
2859 @findex \@@
2860 @findex \/
2861 @findex \c
2862 @findex \e
2863 @findex \p
2864 @item
2865 All escape sequences except @code{\%}, @code{\@{}, @code{\@}},
2866 @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!}, @code{\@@},
2867 @code{\/}, @code{\c}, @code{\e}, and @code{\p}.
2868 @end itemize
2870 @findex \\
2871 @findex \e
2872 @findex \E
2873 To have a backslash appear in the output several escapes are defined:
2874 @code{\\}, @code{\e} or @code{\E}.  These are very similar, and only
2875 differ with respect to being used in macros or diversions.
2876 @xref{Copy-in Mode}, and @ref{Diversions}, for more information.
2878 @xref{Identifiers}.
2880 @menu
2881 * Comments::                    
2882 @end menu
2884 @node Comments,  , Escapes, Escapes
2885 @subsubsection Comments
2886 @cindex comments
2888 Probably one of the most@footnote{Unfortunately, this is a lie.  But
2889 hopefully future @code{gtroff} hackers will believe it :-)} common forms
2890 of escapes is the comment.
2892 @Deffn{Escape, \\"}
2893 Start a comment.  Everything to the end of the input line is ignored.
2895 This may sound simple, but it can be tricky to keep the comments from
2896 interfering with the appearance of the final output.
2898 @findex ds
2899 If the escape is to the right of some text or a request, that portion of
2900 the line will be ignored, but the space leading up to it will be noticed
2901 by @code{gtroff}.  This only affects the @code{.ds} request.
2902 @c XXX (any others?)
2904 One possibly irritating idiosyncracy is that tabs must not be used to
2905 line up comments.  Tabs are not treated as white space between the
2906 request and macro arguments.
2908 @cindex undefined request
2909 @cindex request, undefined
2910 A comment on a line by itself will be treated as a blank line, because
2911 after eliminating the comment, that is all that remains:
2913 @example
2914 Test
2915 \" comment
2916 Test
2917 @end example
2919 @noindent
2920 will produce
2922 @example
2923 Test
2925 Test
2926 @end example
2928 As a consequence, it is common to start the line with @code{.\"} which
2929 will cause the line to be treated as an undefined request and thus
2930 ignored completely.
2932 @findex '
2933 Another commenting scheme seen sometimes is three consecutive single
2934 quotes (@code{'''}) at the beginning of a line.  This works, but
2935 @code{gtroff} will give a warning about an undefined macro (namely
2936 @code{''}), which is harmless, but irritating.
2937 @end_Deffn
2939 @Deffn{Escape, \\#}
2940 Now to avoid all this @code{gtroff} has a new comment mechanism using
2941 the @code{\#} escape.  This escape works the same as @code{\"} except
2942 that the newline is also ignored:
2944 @example
2945 Test
2946 \# comment
2947 Test
2948 @end example
2950 @noindent
2951 will produce
2953 @example
2954 Test Test
2955 @end example
2957 @noindent
2958 as expected.
2959 @end_Deffn
2961 @findex ig
2962 For large blocks of text, the @code{ig} request may be useful.
2964 @c XXX definition of .ig
2966 @xref{Strings}.
2968 @node Registers, Manipulating Filling and Adjusting, Embedded Commands, Programming Tutorial
2969 @section Registers
2970 @cindex registers
2972 Numeric variables in @code{gtroff} are called @dfn{registers}.  There
2973 are a number of built-in registers, supplying anything from the date to
2974 details of formatting parameters.
2976 @xref{Identifiers}, for details on register identifiers.
2978 @menu
2979 * Setting Registers::           
2980 * Interpolating Registers::     
2981 * Auto-increment::              
2982 * Assigning Formats::           
2983 * Built-in Registers::          
2984 @end menu
2986 @node Setting Registers, Interpolating Registers, Registers, Registers
2987 @subsection Setting Registers
2988 @cindex setting registers
2989 @cindex registers, setting
2991 Registers are defined resp.@: set via the @code{nr} request or the
2992 @code{\R} escape.
2994 @Deffn{Request, nr, ident value}
2995 @Deffnx{Escape, \\R, ident value}
2996 Set number register @var{ident} to @var{value}.  If @var{ident} doesn't
2997 exist, it will be created.
2998 @end_Deffn
3000 For example, the following two lines are equivalent:
3002 @example
3003 .nr a 1
3004 \R'a 1'
3005 @end example
3007 Both @code{nr} and @code{\N} have two additional special forms to
3008 increment resp.@: decrement a register.
3010 @Deffn{Request, nr, ident +value}
3011 @Deffnx{Request, nr, ident -value}
3012 @Deffnx{Escape, \\N, ident +value}
3013 @Deffnx{Escape, \\N, ident -value}
3014 Increment (decrement) register @var{ident} by @var{value}.
3016 @example
3017 .nr a 1
3018 .nr a +1
3020     @result{} 2
3021 @end example
3023 To assign the negated value of a register to another register, some care
3024 must be taken to get the desired result:
3026 @example
3027 .nr a 7
3028 .nr b 3
3029 .nr a -\nb
3031     @result{} 4
3032 .nr a (-\nb)
3034     @result{} -3
3035 @end example
3037 @noindent
3038 The surrounding parentheses prevent the interpretation of the minus sign
3039 as a decrementing operator.
3040 @end_Deffn
3042 @Deffn{Request, rr, ident}
3043 Remove number register @var{ident}.
3044 @end_Deffn
3046 @Deffn{Request, rnn, ident1 ident2}
3047 Rename number register @var{ident1} to @var{ident2}.
3048 @end_Deffn
3050 @Deffn{Request, aln, ident1 ident2}
3051 This request creates an alias @var{ident1} for a number register
3052 @var{ident2}.  The new name and the old name will be exactly equivalent.
3053 If @var{ident1} is undefined, a warning of type @samp{reg} will be
3054 generated, and the request will be ignored.  @xref{Debugging}, for
3055 information about warnings.
3056 @end_Deffn
3058 @node Interpolating Registers, Auto-increment, Setting Registers, Registers
3059 @subsection Interpolating Registers
3060 @cindex interpolating registers
3061 @cindex registers, interpolating
3063 Numeric registers can be accessed via the @code{\n} escape.
3065 @Deffn{Escape, \\n, ident}
3066 @c XXX is the following correct?
3067 Interpolate number register @var{ident}.  This means that the value of
3068 the register is expanded in-place while @code{gtroff} is parsing the
3069 input line.
3071 @example
3072 .nr a 5
3073 .nr as \na+\na
3074 \n(as
3075     @result{} 10
3076 @end example
3077 @end_Deffn
3079 @node Auto-increment, Assigning Formats, Interpolating Registers, Registers
3080 @subsection Auto-increment
3081 @cindex auto-increment
3082 @cindex increment, automatic
3084 Number registers can also be auto-incremented and auto-decremented.  The
3085 increment resp.@: decrement factor can be specified with a third
3086 argument to the @code{nr} request or @code{\N} escape.
3088 @Deffn{Request, nr, ident value incr}
3089 @Deffnx{Escape, \\N, ident value incr}
3090 Set number register @var{ident} to @var{value}; the increment for
3091 auto-incrementing is set to @var{incr}.
3092 @end_Deffn
3094 To activate auto-incrementing, the escape @code{\n} has a special syntax
3095 form.
3097 @Deffn{Escape, \\n, +ident}
3098 @Deffnx{Escape, \\n, -ident}
3099 Before interpolating, increment resp.@: decrement @var{ident} by the
3100 auto-increment value as specified with the @code{nr} request (or the
3101 @code{\N} escape).  If no auto-increment value has been specified, both
3102 syntax forms are identical to @code{\n}.
3103 @end_Deffn
3105 For example,
3107 @example
3108 .nr a 0 1
3109 .nr xx 0 5
3110 .nr foo 0 -2
3111 \n+a, \n+a, \n+a, \n+a, \n+a
3113 \n-(xx, \n-(xx, \n-(xx, \n-(xx, \n-(xx
3115 \n+[foo], \n+[foo], \n+[foo], \n+[foo], \n+[foo]
3116 @end example
3118 @noindent
3119 produces
3121 @example
3122 1, 2, 3, 4, 5
3123 -5, -10, -15, -20, -25
3124 -2, -4, -6, -8, -10
3125 @end example
3127 To change the increment value without changing the value of a register,
3128 the following can be used.
3130 @example
3131 .nr a \na 10
3132 @end example
3134 @node Assigning Formats, Built-in Registers, Auto-increment, Registers
3135 @subsection Assigning Formats
3136 @cindex assigning formats
3137 @cindex formats, assigning
3139 When a register is used in the text of an input file (as opposed to part
3140 of an expression) it is textually replaced (or interpolated) with a
3141 representation of that number.  This output format can be changed to a
3142 variety of formats (numbers, Roman numerals, etc).  This is done using
3143 the @code{af} request.
3145 @Deffn{Request, af, ident format}
3147 Change the output format of a number register.  The first argument
3148 @var{ident} is the name of the number register to be changed, and the
3149 second argument @var{format} is the output format.  The following output
3150 formats are available:
3152 @table @code
3153 @item 1
3154 This is the default format, decimal numbers: 1, 2, 3,@w{ }@dots{}
3155 @item 0@dots{}01
3156 Decimal numbers with as many leading zeros as specified.  So, @samp{01}
3157 would result in 01, 02, 03,@w{ }@dots{}
3158 @item I
3159 @cindex roman numerals
3160 @cindex numerals, Roman
3161 Upper-case Roman numerals: 0, I, II, III, IV,@w{ }@dots{}
3162 @item i
3163 Lower-case Roman numerals: 0, i, ii, iii, iv,@w{ }@dots{}
3164 @item A
3165 Upper-case letters: A, B, C, @dots{},@w{ }Z, AA, AB,@w{ }@dots{}
3166 @item a
3167 Lower-case letters: a, b, c, @dots{},@w{ }z, aa, ab,@w{ }@dots{}
3168 @end table
3170 The following example will produce @samp{10, X, j, 010}:
3172 @example
3173 .nr a 10
3174 .af a 1           \" the default format
3175 \na,
3176 .af a I
3177 \na,
3178 .af a a
3179 \na,
3180 .af a 001
3182 @end example
3183 @end_Deffn
3185 @Deffn{Escape, \\g, ident}
3186 Return the current format of the specified register @var{ident}.  For
3187 example, @samp{\ga} after the previous example would produce the string
3188 @samp{001}.  If the register hasn't been defined yet, nothing is
3189 returned.
3190 @end_Deffn
3192 @node Built-in Registers,  , Assigning Formats, Registers
3193 @subsection Built-in Registers
3194 @cindex built-in registers
3195 @cindex registers, built-in
3197 The following lists some built-in registers which are not described
3198 elsewhere in this manual.  Any register which begin with a @samp{.} is
3199 read-only.  A complete listing of all built-in registers can be found in
3200 @ref{Register Index}.
3202 @table @code
3203 @item .H
3204 @cindex horizontal resolution
3205 @cindex resolution, horizontal
3206 @vindex .H
3207 Horizontal resolution in basic units.
3208 @item .V
3209 @cindex vertical resolution
3210 @cindex resolution, vertical
3211 @vindex .V
3212 Vertical resolution in basic units.
3213 @item dw
3214 @cindex day of the week
3215 @cindex date, day of the week
3216 @vindex dw
3217 Day of the week (1-7).
3218 @item dy
3219 @cindex day of the month
3220 @cindex date, day of the month
3221 @vindex dy
3222 Day of the month (1-31).
3223 @item mo
3224 @cindex month of the year
3225 @cindex date, month of the year
3226 @vindex mo
3227 Current month (1-12).
3228 @item year
3229 @cindex date, year
3230 @cindex year, current
3231 @vindex year
3232 The current year.
3233 @item yr
3234 @vindex yr
3235 The current year minus@w{ }1900.  Unfortunately, the documentation of
3236 @acronym{UNIX} Version@w{ }7's @code{troff} had a year@w{ }2000 bug: It
3237 incorrectly claimed that @code{yr} contains the last two digits of the
3238 year.  That claim has never been true of either traditional @code{troff}
3239 or GNU @code{troff}.  Old @code{troff} input that looks like this:
3241 @example
3242 '\" The following line stopped working after 1999
3243 This document was formatted in 19\n(yr.
3244 @end example
3246 @noindent
3247 can be corrected as follows:
3249 @example
3250 This document was formatted in \n[year].
3251 @end example
3253 @noindent
3254 or, to be portable to older @code{troff} versions, as follows:
3256 @example
3257 .nr y4 1900+\n(yr
3258 This document was formatted in \n(y4.
3259 @end example
3261 @item .c
3262 @vindex .c
3263 @itemx c.
3264 @vindex c.
3265 @cindex input line number
3266 @cindex line number, input
3267 The current @emph{input} line number.  Register @samp{.c} is read-only,
3268 whereas @samp{c.} (a @code{gtroff} extension) is writable also,
3269 affecting both @samp{.c} and @samp{c.}.
3270 @item ln
3271 @vindex ln
3272 @findex nm
3273 @cindex output line number
3274 @cindex line number, output
3275 The current @emph{output} line number after a call to the @code{nm}
3276 request to activate line numbering.
3277 @c XXX xref nm request
3278 @item .x
3279 @vindex .x
3280 @cindex major version number
3281 @cindex version number, major
3282 The major version number.  For example, if the version number is@w{
3283 }1.03 then @code{.x} will contain@w{ }@samp{1}.
3284 @item .y
3285 @vindex .y
3286 @cindex minor version number
3287 @cindex version number, minor
3288 The minor version number.  For example, if the version number is@w{
3289 }1.03 then @code{.y} will contain@w{ }@samp{03}.
3290 @item .Y
3291 @vindex .Y
3292 @cindex revision number
3293 The revision number of @code{groff}.
3294 @item .g
3295 @vindex .g
3296 Always@w{ }1.  Macros should use this to determine whether they are
3297 running under GNU @code{troff}.
3298 @item .A
3299 @vindex .A
3300 If the command line option @option{-a} is used to produce an
3301 @acronym{ASCII} approximation of the output, this is set to@w{ }1, zero
3302 otherwise.  @xref{Groff Options}.
3303 @item .P
3304 @vindex .P
3305 This register indicates whether the current page is actually being
3306 printed, i.e., whether the @option{-o} option is being used to only
3307 print selected pages.  @xref{Groff Options}, for more information.
3308 @item .T
3309 @vindex .T
3310 If @code{gtroff} is called with the @option{-T} command line option, the
3311 number register @code{.T} is set to@w{ }1, and zero otherwise.
3312 @xref{Groff Options}.
3314 @maindex \*(.T
3315 Additionally, @code{gtroff} predefines a single (read/write) string
3316 register @code{.T} which contains the current output device (for
3317 example, @samp{latin1} or @samp{ps}).
3318 @end table
3321 @node Manipulating Filling and Adjusting, Manipulating Hyphenation, Registers, Programming Tutorial
3322 @section Manipulating Filling and Adjusting
3323 @cindex manipulating filling and adjusting
3324 @cindex filling and adjusting, manipulating
3325 @cindex adjusting and filling, manipulating
3326 @cindex justifying text
3327 @cindex text, justifying
3329 @cindex break
3330 @cindex line break
3331 @findex bp
3332 @findex ce
3333 @findex cf
3334 @findex fi
3335 @findex fl
3336 @findex in
3337 @findex nf
3338 @findex rj
3339 @findex sp
3340 @findex ti
3341 @findex trf
3342 Various ways of causing @dfn{breaks} were given in @ref{Implicit Line
3343 Breaks}.  The @code{br} request will likewise cause a break.  Several
3344 other requests will also cause breaks, but implicitly.  These are
3345 @code{bp}, @code{ce}, @code{cf}, @code{fi}, @code{fl}, @code{in},
3346 @code{nf}, @code{rj}, @code{sp}, @code{ti}, and @code{trf}.
3348 @Deffn{Request, br, }
3349 Break the current line, i.e., the input collected so far will be emitted
3350 without adjustment.
3351 @end_Deffn
3353 @vindex .u
3354 Initially, @code{gtroff} will fill and adjust text to both margins.
3355 Filling can be disabled via the @code{nf} request and re-enabled with
3356 the @code{fi} request.
3358 @Deffn{Request, fi, }
3359 Activate fill mode (which is the default).  This request implicitly
3360 enables adjusting; it will also cause a break in the text currently
3361 being filled.  The number register @code{.u} is set to@w{ }1.
3362 @end_Deffn
3364 @Deffn{Request, nf, }
3365 Activate no-fill mode.  Input lines are output as-is, retaining line
3366 breaks.  The current line length will be ignored.  This command
3367 implicitly disables adjusting; it also causes a break.  The number
3368 register @code{.u} will be set to@w{ }0.
3369 @end_Deffn
3371 @Deffn{Request, ad, [@var{mode}]}
3372 Enable adjusting.  @var{mode} can have one of the following values:
3374 @table @code
3375 @item l
3376 @cindex ragged-right
3377 Adjust text to the left margin.  This produces what is traditionally
3378 called ragged-right text.
3379 @item r
3380 @cindex ragged-left
3381 Adjust text to the right margin, producing ragged-left text.
3382 @item c
3383 @cindex centered text
3384 @findex ce
3385 Center filled text.  This is different to the @code{ce} request which
3386 only centers text without filling.
3387 @item b
3388 @itemx n
3389 Justify to both margins.  This is default of @code{gtroff}.
3390 @end table
3392 With no argument, @code{gtroff} will adjust lines the same way before
3393 adjusting has been deactivated (with a call to @code{na}, for example).
3395 @example
3396 text
3397 .ad r
3398 text
3399 .ad c
3400 text
3402 text
3403 .ad  \" back to centering
3404 text
3405 @end example
3407 @vindex .j
3408 The current adjustment mode is available in the number register
3409 @code{.j}; it can be stored and subsequently used to set adjustment.
3410 @end_Deffn
3412 @Deffn{Request, na, }
3413 Disable adjusting.  This request won't change the current adjustment
3414 mode: A call to @code{ad} afterwards will use the previous adjustment
3415 setting.
3416 @end_Deffn
3418 @Deffn{Escape, \\p, }
3419 Adjust the current line and cause a break.
3421 In most cases this will produce very ugly results, since @code{gtroff}
3422 doesn't have a sophisticated paragraph building algorithm (as @TeX{}
3423 have, for example); instead, @code{gtroff} fills and adjusts a paragraph
3424 line by line:
3426 @example
3427   This is an uninteresting sentence.
3428   This is an uninteresting sentence.\p
3429   This is an uninteresting sentence.
3430 @end example
3432 is formatted as
3434 @example
3435   This is  an uninteresting  sentence.   This  is an
3436   uninteresting                            sentence.
3437   This is an uninteresting sentence.
3438 @end example
3439 @end_Deffn
3441 @cindex word space size
3442 @cindex size of word space
3443 @cindex space between words
3444 @cindex sentence space size
3445 @cindex size of sentence space
3446 @cindex space between sentences
3447 @Deffn{Request, ss, word_space_size [@var{sentence_space_size}]}
3448 Change the minimum size of a space between filled words.  It takes its
3449 units as one twelfth of the space width parameter for the current font.
3450 Initially both the @var{word_space_size} and @var{sentence_space_size}
3451 are@w{ }12.
3453 If two arguments are given to the @code{ss} request, the second argument
3454 sets the sentence space size.  If the second argument is not given,
3455 @var{sentence_space_size} will be the same as @var{word_space_size}.
3456 The sentence space size is used in two circumstances: If the end of a
3457 sentence occurs at the end of a line in fill mode, then both an
3458 inter-word space and a sentence space will be added; if two spaces
3459 follow the end of a sentence in the middle of a line, then the second
3460 space will be a sentence space.  Note that the behaviour of
3461 @acronym{UNIX} @code{troff} will be exactly that exhibited by GNU
3462 @code{troff} if a second argument is never given to the @code{ss}
3463 request.  In GNU @code{troff}, as in @acronym{UNIX} @code{troff}, a
3464 sentence should always be followed with either a newline or two spaces.
3466 @vindex .ss
3467 @vindex .sss
3468 The number registers @code{.ss} and @code{.sss} are the values of the
3469 parameters set by the first and second arguments of the @code{ss}
3470 request.
3471 @end_Deffn
3473 @cindex centering lines
3474 @cindex lines, centering
3475 @Deffn{Request, ce, [@var{nnn}]}
3476 Center text.  While the @w{@samp{ad c}} request will also center text,
3477 it has the side effect of filling the text.  @code{ce} will not fill the
3478 text it affects.  This request causes a break.
3480 With no arguments, @code{ce} will center the next line of text.
3481 @var{nnn} is a number indicating the number of lines to be centered.  If
3482 the argument is zero, centering is disabled.
3484 A common idiom is to turn on centering for a large number of lines, and
3485 to turn off centering after text to be centered.  This is useful for any
3486 request which takes a number of lines as an argument.
3488 @example
3489 .ce 1000
3490 replace this
3491 with
3492 something
3493 more interesting
3494 @dots{}
3495 .ce 0
3496 @end example
3498 @vindex .ce
3499 The @code{.ce} number register contains the number of lines remaining to
3500 be centered, as set by the @code{ce} request.
3501 @end_Deffn
3503 @cindex justifying text
3504 @cindex text, justifying
3505 @cindex right-justifying
3506 @vindex .rj
3507 @Deffn{Request, rj, [@var{nnn}]}
3508 Justify unfilled text to the right margin.  Its arguments are identical
3509 to the @code{ce} request.  The @code{.rj} number register is the number
3510 of lines to be right-justified as set by the @code{rj} request.  This
3511 request causes a line break.
3512 @end_Deffn
3514 @node Manipulating Hyphenation, Manipulating Spacing, Manipulating Filling and Adjusting, Programming Tutorial
3515 @section Manipulating Hyphenation
3516 @cindex manipulating hyphenation
3517 @cindex hyphenation, manipulating
3519 As discussed in @ref{Hyphenation}, @code{gtroff} will hyphenate words.
3520 There are a number of ways to influence how hyphenation is done.
3522 @Deffn{Request, hy, [@var{mode}]}
3524 Enable hyphenation.  The request has an optional numeric argument,
3525 @var{mode}, to restrict hyphenation if necessary:
3527 @table @code
3528 @item 1
3529 The default argument if @var{mode} is omitted.  Hyphenate without
3530 restrictions.
3531 @item 2
3532 Do not hyphenate the last word on a page or column.
3533 @item 4
3534 Do not hyphenate the last two characters of a word.
3535 @item 8
3536 Do not hyphenate the first two characters of a word.
3537 @end table
3539 Values in the previous table are additive.  For example, the value@w{
3540 }12 causes @code{gtroff} to neither hyphenate the last two nor the first
3541 two characters of a word.
3543 @vindex .hy
3544 The current hyphenation restrictions can be found in the number register
3545 @samp{.hy}.
3546 @end_Deffn
3548 @Deffn{Request, nh, }
3549 Disable hyphenation.  Note that the hyphenation mode of the last call to
3550 @code{hy} is not remembered.
3551 @end_Deffn
3553 @vindex .hlc
3554 @vindex .hlm
3555 @findex \%
3556 @cindex explicit hyphens
3557 @cindex hyphen, explicit
3558 @cindex consecutive hyphenated lines
3559 @cindex lines, consecutive hyphenated
3560 @cindex hyphenated lines, consecutive
3561 @Deffn{Request, hlm, [@var{nnn}]}
3562 Set the maximum number of consecutive hyphenated lines to @var{nnn}.  If
3563 this number is negative, there is no maximum.  The default is@w{ }-1 if
3564 @var{nnn} is omitted.  This value is associated with the current
3565 environment.  Only lines output from a given environment count towards
3566 the maximum associated with that environment.  Hyphens resulting from
3567 @code{\%} are counted; explicit hyphens are not.
3569 The current setting of @code{hlm} is available in the @code{.hlm}
3570 register.  Also the number of immediately preceding consecutive
3571 hyphenated lines are available in the number register @samp{.hlc}.
3572 @end_Deffn
3574 @Deffn{Request, hw, word}
3575 Define how @var{word} is to be hyphenated.  @var{word} must be given
3576 with hyphens at the hyphenation points.  For example:
3578 @example
3579 .hw in-sa-lub-rious
3580 @end example
3582 This request can be used more than once.
3584 In old versions of @code{troff} there was a limited amount of space to
3585 store such information; fortunately, with @code{gtroff}, this is no
3586 longer a restriction.
3587 @end_Deffn
3589 @cindex hyphenation character
3590 @cindex character, hyphenation
3591 @cindex disabling hyphenation
3592 @cindex hyphenation, disabling
3593 @Deffn{Escape, \\%, }
3594 To tell @code{gtroff} how to hyphenate words on the fly, the @code{\%}
3595 escape, also known as the @dfn{hyphenation character}, can be used.
3596 Preceding a word with this character will prevent it from being
3597 hyphenated, putting it in a word will indicate to @code{gtroff} that the
3598 word may be hyphenated at that point.  Note that this mechanism will
3599 only affect one word; to change the hyphenation of a word for the entire
3600 document, use the @code{hw} request.
3601 @end_Deffn
3603 @Deffn{Request, hc, [@var{char}]}
3604 Change the hyphenation character to @var{char}.  This character will
3605 then work the same as the @code{\%} escape, and, thus, no longer appear
3606 in the output.  Without an argument, @code{hc} will reset the
3607 hyphenation character to @code{\%} only.
3608 @end_Deffn
3610 @cindex hyphenation patterns
3611 @cindex pattern for hyphenation
3612 @Deffn{Request, hpf, pattern_file}
3613 Read in a file of hyphenation patterns.  This file will be searched for
3614 in the same way as @file{tmac.@var{name}} is searched for if the
3615 @option{-m@var{name}} option is specified.
3617 It should have the same format as the argument to the @code{\patterns}
3618 primitive in @TeX{} (without using @TeX{}'s macro expansion); the
3619 letters appearing in this file are interpreted as hyphenation codes.  A
3620 @samp{%} character in the patterns file introduces a comment that
3621 continues to the end of the line.
3623 If no @code{hpf} request is specified (either in the document or in a
3624 macro package), @code{gtroff} won't hyphenate at all.
3626 @findex hla
3627 @pindex troffrc
3628 @pindex troffrc-end
3629 @pindex hyphen.us
3630 The set of hyphenation patterns is associated with the current language
3631 set by the @code{hla} request.  The @code{hpf} request is usually
3632 invoked by the @file{troffrc} or @file{troffrc-end} file; by default,
3633 @file{troffrc} loads hyphenation patterns for American English (in file
3634 @file{hyphen.us}).
3635 @end_Deffn
3637 @cindex hyphenation code
3638 @cindex code, hyphenation
3639 @Deffn{Request, hcode, c1 code1 c2 code2 @dots{}}
3640 Sets the hyphenation code of character @var{c1} to @var{code1}, that of
3641 @var{c2} to @var{code2}, etc.  A hyphenation code must be a single input
3642 character (not a special character) other than a digit or a space.
3643 Initially each lower-case letter (@samp{a}-@samp{z})has a hyphenation
3644 code, which is itself, and each upper-case letter (@samp{A}-@samp{Z})
3645 has a hyphenation code which is the lower-case version of itself.
3646 @end_Deffn
3648 @cindex hyphenation margin
3649 @cindex margin for hyphenation
3650 @findex ad
3651 @Deffn{Request, hym, [@var{length}]}
3652 Set the (right) hyphenation margin to @var{length}.  If the current
3653 adjustment mode is not@w{ }@samp{b}, the line will not be hyphenated if
3654 it is shorter than @var{length}.  Without argument, the hyphenation
3655 margin will be reset to its default value, which is@w{ }0.  The default
3656 scaling indicator for this request is@w{ }m.  The hyphenation margin is
3657 associated with the current environment.
3659 @vindex .hym
3660 The current hyphenation margin is available in the @code{.hym} register.
3661 @end_Deffn
3663 @cindex hyphenation space
3664 @findex ad
3665 @Deffn{Request, hys, [@var{hyphenation_space}]}
3667 Set the hyphenation space to @var{hyphenation_space}.  If the current
3668 adjustment mode is@w{ }@samp{b}, don't hyphenate the line if the line
3669 can be justified by adding no more than @var{hyphenation_space} extra
3670 space to each word space.  Without argument, the hyphenation space is
3671 set to its default value, which is@w{ }0.  The default scaling indicator
3672 for this request is@w{ }m.  The hyphenation space is associated with the
3673 current environment.
3675 @vindex .hys
3676 The current hyphenation space is available in the @code{.hys} register.
3677 @end_Deffn
3679 @cindex soft hyphen character
3680 @cindex character, soft hyphen
3681 @glindex hy
3682 @findex char
3683 @findex tr
3684 @Deffn{Request, shc, [@var{char}]}
3685 Set the soft hyphen character to @var{char}.  If the argument is
3686 omitted, the soft hyphen character will be set to the default character
3687 @code{\(hy}.  The soft hyphen character is the character which will be
3688 inserted when a word is hyphenated at a line break.  If the soft hyphen
3689 character does not exist in the font of the character immediately
3690 preceding a potential break point, then the line will not be broken at
3691 that point.  Neither definitions (specified with the @code{char}
3692 request) nor translations (specified with the @code{tr} request) are
3693 considered when finding the soft hyphen character.
3694 @end_Deffn
3696 @findex hpf
3697 @findex hw
3698 @pindex troffrc
3699 @pindex troffrc-end
3700 @Deffn{Request, hla, language}
3701 Set the current hyphenation language to the string @var{language}.
3702 Hyphenation exceptions specified with the @code{hw} request and
3703 hyphenation patterns specified with the @code{hpf} request are both
3704 associated with the current hyphenation language.  The @code{hla}
3705 request is usually invoked by the @file{troffrc} or the
3706 @file{troffrc-end} files; by default, @file{troffrc} sets the default
3707 language to @samp{us}.
3709 @vindex .hla
3710 The current hyphenation language is available in the read-only register
3711 @samp{.hla}.
3712 @end_Deffn
3715 @node Manipulating Spacing, Tabs and Fields, Manipulating Hyphenation, Programming Tutorial
3716 @section Manipulating Spacing
3717 @cindex manipulating spacing
3718 @cindex spacing, manipulating
3720 @Deffn{Request, sp, [@var{distance}]}
3721 Space downwards @var{distance}.  With no argument it will advance 1@w{
3722 }line.  A negative argument will cause @code{gtroff} to move up the page
3723 the specified distance.  If the argument is preceded by a @samp{|}
3724 @code{gtroff} will move that distance from the top of the page.  This
3725 request causes a line break.
3726 @end_Deffn
3728 @cindex double-spacing
3729 @Deffn{Request, ls, [@var{nnn}]}
3730 Output @var{nnn}-1 blank lines after each line of text.  With no
3731 argument @code{gtroff} will go back to single spacing.  For example,
3732 @w{@samp{.ls 2}} causes double-spaced output.
3734 @vindex .L
3735 The number register @code{.L} contains the current line spacing setting.
3736 @end_Deffn
3738 @Deffn{Escape, \\x, spacing}
3739 Sometimes, extra vertical spacing is only needed occasionally, e.g.@: to
3740 allow space for a tall construct (like an equation).  The @code{\x}
3741 escape will do this.  The escape is given a numerical argument, usually
3742 enclosed in quotes (like @samp{\x'3p'}).  If this number is positive
3743 extra vertical space will be inserted below the current line.  A
3744 negative number will add space above.  If this escape is used multiple
3745 times on the same line, the maximum of the values is used.
3747 @vindex .a
3748 The @code{.a} number register contains the most recent (nonnegative)
3749 extra vertical line space.
3751 @c XXX
3752 @example
3753 ... example of inline equation ...
3754 @end example
3755 @end_Deffn
3757 @findex sp
3758 @cindex no-space mode
3759 @cindex mode, no-space
3760 @cindex blank lines
3761 @cindex lines, blank
3762 @Deffn{Request, ns, }
3763 Enable @dfn{no-space mode}.  In this mode, spacing (either via @code{sp}
3764 or via blank lines) is disabled.  The @code{bp} request to advance to
3765 the next page is also disabled, except if it is accompanied by a page
3766 number (@pxref{Page Control}, for more information).  This mode will end
3767 when actual text is output or the @code{rs} request is encountered.
3769 This request is useful for macros which want to avoid that subsequent
3770 macros inadvertently insert some vertical space before the text starts
3771 (for example, to set up the first paragraph after a section header).
3772 @end_Deffn
3774 @Deffn{Request, rs, }
3775 Disable no-space mode.
3776 @end_Deffn
3779 @node Tabs and Fields, Character Translations, Manipulating Spacing, Programming Tutorial
3780 @section Tabs and Fields
3781 @cindex tabs and fields
3782 @cindex fields and tabs
3784 A tab character (@acronym{ASCII} char@w{ }9) causes a horizontal
3785 movement to the next tab stop (which is much like that on a typewriter).
3787 @Deffn{Escape, \\t, }
3788 This escape is a non-interpreted tab character.  In copy mode
3789 (@pxref{Copy-in Mode}), @code{\t} is the same as a real tab character.
3790 @end_Deffn
3792 @Deffn{Request, ta, n1 n2 @dots{} nn @t{T} r1 r2 @dots{} rn}
3793 Change tab stop positions.  This request takes a series of tab
3794 specifiers as arguments (optionally divided into two groups with the
3795 letter @samp{T}) which indicate where each tab stop is to be (overriding
3796 any previous settings).
3798 Tab stops can be specified absolutely, i.e., as the distance from the
3799 left margin.  For example, the following will set 6@w{ }tab stops every
3800 one inch.
3802 @example
3803 .ta 1i 2i 3i 4i 5i 6i
3804 @end example
3806 Tab stops can also be specified relatively (using a leading @samp{+})
3807 which means that the specified tab stop will be set that distance from
3808 the previous tab stop.  For example, the following is equivalent to the
3809 previous example.
3811 @example
3812 .ta 1i +1i +1i +1i +1i +1i
3813 @end example
3815 @code{gtroff} supports an extended syntax to specify repeat values after
3816 the @samp{T} mark (these values are always taken as relative)---this is
3817 the usual way to specify tabs set at equal intervals.  The following is,
3818 yet again, the same as the previous examples.  It does even more since
3819 it defines an infinite number of tab stops separated by one inch.
3821 @example
3822 .ta T 1i
3823 @end example
3825 Now we are ready to interpret the full syntax given at the beginning:
3826 Set tabs at positions @var{n1}, @var{n2}, @dots{}, @var{nn} and then set
3827 tabs at @var{nn}+@var{r1}, @var{nn}+@var{r2}, @dots{}, @var{nn}+@var{rn}
3828 and then at @var{nn}+@var{rn}+@var{r1}, @var{nn}+@var{rn}+@var{r2},
3829 @dots{}, @var{nn}+@var{rn}+@var{rn}, and so on.
3831 Example: @samp{4c +6c T 3c 5c 2c} is equivalent to @samp{4c 10c 13c 18c
3832 20c 23c 28c 30c @dots{}}.
3834 The material in each tab column may be justified to the right or left or
3835 centered in the column.  This is specified by appending an @samp{R},
3836 @samp{L}, or @samp{C} to the tab specifier.  The default justification
3837 is @samp{L}.  Example:
3839 @example
3840 .ta 1i 2iC 2iR
3841 @end example
3843 Some notes:
3845 @itemize @bullet
3846 @item
3847 The default unit of the @code{ta} request is @samp{m}.
3849 @item
3850 A tab stop is converted into a non-breakable horizontal movement which
3851 can't be neither stretched nor squeezed.  For example,
3853 @example
3854 .de foo
3855 a\tb\tc
3857 .ta T 5i
3858 .foo
3859 @end example
3861 @noindent
3862 creates a single line which is a bit longer than 10@w{ }inches (a macro
3863 is used to show exactly where the tab characters are).  Now consider the
3864 following:
3866 @example
3867 .de bar
3868 a\tb b\tc
3870 .ta T 5i
3871 .bar
3872 @end example
3874 @noindent
3875 @code{gtroff} first converts the tab stops of the line into unbreakable
3876 horizontal movements, then splits the line after the second @samp{b}
3877 (assuming a sufficiently short line length).  Usually, this isn't what
3878 the user wants.
3880 @c XXX superfluous tab stops
3882 @end itemize
3884 @vindex .tabs
3885 The number register @code{.tabs} contains a string representation of the
3886 current tab settings suitable for use as an argument to the @code{ta}
3887 request.
3888 @end_Deffn
3890 @findex tc
3891 Normally @code{gtroff} will fill the space to the next tab stop with
3892 spaces.  This can be change with the @code{tc} request.  With no
3893 argument @code{gtroff} will revert to using spaces.
3895 @subsection Leaders
3896 @cindex leaders
3898 @findex lc
3899 Sometimes it may may be desirable to use the @code{tc} request to fill a
3900 particular tab stop with a given character, but also normal tab stops on
3901 the rest of the line.  For this @code{gtroff} provides an alternate tab
3902 mechanism, called @dfn{leaders} which will do just that.  They are used
3903 exclusively to produce a repeated run of characters to the next tab
3904 stop.
3906 The character that will be repeated can be declared with the @code{lc}
3907 request.  Without an argument, the leaders will act the same as tabs.
3909 @findex \a
3910 Leader are invoked by using the @code{\a} escape while specifying the
3911 @code{ta} request.
3913 @cindex table of contents
3914 @cindex contents, table of
3915 For a table of contents, to name an example, tab stops may be defined so
3916 that the section number is one tab stop, the title is the second with
3917 the remaining space being filled with a line of dots, and then the page
3918 number slightly separated from the dots.
3920 @example
3921 .lc .
3922 .ta .5iR 5i +.25i
3923 1.1\tFoo\a\t12
3924 @end example
3926 @subsection Fields
3927 @cindex fields
3929 @findex fc
3930 Fields are a more general way of laying out tabular data.
3932 @code{fc}
3934 @c XXX add explanation
3936 @node Character Translations, Line Layout, Tabs and Fields, Programming Tutorial
3937 @section Character Translations
3938 @cindex character translations
3939 @cindex translations of characters
3941 @findex cc
3942 @findex c2
3943 @findex .
3944 @findex '
3945 The control character (@samp{.}) and the no-break control character
3946 (@samp{'}) can be changed with the @code{cc} and @code{c2} requests,
3947 respectively.  The single argument is the new character to be used.
3948 With no argument the normal control character is restored.
3950 @findex ec
3951 @findex eo
3952 The @code{eo} request will completely disable the escape mechanism.  The
3953 @code{ec} request can be used to change the escape character from the
3954 default @samp{\} to what is specified as an argument.  It can be also
3955 used to re-enable the escape mechanism after an @code{eo} request.
3957 @findex tr
3958 The @code{tr} request will translate characters.
3960 @c XXX more info
3962 @findex trnt
3963 @findex \!
3964 @code{trnt} is the same as the @code{tr} request except that the
3965 translations do not apply to text that is transparently throughput into
3966 a diversion with @code{\!}.  @xref{Diversions}, for more information.
3967 For example,
3969 @example
3970 .tr ab
3971 .di x
3972 \!.tm a
3975 @end example
3977 @noindent
3978 will print @samp{b}; if @code{trnt} is used instead of @code{tr} it will
3979 print @samp{a}.
3982 @node Line Layout, Page Layout, Character Translations, Programming Tutorial
3983 @section Line Layout
3984 @cindex line layout
3985 @cindex layout, line
3987 @cindex dimensions, line
3988 @cindex line dimensions
3989 The following drawing shows the dimensions which @code{gtroff} uses for
3990 placing a line of output onto the page.  They are labeled with the
3991 request which manipulates that dimension.
3993 @example
3994 @group
3995               | -->| in |<--                   |
3996            -->| po |<-----------ll------------>|
3997               +----+----+----------------------+----+
3998               |    :    :                      :    |
3999               +----+----+----------------------+----+
4000 @end group
4001 @end example
4003 @noindent
4004 These dimensions are:
4006 @ftable @code
4007 @item po
4008 @cindex left margin
4009 @cindex margin, left
4010 @cindex page offset
4011 @cindex offset, page
4012 @vindex .o
4013 @dfn{Page offset}--This is the leftmost position of text on the final
4014 output, defining the @dfn{left margin}.  It can be adjusted with the
4015 @code{po} request, and the current setting can be found in the built-in
4016 number register @code{.o}.  Note that this request does not cause a
4017 break, so changing the page offset in the middle of text being filled
4018 may not yield the expected result.
4019 @item in
4020 @cindex indentation
4021 @cindex line indentation
4022 @findex in
4023 @vindex .i
4024 @dfn{Indentation}--This is the distance from the left margin where text
4025 will be printed.  This can be adjusted with the @code{in} request, and
4026 the current setting can be found in the built-in number register.
4027 @code{.i}.  This request causes a break.
4029 @findex ti
4030 @vindex .in
4031 There is also the request @code{ti} which will cause one output line to
4032 be indented, after which the indentation returns to@w{ }0.  This request
4033 causes a break.  The number register @code{.in} is the indent that
4034 applies to the current output line.
4035 @item ll
4036 @cindex line length
4037 @cindex length of line
4038 @vindex .l
4039 @vindex .ll
4040 @dfn{Line length}--This is the distance from the left margin to right
4041 margin.  This can be adjusted with the @code{ll} request, and the
4042 current setting can be found in the built-in number register @code{.l}
4043 Note, as the figure implies, line length is not affected by the current
4044 indentation.  The number register @code{.ll} is the line length that
4045 applies to the current output line.
4046 @end ftable
4048 @example
4049 .in +.5i
4050 .ll -.5i
4051 A bunch of really boring text which should
4052 be indented from both margins.
4053 Replace me with a better (and more) example!
4054 .in -.5i
4055 .ll +.5i
4056 @end example
4059 @node Page Layout, Page Control, Line Layout, Programming Tutorial
4060 @section Page Layout
4061 @cindex page layout
4062 @cindex layout, page
4064 @code{gtroff} provides some very primitive operations for controlling
4065 page layout.
4067 @cindex page length
4068 @cindex length of page
4069 @findex pl
4070 @vindex .p
4071 The @dfn{page length} can be specified via the @code{pl} request.  This
4072 is the length of the physical output page.  The current setting can be
4073 found in the built-in number register @code{.p}.  Note that this only
4074 specifies the size of the page, not the top and bottom margins.  Those
4075 are not done by groff directly.  @xref{Traps}, for further information
4076 on how to do this.
4078 @cindex headers
4079 @cindex footers
4080 @cindex titles
4081 @code{gtroff} provides several operations which help in setting up top
4082 and bottom titles (or headers and footers)
4084 @cindex title line
4085 @cindex three-part title
4086 @findex tl
4087 @vindex %
4088 The @code{tl} request will print a @dfn{title line}, which consists of
4089 three parts: a left justified portion, a centered portion and a right
4090 justified portion.  The argument to @code{tl} is specified as
4091 @code{'@var{left}'@var{center}'@var{right}'}.  The @samp{%} character is
4092 replaced with the current page number.  This character can be changed
4093 with the @code{pc} request (see below).
4095 @cindex length of title line
4096 @cindex title line, length
4097 @findex lt
4098 @vindex .lt
4099 The title line is printed using its own line length, which is specified
4100 with the @code{lt} request.  The current setting of this is available in
4101 the @code{.lt} number register.
4103 @cindex page number
4104 @cindex number, page
4105 @findex pn
4106 The @code{pn} request will change the page number of the @emph{next}
4107 page.  The only argument is the page number.
4109 @vindex %
4110 @vindex .pn
4111 The current page number is stored in the number register @code{%}.  The
4112 number register @code{.pn} contains the number of the next page: either
4113 the value set by a @code{pn} request, or the number of the current page
4114 plus@w{ }1.
4116 @cindex changing the page number character
4117 @cindex page number character, changing
4118 @findex pc
4119 The @code{pc} request will change the page number character (used by the
4120 @code{tl} request) to a different character.  With no argument, this
4121 mechanism is disabled.
4123 @xref{Traps}.
4126 @node Page Control, Fonts, Page Layout, Programming Tutorial
4127 @section Page Control
4128 @cindex page control
4129 @cindex control, page
4131 @findex bp
4132 @findex pn
4133 To stop processing the current page, and move to the next page, invoke
4134 the @code{bp} request.  This request will also cause a break.  It can
4135 also take an argument of what the next page should be numbered.  The
4136 only difference between @code{bp} and @code{pn} is that @code{pn} does
4137 not cause a break or actually eject a page.
4139 @example
4140 .de newpage
4142 'sp .5i
4143 .tl 'left top'center top'right top'
4144 'sp .3i
4146 @end example
4148 @cindex orphan
4149 @findex ne
4150 It is often necessary to force a certain amount of space before a new
4151 page occurs.  This is most useful to make sure that there is not a
4152 single @dfn{orphan} line left at the bottom of a page.  The @code{ne}
4153 request will ensure that there is a certain distance, specified by the
4154 first argument, before the next page is triggered (@pxref{Traps}, for
4155 further information).  The default unit for @code{ne} is @code{v} and
4156 the default argument is@w{ }1@dmn{v}.
4158 For example, to make sure that no fewer than 2@w{ }lines get orphaned,
4159 do the following before each paragraph:
4161 @example
4162 .ne 2
4163 .ti +5n
4164 text
4165 @end example
4167 @findex sv
4168 @findex os
4169 @findex ne
4170 @code{sv} is similar to the @code{ne} request; it reserves the specified
4171 amount of vertical space.  If the desired amount of space exists before
4172 the next trap (bottom page boundary), the space will be output
4173 immediately.  If there is not enough space, it is stored for later
4174 output via the @code{os} request.  The default argument is@w{ }1@dmn{v}
4175 and the default unit is @code{v}.
4178 @node Fonts, Sizes, Page Control, Programming Tutorial
4179 @section Fonts
4180 @cindex fonts
4182 @findex ft
4183 @findex \f
4184 @code{gtroff} has the ability to switch fonts at any point in the text.
4185 There are two ways to do this, via the @code{ft} request and the
4186 @code{\f} escape.
4188 Fonts are generally specified as upper-case strings, which are usually
4189 1@w{ }to 4 characters representing an abbreviation or acronym of the font
4190 name.
4192 The basic set of fonts are @samp{R}, @samp{I}, @samp{B}, and @samp{BI}.
4193 These are Times Roman, Italic, Bold, and Bold Italic.  There is also at
4194 least one symbol font which contains various special symbols (Greek,
4195 mathematics).  Such symbols fonts cannot be used directly, but should be
4196 used via an escape.
4198 @menu
4199 * Changing Fonts::              
4200 * Font Families::               
4201 * Font Positions::              
4202 * Using Symbols::               
4203 * Artificial Fonts::            
4204 * Ligatures and Kerning::       
4205 @end menu
4207 @node Changing Fonts, Font Families, Fonts, Fonts
4208 @subsection Changing Fonts
4209 @cindex changing fonts
4210 @cindex fonts, changing
4212 @findex ft
4213 @cindex previous font
4214 @cindex font, previous
4215 Font changes can be done either with the @code{ft} request or the
4216 @code{\f} request.  With no arguments it will switch to the previous
4217 font (also known as @samp{P}).
4219 @example
4220 eggs, bacon,
4221 .ft B
4222 spam
4224 and sausage.
4225 @end example
4227 @findex \f
4228 The @code{\f} escape is useful for changing fonts in the middle of
4229 words:
4231 @example
4232 eggs, bacon, \fBspam\fP and sausage.
4233 @end example
4235 @noindent
4236 Both of the above examples will produce the same output.  Note the usage
4237 of @samp{P} to indicate the previous font---using @code{\f} it is not
4238 possible to omit this parameter.
4240 Sometimes when putting letters of different fonts, more or less space at
4241 such boundaries are needed.  There are two escapes to help with this.
4243 @findex \/
4244 @cindex italic correction
4245 @cindex correction, italic
4246 The @code{\/} escape increases the width of the preceding character so
4247 that the spacing between that character and the following character will
4248 be correct if the following character is a Roman character.  For
4249 example, if an italic@w{ }f is immediately followed by a Roman right
4250 parenthesis, then in many fonts the top right portion of the f will
4251 overlap the top left of the right parenthesis.  It is a good idea to use
4252 this escape sequence whenever an italic character is immediately
4253 followed by a Roman character without any intervening space.  This small
4254 amount of space is also called @dfn{italic correction}.
4256 @c XXX example
4257 @c producing @i{f}), which is ugly.  Inserting \/ produces f) and avoids
4258 @c this problem.
4260 @findex \,
4261 @cindex left italic correction
4262 @cindex correction, left italic
4263 The @code{\,} escape modifies the spacing of the following character so
4264 that the spacing between that character and the preceding character will
4265 be correct if the preceding character is a Roman character.  It is a
4266 good idea to use this escape sequence whenever a Roman character is
4267 immediately followed by an italic character without any intervening
4268 space.  In analogy to above, this space could be called @dfn{left italic
4269 correction}, but this term isn't used widely.
4271 @c XXX example
4272 @c For example, inserting \, between the parenthesis and the f changes
4273 @c (f to (f.
4275 @findex ftr
4276 @findex ft
4277 @findex ul
4278 @findex bd
4279 @findex \f
4280 @findex cs
4281 @findex tkf
4282 @findex special
4283 @findex fspecial
4284 @findex fp
4285 @findex code
4286 The @code{ftr} request will translate fonts; its syntax is
4288 @example
4289 .ftr @var{F} @var{G}
4290 @end example
4292 @noindent
4293 which translates font@w{ }@var{F} to font@w{ }@var{G}.  Whenever a font
4294 named @var{F} is referred to in a @code{\f} escape sequence, or in the
4295 @code{ft}, @code{ul}, @code{bd}, @code{cs}, @code{tkf}, @code{special},
4296 @code{fspecial}, @code{fp}, or @code{code} requests, font@w{ }@var{G} will
4297 be used.  If @var{G} is missing, or equal to @var{F} then font@w{
4298 }@var{F} will not be translated.
4300 @node Font Families, Font Positions, Changing Fonts, Fonts
4301 @subsection Font Families
4302 @cindex font families
4303 @cindex families, font
4305 Due to the variety of fonts available, @code{gtroff} has added the
4306 concept of font families.  Each of these families has four styles
4307 (@samp{R}, @samp{I}, @samp{B} and @samp{BI}).
4309 The fonts are specified as the concatenation of the font family and
4310 style.  Specifying a font without the family part will cause
4311 @code{gtroff} to use that style of the current family.  By default,
4312 @code{gtroff} uses the Times family.
4314 This way, it is possible to use the basic four fonts and to select a
4315 different font family on the command line.
4317 @findex fam
4318 @vindex .fam
4319 Font families can be switched with the @code{fam} request.  The current
4320 font family is available in the number register @code{.fam}.  This is a
4321 string-valued register.
4323 @example
4324 spam,
4325 .fam H
4326 spam,
4327 .ft B
4328 spam,
4329 .fam T
4330 spam,
4331 .ft AR
4332 baked beans,
4333 .ft R
4334 and spam.
4335 @end example
4337 @node Font Positions, Using Symbols, Font Families, Fonts
4338 @subsection Font Positions
4339 @cindex font positions
4340 @cindex positions, font
4342 For the sake of old phototypesetters and compatability with old versions
4343 of @code{troff}, @code{gtroff} has the concept of font @dfn{positions},
4344 on which various fonts are mounted.  The last one or two are reserved
4345 for the symbol font(s).
4347 @findex fp
4348 New fonts can be mounted with the @code{fp} request.  These numeric
4349 positions can then be referred to with font changing commands.  When
4350 @code{gtroff} starts it is using font number one.
4352 @example
4353 .fp 1 H
4354 .fp 2 HI
4355 .fp 3 HB
4356 wink, wink,
4357 .ft 2
4358 nudge, nudge,
4360 .ft 3
4361 say no more!
4363 @end example
4365 @noindent
4366 Note that after these font changes have taken place the original font
4367 is restored.
4369 @vindex .f
4370 The current font in use, as a font position, is available in number
4371 register @code{.f}.  This can be useful to remember the current font,
4372 for later recall.
4374 @example
4375 .nr save-font \n(.f
4376 ... lots 'o text ...
4377 .ft \n[save-font]
4378 @end example
4380 @vindex .fp
4381 The number of the next free font position is available in the number
4382 register @code{.fp}.  This is useful when mounting a new font, like so:
4384 @example
4385 .fp \n[.fp] NEATOFONT
4386 @end example
4388 @pindex DESC
4389 Fonts not listed in the @file{DESC} file are automatically mounted on
4390 the next available font position when they are referenced.  If a font is
4391 to be mounted explicitly with the @code{fp} request on an unused font
4392 position, it should be mounted on the first unused font position, which
4393 can be found in the @code{.fp} register.  Although @code{gtroff} does
4394 not enforce this strictly, it will not allow a font to be mounted at a
4395 position whose number is much greater than that of any currently used
4396 position.
4398 @findex fp
4399 The @code{fp} request has an optional third argument.  This argument
4400 gives the external name of the font, which is used for finding the font
4401 description file.  The second argument gives the internal name of the
4402 font which is used to refer to the font in @code{gtroff} after it has
4403 been mounted.  If there is no third argument then the internal name will
4404 be used as the external name.  This feature make it possible to use
4405 fonts with long names in compatibility mode.
4407 @node Using Symbols, Artificial Fonts, Font Positions, Fonts
4408 @subsection Using Symbols
4409 @cindex using symbols
4410 @cindex symbols, using
4412 @findex \(
4413 @findex \[
4414 Symbols can be inserted by using a special escape sequence.  This escape
4415 is simply the escape character (usually a backslash) followed by an
4416 identifier.  The symbol identifiers have to be two or more characters,
4417 since single characters conflict with all the other escapes.  The
4418 identifier can be either preceded by a parenthesis if it is two
4419 characters long, or surrounded by square brackets.  So, the symbol for
4420 the mathematical Greek letter `pi' can be produced either by @code{\(*p}
4421 or @code{\[*p]}.
4423 @example
4424 area = \(*p\fIr\fP\u2\d
4425 @end example
4427 @findex \C
4428 The escape @code{\C'@var{xxx}'} will typeset the character named
4429 @var{xxx}.  Normally it is more convenient to use @code{\[@var{xxx}]}.
4430 But @code{\C} has the advantage that it is compatible with recent
4431 versions of @code{ditroff} and is available in compatibility mode.
4433 @findex \N
4434 @findex char
4435 The escape @code{\N'@var{n}'} will typeset the character with code@w{
4436 }@var{n} in the current font.  @var{n} can be any integer.  Most devices
4437 only have characters with codes between 0 and@w{ }255.  If the current
4438 font does not contain a character with that code, special fonts will
4439 @emph{not} be searched.  The @code{\N} escape sequence can be
4440 conveniently used on conjunction with the @code{char} request:
4442 @example
4443 .char \[phone] \f(ZD\N'37'
4444 @end example
4446 @noindent
4447 @pindex DESC
4448 @cindex unnamed characters
4449 @cindex characters, unnamed
4450 The code of each character is given in the fourth column in the font
4451 description file after the charset command.  It is possible to include
4452 unnamed characters in the font description file by using a name of
4453 @samp{---}; the @code{\N} escape sequence is the only way to use these.
4455 @c XXX should be `glyph', not `character'
4457 @findex cflags
4458 @cindex character properties
4459 @cindex properties of characters
4460 Each character has certain properties associated with it.  These
4461 properties can be modified with the @code{cflags} request.  The first
4462 argument is the the sum of the desired flags and the remaining arguments
4463 are the characters to have those properties.
4465 @table @code
4466 @item 1
4467 @cindex end of sentence characters
4468 @cindex characters, end of sentence
4469 the character ends sentences (initially characters @samp{.?!} have this
4470 property)
4471 @item 2
4472 @cindex hyphenating characters
4473 @cindex characters, hyphenation
4474 lines can be broken before the character (initially no characters have
4475 this property)
4476 @item 4
4477 @glindex hy
4478 @glindex em
4479 lines can be broken after the character (initially the characters
4480 @samp{-\(hy\(em} have this property)
4481 @item 8
4482 @cindex overlapping characters
4483 @cindex characters, overlapping
4484 @glindex ul
4485 @glindex rn
4486 @glindex ru
4487 the character overlaps horizontally (initially the characters
4488 @samp{\(ul\(rn\(ru} have this property)
4489 @item 16
4490 @glindex br
4491 the character overlaps vertically (initially character @samp{\(br} has
4492 this property)
4493 @item 32
4494 @cindex transparent characters
4495 @cindex character, transparent
4496 @cindex '
4497 @cindex "
4498 @cindex ]
4499 @cindex )
4500 @cindex *
4501 @glindex dg
4502 @glindex rq
4503 an end of sentence character followed by any number of characters with
4504 this property will be treated as the end of a sentence if followed by a
4505 newline or two spaces; in other words the character is @dfn{transparent}
4506 for the purposes of end of sentence recognition---this is the same as
4507 having a zero space factor in @TeX{} (initially characters
4508 @samp{"')]*\(dg\(rq} have this property).
4509 @end table
4511 @findex char
4512 @cindex defining characters
4513 @cindex characters, defining
4514 New characters can be created with the @code{char} request.  It is
4515 called as
4517 @example
4518 .char @var{c} @var{string}
4519 @end example
4521 @findex tr
4522 @findex lc
4523 @findex \l
4524 @findex \L
4525 @findex hcode
4526 @noindent
4527 This defines character@w{ }@var{c} to be @var{string}.  Every time
4528 character@w{ }@var{c} needs to be printed, @var{string} will be
4529 processed in a temporary environment and the result will be wrapped up
4530 into a single object.  Compatibility mode will be turned off and the
4531 escape character will be set to @samp{\} while @var{string} is being
4532 processed.  Any emboldening, constant spacing or track kerning will be
4533 applied to this object rather than to individual characters in
4534 @var{string}.  A character defined by this request can be used just like
4535 a normal character provided by the output device.  In particular other
4536 characters can be translated to it with the @code{tr} request; it can be
4537 made the leader character by the @code{lc} request; repeated patterns
4538 can be drawn with the character using the @code{\l} and @code{\L} escape
4539 sequences; words containing the character can be hyphenated correctly,
4540 if the @code{hcode} request is used to give the character a hyphenation
4541 code.  There is a special anti-recursion feature: use of character
4542 within the character's definition will be handled like normal characters
4543 not defined with @code{char}.
4545 @findex rchar
4546 @cindex removing character definition
4547 @cindex character, removing definition
4548 A character definition can be removed with the @code{rchar} request.
4549 Its arguments are the characters to be removed.  This undoes the effect
4550 of a @code{char} request.
4552 @xref{Special Characters}.
4554 @node Artificial Fonts, Ligatures and Kerning, Using Symbols, Fonts
4555 @subsection Artificial Fonts
4556 @cindex artificial fonts
4557 @cindex fonts, artificial
4559 There are a number of requests for artificially creating fonts.  These
4560 are largely vestigial remains from the days when output devices did not
4561 have a wide variety of fonts, and when @code{nroff} and @code{troff}
4562 were separate programs.  These are no longer necessary in GNU
4563 @code{troff}.
4565 @findex ul
4566 @cindex underlining
4567 The @code{ul} request will print subsequent lines in italics on a device
4568 capable of it, or underline the text on an character output device.  The
4569 single argument is the number of lines to be ``underlined,'' with no
4570 argument, the next line will be underlined.
4572 @findex cu
4573 @cindex continuous underlining
4574 @cindex underlining, continuous
4575 The @code{cu} request is similar to @code{ul} ...
4577 @c XXX more info
4579 @findex uf
4580 @cindex underline font
4581 @cindex font for underlining
4582 The @code{uf} request will set the underline font used by @code{ul} and
4583 @code{cu}.
4585 @findex bd
4586 @cindex imitating bold face
4587 @cindex bold face, imitating
4588 The @code{bd} request artificially creates a bold font by printing each
4589 character twice, slightly offset.  The first argument specifies the font
4590 to embolden, and the second is the number of basic units, minus one, by
4591 which the two characters will be offset.  If the second argument is
4592 missing, emboldening will be turned off.
4594 @node Ligatures and Kerning,  , Artificial Fonts, Fonts
4595 @subsection Ligatures and Kerning
4596 @cindex ligatures and kerning
4597 @cindex kerning and ligatures
4599 What are ligatures?
4601 @c XXX more info
4603 @findex lg
4604 @vindex .lg
4605 The ligature mechanism can be switched on or off with the @code{lg}
4606 request; if the parameter is non-zero or missing, ligatures are enabled,
4607 otherwise disabled.  Default is on.  The current ligature mode can be
4608 found in the number register @code{.lg} (set to@w{ }1 if ligatures are
4609 enabled, 0@w{ }otherwise).
4611 What is kerning?
4613 @c XXX more info
4615 @cindex zero width space character
4616 @cindex character, zero width space
4617 @cindex space character, zero width
4618 If the font description file contains pairwise kerning information,
4619 characters from that font will be kerned.  Kerning between two
4620 characters can be inhibited by placing @code{\&} between them.
4622 @findex kern
4623 @vindex .kern
4624 Kerning can be activated with the @code{kern} request.  If the parameter
4625 is non-zero or missing, enable pairwise kerning, otherwise disable it.
4626 The number register @code{.kern} is set to@w{ }1 if pairwise kerning is
4627 enabled, 0@w{ }otherwise.
4629 @findex tkf
4630 @cindex track kerning
4631 @cindex kerning, track
4632 What is track kerning?
4634 @c XXX more info
4636 Track kerning must be used with great care since it is usually
4637 considered bad typography if the reader notices the effect.  The syntax
4638 of the @code{tkf} request is
4640 @example
4641 .tkf @var{f} @var{s1} @var{n1} @var{s2} @var{n2}
4642 @end example
4644 @noindent
4645 Enable track kerning for font@w{ }@var{f}.  If the current font is@w{
4646 }@var{f} the width of every character will be increased by an amount
4647 between @var{n1} and @var{n2}; if the current point size is less than or
4648 equal to @var{s1} the width will be increased by @var{n1}; if it is
4649 greater than or equal to @var{s2} the width will be increased by
4650 @var{n2}; if the point size is greater than or equal to @var{s1} and
4651 less than or equal to @var{s2} the increase in width is a linear
4652 function of the point size.
4655 @node Sizes, Strings, Fonts, Programming Tutorial
4656 @section Sizes
4657 @cindex sizes
4659 @cindex baseline
4660 @cindex type size
4661 @cindex size of type
4662 @cindex vertical spacing
4663 @cindex spacing, vertical
4664 @code{gtroff} uses two dimensions with each line of text, type size and
4665 vertical spacing.  The @dfn{type size} is the height from the text
4666 @dfn{baseline} to the top of the tallest character (descenders may drop
4667 below this baseline).  @dfn{Vertical spacing} is the amount of space
4668 @code{gtroff} allows for a line of text; normally, this is about 20%@w{
4669 }larger than the current type size.  Ratios smaller than this can result
4670 in hard-to-read text; larger that this, it will spread the text out more
4671 vertically (useful for term papers).  By default, @code{gtroff} uses
4672 10@w{ }point type on 12@w{ }point spacing.
4674 @cindex leading
4675 The difference between type size and vertical spacing is known, by
4676 typesetters, as @dfn{leading}.
4678 @menu
4679 * Changing Type Sizes::         
4680 * Fractional Type Sizes::       
4681 @end menu
4683 @node Changing Type Sizes, Fractional Type Sizes, Sizes, Sizes
4684 @subsection Changing Type Sizes
4685 @cindex changing type sizes
4686 @cindex type sizes, changing
4688 @findex ps
4689 @findex vs
4690 @findex \s
4691 @vindex .s
4692 @vindex .v
4693 Using the @code{ps} request and the @code{\s} escape the type size can
4694 be changed.  The @code{vs} request will change the vertical spacing.
4695 The default unit for the @code{ps} and @code{vs} requests are points.
4696 The number registers @code{.s} and @code{.v} contain the current type
4697 size and vertical spacing.
4699 These requests take parameters in units of points.  It is possible to
4700 specify sizes as an absolute size, or as a relative change from the
4701 current size.  The size@w{ }0 means go back to the previous size.  With
4702 no argument it will also revert to the previous size.
4704 @example
4705 snap, snap,
4706 .ps +2
4707 grin, grin,
4708 .ps +2
4709 wink, wink, \s+2nudge, nudge,\s+8 say no more!
4710 .ps 10
4711 @end example
4713 The @code{\s} escape may be called in a variety of ways.  Much like
4714 other escapes there must be a way to determine where the argument ends
4715 and the text begins.  Any of the following forms are valid:
4717 @table @code
4718 @item \s@var{n}
4719 Set the point size to @var{n}@w{ }points.  @var{n}@w{ }must be either 0
4720 or in the range 4 to@w{ }39.
4721 @itemx \s+@var{n}
4722 @itemx \s-@var{n}
4723 Increase resp.@: decrease the point size by @var{n}@w{ }points.
4724 @var{n}@w{ }must be exactly one digit.
4725 @item \s(@var{nn}
4726 Set the point size to @var{nn}@w{ }points.  @var{nn} must be exactly two
4727 digits.
4728 @item \s+(@var{nn}
4729 @itemx \s-(@var{nn}
4730 @itemx \s(+@var{nn}
4731 @itemx \s(-@var{nn}
4732 Increase resp.@: decrease the point size by @var{nn}@w{ }points.
4733 @var{nn} must be exactly two digits.
4734 @end table
4736 @xref{Fractional Type Sizes}, for yet another syntactical form of using
4737 the @code{\s} escape.
4739 Some devices may only have certain permissible sizes, in which case
4740 @code{gtroff} will round to the nearest permissible size.
4742 @c XXX example
4744 @example
4745 ... .sz macro example?? ...
4746 @end example
4748 @node Fractional Type Sizes,  , Changing Type Sizes, Sizes
4749 @subsection Fractional Type Sizes
4750 @cindex fractional type sizes
4751 @cindex type sizes, fractional
4753 @cindex @code{s} unit
4754 @cindex unit, @code{s}
4755 @cindex @code{z} unit
4756 @cindex unit, @code{z}
4757 @findex ps
4758 @findex cs
4759 @findex tkf
4760 @findex \H
4761 @findex \s
4762 A @dfn{scaled point} is equal to 1/@var{sizescale} points, where
4763 @var{sizescale} is specified in the @file{DESC} file (1@w{ }by default.)
4764 There is a new scale indicator @samp{z} which has the effect of
4765 multiplying by @var{sizescale}.  Requests and escape sequences in
4766 @code{gtroff} interpret arguments that represent a point size as being in
4767 units of scaled points, but they evaluate each such argument using a
4768 default scale indicator of @samp{z}.  Arguments treated in this way are
4769 the argument to the @code{ps} request, the third argument to the
4770 @code{cs} request, the second and fourth arguments to the @code{tkf}
4771 request, the argument to the @code{\H} escape sequence, and those
4772 variants of the @code{\s} escape sequence that take a numeric expression
4773 as their argument (see below).
4775 For example, suppose @var{sizescale} is@w{ }1000; then a scaled point
4776 will be equivalent to a millipoint; the request @w{@samp{.ps 10.25}} is
4777 equivalent to @w{@samp{.ps 10.25z}} and thus sets the point size to 10250
4778 scaled points, which is equal to 10.25@w{ }points.
4780 It would make no sense to use the @samp{z} scale indicator in a numeric
4781 expression whose default scale indicator was neither @samp{u} nor
4782 @samp{z}, and so @code{gtroff} disallows this.  Similarly it would make
4783 no sense to use a scaling indicator other than @samp{z} or @samp{u} in a
4784 numeric expression whose default scale indicator was @samp{z}, and so
4785 @code{gtroff} disallows this as well.
4787 There is also new scale indicator @samp{s} which multiplies by the
4788 number of units in a scaled point.  So, for example, @samp{\n[.ps]s} is
4789 equal to @samp{1m}.  Be sure not to confuse the @samp{s} and @samp{z}
4790 scale indicators.
4792 @vindex .s
4793 @vindex .ps
4794 The number register @code{.s} returns the point size in points as decimal
4795 fraction.  There is also a new number register @code{.ps} that returns
4796 the point size in scaled points.
4798 @vindex .psr
4799 @vindex .sr
4800 The last-requested point size in scaled points is contained in the
4801 @code{.psr} number register.  The last requested point size in points as
4802 a decimal fraction can be found in @code{.psr}.  This is a string-valued
4803 register.
4805 @table @code
4806 @item \s[@var{n}]
4807 @itemx \s'@var{n}'
4808 Set the point size to @var{n} scaled points; @var{n}@w{ }is a numeric
4809 expression with a default scale indicator of @samp{z}.
4810 @item \s[+@var{n}]
4811 @itemx \s[-@var{n}]
4812 @itemx \s+[@var{n}]
4813 @itemx \s-[@var{n}]
4814 @itemx \s'+@var{n}'
4815 @itemx \s'-@var{n}'
4816 @itemx \s+'@var{n}'
4817 @itemx \s-'@var{n}'
4818 Increases resp.@: decreases the point size by @var{n} scaled points;
4819 @var{n} is a numeric expression with a default scale indicator of
4820 @samp{z}.
4821 @end table
4823 @xref{Font Files}.
4826 @node Strings, Conditionals and Loops, Sizes, Programming Tutorial
4827 @section Strings
4828 @cindex strings
4830 @findex ds
4831 @code{gtroff} has string variables, which are entirely for user
4832 convenience (i.e.@: there are no built-in strings).  They are defined
4833 via the @code{ds} request.
4835 @example
4836 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d
4837 @end example
4839 @findex \*
4840 @cindex string interpolation
4841 @cindex string expansion
4842 @cindex interpolation of strings
4843 @cindex expansion of strings
4844 They are interpolated, or expanded in-place, via the @code{\*} escape:
4846 @example
4847 The \*(UX Operating System
4848 @end example
4850 If the string named by the @code{\*} does not exist, the escape will be
4851 replaced by nothing.
4853 @cindex comments, with @code{ds}
4854 @strong{Caution:} Unlike other requests, the second argument to the
4855 @code{ds} request takes up the entire line including trailing spaces.
4856 This means that comments on a line with such a request can introduce
4857 unwanted space into a string.
4859 @example
4860 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d \" UNIX trademark
4861 @end example
4863 @noindent
4864 Instead the comment should be put on another line or have the comment
4865 escape adjacent with the end of the string.
4867 @example
4868 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d\"  UNIX trademark
4869 @end example
4871 @cindex trailing quotes
4872 @cindex quotes, trailing
4873 @cindex leading spaces with @code{ds}
4874 @cindex spaces with @code{ds}
4875 To produce leading space the string can be started with a double quote.
4876 No trailing quote is needed; in fact, any trailing quote is included in
4877 your string.
4879 @example
4880 .ds sign "           Yours in a white wine sauce,
4881 @end example
4883 @findex as
4884 @cindex appending to strings
4885 @cindex strings, appending
4886 The @code{as} request will append a string to another string.  It works
4887 similar to the @code{ds} request except that it appends the second
4888 argument onto the string named by the first argument.
4890 @example
4891 .as sign " with shallots, onions and garlic,
4892 @end example
4894 @findex \@key{RET}
4895 @cindex multi-line strings
4896 @cindex strings, multi-line
4897 @cindex newline character, escaping
4898 @cindex escaping newline characters
4899 Strings are not limited to a single line of text.  A string can span
4900 several lines by escaping the newlines with a backslash.  The resulting
4901 string will be stored @emph{without} the newlines.
4903 @example
4904 .ds foo lots and lots \
4905 of text are on these \
4906 next several lines
4907 @end example
4909 @findex substring
4910 @cindex substrings
4911 Rudimentary string manipulation routines are given with the
4912 @code{substring} and @code{length} requests.  The former has the
4913 following syntax:
4915 @example
4916 .substring @var{xx} @var{n1} [@var{n2}]
4917 @end example
4919 @noindent
4920 It replaces the string in register@w{ }@var{xx} with the substring
4921 defined by the indices @var{n1} and@w{ }@var{n2}.  The first character
4922 in the string has index one.  If @var{n2} is omitted, it is taken to be
4923 equal to the string's length.  If the index value @var{n1} or @var{n2}
4924 is negative or zero, it will be counted from the end of the string,
4925 going backwards: The last character has index@w{ }0, the character
4926 before the last character has index@w{ }-1, etc.
4928 @findex length
4929 @cindex length of a string
4930 @cindex string, length of
4931 Here the syntax of the @code{length} request:
4933 @example
4934 .length @var{xx} @var{string}
4935 @end example
4937 @noindent
4938 It computes the length of @var{string} and returns it in the number
4939 register@w{ }@var{xx} (which is not necessarily defined before).
4941 @findex rn
4942 @code{rn}
4944 @c XXX
4946 @findex rm
4947 @code{rm}
4949 @c XXX
4951 @findex als
4952 @code{als}
4954 @c XXX
4956 @findex chop
4957 @code{chop}
4959 @c XXX
4961 @xref{Identifiers}, and @ref{Comments}.
4964 @node Conditionals and Loops, Writing Macros, Strings, Programming Tutorial
4965 @section Conditionals and Loops
4966 @cindex conditionals and loops
4967 @cindex loops and conditionals
4969 @findex if
4970 @findex while
4971 In @code{if} and @code{while} requests, there are several more operators
4972 available:
4974 @table @code
4975 @item e
4976 @itemx o
4977 True if the current page is even or odd numbered (respectively).
4978 @item n
4979 @itemx t
4980 True if the document is being processed by @code{nroff} (or a character
4981 device) resp.@: @code{troff}.
4982 @item '@var{xxx}'@var{yyy}'
4983 True if the string @var{xxx} is equal to the string @var{yyy}.  Other
4984 characters can be used in place of the single quotes.
4985 @c XXX (Which?)
4986 The strings are `formatted' before being compared.
4987 @c XXX (?)
4988 @item r@var{xxx}
4989 True if there is a number register named @var{xxx}.
4990 @item d@var{xxx}
4991 True if there is a string, macro, diversion, or request named @var{xxx}.
4992 @item c@var{ch}
4993 @findex char
4994 True if there is a character @var{ch} available; @var{ch} is either an
4995 @acronym{ASCII} character or a special character (@code{\(@var{ch}} or
4996 @code{\[@var{ch}]}); the condition will also be true if @var{ch} has
4997 been defined by the @code{char} request.
4998 @end table
5000 @menu
5001 * if-else::                     
5002 * while::                       
5003 @end menu
5005 @node if-else, while, Conditionals and Loops, Conditionals and Loops
5006 @subsection if-else
5007 @cindex if-else
5009 @code{gtroff} has if-then-else constructs like other languages, although
5010 the formatting can be painful.
5012 @findex if
5013 The @code{if} request has the following syntax:
5015 @example
5016 .if @var{expr} @var{anything}
5017 @end example
5019 @noindent
5020 where @var{expr} is the expression to be evaluated; @var{anything} (the
5021 remainder of the line) will be executed if @var{expr} evaluates to
5022 non-zero (true).  @var{anything} will be interpreted as though it was on
5023 a line by itself.  @xref{Expressions}, for more info.
5025 Here are some examples:
5027 @example
5028 .if t .ls 2                             \" double spacing in troff
5029 .if 0 .ab how'd this happen?
5030 @end example
5032 @findex ie
5033 @findex el
5034 An if-then-else is written using two requests @code{ie} and @code{el}.
5035 The first request is the `if' part and the latter is the `else' part.
5037 @c XXX example
5039 @example
5042 @end example
5044 @findex \@{
5045 @findex \@}
5046 In many cases more than one request is to be executed as a result of any
5047 of these requests.  This can be done using the @code{\@{} and @code{\@}}
5048 escapes.  The following example shows the possible ways to use these
5049 escapes (note the position of the opening and closing braces).
5051 @example
5052 .ie t \@{\
5053 .    ds lq ``
5054 .    ds rq ''
5055 .\@}
5056 .el \
5057 .\@{\
5058 .    ds lq "
5059 .    ds rq "\@}
5060 .ds qq "
5061 @end example
5063 @xref{Expressions}.
5065 @node while,  , if-else, Conditionals and Loops
5066 @subsection while
5067 @cindex while
5069 @findex while
5070 @code{gtroff} provides a looping construct using the @code{while}
5071 request, which is used much like the @code{if} (and related) requests.
5072 The first argument is an expression which will be evaluated.  The
5073 @code{while} request will interpret the remainder of the line until the
5074 expression evaluates to 0 or false.
5076 @example
5077 .nr a 0 1
5078 .while (\na<9) \&\n+a,
5079 \&\n+a
5080 @end example
5082 @noindent
5083 The preceding example produces:
5085 @example
5086 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
5087 @end example
5089 @cindex zero width space character
5090 @cindex character, zero width space
5091 @cindex space character, zero width
5092 @findex \&
5093 @noindent
5094 Note the usage of the @code{\&} escape to avoid a control character at
5095 the beginning of a line.
5097 @findex break
5098 @findex continue
5099 The @code{break} request will @dfn{break} out of a while loop.  Be sure
5100 not to confuse this with the @code{br} request (causing a line break).
5101 The @code{continue} request will finish the current iteration of a while
5102 loop, immediately restarting the next iteration.
5104 @xref{Expressions}.
5107 @node Writing Macros, Page Motions, Conditionals and Loops, Programming Tutorial
5108 @section Writing Macros
5109 @cindex writing macros
5110 @cindex macros, writing
5112 @findex de
5113 A @dfn{macro} is a collection of text and embedded commands which can be
5114 invoked multiple times.  Macros are used for defining common operations.
5115 Macros are defined using the @code{de} request.  This request takes a
5116 name for the macro as the first argument.  Subsequent lines are copied
5117 into an internal buffer until the line @code{..} is encountered.  The
5118 optional second argument to @code{de} can change this ending token.
5120 Here a small example macro called @samp{P} which will cause a break and
5121 the insertion of some vertical space.  It could be used to separate
5122 paragraphs.
5124 @example
5125 .de P
5127 .sp .8v
5129 @end example
5131 @findex am
5132 The @code{am} request works similarly to @code{de} except it appends
5133 onto the macro named by the first argument.  So, to make the previously
5134 defined @samp{P} macro actually do indented instead of block paragraphs,
5135 is is possible to add the necessary code to the existing macro like
5136 this:
5138 @example
5139 .am P
5140 .ti +5n
5142 @end example
5144 @findex als
5145 @cindex aliases, macro
5146 @cindex macro aliases
5147 Macros can be aliased with the @code{als} request.
5149 @c XXX example
5151 @menu
5152 * Copy-in Mode::                
5153 * Parameters::                  
5154 @end menu
5156 @node Copy-in Mode, Parameters, Writing Macros, Writing Macros
5157 @subsection Copy-in Mode
5158 @cindex copy-in mode
5159 @cindex mode, copy-in
5161 @findex \n
5162 @findex \$
5163 @findex \*
5164 @findex \\
5165 @findex \@key{RET}
5166 When @code{gtroff} reads in the text for a macro or diversion it copies
5167 the text (including request lines, but excluding escapes) into an
5168 internal buffer.  Escapes will be converted into an internal form,
5169 except for @code{\n}, @code{\$}, @code{\*}, @code{\\} and
5170 @code{\@key{RET}} which are evaluated and inserted into the text where
5171 the escape was located.  This is known as @dfn{copy-in} mode or
5172 @dfn{copy} mode.
5174 What this means is that you can specify when these escapes are to be
5175 evaluated (either at copy-in time or at the time of use) by insulating
5176 the escapes with an extra backslash.  Compare this to the @code{\def}
5177 and @code{\edef} commands in @TeX{}.
5179 For example, the following will result in the numbers 20 and@c{ }10
5180 being printed:
5182 @example
5183 .nr x 20
5184 .de y
5185 .nr x 10
5186 \&\nx
5187 \&\\nx
5190 @end example
5192 @node Parameters,  , Copy-in Mode, Writing Macros
5193 @subsection Parameters
5194 @cindex parameters
5196 @findex \$
5197 @vindex .$
5198 The arguments to a macro can be examined using a variety of escapes.
5199 The number of arguments is available in the @code{.$} number register.
5200 Any individual argument can be retrieved with one of the following
5201 escapes:
5203 @cindex copy-in mode
5204 The escapes @code{\$@var{n}}, @code{\$(@var{nn}} and
5205 @code{\$[@var{nnn}]} will result in the @var{n}th, @var{nn}th or
5206 @var{nnn}th argument.  As usual, the first form only accepts a single
5207 number (larger than zero), the second only a two-digit number (larger or
5208 equal to@w{ }10), and the third any positive integer value (larger than
5209 zero).  Macros can have an unlimited number of arguments.  Note that due
5210 to copy-in mode, two backslashes should be used on these in actual use
5211 to prevent interpolation until the macro is actually invoked.
5213 @findex shift
5214 The request @code{shift} will shift the arguments 1@w{ }position, or as
5215 many positions as specified by its argument.  After executing this
5216 request, argument@w{ }@var{i} will become argument @var{i}-@var{n};
5217 arguments 1 to@w{ }@var{n} will no longer be available.  Shifting by
5218 negative amounts is currently undefined.
5220 @findex \$*
5221 @findex \$@@
5222 In some cases it is convenient to use all of the arguments at once (for
5223 example, to pass the arguments along to another macro).  The @code{\$*}
5224 escape is the concatenation of all the arguments separated by spaces.  A
5225 similar escape is @code{\$@@}, which is the concatenation of all the
5226 arguments with each surrounded by double quotes, and separated by
5227 spaces.
5229 @findex \$0
5230 @findex als
5231 The @code{\$0} escape is the name by which the current macro was
5232 invoked.  The @code{als} request can make a macro have more than one
5233 name.
5235 @example
5236 .de vl
5237 .ie \\n(.$=1 .ds Vl Pre-Release Version
5238 .el          .ds Vl Version \\$3, \\$4.
5240 @end example
5242 This would be called as
5244 @example
5245 .vl $Id$
5246 @end example
5248 @xref{Request Arguments}.
5251 @node Page Motions, Drawing Requests, Writing Macros, Programming Tutorial
5252 @section Page Motions
5253 @cindex page motions
5254 @cindex motions, page
5256 @findex sp
5257 Motions up and down the page can be done with the @code{sp} request.
5258 However, this causes a break so that the actual effect is to move to the
5259 left margin and then to the specified location.
5261 @findex mk
5262 @findex rt
5263 The request @code{mk} can be used to mark a location on a page, for
5264 movement to later.  This request takes a register name as an argument in
5265 which to store the current page location.  With no argument it will
5266 store the location in an internal register.  The results of this can be
5267 used later by the @code{rt} or the @code{sp} request.  The @code{rt}
5268 request will return @emph{upwards} to the location given in the register
5269 name given as an argument, with no argument it will return to the
5270 location marked with the @code{mk} request
5272 @c XXX example
5274 @example
5275 ... dual column example ...
5276 @end example
5278 The following escapes give fine control of movements about the page.
5280 @findex \v
5281 @cindex vertical motion
5282 @cindex motion, vertical
5283 The @code{\v'@var{e}'} enables arbitrary vertical motion from the
5284 current location on the page.  The argument@w{ }@var{e} specifies the
5285 distance to move; positive is downwards and negative upwards.  The
5286 default unit for this escape is vertical spaces, @code{v}'s.  Beware,
5287 however, that @code{gtroff} will leave text processing to continue
5288 wherever the motion ends, so to avoid interference with text processing,
5289 motions should be balanced.
5291 There are some special case escapes for vertical motion.
5293 @ftable @code
5294 @item \r
5295 move upwards@w{ }1@dmn{v}.
5296 @item \u
5297 move upwards@w{ }.5@dmn{v}.
5298 @item \d
5299 move down@w{ }.5@dmn{v}.
5300 @end ftable
5302 @findex \h
5303 Horizontal motions can be done via the @code{\h'@var{e}'} escape.  The
5304 expression@w{ }@var{e} indicates how far to move: positive is rightwards
5305 and negative leftwards.
5307 There are a number of special case escapes for horizontal motion:
5309 @ftable @code
5310 @item \@key{SP}
5311 an unbreakable and unpaddable (i.e.@: not expanded during filling)
5312 space.  (Note: It is a backslash followed by a space.)
5313 @item \~
5314 an unbreakable space that stretches like a normal inter-word space when a
5315 line is adjusted.
5316 @item \|
5317 a 1/6th em space.
5318 @item \^
5319 a 1/12th em space.
5320 @item \0
5321 a space the size of a digit.
5322 @cindex zero width space character
5323 @cindex character, zero width space
5324 @cindex space character, zero width
5325 @item \&
5326 A zero width space.
5327 @item \)
5328 Like @code{\&} except that it behaves like a character declared with the
5329 @code{cflags} request to be transparent for the purposes of end of
5330 sentence recognition.
5331 @end ftable
5333 @c XXX example
5335 @example
5336 ... tex logo example ...
5337 @end example
5339 @findex \w
5340 @cindex width escape
5341 @cindex escape, width
5342 A frequent need is to do horizontal movement based on the width of some
5343 arbitrary text (e.g.@: given as an argument to a macro).  For that,
5344 there is the escape @code{\w'@var{text}'} which will interpolate to the
5345 width of the given @var{text} in basic units.
5347 @c XXX example
5349 @example
5350 ... strlen example ...
5351 @end example
5353 Font changes may occur in @var{text} which don't affect current
5354 settings.
5356 After use, @code{\w} sets several registers:
5358 @table @code
5359 @vindex st
5360 @vindex sb
5361 @item st
5362 @itemx sb
5363 The highest and lowest point, respectively, in @var{text}.
5364 @vindex rst
5365 @vindex rsb
5366 @item rst
5367 @itemx rsb
5368 Like the @code{st} and @code{sb} registers, but takes account of the
5369 heights and depths of characters.
5370 @vindex ct
5371 @item ct
5372 is set according to what kinds of characters occur in @var{text}:
5373 @table @asis
5374 @item 0
5375 only short characters, no descenders or tall characters.
5376 @item 1
5377 descender
5378 @item 2
5379 tall character
5380 @item 3
5381 both a descender and a tall character
5382 @end table
5383 @vindex ssc
5384 @item ssc
5385 The amount of horizontal space (possibly negative) that should be added
5386 to the last character before a subscript.
5387 @vindex skw
5388 @item skw
5389 How far to right of the center of the last character in the @code{\w}
5390 argument, the center of an accent from a Roman font should be placed
5391 over that character.
5392 @end table
5394 @findex \k
5395 @vindex .k
5396 @code{\k}
5398 @code{.k}
5400 @c XXX documentation
5403 @node Drawing Requests, Traps, Page Motions, Programming Tutorial
5404 @section Drawing Requests
5405 @cindex drawing requests
5406 @cindex requests for drawing
5408 @code{gtroff} provides a number of ways to draw lines and other figures
5409 on the page.  Used in combination with the page motion commands
5410 (@pxref{Page Motions}, for more info), a wide variety of figures can be
5411 drawn.  However, for complex drawings these operations can be quite
5412 cumbersome, and it may be wise to use graphic preprocessors like
5413 @code{gpic} or @code{ggrn}.  @xref{gpic}, and @ref{ggrn}, for more
5414 information.
5416 All drawing is done via escapes.
5418 @findex \l
5419 @cindex horizontal line
5420 @cindex line, horizontal
5421 The @code{\l} escape will draw a line rightwards from the current
5422 location.  The full syntax for this escape is
5424 @example
5425 \l'@var{l}@var{c}'
5426 @end example
5428 @noindent
5429 where @var{l} is the length of the line to be drawn, starting at the
5430 current location; positive numbers will draw to the right, and negative
5431 will draw towards the left.  This can also be specified absolutely
5432 (i.e.@: with a leading @samp{|}) which will draw back to the beginning
5433 of the line.
5435 @cindex underscore character
5436 @cindex character, underscore
5437 @cindex line drawing character
5438 @cindex character for line drawing
5439 The optional second parameter @var{c} is a character to draw the line
5440 with.  If this second argument is not specified, @code{gtroff} will use
5441 the underscore character.
5443 @cindex zero width space character
5444 @cindex character, zero width space
5445 @cindex space character, zero width
5446 @findex \&
5447 To separate the two arguments (to prevent @code{gtroff} from
5448 interpreting a drawing character as a scaling indicator) use @code{\&}.
5450 Here a small useful example:
5452 @example
5453 .de box
5454 \(br\\$*\(br\l'|0\(rn'\l'|0\(ul'
5456 @end example
5458 @noindent
5459 @opindex |
5460 Note that this works by outputting a box rule (a vertical line), then
5461 the text given as an argument and then another box rule.  Then the line
5462 drawing escapes both draw from the current location to the beginning of
5463 the @emph{input} line.
5465 @findex \L
5466 @cindex vertical line
5467 @cindex line, vertical
5468 @cindex line drawing character
5469 @cindex character for line drawing
5470 @cindex box rule character
5471 @cindex character, box rule
5472 Vertical lines are drawn using the @code{\L} escape.  Its parameters are
5473 specified similar to the @code{\l} escape.  If the length is positive,
5474 the movement will be downwards, and upwards for negative values.  The
5475 default character is the box rule character.  As with the vertical
5476 motion escapes, text processing will blindly continue where the line
5477 ends.
5479 @c XXX example
5481 @example
5482 ...box macro...
5483 @end example
5485 @findex \D
5486 More flexible drawing functions are available via the @code{\D} escape.
5487 While the previous escapes will work on a character device, these
5488 escapes will not.
5490 @table @code
5491 @item \D'l @var{dx} @var{dy}'
5492 Draw a line from the current location to the relative point specified by
5493 (@var{dx},@var{dy}).
5495 @c XXX example
5497 @example
5498 ...revised box macro...
5499 @end example
5501 @item \D'c @var{d}'
5502 @cindex circles
5503 Draw a circle with a diameter of @var{d} with the leftmost point at the
5504 current position.
5505 @item \D'C @var{d}'
5506 Draw a solid circle with the same parameters as an outlined circle.
5507 @item \D'e @var{dx} @var{dy}'
5508 @cindex ellipses
5509 Draw an ellipse with a horizontal diameter of @var{dx} and a vertical
5510 diameter of @var{dy} with the leftmost point at the current position.
5511 @item \D'E @var{dx} @var{dy}'
5512 Draw a solid ellipse with the same parameters as an outlined ellipse.
5513 @item \D'a @var{dx1} @var{dy1} @var{dx2} @var{dy2}'
5514 @cindex arcs
5515 Draw an arc clockwise from the current location through the two
5516 specified locations (@var{dx1},@var{dy1}) and (@var{dx2},@var{dy2}).
5517 @item \D'~ @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
5518 @cindex splines
5519 Draw a spline from the current location to (@var{dx1},@var{dy1}) and
5520 then to (@var{dx2},@var{dy2}), and so on.
5521 @item \D'f @var{n}'
5522 @cindex gray shading
5523 @cindex shading
5524 Set the shade of gray to be used for filling solid objects to@w{
5525 }@var{n}; @var{n}@w{ }must be an integer between 0 and@w{ }1000, where 0
5526 corresponds solid white and 1000 to solid black, and values in between
5527 correspond to intermediate shades of gray.  This applies only to solid
5528 circles, solid ellipses and solid polygons.  By default, a level of@w{
5529 }1000 will be used.
5530 @item \D'p @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
5531 @cindex polygons
5532 Draw a polygon from the current location to (@var{dx1},@var{dy1}) and
5533 then to (@var{dx2},@var{dy2}) and so on.  When the specified data points
5534 are exhausted, a line is drawn back to the starting point.
5536 @c XXX example
5538 @example
5539 ... box example (yes, again)...
5540 @end example
5542 @itemx \D'P @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
5543 Draw a solid polygon with the same parameters as an outlined polygon.
5545 @c XXX example
5547 @example
5548 ... shaded box example ...
5549 @end example
5551 @item \D't @var{n}'
5552 @cindex line thickness
5553 @cindex thickness of lines
5554 Set the current line thickness to @var{n} machine units.  A value of
5555 zero selects the smallest available line thickness.  A negative value
5556 makes the line thickness proportional to the current point size (this is
5557 the default behaviour of @code{ditroff}).
5558 @end table
5560 @findex \b
5561 @cindex pile, character
5562 @cindex character pile
5563 The @code{\b} escape will @dfn{pile} a sequence of characters
5564 vertically, and center it vertically on the current line.  This can be
5565 used to build large brackets and braces.
5567 @example
5568 \b'\(lt\(bv\(lk\(bv\(lb'
5569 @end example
5571 @xref{Drawing Functions}.
5573 @node Traps, Diversions, Drawing Requests, Programming Tutorial
5574 @section Traps
5575 @cindex traps
5577 @dfn{Traps} are locations, which, when reached, will call a specified
5578 macro.  These traps can occur at a given location on the page, at a
5579 given location in the current diversion, after a certain number of input
5580 lines or at the end of input.
5582 @menu
5583 * Page Location Traps::         
5584 * Diversion Traps::             
5585 * Input Line Traps::            
5586 * End-of-input Traps::          
5587 @end menu
5589 @node Page Location Traps, Diversion Traps, Traps, Traps
5590 @subsection Page Location Traps
5591 @cindex page location traps
5592 @cindex traps, page location
5594 @c XXX definition of wh request
5596 @cindex page headers
5597 @cindex page footers
5598 @cindex headers
5599 @cindex footers
5600 Page location traps are frequently used for page headers and footers.
5601 The following is a simple example of this.
5603 @example
5604 .de hd                \" Page header
5605 'sp .5i
5606 .tl 'Title''date'
5607 'sp .3i
5609 .de fo                \" Page footer
5610 'sp 1v
5611 .tl ''%''
5614 .wh 0   hd            \" trap at top of the page
5615 .wh -1i fo            \" trap one inch from bottom
5616 @end example
5618 @vindex .t
5619 @cindex distance to next trap
5620 @cindex trap, distance
5621 The number register @code{.t} is the distance to the next trap.
5623 @findex ch
5624 @cindex changing trap location
5625 @cindex trap, changing location
5626 The location of a trap can be changed later on with the @code{ch}
5627 request.  The first argument is the name of the macro to be invoked at
5628 the trap, and the second argument is the new location for the trap.
5629 This is useful for building up footnotes in a diversion to allow more
5630 space at the bottom of the page for them.
5632 @c XXX
5634 @example
5635 ... (simplified) footnote example ...
5636 @end example
5638 @findex vpt
5639 @findex wh
5640 @findex dt
5641 @vindex .vpt
5642 The @code{vpt} request will enable vertical position traps if the
5643 argument is non-zero, disable them otherwise.  Vertical position traps
5644 are traps set by the @code{wh} or @code{dt} requests.  Traps set by the
5645 @code{it} request are not vertical position traps.  The parameter that
5646 controls whether vertical position traps are enabled is global.
5647 Initially vertical position traps are enabled.  The current setting of
5648 this is available in the number register @code{.vpt}.
5650 @vindex .trunc
5651 @findex ne
5652 The number register @code{.trunc} contains the amount of vertical space
5653 truncated by the most recently sprung vertical position trap, or, if the
5654 trap was sprung by a @code{ne} request, minus the amount of vertical
5655 motion produced by the @code{ne} request.  In other words, at the point
5656 a trap is sprung, it represents the difference of what the vertical
5657 position would have been but for the trap, and what the vertical
5658 position actually is.
5660 @vindex .ne
5661 The number register @code{.ne} contains the amount of space that was
5662 needed in the last @code{ne} request that caused a trap to be sprung.
5663 Useful in conjunction with the @code{.trunc} register.  @xref{Page
5664 Control}, for more information.
5666 @node Diversion Traps, Input Line Traps, Page Location Traps, Traps
5667 @subsection Diversion Traps
5668 @cindex diversion traps
5669 @cindex traps, diversion
5671 @findex dt
5672 @vindex .t
5673 Traps can also be set @emph{within} a diversion using the @code{dt}
5674 request.  Like @code{wh} the first argument is the location of the trap
5675 and the second argument is the name of the macro to be invoked.  The
5676 number register @code{.t} will still work within diversions.
5677 @xref{Diversions}, for more information.
5679 @node Input Line Traps, End-of-input Traps, Diversion Traps, Traps
5680 @subsection Input Line Traps
5681 @cindex input line traps
5682 @cindex traps, input line
5684 @findex it
5685 The @code{it} request will set an input line trap.  The format for
5686 calling this is
5688 @example
5689 .it @var{n} @var{name}
5690 @end example
5692 @noindent
5693 where @var{n} is the number of lines of input which may be read before
5694 @dfn{springing} the trap, @var{name} is the macro to be invoked.
5695 Request lines are not counted as input lines.
5697 For example, one possible use is to have a macro which will print the
5698 next @var{n}@w{ }lines in a bold font.
5700 @example
5701 .de B
5702 .it B-end \\$1
5703 .ft B
5705 .de B-end
5706 .ft R
5708 @end example
5710 @node End-of-input Traps,  , Input Line Traps, Traps
5711 @subsection End-of-input Traps
5712 @cindex end-of-input traps
5713 @cindex traps, end-of-input
5715 @findex em
5716 The @code{em} request will set a trap at the end of input.  The macro
5717 specified as an argument will be executed after the last line of the
5718 input file has been processed.
5720 For example, if the document had to have a section at the bottom of the
5721 last page for someone to approve it, the @code{em} request could be
5722 used.
5724 @example
5725 .de approval
5726 .ne 5v
5727 .sp |(\\n(.t-6v)
5728 .in +4i
5729 .lc _
5731 Approved:\t\a
5733 Date:\t\t\a
5735 .em approval
5736 @end example
5739 @node Diversions, Environments, Traps, Programming Tutorial
5740 @section Diversions
5741 @cindex diversions
5743 In @code{gtroff} it is possible to @dfn{divert} text into a named
5744 storage area.  Due to the similarity to defining macros it is sometimes
5745 said to be stored in a macro.  This is used for saving text for output
5746 at a later time, which is useful for keeping blocks of text on the same
5747 page, footnotes, tables of contents and indices.
5749 @findex di
5750 @findex da
5751 A diversion is initiated by the @code{di} request.  Like the @code{de}
5752 request, it takes an argument of a macro name to divert subsequent text
5753 into.  The @code{da} macro will append to an existing diversion.
5755 @code{di} (resp.@: @code{da}) without an argument ends the diversion.
5757 @c XXX example
5759 @example
5760 ... end-note example ...
5761 @end example
5763 @vindex .z
5764 @vindex .d
5765 @vindex nl
5766 @vindex .h
5767 @cindex nested diversions
5768 @cindex diversion, nested
5769 Diversions may be nested.  The number register @code{.z} contains the
5770 name of the current diversion.  The number register @code{.d} contains
5771 the current vertical place in the diversion.  If not in a diversion it
5772 is the same as the register @code{nl}.
5774 @c XXX more info
5776 @code{.h}
5778 @vindex dn
5779 @vindex dl
5780 After completing a diversion, the built-in number registers @code{dn}
5781 and @code{dl} contain the vertical and horizontal size of the diversion.
5783 @example
5784 .\" Center text both horizontally & vertically
5785 .de (c
5788 .di @@c
5790 .de )c
5793 .nr @@s (((\\n(.tu-\\n(dnu)/2u)-1v)
5794 .sp \\n(@@su
5795 .ce 1000
5799 .ce 0
5800 .sp \\n(@@su
5803 .rr @@s
5805 @end example
5807 @findex \!
5808 @cindex transparent output
5809 @cindex output, transparent
5810 Requests, macros and escapes are interpreted when read into a diversion.
5811 There are two ways to prevent this; either way will take the given text
5812 and @dfn{transparently} embed it into the diversion.  The first method
5813 is to prefix the line with @code{\!}.  This will cause the entire line
5814 to be transparently inserted into the diversion.  This is useful for
5815 macros which shouldn't be invoked until the diverted text is actually
5816 output.
5818 @c XXX anything is read in copy mode. (what about \! ??)
5820 @findex \?
5821 The other way is to surround the text by the @code{\?} escape, i.e.
5823 @example
5824 \?@var{anything}\?
5825 @end example
5827 @noindent
5828 @var{anything} may not contain newlines; use @code{\!}  to embed
5829 newlines in a diversion.  The escape sequence @code{\?} is also
5830 recognized in copy mode and turned into a single internal code; it is
5831 this code that terminates anything.  Thus the following example will
5832 print@w{ }4.
5834 @example
5835 .nr x 1
5837 .di d
5838 \?\\?\\\\?\\\\\\\\nx\\\\?\\?\?
5840 .nr x 2
5841 .di e
5844 .nr x 3
5845 .di f
5848 .nr x 4
5850 @end example
5852 @findex asciify
5853 @cindex unformatting diversions
5854 @cindex diversion, unformatting
5855 The @code{asciify} request only exists in order to make certain gross
5856 hacks work with GNU @code{troff}.  It @dfn{unformats} the diversion
5857 specified as an argument in such a way that @acronym{ASCII} characters
5858 that were formatted and diverted will be treated like ordinary input
5859 characters when the diversion is reread.  For example, the following
5860 will set register @code{n} to@w{ }1.
5862 @example
5863 .tr @@.
5864 .di x
5865 @@nr\ n\ 1
5868 .tr @@@@
5869 .asciify x
5871 @end example
5873 @xref{Copy-in Mode}.
5876 @node Environments, I/O, Diversions, Programming Tutorial
5877 @section Environments
5878 @cindex environments
5880 It happens frequently that some text should be printed in a certain
5881 format regardless of what may be in effect at the time, for example, in
5882 a trap invoked macro to print headers and footers.  To solve this
5883 @code{gtroff} has @dfn{environments} in which text is processed.  An
5884 environment contains most of the parameters that control text
5885 processing.  It is possible to switch amongst these environments; by
5886 default @code{gtroff} processes text in environment@w{ }0.  The
5887 following is the information kept in an environment.
5889 @itemize @bullet{}
5890 @item
5891 type size
5892 @item
5893 font (family and style)
5894 @item
5895 page parameters
5896 @item
5897 fill/adjust mode
5898 @item
5899 tab stops
5900 @item
5901 partially collected lines
5902 @end itemize
5904 These environments may be given arbitrary names (@pxref{Identifiers},
5905 for more info).  Old versions of @code{troff} only had environments
5906 named @samp{0}, @samp{1} and@w{ }@samp{2}.
5908 @findex ev
5909 @vindex .ev
5910 The @code{ev} request will switch among environments.  The single
5911 argument is the name of the environment to switch to.  With no argument
5912 @code{gtroff} will switch back to the previous environment.  There is no
5913 limit on the number of named environments; they will be created the
5914 first time that they are referenced.  The @code{.ev} register contains
5915 the name or number of the current environment.  This is a string-valued
5916 register.
5918 Note that a call to @code{ev} (with argument) will push the previously
5919 active environment onto a stack.  If, say, environments @samp{foo},
5920 @samp{bar}, and @samp{zap} are called (in that order), the first
5921 @code{ev} request without parameter will switch back to environment
5922 @samp{bar} (which will be popped off the stack), and a second call will
5923 switch back to environment @samp{foo}.
5925 @c XXX example
5927 @example
5928 ... page break macro, revised ...
5929 @end example
5931 Here another example:
5933 @example
5934 .ev footnote-env
5935 .fam N
5936 .ps 6
5937 .vs 8
5938 .ll -.5i
5941 .ev footnote-env
5942 \(dg Note the large, friendly letters.
5944 @end example
5946 @findex evc
5947 To copy an environment into the current one, use the @code{evc} request,
5948 which takes the name of the environment to copy from as an argument.
5951 @node I/O, Postprocessor Access, Environments, Programming Tutorial
5952 @section I/O
5953 @cindex i/o
5954 @cindex input and output requests
5955 @cindex requests for input and output
5956 @cindex output and input requests
5958 @findex so
5959 The @code{so} request will read in the file given as an argument and
5960 include it in place of the @code{so} request.  This is quite useful for
5961 large documents, i.e.@: keeping each chapter in a separate file.
5962 @xref{gsoelim}, for more information.
5964 @findex mso
5965 The @code{mso} request is the same as the @code{so} request except that
5966 the file is searched for in the same way that @file{tmac.@var{name}} is
5967 searched for when the @option{-m@var{name}} option is specified.
5969 @findex cf
5970 @cindex transparent output
5971 @cindex output, transparent
5972 The @code{cf} and @code{trf} requests are to include a file.  It will
5973 transparently output the contents of file filename.  Each line is output
5974 as it were preceded by @code{\!}; however, the lines are not subject to
5975 copy mode interpretation.  If the file does not end with a newline, then
5976 a newline will be added.  For example, to define a macro@w{ }@code{x}
5977 containing the contents of file@w{ }@file{f}, use
5979 @example
5980 .di x
5981 .trf f
5983 @end example
5985 The request @w{@code{.cf @var{filename}}}, when used in a diversion,
5986 will embed in the diversion an object which, when reread, will cause the
5987 contents of @var{filename} to be transparently copied through to the
5988 output.  In @acronym{UNIX} @code{troff}, the contents of @var{filename}
5989 is immediately copied through to the output regardless of whether there
5990 is a current diversion; this behaviour is so anomalous that it must be
5991 considered a bug.  This request causes a line break.
5993 @findex trf
5994 With @code{trf}, unlike @code{cf}, the file cannot contain characters
5995 such as NUL that are not legal @code{gtroff} input characters.  This
5996 request causes a line break.
5998 @c XXX xref to illegal input characters
6000 @findex nx
6001 The @code{nx} request will force @code{gtroff} to continue processing of
6002 the file specified as an argument.
6004 @findex rd
6005 The @code{rd} request will read from standard input, and include what is
6006 read as though it were part of the input file.  Text is read until a
6007 blank line is encountered.
6009 @cindex form letters
6010 @cindex letters, form
6011 Using these two requests it is easy to set up form letters.  The form
6012 letter template is constructed like this:
6014 @example
6016 \*(td
6017 .sp 2
6023 Body of letter.
6025 .nx repeat.let
6026 @end example
6028 @findex ex
6029 @noindent
6030 When this is run, the following file should be redirected in.  Note that
6031 requests included in this file are executed as though they were part of
6032 the form letter.  The last block of input is the @code{ex} requests
6033 which tells groff to stop processing.  If this was not there, groff
6034 would not know when to stop.
6036 @example
6037 Trent A. Fisher
6038 708 NW 19th Av., #202
6039 Portland, OR  97209
6041 Dear Trent,
6043 Len Adollar
6044 4315 Sierra Vista
6045 San Diego, CA  92103
6047 Dear Mr. Adollar,
6050 @end example
6052 @findex pi
6053 @code{pi}
6055 @c XXX documentation
6057 @findex sy
6058 The @code{sy} request will allow arbitrary system commands to be
6059 executed from within a @code{gtroff} document.  The output is not saved
6060 anyplace, so it is up to the user to do so.
6062 @c XXX add info about safer and unsafe mode
6064 For example, the following example will introduce the current time
6065 into a document:
6067 @cindex time, current
6068 @cindex current time
6069 @pindex perl
6070 @example
6071 .sy perl -e 'printf ".nr H %d\\n.nr M %d\\n.nr S %d\\n",\
6072              (localtime(time))[2,1,0]' > /tmp/x\n[$$]
6073 .so /tmp/x\n[$$]
6074 .sy rm /tmp/x\n[$$]
6075 \nH:\nM:\nS
6076 @end example
6078 @noindent
6079 Note that this works by having the @code{perl} script (run by @code{sy})
6080 print out the @code{nr} requests which will set the number registers
6081 @samp{H}, @samp{M} and @samp{S}, and then reads those commands in with
6082 the @code{so} request.
6084 @vindex systat
6085 The @code{systat} number register contains the return value of the
6086 @code{system()} function executed by the last @code{sy} request.
6088 @findex open
6089 The @code{open} request will open a file (specified as the second
6090 argument) for writing and associate the stream (specified as the first
6091 argument) with it.
6093 @findex opena
6094 The @code{opena} is like @code{open}, but if the file exists, append to
6095 it instead of truncating it.
6097 @findex write
6098 @findex ds
6099 @cindex copy-in mode
6100 @cindex mode, copy-in
6101 The @code{write} request will write to the file associated with the
6102 stream specified by the first argument.  The stream must previously have
6103 been the subject of an open request.  The remainder of the line is
6104 interpreted as the @code{ds} request reads its second argument: A
6105 leading @samp{"} will be stripped, and it will be read in copy-in mode.
6107 @findex close
6108 The @code{close} request will close the stream specified by the first
6109 argument; stream will no longer be an acceptable argument to the
6110 @code{write} request.
6112 @c XXX example
6114 @example
6115 ... example of open write &c...
6116 @end example
6118 @findex \V
6119 The @code{\V} escape will interpolate the contents of the specified
6120 environment variable, as returned by @code{getenv()}.  The argument to
6121 @code{\V} is specified as an identifier, i.e.@: @samp{\V@var{x}},
6122 @samp{\V(@var{xx}} or @samp{\V[@var{xxx}]}.  @code{\V} is interpreted in
6123 copy-in mode.
6126 @node Postprocessor Access, Miscellaneous, I/O, Programming Tutorial
6127 @section Postprocessor Access
6128 @cindex postprocessor access
6129 @cindex access of postprocessor
6131 There are two escapes which will allow information to be directly given
6132 to the postprocessor.  This is particularly useful for embedding
6133 @sc{PostScript} into the final document.
6135 @findex \X
6136 The @code{\X} escape will embed its argument into the @code{gtroff}
6137 output preceded with @w{@samp{x X}}.
6139 @findex \Y
6140 The @code{\Y} escape is called with an identifier (i.e.@:
6141 @code{\Y@var{x}}, @code{\Y(@var{xx}} or @code{\Y[@var{xxx}]}).  This is
6142 approximately equivalent to @samp{\X'\*[@var{xxx}]'}.  However, the
6143 contents of the string or macro @var{xxx} are not interpreted; also it
6144 is permitted for @var{xxx} to have been defined as a macro and thus
6145 contain newlines (it is not permitted for the argument to @code{\X} to
6146 contain newlines).  The inclusion of newlines requires an extension to
6147 the @acronym{UNIX} @code{troff} output format, and will confuse drivers
6148 that do not know about this extension.
6150 @xref{Output Devices}.
6153 @node Miscellaneous, Debugging, Postprocessor Access, Programming Tutorial
6154 @section Miscellaneous
6155 @cindex miscellaneous
6157 This section contains parts of @code{gtroff} which cannot (yet) be
6158 categorized elsewhere in this manual.
6160 @findex nm
6161 @cindex line numbers
6162 @cindex numbers, line
6163 Line numbers can be printed in the left margin using the @code{nm}
6164 request.  The first argument is the line number of the @emph{next}
6165 output line; this defaults to@w{ }1.  The second argument indicates on
6166 which lines numbers will be printed, i.e.@: 5 means put line numbers on
6167 every 5@w{ }lines; this defaults to@w{ }1.  The third argument is the
6168 space to be left between the number and the text; this defaults to@w{
6169 }1.  The fourth argument is the indentation of the line numbers.
6170 Without arguments, line numbers are turned off.
6172 @c XXX xref ln register
6174 @findex nn
6175 The @code{nn} request will temporarily turn off line numbering.  The
6176 first argument is the number of lines not to be numbered; this defaults
6177 to@w{ }1.
6179 @c XXX (does this disable incrementing or display?)
6181 @c XXX example
6183 @example
6184 ... line numbering example ...
6185 @end example
6187 @findex mc
6188 @cindex margin characters
6189 @cindex characters for margins
6190 Margin characters can be automatically printed to the right of the text
6191 with the @code{mc} request.  The first argument is the character to be
6192 printed, and the second argument is the distance away from the main body
6193 text.  With no arguments the margin characters are turned off.  If this
6194 occurs before a break, no margin character will be printed.
6196 @pindex nrchbar
6197 @pindex changebar
6198 This is quite useful for indicating text that has changed, and, in fact,
6199 there are programs available for doing this (they are called
6200 @code{nrchbar} and @code{changebar} and can be found in any
6201 @samp{comp.sources.unix} archive.
6203 @c XXX example
6205 @example
6206 ... margin char example ...
6207 @end example
6209 @findex lf
6210 @pindex soelim
6211 @cindex multi-file documents
6212 @cindex documents, multi-file
6213 The primary reason for the existence of @code{lf} is to make debugging
6214 documents which are split into many files, which are then put together
6215 with @code{soelim} and other preprocessors.  The first argument is the
6216 name of the file and the second argument is the input line number in
6217 that file.  This way @code{gtroff} can produce error messages which are
6218 intelligible to the user.
6220 @c XXX example
6222 @example
6223 ... example of soelim'ed doc ...
6224 @end example
6227 @node Debugging, Implementation Differences, Miscellaneous, Programming Tutorial
6228 @section Debugging
6229 @cindex debugging
6231 @code{gtroff} is not easy to debug, but there are some useful features
6232 and strategies for debugging.
6234 @itemize @bullet{}
6235 @item
6236 @findex tm
6237 The @code{tm} request will send output to stderr; this is very useful
6238 for printing debugging output.
6239 @item
6240 When doing something involved it is useful to leave the debugging
6241 statements in the code and have them turned on by a command line flag.
6243 @example
6244 .if \n(DB .tm debugging output
6245 @end example
6247 @noindent
6248 To activate these statements say
6250 @example
6251 groff -rDB=1 file
6252 @end example
6254 @item
6255 @findex ab
6256 @cindex aborting
6257 The @code{ab} request is similar to the @code{tm} request, except that
6258 it will cause @code{gtroff} to stop processing.  With no argument it
6259 will print @samp{User Abort}.
6260 @item
6261 @findex ex
6262 @cindex exiting
6263 The @code{ex} request will also cause @code{gtroff} to stop processing
6264 (if encountered at the topmost level; see also @ref{I/O}.
6265 @item
6266 If it is known in advance that there will be many errors and no useful
6267 output, @code{gtroff} can be forced to suppress formatted output with
6268 the @option{-z} flag.
6269 @item
6270 @findex pm
6271 @cindex dumping symbol table
6272 @cindex symbol table, dumping
6273 The @code{pm} request will dump out the entire symbol table.
6274 @item
6275 @findex pnr
6276 @cindex dumping number registers
6277 @cindex number registers, dumping
6278 The @code{pnr} request will print the names and contents of all
6279 currently defined number registers on stderr.
6280 @item
6281 @findex ptr
6282 @cindex dumping traps
6283 @cindex traps, dumping
6284 The @code{ptr} request will print the names and positions of all traps
6285 (not including input line traps and diversion traps) on stderr.  Empty
6286 slots in the page trap list are printed as well, because they can affect
6287 the priority of subsequently planted traps.
6288 @item
6289 @findex fl
6290 @cindex flush output
6291 @cindex output, flush
6292 @cindex interactive use of @code{gtroff}
6293 @cindex @code{gtroff}, interactive use
6294 The @code{fl} request instructs @code{gtroff} to flush its output
6295 immediately.  The intention is that this be used when using
6296 @code{gtroff} interactively.  There is little other use for it.  This
6297 request causes a line break.
6298 @item
6299 @findex backtrace
6300 @cindex backtrace of input stack
6301 @cindex input stack, backtrace
6302 The @code{backtrace} request will print a backtrace of the input stack
6303 on stderr.
6304 @item
6305 @cindex warnings
6306 @code{gtroff} has command line options for printing out more warnings
6307 (@option{-w}) and for printing backtraces (@option{-b}) when a warning
6308 or an error occurs.  The most verbose level of warnings is @option{-ww}.
6309 @item
6310 @findex warn
6311 @vindex .warn
6312 @cindex level of warnings
6313 @cindex warnings, level
6314 The @code{warn} request controls the level of warnings checked for.  The
6315 only argument is the sum of the numbers associated with each warning
6316 that is to be enabled; all other warnings will be disabled.  The number
6317 associated with each warning is listed below.  For example,
6318 @w{@code{.warn 0}} will disable all warnings, and @w{@code{.warn 1}}
6319 will disable all warnings except that about missing characters.  If an
6320 argument is not given, all warnings will be enabled.  The number
6321 register @code{.warn} contains the current warning level.
6322 @end itemize
6324 @subsection Warnings
6325 @cindex warnings
6327 The warnings that can be given to @code{gtroff} are divided into the
6328 following categories.  The name associated with each warning is used by
6329 the @option{-w} and @option{-W} options; the number is used by the
6330 @code{warn} request and by the @code{.warn} register.
6332 @table @samp
6333 @item char
6334 @itemx 1
6335 Non-existent characters.  This is enabled by default.
6336 @item number
6337 @itemx 2
6338 Invalid numeric expressions.  This is enabled by default.
6339 @xref{Expressions}.
6340 @item break
6341 @itemx 4
6342 In fill mode, lines which could not be broken so that their length was
6343 less than the line length.  This is enabled by default.
6344 @item delim
6345 @itemx 8
6346 Missing or mismatched closing delimiters.
6347 @item el
6348 @itemx 16
6349 @findex ie
6350 @findex el
6351 Use of the @code{el} request with no matching @code{ie} request.
6352 @xref{if-else}.
6353 @item scale
6354 @itemx 32
6355 Meaningless scaling indicators.
6356 @item range
6357 @itemx 64
6358 Out of range arguments.
6359 @item syntax
6360 @itemx 128
6361 Dubious syntax in numeric expressions.
6362 @item di
6363 @itemx 256
6364 @findex di
6365 @findex da
6366 Use of @code{di} or @code{da} without an argument when there is no
6367 current diversion.
6368 @item mac
6369 @itemx 512
6370 @findex de
6371 @c XXX more findex entries
6372 Use of undefined strings, macros and diversions.  When an undefined
6373 string, macro or diversion is used, that string is automatically defined
6374 as empty.  So, in most cases, at most one warning will be given for each
6375 name.
6376 @item  reg
6377 @itemx 1024
6378 @findex nr
6379 @c XXX more findex entries
6380 Use of undefined number registers.  When an undefined number register is
6381 used, that register is automatically defined to have a value of@w{ }0.
6382 A definition is automatically made with a value of@w{ }0.  So, in most
6383 cases, at most one warning will be given for use of a particular name.
6384 @item  tab
6385 @itemx 2048
6386 Use of a tab character where a number was expected.
6387 @item  right-brace
6388 @itemx 4096
6389 @findex \@}
6390 Use of @code{\@}} where a number was expected.
6391 @item  missing
6392 @itemx 8192
6393 Requests that are missing non-optional arguments.
6394 @item  input
6395 @itemx 16384
6396 Illegal input characters.
6397 @item  escape
6398 @itemx 32768
6399 Unrecognized escape sequences.  When an unrecognized escape sequence is
6400 encountered, the escape character is ignored.
6401 @item  space
6402 @itemx 65536
6403 @cindex compatibility mode
6404 Missing space between a request or macro and its argument.  This warning
6405 will be given when an undefined name longer than two characters is
6406 encountered, and the first two characters of the name make a defined
6407 name.  The request or macro will not be invoked.  When this warning is
6408 given, no macro is automatically defined.  This is enabled by default.
6409 This warning will never occur in compatibility mode.
6410 @item  font
6411 @itemx 131072
6412 Non-existent fonts.  This is enabled by default.
6413 @item all
6414 All warnings except @samp{di}, @samp{mac} and @samp{reg}.  It is
6415 intended that this covers all warnings that are useful with traditional
6416 macro packages.
6417 @item w
6418 All warnings.
6419 @end table
6422 @node Implementation Differences, Summary, Debugging, Programming Tutorial
6423 @section Implementation Differences
6424 @cindex implementation differences
6425 @cindex differences in implementation
6426 @cindex compatibility mode
6427 @cindex mode, compatibility
6429 GNU @code{troff} has a number of features which cause incompatibilities
6430 with documents written with old versions of @code{troff}.
6432 @cindex long names
6433 @cindex names, long
6434 Long names cause some incompatibilities.  @acronym{UNIX} @code{troff}
6435 will interpret
6437 @example
6438 .dsabcd
6439 @end example
6441 @findex \*
6442 @findex \n
6443 @findex cp
6444 @vindex .C
6445 @noindent
6446 as defining a string @samp{ab} with contents @samp{cd}.  Normally, GNU
6447 @code{troff} will interpret this as a call of a macro named
6448 @code{dsabcd}.  Also @acronym{UNIX} @code{troff} will interpret
6449 @code{\*[} or @code{\n[} as references to a string or number register
6450 called @samp{[}.  In GNU @code{troff}, however, this will normally be
6451 interpreted as the start of a long name.  In compatibility mode GNU
6452 @code{troff} will interpret these things in the traditional way.  In
6453 compatibility mode, however, long names are not recognized.
6454 Compatibility mode can be turned on with the @option{-C} command line
6455 option, and turned on or off with the @code{cp} request.  The number
6456 register @code{.C} is@w{ }1 if compatibility mode is on, 0@w{
6457 }otherwise.
6459 @findex \A
6460 @findex \|
6461 @findex \^
6462 @findex \&
6463 @findex \@}
6464 @findex \@{
6465 @findex \@key{SP}
6466 @findex \'
6467 @findex \`
6468 @findex \-
6469 @findex \_
6470 @findex \!
6471 @findex \%
6472 @findex \c
6473 GNU @code{troff} does not allow the use of the escape sequences
6474 @code{\|}, @code{\^}, @code{\&}, @code{\@}}, @code{\@{},
6475 @code{\@key{SP}}, @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!},
6476 @code{\%}, and @code{\c} in names of strings, macros, diversions, number
6477 registers, fonts or environments; @acronym{UNIX} @code{troff} does.  The
6478 @code{\A} escape sequence (@pxref{Identifiers}) may be helpful in
6479 avoiding use of these escape sequences in names.
6481 @cindex fractional point sizes
6482 @cindex point sizes, fractional
6483 @findex ps
6484 Fractional point sizes cause one noteworthy incompatibility.  In
6485 @acronym{UNIX} @code{troff} the @code{ps} request ignores scale
6486 indicators and thus
6488 @example
6489 .ps 10u
6490 @end example
6492 @noindent
6493 will set the point size to 10@w{ }points, whereas in GNU @code{troff} it
6494 will set the point size to 10@w{ }scaled points.  @xref{Fractional Type
6495 Sizes}, for more information.
6497 @findex bd
6498 @findex cs
6499 @findex tkf
6500 @findex tr
6501 @findex fp
6502 @cindex input and output characters
6503 @cindex output characters
6504 @cindex characters, input and output
6505 In GNU @code{troff} there is a fundamental difference between
6506 unformatted, input characters, and formatted, output characters.
6507 Everything that affects how an output character will be output is stored
6508 with the character; once an output character has been constructed it is
6509 unaffected by any subsequent requests that are executed, including
6510 @code{bd}, @code{cs}, @code{tkf}, @code{tr}, or @code{fp} requests.
6511 Normally output characters are constructed from input characters at the
6512 moment immediately before the character is added to the current output
6513 line.  Macros, diversions and strings are all, in fact, the same type of
6514 object; they contain lists of input characters and output characters in
6515 any combination.  An output character does not behave like an input
6516 character for the purposes of macro processing; it does not inherit any
6517 of the special properties that the input character from which it was
6518 constructed might have had.  For example,
6520 @example
6521 .di x
6522 \\\\
6526 @end example
6528 @findex \e
6529 @findex \!
6530 @findex \?
6531 @cindex transparent output
6532 @cindex output, transparent
6533 @noindent
6534 will print @samp{\\} in GNU @code{troff}; each pair of input backslashes
6535 is turned into one output backslash and the resulting output backslashes
6536 are not interpreted as escape characters when they are reread.
6537 @acronym{UNIX} @code{troff} would interpret them as escape characters
6538 when they were reread and would end up printing one @samp{\}.  The
6539 correct way to obtain a printable backslash is to use the @code{\e}
6540 escape sequence: This will always print a single instance of the current
6541 escape character, regardless of whether or not it is used in a
6542 diversion; it will also work in both GNU @code{troff} and @acronym{UNIX}
6543 @code{troff}.  To store, for some reason, an escape sequence in a
6544 diversion that will be interpreted when the diversion is reread, either
6545 use the traditional @code{\!} transparent output facility, or, if this
6546 is unsuitable, the new @code{\?} escape sequence.
6548 @xref{Diversions}, for more information.
6551 @node Summary,  , Implementation Differences, Programming Tutorial
6552 @section Summary
6553 @cindex summary
6555 @c XXX documentation
6559 @node Preprocessors, Output Devices, Programming Tutorial, Top
6560 @chapter Preprocessors
6561 @cindex preprocessors
6563 This chapter describes all preprocessors that come with @code{groff} or
6564 which are freely available.
6566 @menu
6567 * geqn::                        
6568 * gtbl::                        
6569 * gpic::                        
6570 * ggrn::                        
6571 * grap::                        
6572 * grefer::                      
6573 * gsoelim::                     
6574 @end menu
6577 @node geqn, gtbl, Preprocessors, Preprocessors
6578 @section @code{geqn}
6579 @cindex @code{eqn}
6580 @cindex @code{geqn}
6582 @c XXX
6584 @menu
6585 * Invoking geqn::               
6586 @end menu
6588 @node Invoking geqn,  , geqn, geqn
6589 @subsection Invoking @code{geqn}
6590 @cindex invoking @code{geqn}
6591 @cindex @code{geqn}, invoking
6593 @c XXX
6596 @node gtbl, gpic, geqn, Preprocessors
6597 @section @code{gtbl}
6598 @cindex @code{tbl}
6599 @cindex @code{gtbl}
6601 @c XXX
6603 @menu
6604 * Invoking gtbl::               
6605 @end menu
6607 @node Invoking gtbl,  , gtbl, gtbl
6608 @subsection Invoking @code{gtbl}
6609 @cindex invoking @code{gtbl}
6610 @cindex @code{gtbl}, invoking
6612 @c XXX
6615 @node gpic, ggrn, gtbl, Preprocessors
6616 @section @code{gpic}
6617 @cindex @code{pic}
6618 @cindex @code{gpic}
6620 @c XXX
6622 @menu
6623 * Invoking gpic::               
6624 @end menu
6626 @node Invoking gpic,  , gpic, gpic
6627 @subsection Invoking @code{gpic}
6628 @cindex invoking @code{gpic}
6629 @cindex @code{gpic}, invoking
6631 @c XXX
6634 @node ggrn, grap, gpic, Preprocessors
6635 @section @code{ggrn}
6636 @cindex @code{grn}
6637 @cindex @code{ggrn}
6639 @c XXX
6641 @menu
6642 * Invoking ggrn::               
6643 @end menu
6645 @node Invoking ggrn,  , ggrn, ggrn
6646 @subsection Invoking @code{ggrn}
6647 @cindex invoking @code{ggrn}
6648 @cindex @code{ggrn}, invoking
6650 @c XXX
6653 @node grap, grefer, ggrn, Preprocessors
6654 @section @code{grap}
6655 @cindex @code{grap}
6657 A freely available implementation of @code{grap}, written by Ted Faber,
6658 is available as an extra package from the following address:
6660 @display
6661 @url{http://www.lunabase.org/~faber/Vault/software/grap/}
6662 @end display
6665 @node grefer, gsoelim, grap, Preprocessors
6666 @section @code{grefer}
6667 @cindex @code{refer}
6668 @cindex @code{grefer}
6670 @c XXX
6672 @menu
6673 * Invoking grefer::             
6674 @end menu
6676 @node Invoking grefer,  , grefer, grefer
6677 @subsection Invoking @code{grefer}
6678 @cindex invoking @code{grefer}
6679 @cindex @code{grefer}, invoking
6681 @c XXX
6684 @node gsoelim,  , grefer, Preprocessors
6685 @section @code{gsoelim}
6686 @cindex @code{soelim}
6687 @cindex @code{gsoelim}
6689 @c XXX
6691 @menu
6692 * Invoking gsoelim::            
6693 @end menu
6695 @node Invoking gsoelim,  , gsoelim, gsoelim
6696 @subsection Invoking @code{gsoelim}
6697 @cindex invoking @code{gsoelim}
6698 @cindex @code{gsoelim}, invoking
6700 @c XXX
6704 @node Output Devices, File formats, Preprocessors, Top
6705 @chapter Output Devices
6706 @cindex output devices
6707 @cindex devices for output
6709 @c XXX
6711 @menu
6712 * Special Characters::          
6713 * grotty::                      
6714 * grops::                       
6715 * grodvi::                      
6716 * grolj4::                      
6717 * grolbp::                      
6718 * grohtml::                     
6719 * gxditview::                   
6720 @end menu
6723 @node Special Characters, grotty, Output Devices, Output Devices
6724 @section Special Characters
6725 @cindex special characters
6726 @cindex characters, special
6728 @c XXX
6730 @xref{Font Files}.
6733 @node grotty, grops, Special Characters, Output Devices
6734 @section @code{grotty}
6735 @cindex @code{grotty}
6737 @c XXX
6739 @menu
6740 * Invoking grotty::             
6741 @end menu
6743 @node Invoking grotty,  , grotty, grotty
6744 @subsection Invoking @code{grotty}
6745 @cindex invoking @code{grotty}
6746 @cindex @code{grotty}, invoking
6748 @c XXX
6751 @node grops, grodvi, grotty, Output Devices
6752 @section @code{grops}
6753 @cindex @code{grops}
6755 @c XXX
6757 @menu
6758 * Invoking grops::              
6759 * Embedding PostScript::        
6760 @end menu
6762 @node Invoking grops, Embedding PostScript, grops, grops
6763 @subsection Invoking @code{grops}
6764 @cindex invoking @code{grops}
6765 @cindex @code{grops}, invoking
6767 @c XXX
6769 @node Embedding PostScript,  , Invoking grops, grops
6770 @subsection Embedding @sc{PostScript}
6771 @cindex embedding postscript
6772 @cindex postscript, embedding
6774 @c XXX
6777 @node grodvi, grolj4, grops, Output Devices
6778 @section @code{grodvi}
6779 @cindex @code{grodvi}
6781 @c XXX
6783 @menu
6784 * Invoking grodvi::             
6785 @end menu
6787 @node Invoking grodvi,  , grodvi, grodvi
6788 @subsection Invoking @code{grodvi}
6789 @cindex invoking @code{grodvi}
6790 @cindex @code{grodvi}, invoking
6792 @c XXX
6795 @node grolj4, grolbp, grodvi, Output Devices
6796 @section @code{grolj4}
6797 @cindex @code{grolj4}
6799 @c XXX
6801 @menu
6802 * Invoking grolj4::             
6803 @end menu
6805 @node Invoking grolj4,  , grolj4, grolj4
6806 @subsection Invoking @code{grolj4}
6807 @cindex invoking @code{grolj4}
6808 @cindex @code{grolj4}, invoking
6810 @c XXX
6813 @node grolbp, grohtml, grolj4, Output Devices
6814 @section @code{grolbp}
6815 @cindex @code{grolbp}
6817 @c XXX
6819 @menu
6820 * Invoking grolbp::             
6821 @end menu
6823 @node Invoking grolbp,  , grolbp, grolbp
6824 @subsection Invoking @code{grolbp}
6825 @cindex invoking @code{grolbp}
6826 @cindex @code{grolbp}, invoking
6828 @c XXX
6831 @node grohtml, gxditview, grolbp, Output Devices
6832 @section @code{grohtml}
6833 @cindex @code{grohtml}
6835 @c XXX
6837 @menu
6838 * Invoking grohtml::            
6839 @end menu
6841 @node Invoking grohtml,  , grohtml, grohtml
6842 @subsection Invoking @code{grohtml}
6843 @cindex invoking @code{grohtml}
6844 @cindex @code{grohtml}, invoking
6846 @c XXX
6849 @node gxditview,  , grohtml, Output Devices
6850 @section @code{gxditview}
6851 @cindex @code{gxditview}
6853 @c XXX
6855 @menu
6856 * Invoking gxditview::          
6857 @end menu
6859 @node Invoking gxditview,  , gxditview, gxditview
6860 @subsection Invoking @code{gxditview}
6861 @cindex invoking @code{gxditview}
6862 @cindex @code{gxditview}, invoking
6864 @c XXX
6865 @c X11's xditview
6869 @node File formats, Installation, Output Devices, Top
6870 @chapter File formats
6871 @cindex file formats
6872 @cindex formats, file
6874 @c XXX
6876 @menu
6877 * gtroff Output::               
6878 * Font Files::                  
6879 @end menu
6882 @node gtroff Output, Font Files, File formats, File formats
6883 @section @code{gtroff} Output
6884 @cindex @code{gtroff} output
6885 @cindex output, @code{gtroff}
6887 This section describes the format output of GNU @code{troff}.  The
6888 output format used by GNU @code{troff} is very similar to that used by
6889 @acronym{UNIX} device-independent @code{troff} (@code{ditroff}).
6891 @menu
6892 * Output Format::               
6893 * Device Control::              
6894 * Drawing Functions::           
6895 * Line Continuation::           
6896 @end menu
6898 @node Output Format, Device Control, gtroff Output, gtroff Output
6899 @subsection Output Format
6900 @cindex output format
6901 @cindex format of output
6903 @cindex 8-bit input
6904 @cindex input, 8-bit
6905 The output format is text based, as opposed to a binary format (like
6906 @TeX{} DVI).  The output format is @w{8-bit} clean, thus single
6907 characters can have the eighth bit set, as can the names of fonts and
6908 special characters.
6910 The output format consists of single command characters with attached
6911 parameters which are separated from subsequent text by whitespace or a
6912 newline.
6914 The names of characters and fonts can be of arbitrary length; drivers
6915 should not assume that they will be only two characters long (as
6916 @code{ditroff} does).
6918 When a character is to be printed, that character will always be in the
6919 current font.  Unlike @code{ditroff}, it is not necessary for drivers to
6920 search special fonts to find a character.
6922 @table @code
6923 @item H@var{n}
6924 @c XXX
6925 @item V@var{n}
6926 @c XXX
6927 @item h@var{n}
6928 @c XXX
6929 @item v@var{n}
6930 @c XXX
6931 @item c@var{n}
6932 @c XXX
6933 @item C@var{n}
6934 @c XXX
6935 @item @var{nn}@var{c}
6936 @c XXX
6937 @item t@var{xxx}
6938 @var{xxx} is any sequence of characters terminated by a space or a
6939 newline; the first character should be printed at the current position,
6940 the the current horizontal position should be increased by the width of
6941 the first character, and so on for each character.  The width of the
6942 character is that given in the font file, appropriately scaled for the
6943 current point size, and rounded so that it is a multiple of the
6944 horizontal resolution.  Special characters cannot be printed using this
6945 command.
6947 @kindex tcommand
6948 @pindex DESC
6949 This command is only allowed if the @samp{tcommand} line is present in
6950 the @file{DESC} file.
6951 @item u@var{n} @var{xxx}
6952 This is same as the @samp{t} command except that after printing each
6953 character, the current horizontal position is increased by the sum of
6954 the width of that character and@w{ }@var{n}.
6956 This command is only allowed if the @samp{tcommand} line is present in
6957 the @file{DESC} file.
6958 @item n@var{a}@var{b}
6959 @c XXX
6960 @item p@var{n}
6961 @c XXX
6962 @item s@var{n}
6963 @kindex sizescale
6964 @pindex DESC
6965 The argument to the @samp{s} command is in scaled points (units of
6966 points/@var{n}, where @var{n} is the argument to the @samp{sizescale}
6967 command in the @file{DESC} file).
6968 @item f@var{n}
6969 @item x @dots{} \n
6970 Device control.
6971 @c XXX more info
6972 @item D@var{c} @var{x}@dots{}\n
6973 @c XXX
6974 @end table
6976 @node Device Control, Drawing Functions, Output Format, gtroff Output
6977 @subsection Device Control
6978 @cindex device control
6979 @cindex control of devices
6981 The @samp{x} command is normally followed by a letter or word indicating
6982 the function to perform, followed by white space separated arguments.
6984 The first argument can be abbreviated to the first letter.
6986 @table @code
6987 @item x init
6988 @c XXX
6989 @item x T
6990 @c XXX
6991 @item x res @var{n} @var{h} @var{v}
6992 @c XXX
6993 @item x H
6994 @c XXX more info
6995 The argument to the @w{@samp{x Height}} command is also in scaled
6996 points.
6997 @end table
6999 The first three output commands are guaranteed to be:
7001 @example
7002 x T device
7003 x res n h v
7004 x init
7005 @end example
7007 @noindent
7008 For example, the input
7010 @example
7011 crunchy \fH\s+2frog\s0\fP!?
7012 @end example
7014 @noindent
7015 will produce
7017 @c XXX example
7019 @example
7020 ... sample output here ...
7021 @end example
7023 @node Drawing Functions, Line Continuation, Device Control, gtroff Output
7024 @subsection Drawing Functions
7025 @cindex drawing functions
7026 @cindex functions for drawing
7028 @pindex gpic
7029 The @samp{D} drawing command has been extended.  These extensions will
7030 only be used by GNU @code{pic} if the @option{-x} option is given.
7032 @xref{Drawing Requests}.
7034 @table @code
7035 @c XXX ...
7036 @item Df @var{n}
7037 Set the shade of gray to be used for filling solid objects to@w{
7038 }@var{n}; @var{n}@w{ }must be an integer between 0 and@w{ }1000, where 0
7039 corresponds solid white and 1000 to solid black, and values in between
7040 correspond to intermediate shades of gray.  This applies only to solid
7041 circles, solid ellipses and solid polygons.  By default, a level of@w{
7042 }1000 will be used.  Whatever color a solid object has, it should
7043 completely obscure everything beneath it.  A value greater than@w{ }1000
7044 or less than@w{ }0 can also be used: this means fill with the shade of
7045 gray that is currently being used for lines and text.  Normally this
7046 will be black, but some drivers may provide a way of changing this.
7047 @item DC @var{d}
7048 Draw a solid circle with a diameter of@w{ }@var{d} with the leftmost
7049 point at the current position.
7050 @item DE @var{dx} @var{dy}
7051 Draw a solid ellipse with a horizontal diameter of@w{ }@var{dx} and a
7052 vertical diameter of@w{ }@var{dy} with the leftmost point at the current
7053 position.
7054 @item Dp @var{dx1} @var{dy1} @var{dx2} @var{dy2} @dots{} @var{dxn} @var{dyn}
7055 Draw a polygon with.  The first vertex is at the current position, the
7056 second vertex at an offset (@var{dx1},@var{dy1}) from the current
7057 position, the second vertex at an offset (@var{dx2},@var{dy2}) from the
7058 first vertex, and so on up to the @var{n}-th vertex.  At the moment, GNU
7059 @code{pic} only uses this command to generate triangles and rectangles.
7060 @item DP @var{dx1} @var{dy1} @var{dx2} @var{dy2} @dots{} @var{dxn} @var{dyn}
7061 Like @code{Dp} but draw a solid rather than outlined polygon.
7062 @item Dt @var{n}
7063 @cindex line thickness
7064 @cindex thickness of lines
7065 Set the current line thickness to @var{n}@w{ }machine units.
7066 Traditionally, @acronym{UNIX} @code{troff} drivers use a line thickness
7067 proportional to the current point size; drivers should continue to do
7068 this if no @code{Dt} command has been given, or if a @code{Dt} command
7069 has been given with a negative value of@w{ }@var{n}.  A zero value of@w{
7070 }@var{n} selects the smallest available line thickness.
7071 @end table
7073 @findex \D
7074 A difficulty arises in how the current position should be changed after
7075 the execution of these commands.  This is not of great importance since
7076 the code generated by GNU @code{pic} does not depend on this.  Given a
7077 drawing command of the form
7079 @example
7080 \D'@var{c} @var{x1} @var{y1} @var{x2} @var{y2} @dots{} @var{xn} @var{yn}'
7081 @end example
7083 @findex \w
7084 @vindex st
7085 @findex sb
7086 @noindent
7087 where @var{c} is not one of @samp{c}, @samp{e}, @samp{l}, @samp{a} or
7088 @samp{~}, @acronym{UNIX} @code{troff} will treat each of the x@w{ }value
7089 as a horizontal quantity, and each of the y@w{ }values as a vertical
7090 quantity and will assume that the width of the drawn object is sum if
7091 all x@w{ }values, and that the height is the sum of all y@w{ }values.
7092 (The assumption about the height can be seen by examining the @code{st}
7093 and @code{sb} registers after using such a @code{D}@w{ }command in a
7094 @code{\w} escape sequence.)  This rule also holds for all the original
7095 drawing commands with the exception of @code{De}.  For the sake of
7096 compatibility GNU @code{troff} also follows this rule, even though it
7097 produces an ugly result in the case of the @code{Df}, @code{Dt}, and, to
7098 a lesser extent, @code{DE}@w{ }commands.  Thus after executing a
7099 @code{D}@w{ }command of the form
7101 @example
7102 D@var{c} @var{x1} @var{y1} @var{x2} @var{y2} @dots{} @var{xn} @var{yn}
7103 @end example
7105 @noindent
7106 the current position should be increased horizontally by the sum of all
7107 x@w{ }values and vertically by the sum of all y@w{ }values.
7109 @node Line Continuation,  , Drawing Functions, gtroff Output
7110 @subsection Line Continuation
7111 @cindex line continuation in output commands
7112 @cindex output commands, line continuation
7114 There is a continuation convention which permits the argument to the
7115 @w{@samp{x X}} command to contain newlines: When outputting the argument
7116 to the @w{@samp{x X}} command, GNU @code{troff} will follow each newline
7117 in the argument with a @samp{+} character (as usual, it will terminate
7118 the entire argument with a newline); thus if the line after the line
7119 containing the @w{@samp{x X}} command starts with @samp{+}, then the
7120 newline ending the line containing the @w{@samp{x X}} command should be
7121 treated as part of the argument to the @w{@samp{x X}} command, the
7122 @samp{+} should be ignored, and the part of the line following the
7123 @samp{+} should be treated like the part of the line following the
7124 @w{@samp{x X}} command.
7127 @node Font Files,  , gtroff Output, File formats
7128 @section Font Files
7129 @cindex font files
7130 @cindex files, font
7132 The @code{gtroff} font format is roughly a superset of the
7133 @code{ditroff} font format.  Unlike the @code{ditroff} font format,
7134 there is no associated binary format; all files are text files.  The
7135 font files for device @var{name} are stored in a directory
7136 @file{dev@var{name}}.  There are two types of file: a device description
7137 file called @file{DESC} and for each font@w{ }@samp{F} a font file
7138 called@w{ }@file{F}.
7140 @menu
7141 * DESC file format::            
7142 * Font file format::            
7143 @end menu
7145 @node DESC file format, Font file format, Font Files, Font Files
7146 @subsection @file{DESC} file format
7147 @cindex @file{DESC} file format
7148 @cindex font description file format
7149 @cindex format of font description file
7150 @pindex DESC
7152 The @file{DESC} file can contain the following types of line:
7154 @table @code
7155 @kindex res
7156 @item res @var{n}
7157 There are @var{n} machine units per inch.
7158 @kindex hor
7159 @item hor @var{n}
7160 The horizontal resolution is @var{n} machine units.
7161 @kindex vert
7162 @item vert @var{n}
7163 The vertical resolution is @var{n} machine units.
7164 @kindex sizescale
7165 @item sizescale @var{n}
7166 The scale factor for point sizes.  By default this has a value of@w{ }1.
7167 One scaled point is equal to one point/@var{n}.  The arguments to the
7168 @code{unitwidth} and @code{sizes} commands are given in scaled points.
7169 @xref{Fractional Type Sizes}, for more information.
7170 @kindex unitwidth
7171 @item unitwidth @var{n}
7172 Quantities in the font files are given in machine units for fonts whose
7173 point size is @var{n}@w{ }scaled points.
7174 @kindex tcommand
7175 @item tcommand
7176 This means that the postprocessor can handle the @samp{t} and @samp{u}
7177 output commands.
7178 @kindex sizes
7179 @item sizes @var{s1} @var{s2} @dots{} @var{sn} 0
7180 This means that the device has fonts at @var{s1}, @var{s2}, @dots{}
7181 @var{sn} scaled points.  The list of sizes must be terminated by a@w{
7182 }0.  Each @var{si} can also be a range of sizes @var{m}-@var{n}.  The
7183 list can extend over more than one line.
7184 @kindex styles
7185 @item styles @var{S1} @var{S2} @dots{} @var{Sm}
7186 The first @var{m}@w{ }font positions will be associated with styles
7187 @var{S1} @dots{} @var{Sm}.
7188 @kindex fonts
7189 @item fonts @var{n} @var{F1} @var{F2} @var{F3} @dots{} @var{Fn}
7190 Fonts @var{F1} @dots{} @var{Fn} will be mounted in the font positions
7191 @var{m}+1, @dots{}, @var{m}+@var{n} where @var{m} is the number of
7192 styles.  This command may extend over more than one line.  A font name
7193 of@var{ }0 will cause no font to be mounted on the corresponding font
7194 position.
7195 @kindex family
7196 @item family @var{fam}
7197 The default font family is @var{fam}.
7198 @kindex charset
7199 @item charset
7200 This line and everything following in the file are ignored.  It is
7201 allowed for the sake of backwards compatibility.
7202 @end table
7204 The @code{res}, @code{unitwidth}, @code{fonts} and @code{sizes} lines
7205 are compulsory.  Other commands are ignored by @code{gtroff} but may be
7206 used by postprocessors to store arbitrary information about the device
7207 in the @file{DESC} file.
7209 @c XXX add other commands resp. xrefs to output devices
7210 @c XXX add obsolete commands
7212 @node Font file format,  , DESC file format, Font Files
7213 @subsection Font file format
7214 @cindex font file format
7215 @cindex format of font files
7217 A font file has two sections.  The first section is a sequence of lines
7218 each containing a sequence of blank delimited words; the first word in
7219 the line is a key, and subsequent words give a value for that key.
7221 @table @code
7222 @kindex name
7223 @item name @var{F}
7224 The name of the font is@w{ }@var{F}.
7225 @kindex spacewidth
7226 @item spacewidth @var{n}
7227 The normal width of a space is@w{ }@var{n}.
7228 @kindex slant
7229 @item slant @var{n}
7230 The characters of the font have a slant of @var{n}@w{ }degrees.
7231 (Positive means forward.)
7232 @kindex ligatures
7233 @item ligatures @var{lig1} @var{lig2} @dots{} @var{lign} [0]
7234 Characters @var{lig1}, @var{lig2}, @dots{}, @var{lign} are ligatures;
7235 possible ligatures are @samp{ff}, @samp{fi}, @samp{fl}, @samp{ffi} and
7236 @samp{ffl}.  For backwards compatibility, the list of ligatures may be
7237 terminated with a@w{ }0.  The list of ligatures may not extend over more
7238 than one line.
7239 @kindex special
7240 @item special
7241 The font is special; this means that when a character is requested that
7242 is not present in the current font, it will be searched for in any
7243 special fonts that are mounted.
7244 @end table
7246 Other commands are ignored by @code{gtroff} but may be used by
7247 postprocessors to store arbitrary information about the font in the font
7248 file.
7250 @cindex comments in font files
7251 @cindex font files, comments
7252 @kindex #
7253 The first section can contain comments which start with the @samp{#}
7254 character and extend to the end of a line.
7256 The second section contains one or two subsections.  It must contain a
7257 @code{charset} subsection and it may also contain a @code{kernpairs}
7258 subsection.  These subsections can appear in any order.  Each
7259 subsection starts with a word on a line by itself.
7261 @kindex charset
7262 The word @code{charset} starts the character set subsection.  The
7263 @code{charset} line is followed by a sequence of lines.  Each line gives
7264 information for one character.  A line comprises a number of fields
7265 separated by blanks or tabs.  The format is
7267 @c XXX fix it for new HTML additions
7269 @example
7270 @var{name} @var{metrics} @var{type} @var{code} @var{comment}
7271 @end example
7273 @cindex 8-bit input
7274 @cindex input, 8-bit
7275 @findex \N
7276 @kindex ---
7277 @noindent
7278 @var{name} identifies the character: If @var{name} is a single
7279 character@w{ }@var{c} then it corresponds to the @code{gtroff} input
7280 character @var{c}; if it is of the form @samp{\@var{c}} where @var{c} is
7281 a single character, then it corresponds to the @code{gtroff} input
7282 character@w{ }\@var{c}; otherwise it corresponds to the groff input
7283 character @samp{\[@var{name}]}.  (If it is exactly two characters
7284 @var{xx} it can be entered as @samp{\(@var{xx}}.)  @code{gtroff}
7285 supports 8-bit characters; however some utilities have difficulties with
7286 eight-bit characters.  For this reason, there is a convention that the
7287 name @samp{char@var{n}} is equivalent to the single character whose code
7288 is@w{ }@var{n}.  For example, @samp{char163} would be equivalent to the
7289 character with code@w{ }163 which is the pounds sterling sign in @w{ISO
7290 Latin-1} character set.  The name @samp{---} is special and indicates
7291 that the character is unnamed; such characters can only be used by means
7292 of the @code{\N} escape sequence in @code{gtroff}.
7294 @c XXX input encodings vs. output encodings
7296 The @var{type} field gives the character type:
7298 @table @code
7299 @item 1
7300 the character has an descender, for example, `p';
7301 @item 2
7302 the character has an ascender, for example, `b';
7303 @item 3
7304 the character has both an ascender and a descender, for example, `('.
7305 @end table
7307 The @var{code} field gives the code which the postprocessor uses to
7308 print the character.  The character can also be input to @code{gtroff}
7309 using this code by means of the @code{\N} escape sequence.  The code can
7310 be any integer.  If it starts with @samp{0} it will be interpreted as
7311 octal; if it starts with @samp{0x} or @samp{0X} it will be interpreted as
7312 hexadecimal.
7314 Anything on the line after the @var{code} field will be ignored.
7316 The @var{metrics} field has the form:
7318 @example
7319 @var{width}[,@var{height}[,@var{depth}[,@var{italic_correction}
7320   [,@var{left_italic_correction}[,@var{subscript_correction}]]]]]
7321 @end example
7323 @noindent
7324 There must not be any spaces between these subfields (it has been split
7325 here into two lines for better legibility only).  Missing subfields are
7326 assumed to be@w{ }0.  The subfields are all decimal integers.  Since
7327 there is no associated binary format, these values are not required to
7328 fit into a variable of type @samp{char} as they are in @code{ditroff}.
7329 The @var{width} subfield gives the width of the character.  The
7330 @var{height} subfield gives the height of the character (upwards is
7331 positive); if a character does not extend above the baseline, it should
7332 be given a zero height, rather than a negative height.  The @var{depth}
7333 subfield gives the depth of the character, that is, the distance below
7334 the lowest point below the baseline to which the character extends
7335 (downwards is positive); if a character does not extend below above the
7336 baseline, it should be given a zero depth, rather than a negative depth.
7337 The @var{italic_correction} subfield gives the amount of space that
7338 should be added after the character when it is immediately to be
7339 followed by a character from a Roman font.  The
7340 @var{left_italic_correction} subfield gives the amount of space that
7341 should be added before the character when it is immediately to be
7342 preceded by a character from a Roman font.  The
7343 @var{subscript_correction} gives the amount of space that should be
7344 added after a character before adding a subscript.  This should be less
7345 than the italic correction.
7347 A line in the @code{charset} section can also have the format
7349 @example
7350 @var{name} "
7351 @end example
7353 @noindent
7354 This indicates that @var{name} is just another name for the character
7355 mentioned in the preceding line.
7357 @kindex kernpairs
7358 The word @code{kernpairs} starts the kernpairs section.  This contains a
7359 sequence of lines of the form:
7361 @example
7362 @var{c1} @var{c2} @var{n}
7363 @end example
7365 This means that when character @var{c1} appears next to character
7366 @var{c2} the space between them should be increased by@w{ }@var{n}.
7367 Most entries in kernpairs section will have a negative value for@w{
7368 }@var{n}.
7372 @node Installation, Request and Escape Index, File formats, Top
7373 @chapter Installation
7374 @cindex installation
7376 @c XXX
7380 @node Request and Escape Index, Operator Index, Installation, Top
7381 @chapter Request and Escape Index
7383 In this index, escapes are listed with a leading backslash (@samp{\}) to
7384 distinguish them from requests which appear without the leading control
7385 character (normally either @samp{.} or @samp{'}).
7387 @printindex fn
7391 @node Operator Index, Register Index, Request and Escape Index, Top
7392 @chapter Operator Index
7394 @printindex op
7398 @node Register Index, Macro and String Index, Operator Index, Top
7399 @chapter Register Index
7401 @printindex vr
7405 @node Macro and String Index, Glyph Name Index, Register Index, Top
7406 @chapter Macro and String Index
7408 In this index, strings are listed with the calling escape sequence
7409 (@samp{\*}) to distinguish them from macros which appear without the
7410 leading control character (normally either @samp{.} or @samp{'}).
7412 @printindex ma
7416 @node Glyph Name Index, Font File Keyword Index, Macro and String Index, Top
7417 @chapter Glyph Name Index
7419 A glyph name @code{xx} consisting of exactly two characters can be
7420 accessed as @samp{\(xx}.  Glyph names @code{xxx} of any length can be
7421 accessed as @samp{\[xxx]}.
7423 @printindex gl
7427 @node Font File Keyword Index, Program and File Index, Glyph Name Index, Top
7428 @chapter Font File Keyword Index
7430 @printindex ky
7434 @node Program and File Index, Concept Index, Font File Keyword Index, Top
7435 @chapter Program  and File Index
7437 @printindex pg
7441 @node Concept Index,  , Program and File Index, Top
7442 @chapter Concept Index
7444 @printindex cp
7448 @summarycontents
7449 @contents
7450 @bye