* src/roff/nroff/nroff.sh: Fix infinite loop.
[s-roff.git] / doc / groff.texinfo
blob417216e1fb8536a692fdee80dab76af14842aca0
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 items
582 -- 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 @c =====================================================================
608 @c =====================================================================
610 @node Introduction, Invoking groff, Copying, Top
611 @chapter Introduction
612 @cindex introduction
614 GNU @code{troff} (or @code{groff}) is a system for typesetting
615 documents.  @code{troff} is very flexible and has been in existence (and
616 use) for about 3@w{ }decades.  It is quite widespread and firmly
617 entrenched in the @acronym{UNIX} community.
619 @menu
620 * What Is groff?::              
621 * History::                     
622 * groff Capabilities::          
623 * Macro Package Intro::         
624 * Preprocessor Intro::          
625 * Output device intro::         
626 * Credits::                     
627 @end menu
630 @c =====================================================================
632 @node What Is groff?, History, Introduction, Introduction
633 @section What Is @code{groff}?
634 @cindex what is @code{groff}?
635 @cindex @code{groff} -- what is it?
637 @code{groff} is of an older generation of document preparation systems,
638 which operate more like compilers than the more recent interactive
639 @acronym{WYSIWYG}@footnote{What You See Is What You Get} systems.
640 @code{groff} and its contemporary counterpart, @TeX{}, both work using a
641 @dfn{batch} paradigm: The input (or @dfn{source}) files are normal text
642 files with embedded formatting commands.  These files can then be
643 processed by @code{groff} to produce a typeset document on a variety of
644 devices.
646 Likewise, @code{groff} should not be confused with a @dfn{word
647 processor}, since that term connotes an integrated system which includes
648 an editor and a text formatter.  Also, many word processors follow the
649 @acronym{WYSIWYG} paradigm which was discussed earlier.
651 Although @acronym{WYSIWYG} systems may be easier to use, they have a
652 number of disadvantages compared to @code{troff}:
654 @itemize @bullet
655 @item
656 They must be used on a graphics display to do any operations on a
657 document.
659 @item
660 Most of the @acronym{WYSIWYG} systems are either non-free or are not
661 very portable.
663 @item
664 @code{troff} is firmly entrenched in all @acronym{UNIX} systems.
666 @item
667 It is difficult to have a wide range of capabilities available within
668 the confines of a GUI/window system.
670 @item
671 It is more difficult to make global changes to a document.
672 @end itemize
674 @quotation
675 ``GUIs normally make it simple to accomplish simple actions and
676 impossible to accomplish complex actions.''  --Doug Gwyn (22/Jun/91 in
677 @code{comp.unix.wizards})
678 @end quotation
681 @c =====================================================================
683 @node History, groff Capabilities, What Is groff?, Introduction
684 @section History
685 @cindex history
687 @cindex @code{runoff}
688 @cindex @code{rf}
689 @code{troff} can trace its origins back to a formatting program called
690 @code{runoff}, written by J.@w{ }E.@w{ }Saltzer, which ran on MIT's CTSS
691 operating system in the mid-sixties.  This name came from the common
692 phrase of the time ``I'll run off a document.''  Bob Morris ported it to
693 the 635 architecture and called the program @code{roff} (an abbreviation
694 of @code{runoff}).  It has then been rewritten as @code{rf} for the
695 PDP-7 (before having @acronym{UNIX}), and at the same time (1969), Doug
696 McIllroy rewrote an extended and simplified version of @code{roff} in
697 the @acronym{BCPL} programming language.
699 @cindex @code{roff}
700 The first version of @acronym{UNIX} was developed on a PDP-7 which was
701 sitting around Bell Labs.  In 1971 the developers wanted to get a PDP-11
702 for further work on the operating system.  In order to justify the cost
703 for this system, they proposed that they would implement a document
704 formatting system for the AT&T patents division.  This first formatting
705 program was a reimplementation of McIllroy's @code{roff}, written by
706 J.@w{ }F.@w{ }Ossanna.
708 @cindex @code{nroff}
709 When they needed a more flexible language, a new version of @code{roff}
710 called @code{nroff} (Newer @code{roff}) was written.  It had a much more
711 complicated syntax, but provided the basis for all future versions.
712 When they got a Graphic Systems CAT Phototypesetter, Ossanna wrote a
713 version of @code{nroff} which would drive it.  It was dubbed
714 @code{troff} for typesetter @code{roff}, although many people have
715 speculated that it actually means Times @code{roff} because of the use
716 of the Times font family in @code{troff} by default.  As such, the name
717 @code{troff} is pronounced `@w{t-roff}' rather than `trough'.
719 With @code{troff} came @code{nroff} (they were actually the same program
720 except for some @samp{#ifdefs}), which was for producing output for line
721 printers and character terminals.  It understood everything @code{troff}
722 did, and ignored the commands which were not applicable (e.g.@: font
723 changes).
725 Since there are several things which cannot be done easily in
726 @code{troff}, work on several preprocessors began.  These programs would
727 transform certain parts of a document into @code{troff}, which made a
728 very natural use of pipes in @acronym{UNIX}.
730 The @code{eqn} preprocessor allowed mathematical formul@ae{} to be
731 specified in a much simpler and more intuitive manner.  @code{tbl} is a
732 preprocessor for formatting tables.  The @code{refer} preprocessor (and
733 the similar program, @code{bib}) processes citations in a document
734 according to a bibliographic database.
736 Unfortunately, Ossanna's @code{troff} was written in PDP-11 assembly
737 language and produced output specifically for the CAT phototypesetter.
738 He rewrote it in C, although it was now 7000@w{ }lines of uncommented
739 code and still dependent on the CAT.  As the CAT became less common, and
740 was no longer supported by the manufacturer, the need to make it support
741 other devices became a priority.  However, before this could be done, he
742 was killed in an auto accident.
744 @pindex ditroff
745 @cindex @code{ditroff}
746 So, Brian Kernighan took on the task of rewriting @code{troff}.  The
747 newly rewritten version produced a device independent code which was
748 very easy for postprocessors to read and translate to the appropriate
749 printer codes.  Also, this new version of @code{troff} (called
750 @code{ditroff} for `device independent @code{troff}') had several
751 extensions, which included drawing functions.
753 Due to the additional abilities of the new version of @code{troff},
754 several new preprocessors appeared.  The @code{pic} preprocessor
755 provides a wide range of drawing functions.  Likewise the @code{ideal}
756 preprocessor did the same, although via a much different paradigm.  The
757 @code{grap} preprocessor took specifications for graphs, but, unlike
758 other preprocessors, produced @code{pic} code.
760 James Clark began work on a GNU implementation of @code{ditroff} in
761 early@w{ }1989.  The first version, @code{groff}@w{ }0.3.1, was released
762 June@w{ }1990.  @code{groff} included
764 @itemize @bullet
765 @item
766 A replacement for @code{ditroff} with many extensions.
768 @item
769 The @code{soelim}, @code{pic}, @code{tbl}, and @code{eqn} preprocessors.
771 @item
772 Postprocessors for character devices, @sc{PostScript}, @TeX{} DVI, and
773 X@w{ }windows.  GNU @code{troff} also eliminated the need for a separate
774 @code{nroff} program with a postprocessor which would produce
775 @acronym{ASCII} output.
777 @item
778 A version of the @file{me} macros and an implementation of the
779 @file{man} macros.
780 @end itemize
782 Also, a front-end was included which could construct the, sometimes
783 painfully long, pipelines required for all the post- and preprocessors.
785 Development of GNU @code{troff} progressed rapidly, and saw the
786 additions of a replacement for @code{refer}, an implementation of the
787 @file{ms} and @file{mm} macros, and a program to deduce how to format a
788 document (@code{grog}).
790 It was declared a stable (i.e.@: non-beta) package with the release of
791 version@w{ }1.04 around November@w{ }1991.
793 Beginning in@w{ }1999, @code{groff} has new maintainers (the package was
794 an orphan for a few years).  As a result, new features and programs like
795 @code{grn}, a preprocessor for gremlin images, and @code{grohtml}, an
796 output device to produce @acronym{HTML} output, have been added.
799 @c =====================================================================
801 @node groff Capabilities, Macro Package Intro, History, Introduction
802 @section @code{groff} Capabilities
803 @cindex @code{groff} capabilities
804 @cindex capabilities of @code{groff}
806 So what exactly is @code{groff} capable of doing?  @code{groff} provides
807 a wide range of low-level text formatting operations.  Using these, it
808 is possible to perform a wide range of formatting tasks, such as
809 footnotes, table of contents, multiple columns, etc.
811 @itemize @bullet
812 @item
813 Text filling, adjusting, and centering
815 @item
816 Hyphenation
818 @item
819 Page control
821 @item
822 Font and character size control
824 @item
825 Vertical spacing (i.e.@: double spacing)
827 @item
828 Line length and indenting
830 @item
831 Macros, strings, diversions, and traps
833 @item
834 Number registers
836 @item
837 Tabs, leaders, and fields
839 @item
840 Input and output conventions and character translation
842 @item
843 Overstrike, bracket, line drawing, and zero-width functions
845 @item
846 Local horizontal and vertical motions and the width function
848 @item
849 Three-part titles
851 @item
852 Output line numbering
854 @item
855 Conditional acceptance of input
857 @item
858 Environment switching
860 @item
861 Insertions from the standard input
863 @item
864 Input/output file switching
866 @item
867 Output and error messages
868 @end itemize
871 @c =====================================================================
873 @node Macro Package Intro, Preprocessor Intro, groff Capabilities, Introduction
874 @section Macro Packages
875 @cindex macro packages
877 Since @code{groff} provides such low level facilities, it can be quite
878 difficult to use by itself.  However, @code{groff} provides a
879 @dfn{macro} facility to specify how certain routine operations (e.g.@w{
880 }starting paragraphs, printing headers and footers, etc.)@: should be
881 done.  These macros can be collected together into a @dfn{macro
882 package}.  There are a number of macro packages available; the most
883 common (and the ones described in this manual) are @file{man},
884 @file{mdoc}, @file{me}, @file{ms}, and @file{mm}.
887 @c =====================================================================
889 @node Preprocessor Intro, Output device intro, Macro Package Intro, Introduction
890 @section Preprocessors
891 @cindex preprocessors
893 Although @code{groff} provides most functions needed to format a
894 document, some operations would be unwieldy (e.g.@: to draw pictures).
895 Therefore, programs called preprocessors were written which understand
896 their own language and produce the necessary @code{groff} operations.
897 These preprocessors are able to differentiate their own input from the
898 rest of the document via markers.
900 To use a preprocessor, @acronym{UNIX} pipes are used to feed the output
901 from the preprocessor into @code{groff}.  Any number of preprocessors
902 may be used on a given document; in this case, the preprocessors are
903 linked together into one pipeline.  However, in @code{groff}, the user
904 does not need to construct the pipe, but only tell @code{groff} what
905 preprocessors to use.
907 @code{groff} currently has preprocessors for producing tables
908 (@code{tbl}), typesetting equations (@code{eqn}), drawing pictures
909 (@code{pic} and @code{grn}), and for processing bibliographies
910 (@code{refer}).  An associated program which is useful when dealing with
911 preprocessors is @code{soelim}.
913 A free implementation of @code{grap}, a preprocessor for drawing graphs,
914 can be obtained as an extra package; @code{groff} can use @code{grap}
915 also.
917 There are other preprocessors in existence, but, unfortunately, no free
918 implementations are available.  Among them are preprocessors for drawing
919 mathematical pictures (@code{ideal}) and chemical structures
920 (@code{chem}).
923 @c =====================================================================
925 @node Output device intro, Credits, Preprocessor Intro, Introduction
926 @section Output Devices
927 @cindex postprocessors
928 @cindex output devices
929 @cindex devices for output
931 @code{groff} actually produces device independent code which may be fed
932 into a postprocessor which will produce output for a particular device.
933 Currently, @code{groff} has postprocessors for @sc{PostScript},
934 character terminals, X@w{ }Windows (for previewing), @TeX{} DVI format,
935 HP LaserJet@w{ }4 and Canon LBP printers (which use @acronym{CAPSL}),
936 and @acronym{HTML}.
939 @c =====================================================================
941 @node Credits,  , Output device intro, Introduction
942 @section Credits
943 @cindex credits
945 Large portions of this manual were taken from existing documents, most
946 notably, the manual pages for the @code{groff} package by James Clark,
947 and Eric Allman's papers on the @file{me} macro package.
949 The section on the @file{man} macro package is partly based on Susan@w{
950 }G.@: Kleinmann's @file{groff_man} manual page written for the Debian
951 GNU/Linux system.
955 @c =====================================================================
956 @c =====================================================================
958 @node Invoking groff, Tutorial for Macro Users, Introduction, Top
959 @chapter Invoking @code{groff}
960 @cindex invoking @code{groff}
961 @cindex @code{groff} invocation
963 @pindex groff
964 @pindex gtroff
965 This section focuses on how to invoke the @code{groff} front end.  This
966 front end takes care of the details of constructing the pipeline among
967 the preprocessors, @code{gtroff} and the postprocessor.
969 It has become a tradition that GNU programs get the prefix @samp{g} to
970 distinguish it from its original counterparts provided by the host
971 (@pxref{Environment}, for more details).  Thus, for example, @code{geqn}
972 is GNU @code{eqn}.  On operating systems like Linux or the Hurd, which
973 don't contain proprietary software, this prefix is omitted since GNU
974 @code{troff} is the only used incarnation of @code{troff}.  Exception:
975 @code{groff} is never replaced by @code{roff}.
977 @menu
978 * Groff Options::               
979 * Environment::                 
980 * Invocation Examples::         
981 @end menu
984 @c =====================================================================
986 @node Groff Options, Environment, Invoking groff, Invoking groff
987 @section Options
988 @cindex options
990 @pindex groff
991 @pindex gtroff
992 @pindex gpic
993 @pindex geqn
994 @pindex ggrn
995 @pindex grap
996 @pindex gtbl
997 @pindex grefer
998 @pindex gsoelim
999 @code{groff} normally runs the @code{gtroff} program and a postprocessor
1000 appropriate for the selected device.  The default device is @samp{ps}.
1001 It can optionally preprocess with any of @code{gpic}, @code{geqn},
1002 @code{gtbl}, @code{ggrn}, @code{grap}, @code{grefer}, or @code{gsoelim}.
1004 This section only documents options to the @code{groff} front end.  Many
1005 of the arguments to @code{groff} are passed on to @code{gtroff},
1006 therefore those are also included.  Arguments to pre- or postprocessors
1007 can be found in @ref{Invoking gpic}, @ref{Invoking geqn}, @ref{Invoking
1008 gtbl}, @ref{Invoking ggrn}, @ref{Invoking grefer}, @ref{Invoking
1009 gsoelim}, @ref{Invoking grotty}, @ref{Invoking grops}, @ref{Invoking
1010 grohtml}, @ref{Invoking grodvi}, @ref{Invoking grolj4}, @ref{Invoking
1011 grolbp}, and @ref{Invoking gxditview}.
1013 The command line format for @code{groff} is:
1015 @example
1016 groff [ -abeghilpstvzCEGNRSUVXZ ] [ -F@var{dir} ] [ -m@var{name} ]
1017       [ -T@var{def} ] [ -f@var{fam} ] [ -w@var{name} ] [ -W@var{name} ]
1018       [ -M@var{dir} ] [ -d@var{cs} ] [ -r@var{cn} ] [ -n@var{num} ]
1019       [ -o@var{list} ] [ -P@var{arg} ] [ -L@var{arg} ] [ -I@var{dir} ]
1020       [ @var{files}@dots{} ]
1021 @end example
1023 The command line format for @code{gtroff} is as follows.  As can be
1024 seen, many of the options to @code{groff} are actually passed on to
1025 @code{gtroff}.
1027 @example
1028 gtroff [ -abivzCERU ] [ -w@var{name} ] [ -W@var{name} ] [ -d@var{cs} ]
1029        [ -f@var{fam} ] [ -m@var{name} ] [ -n@var{num} ]
1030        [ -o@var{list} ] [ -r@var{cn} ] [ -T@var{name} ]
1031        [ -F@var{dir} ] [ -M@var{dir} ] [ @var{files}@dots{} ]
1032 @end example
1034 Options without an argument can be grouped behind a single @option{-}.
1035 A filename of @samp{-} denotes the standard input.  It is possible to
1036 have whitespace between an option and its parameter.
1038 @pindex grog
1039 The @code{grog} command can be used to guess the correct @code{groff}
1040 command to format a file.
1042 @table @samp
1043 @item -h
1044 Print a help message.
1046 @item -e
1047 Preprocess with @code{geqn}.
1049 @item -t
1050 Preprocess with @code{gtbl}.
1052 @item -g
1053 Preprocess with @code{ggrn}.
1055 @item -G
1056 Preprocess with @code{grap}.
1058 @item -p
1059 Preprocess with @code{gpic}.
1061 @item -s
1062 Preprocess with @code{gsoelim}.
1064 @item -R
1065 Preprocess with @code{grefer}.  No mechanism is provided for passing
1066 arguments to @code{grefer} because most @code{grefer} options have
1067 equivalent commands which can be included in the file.  @xref{grefer},
1068 for more details.
1070 @pindex troffrc
1071 @pindex troffrc-end
1072 Note that @code{gtroff} also accepts a @option{-R} option, which is not
1073 accessible via @code{groff}.  This option prevents the loading of the
1074 @file{troffrc} and @file{troffrc-end} files.
1076 @item -v
1077 Make programs run by @code{groff} print out their version number.
1079 @item -V
1080 Print the pipeline on stdout instead of executing it.
1082 @item -z
1083 Suppress output from @code{gtroff}.  Only error messages will be
1084 printed.
1086 @item -Z
1087 Do not postprocess the output of @code{gtroff}.  Normally @code{groff}
1088 will automatically run the appropriate postprocessor.
1090 @item -P@var{arg}
1091 Pass @var{arg} to the postprocessor.  Each argument should be passed
1092 with a separate @option{-P} option.  Note that @code{groff} does not
1093 prepend @samp{-} to @var{arg} before passing it to the postprocessor.
1095 @item -l
1096 Send the output to a printer.  The command used for this is specified by
1097 the print command in the device description file.
1099 @item -L@var{arg}
1100 Pass @var{arg} to the spooler.  Each argument should be passed with a
1101 separate @option{-L} option.  Note that @code{groff} does not prepend a
1102 @samp{-} to @var{arg} before passing it to the postprocessor.
1104 @item -T@var{dev}
1105 Prepare output for device @var{dev}.  The default device is @samp{ps}.
1106 The following are the output devices currently available:
1107 @table @code
1108 @item ps
1109 For @sc{PostScript} printers and previewers.
1111 @item dvi
1112 For @TeX{} DVI format.
1114 @item X75
1115 For a 75@dmn{dpi} X11 previewer.
1117 @item X100
1118 For a 100@dmn{dpi} X11 previewer.
1120 @item ascii
1121 For typewriter-like devices.
1123 @item latin1
1124 For typewriter-like devices using the @w{ISO Latin-1} (@w{ISO 8859-1})
1125 character set.
1127 @item utf8
1128 For typewriter-like devices which use the Unicode (@w{ISO 10646})
1129 character set with @w{UTF-8} encoding.
1131 @item cp1047
1132 @cindex @acronym{EBCDIC} encoding
1133 @cindex cp1047
1134 @cindex IBM cp1047
1135 For typewriter-like devices which use the @acronym{EBCDIC} encoding IBM
1136 cp1047.
1138 @item lj4
1139 For an HP LaserJet4-compatible (or other PCL5-compatible) printer.
1141 @item lbp
1142 For Canon @acronym{CAPSL} printers (@w{LBP-4} and @w{LBP-8} series laser
1143 printers).
1145 @item html
1146 To produce @acronym{HTML} output.
1147 @end table
1149 @vindex .T
1150 @maindex \*(.T
1151 The predefined @code{gtroff} string register @code{.T} contains the
1152 current output device; the read-only number register @code{.T} is set
1153 to@w{ }1 if this option is used (which is always true if @code{groff} is
1154 used to call @code{gtroff}).  @xref{Built-in Registers}.
1156 The postprocessor to be used for a device is specified by the
1157 @code{postpro} command in the device description file.  (@xref{Font
1158 Files}, for more info.)  This can be overridden with the @option{-X}
1159 option.
1161 @item -X
1162 Preview with @code{gxditview} instead of using the usual postprocessor.
1163 This is unlikely to produce good results except with @option{-Tps}.
1165 Note that this is not the same as using @option{-TX75} or
1166 @option{-TX100} to view a document with @code{gxditview}: The former
1167 will us the metrics of the specified device, whereas the latter will use
1168 X-specific fonts and metrics.
1170 @item -N
1171 Don't allow newlines with @code{eqn} delimiters.  This is the same as
1172 the @option{-N} option in @code{geqn}.
1174 @item -S
1175 Safer mode.  Pass the @option{-S} option to @code{gpic} and use the
1176 @option{-msafer} macros with @code{gtroff} (enabled by default).
1178 @item -U
1179 Unsafe mode.  Reverts to the old unsafe behaviour.
1181 @item -a
1182 @vindex .A
1183 Generate an @acronym{ASCII} approximation of the typeset output.  The
1184 read-only register @code{.A} is then set to@w{ }1.  @xref{Built-in
1185 Registers}.
1187 @item -b
1188 Print a backtrace with each warning or error message.  This backtrace
1189 should help track down the cause of the error.  The line numbers given
1190 in the backtrace may not always be correct: @code{gtroff} can get
1191 confused by @code{as} or @code{am} requests while counting line numbers.
1193 @item -i
1194 Read the standard input after all the named input files have been
1195 processed.
1197 @item -w@var{name}
1198 Enable warning @var{name}.  Available warnings are described in
1199 @ref{Debugging}.  Multiple @option{-w} options are allowed.
1201 @item -W@var{name}
1202 Inhibit warning @var{name}.  Multiple @option{-W} options are allowed.
1204 @item -E
1205 Inhibit all error messages.
1207 @item -C
1208 Enable compatibility mode.
1210 @item -d@var{cs}
1211 @itemx -d@var{name}=s
1212 Define @var{c} or @var{name} to be a string @var{s}.  @var{c} must be a
1213 one-letter name; @var{name} can be of arbitrary length.
1215 @item -f@var{fam}
1216 Use @var{fam} as the default font family.
1218 @item -m@var{name}
1219 Read in the file @file{tmac.@var{name}}.  Normally this will be searched
1220 for in the library directory of @code{groff}.
1222 @item -n@var{num}
1223 Number the first page @var{num}.
1225 @item -o@var{list}
1226 @vindex .P
1227 Output only pages in @var{list}, which is a comma-separated list of page
1228 ranges; @var{n} means print page @var{n}, @samp{@var{m}-@var{n}} means
1229 print every page between @var{m} and @var{n}, @samp{-@var{n}} means
1230 print every page up to @var{n}, @samp{@var{n}-} means print every page
1231 from @var{n}.  @code{gtroff} will exit after printing the last page in
1232 the list.
1234 Within @code{gtroff}, this information can be extracted with the
1235 @samp{.P} register.  @xref{Built-in Registers}.
1237 @item -r@var{cn}
1238 @itemx -r@var{name}=@var{n}
1239 Set number register @var{c} or @var{name} to @var{n}.  @var{c} must be a
1240 one-letter name; @var{name} can be of arbitrary length.  @var{n} can be
1241 any @code{gtroff} numeric expression.
1243 @item -F@var{dir}
1244 Search @var{dir} for subdirectories dev@var{name} (@var{name} is the
1245 name of the device) for the @file{DESC} file and font files before the
1246 normal directory.
1248 @item -M@var{dir}
1249 Search directory @var{dir} for macro files before the normal directory.
1251 @item -I@var{dir}
1252 This option is as described in @ref{gsoelim}.  It implies the
1253 @option{-s} option.
1254 @end table
1257 @c =====================================================================
1259 @node Environment, Invocation Examples, Groff Options, Invoking groff
1260 @section Environment
1261 @cindex environment variables
1262 @cindex variables in environment
1264 There are also several environment variables (of the operating system,
1265 not within @code{gtroff}) which can modify the behavior of @code{groff}.
1267 @table @code
1268 @item GROFF_COMMAND_PREFIX
1269 @tindex GROFF_COMMAND_PREFIX
1270 If this is set to @var{X}, then @code{groff} will run
1271 @var{X}@code{troff} instead of @code{gtroff}.  This also applies to
1272 @code{tbl}, @code{pic}, @code{eqn}, @code{grn}, @code{refer}, and
1273 @code{soelim}.  It does not apply to @code{grops}, @code{grodvi},
1274 @code{grotty}, @code{grohtml}, @code{grolj4}, and @code{gxditview}.
1276 @item GROFF_TMAC_PATH
1277 @tindex GROFF_TMAC_PATH
1278 A colon separated list of directories in which to search for macro
1279 files.
1281 @item GROFF_TYPESETTER
1282 @tindex GROFF_TYPESETTER
1283 The default output device.
1285 @item GROFF_FONT_PATH
1286 @tindex GROFF_FONT_PATH
1287 A colon separated list of directories in which to search for the
1288 @code{dev}@var{name} directory.
1290 @item PATH
1291 @tindex PATH
1292 The search path for commands executed by @code{groff}.
1294 @item GROFF_TMPDIR
1295 @tindex GROFF_TMPDIR
1296 @tindex TMPDIR
1297 The directory in which temporary files will be created.  If this is not
1298 set and @env{TMPDIR} is set, temporary files will be created in that
1299 directory.  Otherwise temporary files will be created in @code{/tmp}.
1300 The @code{grops} and @code{grefer} commands can create temporary files.
1301 @end table
1304 @c =====================================================================
1306 @node Invocation Examples,  , Environment, Invoking groff
1307 @section Invocation Examples
1308 @cindex invocation examples
1309 @cindex examples of invocation
1311 This section will list several common uses of @code{groff} and the
1312 command line which will accomplish it.
1314 @example
1315 groff file
1316 @end example
1318 @noindent
1319 This command processes @var{file} without a macro package or a
1320 preprocessor.  The output device is the default, @var{ps}, and the
1321 output is sent to stdout.
1323 @example
1324 groff -t -mandoc -Tascii file | less
1325 @end example
1327 @noindent
1328 This is basically what a call to the @code{man} program does.  The
1329 manual page @var{file} is processed with the @file{mandoc} macros (which
1330 in turn either calls the @file{man} or the @file{mdoc} macro package),
1331 using the @code{tbl} preprocessor and the @acronym{ASCII} output device.
1332 Finally, the result is displayed with the @code{less} pager.
1334 @example
1335 groff -X -m me file
1336 @end example
1338 @noindent
1339 Preview @var{file} with @code{gxditview}, using the @file{me} macro
1340 package.  Since no @option{-T} option is specified, use the default
1341 device (@samp{ps}).  Note that you can either say @w{@samp{-m me}} or
1342 @w{@samp{-me}}; the latter is an anachronism from the early days of
1343 @acronym{UNIX}.@footnote{The same is true for the other main macro
1344 packages that come with @code{groff}: @file{man}, @file{mdoc},
1345 @file{ms}, @file{mm}, and @file{mandoc}.  This won't work in general;
1346 for example, to load @file{tmac.safer}, either @samp{-msafer} or
1347 @w{@samp{-m safer}} must be used.}
1349 @example
1350 groff -man -rD1 -z file
1351 @end example
1353 @noindent
1354 Check @var{file} with the @file{man} macro package, forcing double-sided
1355 printing -- don't produce any output.
1357 @c ---------------------------------------------------------------------
1359 @menu
1360 * grog::                        
1361 @end menu
1363 @node grog,  , Invocation Examples, Invocation Examples
1364 @subsection @code{grog}
1366 @code{grog} reads files and guesses which of the @code{groff}
1367 preprocessors and/or macro packages are are required for formatting
1368 them, and prints the @code{groff} command including those options on the
1369 standard output.  The options generated are one of @option{-e},
1370 @option{-man}, @option{-me}, @option{-mm}, @option{-ms}, @option{-p},
1371 @option{-R}, @option{-g}, @option{-G}, @option{-s}, and @option{-t}.
1373 A filename of @samp{-} is taken to refer to the standard input.  If no
1374 files are specified the standard input will be read.  Any specified
1375 options will be included in the printed command.  No space is allowed
1376 between options and their arguments.  For example,
1378 @example
1379 grog -Tdvi paper.ms
1380 @end example
1382 @noindent
1383 will guess the appropriate command to print @file{paper.ms} and then
1384 print it to the command line after adding the @option{-Tdvi} option.
1385 For direct execution, enclose the call to @code{grog} in backquotes on
1386 the @acronym{UNIX} shell prompt:
1388 @example
1389 `grog -Tdvi paper.ms` > paper.dvi
1390 @end example
1392 @noindent
1393 As seen in the example, it is still necessary to redirect the output to
1394 something meaningful (i.e.@: either a file or a pager program like
1395 @code{less}).
1399 @c =====================================================================
1400 @c =====================================================================
1402 @node Tutorial for Macro Users, Macro Packages, Invoking groff, Top
1403 @chapter Tutorial for Macro Users
1404 @cindex tutorial for macro users
1405 @cindex macro tutorial for users
1406 @cindex user's tutorial for macros
1407 @cindex user's macro tutorial
1409 Most users tend to use a macro package to format their papers.  This
1410 means that the whole breadth of @code{groff} is not necessary for most
1411 people.  This chapter covers the material needed to efficiently use a
1412 macro package.
1414 @menu
1415 * Basics::                      
1416 * Common Features::             
1417 @end menu
1420 @c =====================================================================
1422 @node Basics, Common Features, Tutorial for Macro Users, Tutorial for Macro Users
1423 @section Basics
1424 @cindex basics
1426 This section covers some of the basic concepts necessary to understand
1427 how to use a macro package.@footnote{This section is derived from
1428 @cite{Writing Papers with nroff using -me} by Eric P.@w{ }Allman.}
1429 References are made throughout to more detailed information, if desired.
1431 @code{gtroff} reads an input file prepared by the user and outputs a
1432 formatted document suitable for publication or framing.  The input
1433 consists of text, or words to be printed, and embedded commands
1434 (@dfn{requests} and @dfn{escapes}), which tell @code{gtroff} how to
1435 format the output.  For more detail on this @pxref{Embedded Commands}.
1437 The word @dfn{argument} is used in this manual to mean a word or number
1438 which appears on the same line as a request which modifies the meaning
1439 of that request.  For example, the request
1441 @example
1443 @end example
1445 @noindent
1446 spaces one line, but
1448 @example
1449 .sp 4
1450 @end example
1452 @noindent
1453 spaces four lines.  The number@w{ }4 is an argument to the @code{sp}
1454 request which says to space four lines instead of one.  Arguments are
1455 separated from the request and from each other by spaces.  More details
1456 on this can be found in @ref{Request Arguments}.
1458 The primary function of @code{gtroff} is to collect words from input
1459 lines, fill output lines with those words, justify the right hand margin
1460 by inserting extra spaces in the line, and output the result.  For
1461 example, the input:
1463 @example
1464 Now is the time
1465 for all good men
1466 to come to the aid
1467 of their party.
1468 Four score and seven
1469 years ago,...
1470 @end example
1472 @noindent
1473 will be read, packed onto output lines, and justified to produce:
1475 @quotation
1476 Now is the time for all good men to come to the aid of their party.
1477 Four score and seven years ago,...
1478 @end quotation
1480 @cindex break
1481 @cindex line break
1482 Sometimes a new output line should be started even though the current
1483 line is not yet full; for example, at the end of a paragraph.  To do
1484 this it is possible to cause a @dfn{break}, which starts a new output
1485 line.  Some requests cause a break automatically, as do blank input
1486 lines and input lines beginning with a space.
1488 Not all input lines are text to be formatted.  Some of the input lines
1489 are requests which describe how to format the text.  Requests always
1490 have a period (@samp{.}) or an apostrophe (@samp{'}) as the first
1491 character of the input line.
1493 The text formatter also does more complex things, such as automatically
1494 numbering pages, skipping over page boundaries, putting footnotes in the
1495 correct place, and so forth.
1497 Here a few hints for preparing text for input to @code{gtroff}.  First,
1498 keep the input lines short.  Short input lines are easier to edit, and
1499 @code{gtroff} will pack words onto longer lines anyhow.  In keeping with
1500 this, it is helpful to begin a new line after every period, comma, or
1501 phrase, since common corrections are to add or delete sentences or
1502 phrases.  Secondly, do not hyphenate words at the end of lines --
1503 @code{gtroff} is smart enough to hyphenate words for the user as needed,
1504 but is not smart enough to take hyphens out and join a word back
1505 together.  Also, words such as ``mother-in-law'' should not be broken
1506 over a line, since then a space can occur where not wanted, such as
1507 ``@w{mother- in}-law''.
1509 @findex ls
1510 @cindex double spacing
1511 @cindex spacing
1512 @code{gtroff} will double space output text automatically if using the
1513 request @w{@samp{.ls 2}}.  Single spaced mode can be reactivated by
1514 typing @w{@samp{.ls 1}}.
1516 A number of requests allow to change the way the output looks, sometimes
1517 called the @dfn{layout} of the output page.  Most of these requests
1518 adjust the placing of @dfn{white space} (blank lines or spaces).
1520 @findex bp
1521 @cindex new page
1522 The @samp{.bp} request starts a new page, causing a line break.
1524 @findex sp
1525 @cindex blank lines
1526 @cindex empty lines
1527 @cindex lines, empty
1528 The request @w{@samp{.sp @var{N}}} leaves @var{N}@w{ }lines of blank
1529 space.  @var{N}@w{ }can be omitted (meaning skip a single line) or can
1530 be of the form @var{N}i (for @var{N}@w{ }inches) or @var{N}c (for
1531 @var{N}@w{ }centimeters).  For example, the input:
1533 @example
1534 .sp 1.5i
1535 My thoughts on the subject
1537 @end example
1539 @noindent
1540 leaves one and a half inches of space, followed by the line ``My
1541 thoughts on the subject'', followed by a single blank line.
1543 @findex ce
1544 @cindex centering lines
1545 @cindex lines, centering
1546 Text lines can be centered by using the @code{ce} request.  The line
1547 after @code{ce} is centered (horizontally) on the page.  To center more
1548 than one line, use @w{@samp{.ce @var{N}}} (where @var{N} is the number
1549 of lines to center), followed by the @var{N}@w{ }lines.  To center many
1550 lines without counting them, type:
1552 @example
1553 .ce 1000
1554 lines to center
1555 .ce 0
1556 @end example
1558 @noindent
1559 The @w{@samp{.ce 0}} request tells @code{groff} to center zero more
1560 lines, in other words, stop centering.
1562 @findex br
1563 @cindex line break
1564 @cindex break
1565 All of these requests cause a break; that is, they always start a new
1566 line.  To start a new line without performing any other action, use
1567 @code{br}.
1570 @c =====================================================================
1572 @node Common Features,  , Basics, Tutorial for Macro Users
1573 @section Common Features
1574 @cindex common features
1575 @cindex features, common
1577 @code{gtroff} provides very low level operations for formatting a
1578 document.  There are many common routine operations which are done in
1579 all documents.  These common operations are written into @dfn{macros}
1580 and collected into a @dfn{macro package}.
1582 All macro packages provide certain common capabilities which fall into
1583 the following categories.
1585 @c ---------------------------------------------------------------------
1587 @menu
1588 * Paragraphs::                  
1589 * Sections and Chapters::       
1590 * Headers and Footers::         
1591 * Page Layout Adjustment::      
1592 * Displays::                    
1593 * Footnotes and Annotations::   
1594 * Table of Contents::           
1595 * Indices::                     
1596 * Paper Formats::               
1597 * Multiple Columns::            
1598 * Font and Size Changes::       
1599 * Predefined Strings::          
1600 * Preprocessor Support::        
1601 * Configuration and Customization::  
1602 @end menu
1604 @node Paragraphs, Sections and Chapters, Common Features, Common Features
1605 @subsection Paragraphs
1606 @cindex paragraphs
1608 One of the most common and most used capability is starting a paragraph.
1609 There are a number of different types of paragraphs, any of which can be
1610 initiated with macros supplied by the macro package.  Normally,
1611 paragraphs start with a blank line and the first line indented, like the
1612 text in this manual.  There are also block style paragraphs, which omit
1613 the indentation:
1615 @example
1616 Some   men  look   at  constitutions   with  sanctimonious
1617 reverence, and deem them like the ark of the covenant, too
1618 sacred to be touched.
1619 @end example
1621 @noindent
1622 And there are also indented paragraphs which begin with a tag or label
1623 at the margin and the remaining text indented.
1625 @example
1626 one   This is  the first paragraph.  Notice  how the first
1627       line of  the resulting  paragraph lines up  with the
1628       other lines in the paragraph.
1629 longlabel
1630       This  paragraph   had  a  long   label.   The  first
1631       character of text on the first line will not line up
1632       with  the  text  on  second  and  subsequent  lines,
1633       although they will line up with each other.
1634 @end example
1636 A variation of this is a bulleted list.
1638 @c XXX description
1640 @c ---------------------------------------------------------------------
1642 @node Sections and Chapters, Headers and Footers, Paragraphs, Common Features
1643 @subsection Sections and Chapters
1645 Most macro packages supply some form of section headers.  The simplest
1646 kind is simply the heading on a line by itself in bold type.  Others
1647 supply automatically numbered section heading or different heading
1648 styles at different levels.  Some, more sophisticated, macro packages
1649 supply macros for starting chapters and appendices.
1651 @c ---------------------------------------------------------------------
1653 @node Headers and Footers, Page Layout Adjustment, Sections and Chapters, Common Features
1654 @subsection Headers and Footers
1656 Every macro package gives some way to manipulate the headers and
1657 footers (or @dfn{titles}) on each page.  Some packages will allow for
1658 different ones on the even and odd pages (for material printed in a book
1659 form).
1661 The titles are called three-part titles, that is, there is a
1662 left-justified part, a centered part, and a right-justified part.  An
1663 automatically generated page number may be put in any of these fields
1664 with the @samp{%} character (@pxref{Page Layout} for more details).
1666 @c ---------------------------------------------------------------------
1668 @node Page Layout Adjustment, Displays, Headers and Footers, Common Features
1669 @subsection Page Layout
1671 Most macro packages let the user specify top and bottom margins and
1672 other details about the appearance of the printed pages.
1674 @c ---------------------------------------------------------------------
1676 @node Displays, Footnotes and Annotations, Page Layout Adjustment, Common Features
1677 @subsection Displays
1678 @cindex displays
1680 Displays are sections of text to be set off from the body of the paper.
1681 Major quotes, tables, and figures are types of displays, as are all the
1682 examples used in this document.
1684 @cindex quotes, major
1685 @cindex major quotes
1686 @dfn{Major quotes} are quotes which are several lines long, and hence
1687 are set in from the rest of the text without quote marks around them.
1689 @cindex list
1690 A @dfn{list} is an indented, single spaced, unfilled display.  Lists
1691 should be used when the material to be printed should not be filled and
1692 justified like normal text, such as columns of figures or the examples
1693 used in this paper.
1695 @cindex keep
1696 A @dfn{keep} is a display of lines which are kept on a single page if
1697 possible.  An example for a keep might be a diagram.  Keeps differ from
1698 lists in that lists may be broken over a page boundary whereas keeps
1699 will not.
1701 @cindex keep, floating
1702 @cindex floating keep
1703 Floating keeps move relative to the text.  Hence, they are good for
1704 things which will be referred to by name, such as ``See figure@w{ }3''.
1705 A floating keep will appear at the bottom of the current page if it will
1706 fit; otherwise, it will appear at the top of the next page.  Meanwhile,
1707 the surrounding text will `flow' around the keep, thus leaving now blank
1708 areas.
1710 @c ---------------------------------------------------------------------
1712 @node Footnotes and Annotations, Table of Contents, Displays, Common Features
1713 @subsection Footnotes and Annotations
1714 @cindex footnotes
1715 @cindex annotations
1717 There are a number of requests to save text for later printing.
1719 @dfn{Footnotes} are printed at the bottom of the current page.
1721 @cindex delayed text
1722 @dfn{Delayed text} is very similar to a footnote except that it is
1723 printed when called for explicitly.  This allows a list of references to
1724 appear (for example) at the end of each chapter, as is the convention in
1725 some disciplines.
1727 Most macro packages which supply this functionality also supply a means
1728 of automatically numbering either type of annotation.
1730 @c ---------------------------------------------------------------------
1732 @node Table of Contents, Indices, Footnotes and Annotations, Common Features
1733 @subsection Table of Contents
1734 @cindex table of contents
1735 @cindex contents, table of
1737 @dfn{Tables of contents} are a type of delayed text having a tag
1738 (usually the page number) attached to each entry after a row of dots.
1739 The table accumulates throughout the paper until printed, usually after
1740 the paper has ended.  Many macro packages will provide the ability to
1741 have several tables of contents (i.e.@: one standard one, one for
1742 tables, etc).
1744 @c ---------------------------------------------------------------------
1746 @node Indices, Paper Formats, Table of Contents, Common Features
1747 @subsection Indices
1748 @cindex index
1750 While some macro packages will use the term @dfn{index}, none actually
1751 provide that functionality.  The facilities they call indices are
1752 actually more appropriate for tables of contents.
1754 @c ---------------------------------------------------------------------
1756 @node Paper Formats, Multiple Columns, Indices, Common Features
1757 @subsection Paper Formats
1758 @cindex paper formats
1760 Some macro packages provide stock formats for various kinds of
1761 documents.  Many of them provide a common format for the title and
1762 opening pages of a technical paper.  The @file{mm} macros in particular
1763 provide formats for letters and memoranda.
1765 @c ---------------------------------------------------------------------
1767 @node Multiple Columns, Font and Size Changes, Paper Formats, Common Features
1768 @subsection Multiple Columns
1770 Some macro packages (except @file{man}) provide the ability to have two
1771 or more columns on a page.
1773 @c ---------------------------------------------------------------------
1775 @node Font and Size Changes, Predefined Strings, Multiple Columns, Common Features
1776 @subsection Font and Size Changes
1778 The built-in font and size functions are not always intuitive, so all
1779 macro packages provide macros to make these operations simpler.
1781 @c ---------------------------------------------------------------------
1783 @node Predefined Strings, Preprocessor Support, Font and Size Changes, Common Features
1784 @subsection Predefined Strings
1786 Most macro packages provide various predefined strings for a variety of
1787 uses; examples are sub- and superscripts, printable dates, quotes and
1788 various special characters.
1790 @c ---------------------------------------------------------------------
1792 @node Preprocessor Support, Configuration and Customization, Predefined Strings, Common Features
1793 @subsection Preprocessor Support
1795 All macro packages provide support for the various preprocessors.
1797 @c ---------------------------------------------------------------------
1799 @node Configuration and Customization,  , Preprocessor Support, Common Features
1800 @subsection Configuration and Customization
1802 Some macro packages provide means of customizing many of details of how
1803 the package behaves.  This ranges from setting the default type size to
1804 changing the appearance of section headers.
1808 @c =====================================================================
1809 @c =====================================================================
1811 @node Macro Packages, Programming Tutorial, Tutorial for Macro Users, Top
1812 @chapter Macro Packages
1813 @cindex macro packages
1814 @cindex packages, macros
1816 This chapter documents the main macro packages that come with
1817 @code{groff}.
1819 @menu
1820 * man::                         
1821 * mdoc::                        
1822 * ms::                          
1823 * me::                          
1824 * mm::                          
1825 @end menu
1828 @c =====================================================================
1830 @node man, mdoc, Macro Packages, Macro Packages
1831 @section @file{man}
1832 @cindex @file{man}
1833 @cindex manual pages
1834 @pindex tmac.an
1835 @pindex tmac.man
1837 This is the most popular and probably the most important macro package
1838 of @code{groff}.  It is easy to use, and a vast majority of manual pages
1839 are based on it.
1841 @menu
1842 * Man options::                 
1843 * Man usage::                   
1844 * Man font macros::             
1845 * Miscellaneous man stuff::     
1846 @end menu
1848 @c ---------------------------------------------------------------------
1850 @node Man options, Man usage, man, man
1851 @subsection Options
1853 The command line format for using the @file{man} macros with
1854 @code{groff} is:
1856 @c XXX document @TMAC_AN_PREFIX@
1858 @example
1859 groff -m man [ -rC1 ] [ -rD1 ] [ -rP@var{nnn} ] [ -rS@var{xx} ]
1860       [ -rX@var{nnn} ] [ @var{files}@dots{} ] 
1861 @end example
1863 It is possible to use @samp{-man} instead of @w{@samp{-m man}}.
1865 @table @code
1866 @item -rC1
1867 If more than one manual page is given on the command line, number the
1868 pages continuously, rather than starting each at@w{ }1.
1870 @item -rD1
1871 Double-sided printing.  Footers for even and odd pages are formatted
1872 differently.
1874 @item -rP@var{nnn}
1875 Enumeration of pages will start with @var{nnn} rather than with@w{ }1.
1877 @item -rS@var{xx}
1878 Use @var{xx} (which can be 10, 11, or@w{ }12@dmn{pt}) as the base
1879 document font size instead of the default value of@w{ }10@dmn{pt}.
1881 @item -rX@var{nnn}
1882 After page @var{nnn}, number pages as @var{nnn}a, @var{nnn}b,
1883 @var{nnn}c, etc.  For example, the option @option{-rX2} will produce the
1884 following page numbers: 1, 2, 2a, 2b, 2c, etc.
1885 @end table
1887 @c ---------------------------------------------------------------------
1889 @node Man usage, Man font macros, Man options, man
1890 @subsection Usage
1892 @pindex man.local
1893 This section describes the available macros for manual pages.  For
1894 further customization, put additional macros and requests into the file
1895 @file{man.local} which will be loaded immediately after @file{tmac.an}.
1897 @maindex TH
1898 @Defmac{TH, title section [@var{extra1}] [@var{extra2}] [@var{extra3}]}
1899 Sets the title of the man page to @var{title} and the section to
1900 @var{section}, which must take on a value between 1 and@w{ }8.  The
1901 value @var{section} may also have a string appended, e.g.@: @samp{.pm},
1902 to indicate a specific subsection of the man pages.
1904 Both @var{title} and @var{section} are positioned at the left and right
1905 in the header line (with @var{section} in parentheses immediately
1906 appended to @var{title}.  @var{extra1} will be positioned in the middle
1907 of the footer line.  @var{extra2} will be positioned at the left in the
1908 footer line (resp.@: at the left on even pages and at the right on odd
1909 pages if double-sided printing is active).  @var{extra3} is centered in
1910 the header line.
1912 For @acronym{HTML} output, headers and footers are completely supressed.
1914 Additionally, this macro starts a new page; the new line number is@w{ }1
1915 again (except if the @option{-rC1} option is given on the command line)
1916 -- this feature is intended only for formatting multiple man pages; a
1917 single man page should contain exactly one @code{TH} macro at the
1918 beginning of the file.
1919 @end_Defmac
1921 @maindex SH
1922 @Defmac{SH, [@var{heading}]}
1923 Sets up an unnumbered section heading sticking out to the left.  Prints
1924 out all the text following @code{SH} up to the end of the line (resp.@:
1925 the text in the next line if there is no argument to @code{SH}) in bold
1926 face, one size larger than the base document size.  Additionally, the
1927 left margin for the following text is reset to its default value.
1928 @end_Defmac
1930 @maindex SS
1931 @Defmac{SS, [@var{heading}]}
1932 Sets up an unnumbered section heading.  Prints out all the text
1933 following @code{SS} up to the end of the line (resp.@: the text in the
1934 next line if there is no argument to @code{SS}) in bold face, at the sam
1935 size as the base document size.  Additionally, the left margin for the
1936 following text is reset to its default value.
1937 @end_Defmac
1939 @maindex TP
1940 @Defmac{TP, [@var{nnn}]}
1941 Sets up an indented paragraph with label.  The indentation is set to
1942 @var{nnn} if that argument is supplied (the default unit is @samp{n} if
1943 omitted), otherwise it is set to the default indentation value.
1945 The first line of text following this macro is interpreted as a string
1946 to be printed flush-left, as it is appropriate for a label.  It is not
1947 interpreted as part of a paragraph, so there is no attempt to fill the
1948 first line with text from the following input lines.  Nevertheless, if
1949 the label is not as wide as the indentation, then the paragraph starts
1950 at the same line (but indented), continuing on the following lines.  If
1951 the label is wider than the indentation, then the descriptive part of
1952 the paragraph begins on the line following the label, entirely indented.
1953 Note that neither font shape nor font size of the label is set to a
1954 default value; on the other hand, the rest of the text will have default
1955 font settings.
1956 @end_Defmac
1958 @maindex LP
1959 @maindex PP
1960 @maindex P
1961 @Defmac{LP}
1962 @Defmacx{PP}
1963 @Defmacx{P}
1964 These macros are mutual aliases.  Any of them causes a line break at the
1965 current position, followed by a vertical space downwards by the amount
1966 specified by the @code{PD} macro.  The font size and shape are reset to
1967 the default value (10@dmn{pt} resp.@: Roman).  Finally, the current left
1968 margin is restored.
1969 @end_Defmac
1971 @maindex IP
1972 @Defmac{IP, [@var{designator}] [@var{nnn}]}
1973 Sets up an indented paragraph, using @var{designator} as a tag to mark
1974 its beginning.  The indentation is set to @var{nnn} if that argument is
1975 supplied (default unit is @samp{n}), otherwise the default indentation
1976 value is used.  Font size and face of the paragraph (but not the
1977 designator) are reset to its default values.  To start an indented
1978 paragraph with a particular indentation but without a designator, use
1979 @samp{""} (two doublequotes) as the first argument of @code{IP}.
1981 For example, to start a paragraph with bullets as the designator and
1982 4@dmn{en} indentation, write
1984 @example
1985 .IP \(bu 4
1986 @end example
1987 @end_Defmac
1989 @maindex HP
1990 @Defmac{HP, [@var{nnn}]}
1991 Sets up a paragraph with hanging left indentation.  The indentation is
1992 set to @var{nnn} if that argument is supplied (default unit is
1993 @samp{n}), otherwise the default indentation value is used.  Font size
1994 and face are reset to its default values.
1995 @end_Defmac
1997 @maindex RS
1998 @Defmac{RS, [@var{nnn}]}
1999 This macro moves the left margin to the right by the value @var{nnn} if
2000 specified (default unit is @samp{n}); otherwise the default indentation
2001 value is used.  Calls to the @code{RS} macro can be nested.
2002 @end_Defmac
2004 @maindex RE
2005 @Defmac{RE, [@var{nnn}]}
2006 This macro moves the left margin back to level @var{nnn}; if no argument
2007 is given, it moves one level back.  The first level (i.e., no call to
2008 @code{RS} yet) has number@w{ }1, and each call to @code{RS} increases
2009 the level by@w{ }1.
2010 @end_Defmac
2012 @maindex SH
2013 @maindex SS
2014 @maindex TP
2015 @maindex LP
2016 @maindex PP
2017 @maindex P
2018 @maindex IP
2019 @maindex HP
2020 To summarize, the following macros cause a line break with the insertion
2021 of vertical space (which amount can be changed with the @code{PD}
2022 macro): @code{SH}, @code{SS}, @code{TP}, @code{LP} (@code{PP},
2023 @code{P}), @code{IP}, and @code{HP}.
2025 @maindex RS
2026 @maindex RE
2027 The macros @code{RS} and @code{RE} also cause a break but no insertion
2028 of vertical space.
2030 @c ---------------------------------------------------------------------
2032 @node Man font macros, Miscellaneous man stuff, Man usage, man
2033 @subsection Macros to set fonts
2035 The standard font is Roman; the default text size is 10@w{ }point.
2037 @maindex SM
2038 @Defmac{SM, [@var{text}]}
2039 Causes the text on the same line or the text on the next line to appear
2040 in a font that is one point size smaller than the default font.
2041 @end_Defmac
2043 @maindex SB
2044 @Defmac{SB, [@var{text}]}
2045 Causes the text on the same line or the text on the next line to appear
2046 in boldface font, one point size smaller than the default font.
2047 @end_Defmac
2049 @maindex BI
2050 @Defmac{BI, text}
2051 Causes text on the same line to appear alternately in bold face and
2052 italic.  The text must be on the same line as the macro call.  Thus
2054 @example
2055 .BI this "word and" that
2056 @end example
2058 @noindent
2059 would cause `this' and `that' to appear in bold face, while `word and'
2060 appears in italics.
2061 @end_Defmac
2063 @maindex IB
2064 @Defmac{IB, text}
2065 Causes text to appear alternately in italic and bold face.  The text
2066 must be on the same line as the macro call.
2067 @end_Defmac
2069 @maindex RI
2070 @Defmac{RI, text}
2071 Causes text on the same line to appear alternately in roman and italic.
2072 The text must be on the same line as the macro call.
2073 @end_Defmac
2075 @maindex IR
2076 @Defmac{IR, text}
2077 Causes text on the same line to appear alternately in italic and roman.
2078 The text must be on the same line as the macro call.
2079 @end_Defmac
2081 @maindex BR
2082 @Defmac{BR, text}
2083 Causes text on the same line to appear alternately in bold face and
2084 roman.  The text must be on the same line as the macro call.
2085 @end_Defmac
2087 @maindex RB
2088 @Defmac{RB, text}
2089 Causes text on the same line to appear alternately in roman and bold
2090 face.  The text must be on the same line as the macro call.
2091 @end_Defmac
2093 @maindex R
2094 @Defmac{R, [@var{text}]}
2095 Causes @var{text} to appear in roman font.  If no text is present on the
2096 line where the macro is called, then the text of the next line appears
2097 in roman.  This is the default font to which text is returned at the end
2098 of processing of the other macros.
2099 @end_Defmac
2101 @maindex B
2102 @Defmac{B, [@var{text}]}
2103 Causes @var{text} to appear in bold face.  If no text is present on the
2104 line where the macro is called, then the text of the next line appears
2105 in bold face.
2106 @end_Defmac
2108 @maindex I
2109 @Defmac{I, [@var{text}]}
2110 Causes @var{text} to appear in italic.  If no text is present on the
2111 line where the macro is called, then the text of the next line appears
2112 in italic.
2113 @end_Defmac
2115 @c ---------------------------------------------------------------------
2117 @node Miscellaneous man stuff,  , Man font macros, man
2118 @subsection Miscellaneous
2120 @pindex grohtml
2121 @cindex @file{man}, default indentation
2122 @cindex default indentation, @file{man}
2123 The default indentation is 7.2@dmn{n} for all output devices except for
2124 @code{grohtml} which uses 1.2@dmn{i} instead.
2126 @maindex DT
2127 @maindex TH
2128 @Defmac{DT}
2129 Sets tabs every 0.5@w{ }inches.  Since this macro is always called
2130 during a @code{TH} request, it makes sense to call it only if the tab
2131 positions have been changed.
2132 @end_Defmac
2134 @maindex PD
2135 @Defmac{PD, [@var{nnn}]}
2136 Adjusts the empty space before a new paragraph (resp.@: section).  The
2137 optional argument gives the amount of space (default units are
2138 @samp{v}); without parameter, the value is reset to its default value
2139 (1@w{ }line for tty devices, 0.4@dmn{v}@w{ }otherwise).
2140 @end_Defmac
2142 @maindex SH
2143 @maindex SS
2144 @maindex TP
2145 @maindex LP
2146 @maindex PP
2147 @maindex P
2148 @maindex IP
2149 @maindex HP
2150 This affects the macros @code{SH}, @code{SS}, @code{TP}, @code{LP}
2151 (resp.@: @code{PP} and @code{P}), @code{IP}, and @code{HP}.
2153 The following strings are defined:
2155 @maindex \*S
2156 @Defmac{\\*S}
2157 Switch back to the default font size.
2158 @end_Defmac
2160 @maindex \*R
2161 @Defmac{\\*R}
2162 The `registered' sign.
2163 @end_Defmac
2165 @maindex \*(Tm
2166 @Defmac{\\*(Tm}
2167 The `trademark' sign.
2168 @end_Defmac
2170 @maindex \*(lq
2171 @maindex \*(rq
2172 @glindex lq
2173 @glindex rq
2174 @Defmac{\\*(lq}
2175 @Defmacx{\\*(rq}
2176 Left and right quote.
2177 This is equal to @code{\(lq} and @code{\(rq}, respectively.
2178 @end_Defmac
2180 @cindex preprocessor, calling convention
2181 @cindex calling convention of preprocessors
2182 If a preprocessor like @code{gtbl} or @code{geqn} is needed, it has
2183 become usage to make the first line of the man page look like this:
2185 @example
2186 .\" @var{word}
2187 @end example
2189 @pindex geqn
2190 @pindex grefer
2191 @pindex gtbl
2192 @pindex man
2193 Note the single space character after the double quote.  @var{word}
2194 consists of letters for the needed preprocessors: @samp{e} for
2195 @code{geqn}, @samp{r} for @code{grefer}, @samp{t} for @code{gtbl}.
2196 Modern implementations of the @code{man} program read this first line
2197 and automatically call the right preprocessor(s).
2200 @c =====================================================================
2202 @node mdoc, ms, man, Macro Packages
2203 @section @file{mdoc}
2204 @cindex @file{mdoc}
2206 @c XXX documentation
2209 @c =====================================================================
2211 @node ms, me, mdoc, Macro Packages
2212 @section @file{ms}
2213 @cindex @file{ms}
2215 @c XXX documentation
2218 @c =====================================================================
2220 @node me, mm, ms, Macro Packages
2221 @section @file{me}
2222 @cindex @file{me}
2224 @c XXX documentation
2227 @c =====================================================================
2229 @node mm,  , me, Macro Packages
2230 @section @file{mm}
2231 @cindex @file{mm}
2233 @c XXX documentation
2237 @c =====================================================================
2238 @c =====================================================================
2240 @node Programming Tutorial, Preprocessors, Macro Packages, Top
2241 @chapter Programming Tutorial
2242 @cindex programming tutorial
2243 @cindex tutorial for programming
2245 This chapter covers @strong{all} of the facilities of @code{gtroff}.
2246 Users of macro packages may skip it if not interested in details.
2249 @menu
2250 * Text::                        
2251 * Input Conventions::           
2252 * Measurements::                
2253 * Expressions::                 
2254 * Identifiers::                 
2255 * Embedded Commands::           
2256 * Registers::                   
2257 * Manipulating Filling and Adjusting::  
2258 * Manipulating Hyphenation::    
2259 * Manipulating Spacing::        
2260 * Tabs and Fields::             
2261 * Character Translations::      
2262 * Troff and Nroff Mode::        
2263 * Line Layout::                 
2264 * Page Layout::                 
2265 * Page Control::                
2266 * Fonts::                       
2267 * Sizes::                       
2268 * Strings::                     
2269 * Conditionals and Loops::      
2270 * Writing Macros::              
2271 * Page Motions::                
2272 * Drawing Requests::            
2273 * Traps::                       
2274 * Diversions::                  
2275 * Environments::                
2276 * I/O::                         
2277 * Postprocessor Access::        
2278 * Miscellaneous::               
2279 * Debugging::                   
2280 * Implementation Differences::  
2281 * Summary::                     
2282 @end menu
2285 @c =====================================================================
2287 @node Text, Input Conventions, Programming Tutorial, Programming Tutorial
2288 @section Text
2289 @cindex text
2291 @code{gtroff} input files contain text with control commands
2292 interspersed throughout.  But, even without control codes, @code{gtroff}
2293 will still do several things with the input text: filling and adjusting,
2294 adding additional space after sentences, hyphenating and inserting
2295 implicit line breaks.
2297 @menu
2298 * Filling and Adjusting::       
2299 * Hyphenation::                 
2300 * Sentences::                   
2301 * Tab Stops::                   
2302 * Implicit Line Breaks::        
2303 @end menu
2305 @c ---------------------------------------------------------------------
2307 @node Filling and Adjusting, Hyphenation, Text, Text
2308 @subsection Filling and Adjusting
2309 @cindex filling and adjusting
2310 @cindex adjusting and filling
2312 When @code{gtroff} reads in text it collects words from input and fits
2313 as many of them together on one output line as it can.  This is known as
2314 @dfn{filling}.
2316 @cindex leading spaces
2317 @cindex spaces, leading
2318 @cindex extra spaces
2319 @cindex spaces, extra
2320 @cindex trailing spaces
2321 @cindex spaces, trailing
2322 Once @code{gtroff} has a @dfn{filled} line it will try to @dfn{adjust}
2323 it.  Which means it will widen the spacing between words until the text
2324 reaches the right margin (in the default adjustment mode).  Extra spaces
2325 between words are preserved, but spaces at the end of lines are ignored.
2326 Spaces at the front of a line will cause a @dfn{break} (breaks will be
2327 explained in @ref{Implicit Line Breaks})
2329 @xref{Manipulating Filling and Adjusting}.
2331 @c ---------------------------------------------------------------------
2333 @node Hyphenation, Sentences, Filling and Adjusting, Text
2334 @subsection Hyphenation
2335 @cindex hyphenation
2337 Since the odds of finding a set of words, for every output line, which
2338 will fit nicely on a line without inserting excessive amounts of space
2339 between words is not great, @code{gtroff} will hyphenate words so that
2340 lines can be justified without there being too much space between words.
2341 It uses an internal hyphenation algorithm (a simplified version of the
2342 algorithm used within @TeX{}) to indicate which words can be hyphenated
2343 and how to do so.  When a word is hyphenated the first part of the word
2344 will be added to the current filled line being output (with an attached
2345 hyphen), and the other portion will be added to the next line to be
2346 filled.
2348 @xref{Manipulating Hyphenation}.
2350 @c ---------------------------------------------------------------------
2352 @node Sentences, Tab Stops, Hyphenation, Text
2353 @subsection Sentences
2354 @cindex sentences
2356 Although it is often debated, some typesetting rules say there should be
2357 different amounts of space after various punctuation marks.  For
2358 example, the @emph{Chicago typsetting manual} says that a period at the
2359 end of a sentence should have twice as much space following it as would
2360 a comma or a period as part of an abbreviation.
2362 @c XXX exact citation of Chigago manual
2364 @cindex sentence space
2365 @cindex space between sentences
2366 @cindex french-spacing
2367 @code{gtroff} does this by flagging certain characters (normally
2368 @samp{!}, @samp{?} and @samp{.}) as @dfn{end of sentence} characters.
2369 When @code{gtroff} encounters one of these characters at the end of a
2370 line it will append two @dfn{sentence spaces} in the formatted output.
2371 (Thus, one of the conventions mentioned in @ref{Input Conventions}.)
2373 @cindex transparent characters
2374 @cindex character, transparent
2375 @glindex dg
2376 @glindex rq
2377 @cindex "
2378 @cindex '
2379 @cindex )
2380 @cindex ]
2381 @cindex *
2382 In addition, the following characters resp.@: glyphs are treated
2383 transparently while handling end of sentence characters: @samp{"},
2384 @samp{'}, @samp{)}, @samp{]}, @samp{*}, @code{dg}, and @code{rq}.
2386 See the @code{cflags} request in @ref{Using Symbols}, for more details.
2388 @findex \&
2389 To prevent the insertion of extra space after an end of sentence
2390 character (at the end of a line), append @code{\&}.
2392 @c ---------------------------------------------------------------------
2394 @node Tab Stops, Implicit Line Breaks, Sentences, Text
2395 @subsection Tab Stops
2396 @cindex tab stops
2397 @cindex stops, tabulator
2398 @cindex tab character
2399 @cindex character, tabulator
2401 @cindex @acronym{EBCDIC} encoding
2402 @code{gtroff} translates @dfn{tabulator characters}, also called
2403 @dfn{tabs} (normally code point @acronym{ASCII} @code{0x09} resp.@:
2404 @acronym{EBCDIC} @code{0x05}), in the input into movements to the next
2405 tabulator stop.  These tab stops are initially located every half inch
2406 across the page.  Using this simple tables can easily be made.  However,
2407 it can often be deceptive as the appearance (and width) of the text on a
2408 terminal and the results from @code{gtroff} can vary greatly.
2410 Also, a possible sticking point is that lines beginning with tab
2411 characters will still be filled, again producing unexpected results.
2412 For example, the following input
2414 @multitable {12345678} {12345678} {12345678} {12345678}
2415 @item
2416 @tab 1 @tab 2 @tab 3
2417 @item
2418 @tab   @tab 4 @tab 5
2419 @end multitable
2421 @noindent
2422 will produce
2424 @multitable {12345678} {12345678} {12345678} {12345678} {12345678} {12345678} {12345678}
2425 @item
2426 @tab 1 @tab 2 @tab 3 @tab   @tab 4 @tab 5
2427 @end multitable
2429 @xref{Tabs and Fields}.
2431 @c ---------------------------------------------------------------------
2433 @node Implicit Line Breaks,  , Tab Stops, Text
2434 @subsection Implicit Line Breaks
2435 @cindex implicit line breaks
2436 @cindex line, implicit breaks
2437 @cindex break
2438 @cindex break, implicit
2439 @cindex line break
2441 An important concept in @code{gtroff} is the @dfn{break}.  When a break
2442 occurs, @code{gtroff} will output the partially filled line
2443 (unjustified), and resume collecting and filling text on the next output
2444 line.
2446 @cindex blank line
2447 @cindex empty line
2448 @cindex line, blank
2449 There are several ways to cause a break in @code{gtroff}.  A blank line
2450 will not only cause a break, but it will also cause a one line vertical
2451 space (effectively a blank line) to be output.
2453 @cindex fill mode
2454 @cindex mode, fill
2455 A line which begins with a space will cause a break and the space will
2456 be output at the beginning of the next line.  Note that this space isn't
2457 adjusted, even in fill mode.
2459 The end of file will also cause a break -- otherwise the last line of
2460 the document may vanish!
2462 Certain requests also cause breaks, implicitly or explicitly.  This will
2463 be discussed in @ref{Manipulating Filling and Adjusting}.
2466 @c =====================================================================
2468 @node Input Conventions, Measurements, Text, Programming Tutorial
2469 @section Input Conventions
2470 @cindex input conventions
2471 @cindex conventions for input
2473 Since @code{gtroff} does filling automatically, it is traditional in
2474 @code{groff} not to try and type things in as nicely formatted
2475 paragraphs.  These are some conventions commonly used when typing
2476 @code{gtroff} text:
2478 @itemize @bullet
2479 @item
2480 Break lines after punctuation, particularly at the end of sentences,
2481 and in other logical places.  Keep separate phrases on lines by
2482 themselves, as entire phrases are often added or deleted when editing.
2484 @item
2485 Try to keep lines less than 40-60@w{ }characters, to allow space for
2486 inserting more text.
2488 @item
2489 Do not try to do any formatting in a @acronym{WYSIWYG} manner (i.e.,
2490 don't try and use spaces to get proper indentation).
2491 @end itemize
2494 @c =====================================================================
2496 @node Measurements, Expressions, Input Conventions, Programming Tutorial
2497 @section Measurements
2498 @cindex measurements
2500 @cindex units of measurement
2501 @cindex basic units
2502 @cindex machine units
2503 @cindex measurement units
2504 @cindex @code{u} unit
2505 @cindex unit, @code{u}
2506 @code{gtroff} (like any other programs) requires numeric parameters to
2507 specify various measurements.  Most numeric parameters@footnote{those
2508 that specify vertical or horizontal motion or a type size} may have a
2509 @dfn{measurement unit} attached.  These units are specified as a single
2510 character which immediately follows the number or expression.  Each of
2511 these units are understood, by @code{gtroff}, to be a multiple of its
2512 @dfn{basic unit}.  So, whenever a different measurement unit is
2513 specified @code{gtroff} converts this into its @dfn{basic units}.  This
2514 basic unit, represented by a @samp{u}, is a device dependent measurement
2515 which is quite small, ranging from 1/75th to 1/72000th of an inch.  The
2516 values may be given as fractional numbers -- nevertheless, fractional
2517 basic units are always rounded to integers.
2519 Some of the measurement units are completely independent of any of the
2520 current settings (e.g.@: type size) of @code{gtroff}.
2522 @table @code
2523 @item i
2524 @cindex inch
2525 @cindex @code{i} unit
2526 @cindex unit, @code{i}
2527 Inches.  An antiquated measurement unit still in use in certain
2528 backwards countries.  One inch is equal to@w{ }2.54@dmn{cm}.
2530 @item c
2531 @cindex centimeter
2532 @cindex @code{c} unit
2533 @cindex unit, @code{c}
2534 Centimeters.  One centimeter is equal to@w{ }0.3937@dmn{in}.
2536 @item p
2537 @cindex points
2538 @cindex @code{p} unit
2539 @cindex unit, @code{p}
2540 Points.  This is a typesetter's measurement used for measure type size.
2541 It is 72@w{ }points to an inch.
2543 @item P
2544 @cindex pica
2545 @cindex @code{P} unit
2546 @cindex unit, @code{P}
2547 Pica.  Another typesetting measurement.  6@w{ }Picas to an inch (and
2548 12@w{ }points to a pica).
2550 @item s
2551 @itemx z
2552 @cindex @code{s} unit
2553 @cindex unit, @code{s}
2554 @cindex @code{z} unit
2555 @cindex unit, @code{z}
2556 @xref{Fractional Type Sizes}, for a discussion of these units.
2557 @end table
2559 The other measurements understood by @code{gtroff} are dependent on
2560 settings currently in effect in @code{gtroff}.  These are very useful
2561 for specifying measurements which should look proper with any size of
2562 text.
2564 @table @code
2565 @item m
2566 @cindex em unit
2567 @cindex @code{m} unit
2568 @cindex unit, @code{m}
2569 Ems.  This unit is equal to the current font size in points.  So called
2570 because it is @emph{approximately} the width of the letter@w{ }@samp{m}
2571 in the current font.
2573 @item n
2574 @cindex en unit
2575 @cindex @code{n} unit
2576 @cindex unit, @code{n}
2577 Ens.  This is half of an em.
2579 @item v
2580 @cindex vertical space
2581 @cindex space, vertical
2582 @cindex @code{v} unit
2583 @cindex unit, @code{v}
2584 Vertical space.  This is equivalent to the current line spacing.
2585 @xref{Sizes}, for more information about this.
2587 @item M
2588 @cindex @code{M} unit
2589 @cindex unit, @code{M}
2590 100ths of an em.
2591 @end table
2593 @menu
2594 * Default Units::               
2595 @end menu
2597 @c ---------------------------------------------------------------------
2599 @node Default Units,  , Measurements, Measurements
2600 @subsection Default Units
2601 @cindex default units
2602 @cindex units, default
2604 Many requests take a default unit.  While this can be helpful at times,
2605 it can cause strange errors in some expressions.  For example, the line
2606 length request expects em units.  Here are several attempts to get a
2607 line length of 3.5@w{ }inches and the results:
2609 @example
2610 3.5i      @result{}   3.5i
2611 7/2       @result{}   0i
2612 7/2i      @result{}   0i
2613 7i/2      @result{}   0.1i
2614 7i/2u     @result{}   3.5i
2615 @end example
2617 @noindent
2618 Everything will be converted to basic units first.  In the above example
2619 it is assumed that 1@dmn{i} equals@w{ }240@dmn{u}, and 1@dmn{m}
2620 equals@w{ }10@dmn{p} (thus 1@dmn{m} equals@w{ }33@dmn{u}).  The value
2621 7i/2 will be first handled as 7i/2m, then converted to 1680u/66u which
2622 is 25@dmn{u}, and this is approximately 0.1@dmn{i}.
2624 As a conclusion, the safest way to specify measurements is to always
2625 attach a scaling indicator.  If you want to multiply or divide by a
2626 certain scalar value, use @samp{u} as the unit for that value.
2629 @c =====================================================================
2631 @node Expressions, Identifiers, Measurements, Programming Tutorial
2632 @section Expressions
2633 @cindex expressions
2635 @code{gtroff} has most of operators common to other languages:
2637 @c XXX more details; examples
2639 @itemize @bullet
2640 @item
2641 @cindex arithmetic operators
2642 @cindex operators, arithmetic
2643 @opindex +
2644 @opindex -
2645 @opindex /
2646 @opindex *
2647 @opindex %
2648 Arithmetic: @samp{+} (addition), @samp{-} (subtraction), @samp{/}
2649 (division), @samp{*} (multiplication), @samp{%} (modulo).
2651 @code{gtroff} only provides integer arithmetic.  The internal type used
2652 for computing results is @samp{int}, which is usually a 32@dmn{bit}
2653 signed integer.
2655 @item
2656 @cindex comparison operators
2657 @cindex operators, comparison
2658 @opindex <
2659 @opindex >
2660 @opindex >=
2661 @opindex <=
2662 @opindex =
2663 @opindex ==
2664 Comparison: @samp{<} (less than), @samp{>} (greater than), @samp{<=}
2665 (less than or equal), @samp{>=} (greater than or equal), @samp{=}
2666 (equal), @samp{==} (the same as @samp{=}).
2668 @item
2669 @cindex logical operators
2670 @cindex operators, logical
2671 @opindex &
2672 @opindex :
2673 Logical: @samp{&} (logical and), @samp{:} (logical or).
2675 @item
2676 @cindex unary operators
2677 @cindex operators, unary
2678 @opindex -
2679 @opindex +
2680 @opindex !
2681 @findex if
2682 @findex while
2683 Unary operators: @samp{-} (negating, i.e.@: changing the sign), @samp{+}
2684 (just for completeness; does nothing in expressions), @samp{!} (logical
2685 not; this works only within @code{if} and @code{while} requests).  See
2686 below for the use of unary operators in motion requests.
2688 @item
2689 @cindex extremum operators
2690 @cindex operators, extremum
2691 @opindex >?
2692 @opindex <?
2693 Extrema: @samp{>?} (maximum), @samp{<?} (minimum).  For example,
2694 @samp{5>?3} yields@w{ }@samp{5}.
2696 @c XXX add examples
2698 @item
2699 @cindex scaling operator
2700 @cindex operator, scaling
2701 Scaling: @code{(@var{c};@var{e})}.  Evaluate @var{e} using @var{c} as
2702 the default scaling indicator.  If @var{c} is missing, ignore scaling
2703 indicators in the evaluation of @var{e}.
2704 @end itemize
2706 @cindex parentheses
2707 @cindex order of evaluation in expressions
2708 @cindex expression, order of evaluation
2709 @opindex (
2710 @opindex )
2711 Parentheses may be used as in any other language.  However, in
2712 @code{gtroff} they are necessary to ensure order of evaluation.
2713 @code{gtroff} has no operator precedence; expressions are evaluated left
2714 to right.  This means that @samp{3+5*4} is evaluated as if it were
2715 parenthesized like @samp{(3+5)*4}, not as @samp{3+(5*4)}, as expected.
2717 @opindex +
2718 @opindex -
2719 @opindex |
2720 @cindex motion operators
2721 @cindex operators, motion
2722 For many requests which cause a motion on the page, the unary operators
2723 work differently.  The @samp{+} and @samp{-} operators then indicate a
2724 motion relative to the current position (down or up, respectively), and
2725 the @samp{|} operator indicates an absolute position on the page or
2726 input line.
2727 @c XXX xref
2728 @samp{+} and @samp{-} are also treated differently by the following
2729 requests and escapes: @code{bp}, @code{in}, @code{ll}, @code{lt},
2730 @code{nm}, @code{nr}, @code{pl}, @code{pn}, @code{po}, @code{ps},
2731 @code{rt}, @code{ti}, @code{\R}, and @code{\s}.  Here the plus and minus
2732 signs indicate increments resp.@: decrements.
2734 @c XXX add more xref
2735 @xref{Setting Registers}.
2737 @cindex space characters in expressions
2738 @cindex expressions and space characters
2739 Due to the way arguments are parsed, spaces are not allowed in
2740 expressions, unless the entire expression is surrounded by parentheses.
2742 @xref{Request Arguments}, and @ref{Conditionals and Loops}.
2745 @c =====================================================================
2747 @node Identifiers, Embedded Commands, Expressions, Programming Tutorial
2748 @section Identifiers
2749 @cindex identifiers
2751 Like any other language, @code{gtroff} has rules for properly formed
2752 @dfn{identifiers}.  In @code{gtroff}, an identifier can be made up of
2753 almost any printable character.  The exception are the following
2754 characters:
2756 @itemize @bullet
2757 @item
2758 @cindex whitespace characters
2759 @cindex newline character
2760 @cindex character, whitespace
2761 Whitespace characters (space, tabs, and newlines).
2763 @item
2764 @cindex character, backspace
2765 @cindex backspace character
2766 @cindex @acronym{EBCDIC} encoding
2767 Backspace (@acronym{ASCII}@w{ }@code{0x08} resp.@: @acronym{EBCDIC}@w{
2768 }@code{0x16}) and character code @code{0x01}.
2770 @item
2771 @cindex illegal input characters
2772 @cindex input characters, illegal
2773 @cindex characters, illegal input
2774 @cindex unicode
2775 The following input characters are illegal and will be ignored if
2776 @code{groff} runs on a machine based on @acronym{ASCII}, causing a
2777 warning message of type @samp{input} (@pxref{Debugging}, for more
2778 details): @code{0x00}, @code{0x0B}, @code{0x0D}-@code{0x1F},
2779 @code{0x80}-@code{0x9F}.
2781 And here the illegal input characters if @code{groff} runs on an
2782 @acronym{EBCDIC} host: @code{0x00}, @code{0x08}, @code{0x09},
2783 @code{0x0B}, @code{0x0D}-@code{0x14}, @code{0x17}-@code{0x1F},
2784 @code{0x30}-@code{0x3F}.
2786 Currently, some of these reserved codepoints are used internally, thus
2787 making it non-trivial to extend @code{gtroff} to cover Unicode or other
2788 character sets resp.@: encodings which use characters of these ranges.
2790 Note that illegal characters will be removed before parsing; an
2791 identifier `foo', followed by an illegal character, followed by `bar'
2792 will be treated as `foobar'.
2793 @end itemize
2795 For example, any of the following is valid.
2797 @example
2801 end-list
2803 @end example
2805 @findex ]
2806 Note that identifiers longer than two characters with a closing bracket
2807 (@samp{]}) in its name can't be accessed with escape sequences which
2808 expect an identifier as a parameter.  For example, @samp{\[foo]]} will
2809 access the glyph @samp{foo}, followed by @samp{]}, whereas
2810 @samp{\C'foo]'} really asks for glyph @samp{foo]}.
2812 @c XXX xref
2814 @Deffn{Escape, \\A, ident}
2815 Whether an identifier @var{ident} is valid in @code{gtroff} can be
2816 tested with the @code{\A} escape.  It expands to the character@w{ }1
2817 or@w{ }0 according to whether its argument (delimited by quotes usually)
2818 is or is not acceptable as the name of a string, macro, diversion,
2819 number register, environment, or font.  It will return@w{ }0 if no
2820 argument is given.  This is useful for looking up user input in some
2821 sort of associative table.
2823 @example
2824 \A'end-list'
2825     @result{} 1
2826 @end example
2827 @end_Deffn
2829 @xref{Escapes}, for details on parameter delimiting characters.
2831 @c XXX add xrefs above
2833 Identifiers in @code{gtroff} can be any length, but, in some contexts,
2834 @code{gtroff} needs to be told where identifiers end and text begins
2835 (and in different ways depending on their length).
2837 @findex (
2838 @findex [
2839 @findex ]
2840 @itemize @bullet
2841 @item
2842 Single character.
2844 @item
2845 Two characters.  Must be prefixed with @samp{(} in some situations.
2847 @item
2848 Arbitrary length (@code{gtroff} only).  Must be bracketed with @samp{[}
2849 and@w{ }@samp{]} in some situations.  Any length identifier can be put
2850 in brackets.
2851 @end itemize
2853 @cindex undefined identifiers
2854 @cindex indentifiers, undefined
2855 Unlike many other programming languages, undefined identifiers are
2856 silently ignored or expanded to nothing.
2858 @c XXX add info about -ww command line option.
2860 @xref{Interpolating Registers}, and @ref{Strings}.
2863 @c =====================================================================
2865 @node Embedded Commands, Registers, Identifiers, Programming Tutorial
2866 @section Embedded Commands
2867 @cindex embedded commands
2868 @cindex commands, embedded
2870 Most documents need more functionality beyond filling, adjusting and
2871 implicit line breaking.  In order to gain further functionality,
2872 @code{gtroff} allows commands to be embedded into the text, in two ways.
2874 The first is a @dfn{request} which takes up an entire line, and does
2875 some large scale operation (e.g.@: break lines, start new pages).
2877 The other is an @dfn{escape} which can be embedded anywhere in the text,
2878 or even as an argument to a request.
2879 @c XXX (Not always?)
2880 Escapes generally do more minor operations like sub- and superscripts,
2881 print a symbol, etc.
2883 @menu
2884 * Requests::                    
2885 * Macros::                      
2886 * Escapes::                     
2887 @end menu
2889 @c ---------------------------------------------------------------------
2891 @node Requests, Macros, Embedded Commands, Embedded Commands
2892 @subsection Requests
2893 @cindex requests
2895 @cindex control character
2896 @cindex character, control
2897 @cindex no-break control character
2898 @cindex character, no-break control
2899 @cindex control character, no-break
2900 @findex '
2901 @findex .
2902 A request line begins with a control character, which is either a single
2903 quote (@samp{'}, the @dfn{no-break control character}) or a period
2904 (@samp{.}, the normal @dfn{control character}).  These can be changed;
2905 see @ref{Character Translations}, for details.  After this there may be
2906 optional tabs or spaces followed by an identifier which is the name of
2907 the request.  This may be followed by any number of space-separated
2908 arguments.
2910 @cindex zero width space character
2911 @cindex character, zero width space
2912 @cindex space character, zero width
2913 @findex \&
2914 To begin a line with a control character without it being interpreted,
2915 precede it with @code{\&}.  This represents a zero width space, which
2916 means it will not affect the output.
2918 In most cases the period is used as a control character.  Several
2919 requests will cause a break implicitly; using the single quote control
2920 character will prevent this.
2922 @menu
2923 * Request Arguments::           
2924 @end menu
2926 @node Request Arguments,  , Requests, Requests
2927 @subsubsection Request Arguments
2928 @cindex request arguments
2929 @cindex arguments to requests
2931 Arguments to requests (and macros) are processed much like the shell:
2932 The line is split into arguments according to spaces.  An argument which
2933 is intended to contain spaces can either be enclosed in quotes (single
2934 or double), or have the spaces @dfn{escaped} with backslashes.
2936 @example
2937 .uh The Mouse Problem
2938 .uh "The Mouse Problem"
2939 .uh The\ Mouse\ Problem
2940 @end example
2942 @findex \~
2943 @findex \@key{SP}
2944 @noindent
2945 The first line is the @code{uh} macro being called with 3 arguments,
2946 @samp{The}, @samp{Mouse}, and @samp{Problem}.  The latter two have the
2947 same effect or calling the @code{uh} macro with one argument @samp{The
2948 Mouse Problem}.@footnote{The last solution, i.e., using escaped spaces,
2949 is `classical' in the sense that it can be found in most @code{troff}
2950 documents.  Nevertheless, it is not optimal in all situations since
2951 @w{@samp{\ }} inserts a fixed-width, non-breaking space character which
2952 can't stretch.  @code{gtroff} provides a different command @code{\~} to
2953 insert a stretchable, non-breaking space.}
2955 @findex ds
2956 Note, however, that the @code{ds} request works differently.
2957 @xref{Strings}, for more details.
2959 @c ---------------------------------------------------------------------
2961 @node Macros, Escapes, Requests, Embedded Commands
2962 @subsection Macros
2963 @cindex macros
2965 @code{gtroff} has a @dfn{macro} facility for defining a series of lines
2966 which can be invoked by name.  They are called in the same manner as
2967 requests -- arguments also may be passed in the same manner.
2969 @xref{Writing Macros}, and @ref{Request Arguments}.
2971 @c ---------------------------------------------------------------------
2973 @node Escapes,  , Macros, Embedded Commands
2974 @subsection Escapes
2975 @cindex escapes
2977 Escapes may occur anywhere in the input to @code{gtroff}.  They begin
2978 with a backslash usually and are followed by a single character which
2979 indicates the function to be performed.  The escape character can be
2980 changed; see @ref{Character Translations}.
2982 @findex (
2983 @findex [
2984 @findex ]
2985 Escape sequences which require an identifier as a parameter accept three
2986 possible syntax forms.
2988 @itemize @bullet
2989 @item
2990 The next single character is the identifier.
2992 @item
2993 If this single character is an opening parenthesis, take the following
2994 two characters as the identifier.  Note that there is no closing
2995 parenthesis after the identifier.
2997 @item
2998 If this single character is an opening bracket, take all characters
2999 until a closing bracket as the identifier.
3000 @end itemize
3002 @noindent
3003 Examples:
3005 @example
3007 \n(XX
3008 \*[TeX]
3009 @end example
3011 @findex '
3012 @cindex argument delimiting characters
3013 @cindex characters, argument delimiting
3014 @cindex delimiting characters for arguments
3015 Other escapes may require several arguments and/or some special format.
3016 In such cases the argument is traditionally enclosed in single quotes
3017 (and quotes are always used in this manual for the definitions of escape
3018 sequences).  The enclosed text is then processed according to what that
3019 escape expects.  Example:
3021 @example
3022 \l'1.5i\(bu'
3023 @end example
3025 @findex \o
3026 @findex \b
3027 @findex \X
3028 Note that the quote character can be replaced with any other character
3029 which does not occur in the argument (even a newline or a space
3030 character) in the following escapes: @code{\o}, @code{\b}, and
3031 @code{\X}.  This makes e.g.
3033 @example
3034 A caf
3039 in Paris
3040   @result{} A caf@'e in Paris
3041 @end example
3043 @noindent
3044 possible, but it is better not to use this feature to avoid confusion.
3046 @findex \%
3047 @findex \@key{SP}
3048 @findex \|
3049 @findex \^
3050 @findex \@{
3051 @findex \@}
3052 @findex \'
3053 @findex \`
3054 @findex \-
3055 @findex \_
3056 @findex \!
3057 @findex \?
3058 @findex \@@
3059 @findex \)
3060 @findex \/
3061 @findex \,
3062 @findex \&
3063 @findex \~
3064 @findex \0
3065 @findex \a
3066 @findex \c
3067 @findex \d
3068 @findex \e
3069 @findex \E
3070 @findex \p
3071 @findex \r
3072 @findex \t
3073 @findex \u
3074 The following escapes sequences (which are handled similarly to
3075 characters since they don't take a parameter) are also allowed as
3076 delimiters: @code{\%}, @w{@samp{\ }}, @code{\|}, @code{\^}, @code{\@{},
3077 @code{\@}}, @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!},
3078 @code{\?}, @code{\@@}, @code{\)}, @code{\/}, @code{\,}, @code{\&},
3079 @code{\~}, @code{\0}, @code{\a}, @code{\c}, @code{\d}, @code{\e},
3080 @code{\E}, @code{\p}, @code{\r}, @code{\t}, and @code{\u}.  Again, don't
3081 use these if possible.
3083 @findex \A
3084 @findex \Z
3085 @findex \C
3086 @findex \w
3087 No newline characters as delimiters are allowed in the following
3088 escapes: @code{\A}, @code{\Z}, @code{\C}, and @code{\w}.
3090 @findex \D
3091 @findex \h
3092 @findex \H
3093 @findex \l
3094 @findex \L
3095 @findex \N
3096 @findex \R
3097 @findex \s
3098 @findex \S
3099 @findex \v
3100 @findex \x
3101 Finally, the escapes @code{\D}, @code{\h}, @code{\H}, @code{\l},
3102 @code{\L}, @code{\N}, @code{\R}, @code{\s}, @code{\S}, @code{\v}, and
3103 @code{\x} can't use the following characters as delimiters:
3105 @itemize @bullet
3106 @item
3107 @cindex numbers
3108 @cindex digits
3109 The digits @code{0}-@code{9}.
3111 @item
3112 @cindex operators
3113 @opindex +
3114 @opindex -
3115 @opindex /
3116 @opindex *
3117 @opindex %
3118 @opindex <
3119 @opindex >
3120 @opindex =
3121 @opindex &
3122 @opindex :
3123 @opindex (
3124 @opindex )
3125 @opindex .
3126 The (single character) operators @samp{+-/*%<>=&:().}.
3128 @item
3129 @cindex space character
3130 @cindex character, space
3131 @cindex tab character
3132 @cindex character, tab
3133 @cindex newline character
3134 @cindex character, newline
3135 The space, tab, and newline characters.
3137 @item
3138 @findex \%
3139 @findex \@{
3140 @findex \@}
3141 @findex \'
3142 @findex \`
3143 @findex \-
3144 @findex \_
3145 @findex \!
3146 @findex \@@
3147 @findex \/
3148 @findex \c
3149 @findex \e
3150 @findex \p
3151 All escape sequences except @code{\%}, @code{\@{}, @code{\@}},
3152 @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!}, @code{\@@},
3153 @code{\/}, @code{\c}, @code{\e}, and @code{\p}.
3154 @end itemize
3156 @findex \\
3157 @findex \e
3158 @findex \E
3159 To have a backslash (resp.@: the current escape character) appear in the
3160 output several escapes are defined: @code{\\}, @code{\e} or @code{\E}.
3161 These are very similar, and only differ with respect to being used in
3162 macros or diversions.  @xref{Copy-in Mode}, and @ref{Diversions}, for
3163 more information.
3165 @c XXX explanation of \E
3167 @xref{Identifiers}, and @ref{Character Translations}.
3169 @menu
3170 * Comments::                    
3171 @end menu
3173 @node Comments,  , Escapes, Escapes
3174 @subsubsection Comments
3175 @cindex comments
3177 Probably one of the most@footnote{Unfortunately, this is a lie.  But
3178 hopefully future @code{gtroff} hackers will believe it :-)} common forms
3179 of escapes is the comment.
3181 @Deffn{Escape, \\"}
3182 Start a comment.  Everything to the end of the input line is ignored.
3184 This may sound simple, but it can be tricky to keep the comments from
3185 interfering with the appearance of the final output.
3187 @findex ds
3188 If the escape is to the right of some text or a request, that portion of
3189 the line will be ignored, but the space leading up to it will be noticed
3190 by @code{gtroff}.  This only affects the @code{.ds} request.
3191 @c XXX (any others?)
3193 One possibly irritating idiosyncracy is that tabs must not be used to
3194 line up comments.  Tabs are not treated as white space between the
3195 request and macro arguments.
3197 @cindex undefined request
3198 @cindex request, undefined
3199 A comment on a line by itself will be treated as a blank line, because
3200 after eliminating the comment, that is all that remains:
3202 @example
3203 Test
3204 \" comment
3205 Test
3206 @end example
3208 @noindent
3209 will produce
3211 @example
3212 Test
3214 Test
3215 @end example
3217 As a consequence, it is common to start the line with @code{.\"} which
3218 will cause the line to be treated as an undefined request and thus
3219 ignored completely.
3221 @findex '
3222 Another commenting scheme seen sometimes is three consecutive single
3223 quotes (@code{'''}) at the beginning of a line.  This works, but
3224 @code{gtroff} will give a warning about an undefined macro (namely
3225 @code{''}), which is harmless, but irritating.
3226 @end_Deffn
3228 @Deffn{Escape, \\#}
3229 Now to avoid all this @code{gtroff} has a new comment mechanism using
3230 the @code{\#} escape.  This escape works the same as @code{\"} except
3231 that the newline is also ignored:
3233 @example
3234 Test
3235 \# comment
3236 Test
3237 @end example
3239 @noindent
3240 will produce
3242 @example
3243 Test Test
3244 @end example
3246 @noindent
3247 as expected.
3248 @end_Deffn
3250 @findex ig
3251 For large blocks of text, the @code{ig} request may be useful.
3253 @c XXX definition of .ig
3255 @xref{Strings}.
3258 @c =====================================================================
3260 @node Registers, Manipulating Filling and Adjusting, Embedded Commands, Programming Tutorial
3261 @section Registers
3262 @cindex registers
3264 Numeric variables in @code{gtroff} are called @dfn{registers}.  There
3265 are a number of built-in registers, supplying anything from the date to
3266 details of formatting parameters.
3268 @xref{Identifiers}, for details on register identifiers.
3270 @menu
3271 * Setting Registers::           
3272 * Interpolating Registers::     
3273 * Auto-increment::              
3274 * Assigning Formats::           
3275 * Built-in Registers::          
3276 @end menu
3278 @c ---------------------------------------------------------------------
3280 @node Setting Registers, Interpolating Registers, Registers, Registers
3281 @subsection Setting Registers
3282 @cindex setting registers
3283 @cindex registers, setting
3285 Registers are defined resp.@: set via the @code{nr} request or the
3286 @code{\R} escape.
3288 @Deffn{Request, nr, ident value}
3289 @Deffnx{Escape, \\R, ident value}
3290 Set number register @var{ident} to @var{value}.  If @var{ident} doesn't
3291 exist, it will be created.
3293 The argument to @code{\R} has to be enclosed in quotes usually.
3294 @xref{Escapes}, for details on parameter delimiting characters.
3295 @end_Deffn
3297 For example, the following two lines are equivalent:
3299 @example
3300 .nr a 1
3301 \R'a 1'
3302 @end example
3304 Both @code{nr} and @code{\R} have two additional special forms to
3305 increment resp.@: decrement a register.
3307 @Deffn{Request, nr, ident +value}
3308 @Deffnx{Request, nr, ident -value}
3309 @Deffnx{Escape, \\R, ident +value}
3310 @Deffnx{Escape, \\R, ident -value}
3311 Increment (decrement) register @var{ident} by @var{value}.
3313 @example
3314 .nr a 1
3315 .nr a +1
3317     @result{} 2
3318 @end example
3320 To assign the negated value of a register to another register, some care
3321 must be taken to get the desired result:
3323 @example
3324 .nr a 7
3325 .nr b 3
3326 .nr a -\nb
3328     @result{} 4
3329 .nr a (-\nb)
3331     @result{} -3
3332 @end example
3334 @noindent
3335 The surrounding parentheses prevent the interpretation of the minus sign
3336 as a decrementing operator.  An alternative is to start the assignment
3337 with a @samp{0}:
3339 @example
3340 .nr a 7
3341 .nr b -3
3342 .nr a \nb
3344     @result{} 4
3345 .nr a 0\nb
3347     @result{} -3
3348 @end example
3349 @end_Deffn
3351 @Deffn{Request, rr, ident}
3352 Remove number register @var{ident}.  If @var{ident} doesn't exist, the
3353 request is ignored.
3354 @end_Deffn
3356 @Deffn{Request, rnn, ident1 ident2}
3357 Rename number register @var{ident1} to @var{ident2}.  If either
3358 @var{ident1} or @var{ident2} doesn't exist, the request is ignored.
3359 @end_Deffn
3361 @Deffn{Request, aln, ident1 ident2}
3362 This request creates an alias @var{ident1} for a number register
3363 @var{ident2}.  The new name and the old name will be exactly equivalent.
3364 If @var{ident1} is undefined, a warning of type @samp{reg} will be
3365 generated, and the request will be ignored.  @xref{Debugging}, for
3366 information about warnings.
3367 @end_Deffn
3369 @c ---------------------------------------------------------------------
3371 @node Interpolating Registers, Auto-increment, Setting Registers, Registers
3372 @subsection Interpolating Registers
3373 @cindex interpolating registers
3374 @cindex registers, interpolating
3376 Numeric registers can be accessed via the @code{\n} escape.
3378 @Deffn{Escape, \\n, ident}
3379 @c XXX is the following correct?
3380 Interpolate number register @var{ident}.  This means that the value of
3381 the register is expanded in-place while @code{gtroff} is parsing the
3382 input line.
3384 @example
3385 .nr a 5
3386 .nr as \na+\na
3387 \n(as
3388     @result{} 10
3389 @end example
3390 @end_Deffn
3392 @c ---------------------------------------------------------------------
3394 @node Auto-increment, Assigning Formats, Interpolating Registers, Registers
3395 @subsection Auto-increment
3396 @cindex auto-increment
3397 @cindex increment, automatic
3399 Number registers can also be auto-incremented and auto-decremented.  The
3400 increment resp.@: decrement factor can be specified with a third
3401 argument to the @code{nr} request or @code{\R} escape.
3403 @findex \R
3404 @Deffn{Request, nr, ident value incr}
3405 Set number register @var{ident} to @var{value}; the increment for
3406 auto-incrementing is set to @var{incr}.  Note that the @code{\R} escape
3407 doesn't support this notation.
3408 @end_Deffn
3410 To activate auto-incrementing, the escape @code{\n} has a special syntax
3411 form.
3413 @Deffn{Escape, \\n, +ident}
3414 @Deffnx{Escape, \\n, -ident}
3415 Before interpolating, increment resp.@: decrement @var{ident} by the
3416 auto-increment value as specified with the @code{nr} request (or the
3417 @code{\R} escape).  If no auto-increment value has been specified, both
3418 syntax forms are identical to @code{\n}.
3419 @end_Deffn
3421 For example,
3423 @example
3424 .nr a 0 1
3425 .nr xx 0 5
3426 .nr foo 0 -2
3427 \n+a, \n+a, \n+a, \n+a, \n+a
3429 \n-(xx, \n-(xx, \n-(xx, \n-(xx, \n-(xx
3431 \n+[foo], \n+[foo], \n+[foo], \n+[foo], \n+[foo]
3432 @end example
3434 @noindent
3435 produces
3437 @example
3438 1, 2, 3, 4, 5
3439 -5, -10, -15, -20, -25
3440 -2, -4, -6, -8, -10
3441 @end example
3443 To change the increment value without changing the value of a register,
3444 the following can be used.
3446 @example
3447 .nr a \na 10
3448 @end example
3450 @c ---------------------------------------------------------------------
3452 @node Assigning Formats, Built-in Registers, Auto-increment, Registers
3453 @subsection Assigning Formats
3454 @cindex assigning formats
3455 @cindex formats, assigning
3457 When a register is used in the text of an input file (as opposed to part
3458 of an expression) it is textually replaced (or interpolated) with a
3459 representation of that number.  This output format can be changed to a
3460 variety of formats (numbers, Roman numerals, etc).  This is done using
3461 the @code{af} request.
3463 @Deffn{Request, af, ident format}
3464 Change the output format of a number register.  The first argument
3465 @var{ident} is the name of the number register to be changed, and the
3466 second argument @var{format} is the output format.  The following output
3467 formats are available:
3469 @table @code
3470 @item 1
3471 Decimal arabic numbers.  This is the default format: 1, 2, 3,@w{
3472 }@dots{}
3474 @item 0@dots{}0
3475 Decimal numbers with as many digits as specified.  So, @samp{00} would
3476 result in printing numbers as 01, 02, 03,@w{ }@dots{}
3478 In fact, any digit instead of zero will do; @code{gtroff} only counts
3479 how many digits are specified.  As a consequence, @code{af}'s default
3480 format @samp{1} could be specified as @samp{0} also (and exactly this is
3481 returned by the @code{\g} escape).
3483 @item I
3484 @cindex roman numerals
3485 @cindex numerals, Roman
3486 Upper-case Roman numerals: 0, I, II, III, IV,@w{ }@dots{}
3488 @item i
3489 Lower-case Roman numerals: 0, i, ii, iii, iv,@w{ }@dots{}
3491 @item A
3492 Upper-case letters: A, B, C, @dots{},@w{ }Z, AA, AB,@w{ }@dots{}
3494 @item a
3495 Lower-case letters: a, b, c, @dots{},@w{ }z, aa, ab,@w{ }@dots{}
3496 @end table
3498 Omitting the number register format will cause a warning of type
3499 @samp{missing}.  @xref{Debugging}, for more details.  Specifying a
3500 nonexistent format causes an error.
3502 The following example will produce @samp{10, X, j, 010}:
3504 @example
3505 .nr a 10
3506 .af a 1           \" the default format
3507 \na,
3508 .af a I
3509 \na,
3510 .af a a
3511 \na,
3512 .af a 001
3514 @end example
3516 The largest number representable for the @samp{i} and @samp{I} formats
3517 is 39999 (resp.@: -39999); @acronym{UNIX} @code{troff} uses @samp{z} and
3518 @samp{w} to represent 10000 and 5000 in Roman numerals, and so does
3519 @code{gtroff}.  Currently, the correct glyphs (Unicode code points
3520 @code{U+2182} and @code{U+2181}, respectively) are not available.
3522 If @var{ident} doesn't exist, it will be created.
3524 Changing the output format of a read-only register causes an error.  It
3525 is necessary to first copy the register's value to a writeable register,
3526 then apply the @code{af} request to this other register.
3527 @end_Deffn
3529 @Deffn{Escape, \\g, ident}
3530 Return the current format of the specified register @var{ident}.  For
3531 example, @samp{\ga} after the previous example would produce the string
3532 @samp{000}.  If the register hasn't been defined yet, nothing is
3533 returned.
3534 @end_Deffn
3536 @c ---------------------------------------------------------------------
3538 @node Built-in Registers,  , Assigning Formats, Registers
3539 @subsection Built-in Registers
3540 @cindex built-in registers
3541 @cindex registers, built-in
3543 The following lists some built-in registers which are not described
3544 elsewhere in this manual.  Any register which begin with a @samp{.} is
3545 read-only.  A complete listing of all built-in registers can be found in
3546 @ref{Register Index}.
3548 @table @code
3549 @item .H
3550 @cindex horizontal resolution
3551 @cindex resolution, horizontal
3552 @vindex .H
3553 Horizontal resolution in basic units.
3555 @item .V
3556 @cindex vertical resolution
3557 @cindex resolution, vertical
3558 @vindex .V
3559 Vertical resolution in basic units.
3561 @item dw
3562 @cindex day of the week
3563 @cindex date, day of the week
3564 @vindex dw
3565 Day of the week (1-7).
3567 @item dy
3568 @cindex day of the month
3569 @cindex date, day of the month
3570 @vindex dy
3571 Day of the month (1-31).
3573 @item mo
3574 @cindex month of the year
3575 @cindex date, month of the year
3576 @vindex mo
3577 Current month (1-12).
3579 @item year
3580 @cindex date, year
3581 @cindex year, current
3582 @vindex year
3583 The current year.
3585 @item yr
3586 @vindex yr
3587 The current year minus@w{ }1900.  Unfortunately, the documentation of
3588 @acronym{UNIX} Version@w{ }7's @code{troff} had a year@w{ }2000 bug: It
3589 incorrectly claimed that @code{yr} contains the last two digits of the
3590 year.  That claim has never been true of either traditional @code{troff}
3591 or GNU @code{troff}.  Old @code{troff} input that looks like this:
3593 @example
3594 '\" The following line stopped working after 1999
3595 This document was formatted in 19\n(yr.
3596 @end example
3598 @noindent
3599 can be corrected as follows:
3601 @example
3602 This document was formatted in \n[year].
3603 @end example
3605 @noindent
3606 or, to be portable to older @code{troff} versions, as follows:
3608 @example
3609 .nr y4 1900+\n(yr
3610 This document was formatted in \n(y4.
3611 @end example
3613 @item .c
3614 @vindex .c
3615 @itemx c.
3616 @vindex c.
3617 @cindex input line number
3618 @cindex line number, input
3619 The current @emph{input} line number.  Register @samp{.c} is read-only,
3620 whereas @samp{c.} (a @code{gtroff} extension) is writable also,
3621 affecting both @samp{.c} and @samp{c.}.
3623 @item ln
3624 @vindex ln
3625 @findex nm
3626 @cindex output line number
3627 @cindex line number, output
3628 The current @emph{output} line number after a call to the @code{nm}
3629 request to activate line numbering.
3631 @c XXX xref nm request
3633 @item .x
3634 @vindex .x
3635 @cindex major version number
3636 @cindex version number, major
3637 The major version number.  For example, if the version number is@w{
3638 }1.03 then @code{.x} will contain@w{ }@samp{1}.
3640 @item .y
3641 @vindex .y
3642 @cindex minor version number
3643 @cindex version number, minor
3644 The minor version number.  For example, if the version number is@w{
3645 }1.03 then @code{.y} will contain@w{ }@samp{03}.
3647 @item .Y
3648 @vindex .Y
3649 @cindex revision number
3650 The revision number of @code{groff}.
3652 @item .g
3653 @vindex .g
3654 Always@w{ }1.  Macros should use this to determine whether they are
3655 running under GNU @code{troff}.
3657 @item .A
3658 @vindex .A
3659 If the command line option @option{-a} is used to produce an
3660 @acronym{ASCII} approximation of the output, this is set to@w{ }1, zero
3661 otherwise.  @xref{Groff Options}.
3663 @item .P
3664 @vindex .P
3665 This register is set to@w{ }1 (and to@w{ }0 otherwise) if the current
3666 page is actually being printed, i.e., if the @option{-o} option is being
3667 used to only print selected pages.  @xref{Groff Options}, for more
3668 information.
3670 @item .T
3671 @vindex .T
3672 If @code{gtroff} is called with the @option{-T} command line option, the
3673 number register @code{.T} is set to@w{ }1, and zero otherwise.
3674 @xref{Groff Options}.
3676 @maindex \*(.T
3677 Additionally, @code{gtroff} predefines a single (read/write) string
3678 register @code{.T} which contains the current output device (for
3679 example, @samp{latin1} or @samp{ps}).
3680 @end table
3683 @c =====================================================================
3685 @node Manipulating Filling and Adjusting, Manipulating Hyphenation, Registers, Programming Tutorial
3686 @section Manipulating Filling and Adjusting
3687 @cindex manipulating filling and adjusting
3688 @cindex filling and adjusting, manipulating
3689 @cindex adjusting and filling, manipulating
3690 @cindex justifying text
3691 @cindex text, justifying
3693 @cindex break
3694 @cindex line break
3695 @findex bp
3696 @findex ce
3697 @findex cf
3698 @findex fi
3699 @findex fl
3700 @findex in
3701 @findex nf
3702 @findex rj
3703 @findex sp
3704 @findex ti
3705 @findex trf
3706 Various ways of causing @dfn{breaks} were given in @ref{Implicit Line
3707 Breaks}.  The @code{br} request will likewise cause a break.  Several
3708 other requests will also cause breaks, but implicitly.  These are
3709 @code{bp}, @code{ce}, @code{cf}, @code{fi}, @code{fl}, @code{in},
3710 @code{nf}, @code{rj}, @code{sp}, @code{ti}, and @code{trf}.
3712 @Deffn{Request, br, }
3713 Break the current line, i.e., the input collected so far will be emitted
3714 without adjustment.
3716 If the no-break control character is used, no break will happen:
3718 @example
3722     @result{} a b
3723 @end example
3724 @end_Deffn
3726 Initially, @code{gtroff} will fill and adjust text to both margins.
3727 Filling can be disabled via the @code{nf} request and re-enabled with
3728 the @code{fi} request.
3730 @cindex fill mode
3731 @cindex mode, fill
3732 @vindex .u
3733 @Deffn{Request, fi, }
3734 Activate fill mode (which is the default).  This request implicitly
3735 enables adjusting; it will also cause a break in the text currently
3736 being filled.  The number register @code{.u} is set to@w{ }1.
3738 The fill mode status is associated with the current environment
3739 (@pxref{Environments}).
3740 @end_Deffn
3742 @cindex no-fill mode
3743 @cindex mode, no-fill
3744 @Deffn{Request, nf, }
3745 Activate no-fill mode.  Input lines are output as-is, retaining line
3746 breaks.  The current line length will be ignored.  This command
3747 implicitly disables adjusting; it also causes a break.  The number
3748 register @code{.u} will be set to@w{ }0.
3750 The fill mode status is associated with the current environment
3751 (@pxref{Environments}).
3752 @end_Deffn
3754 @Deffn{Request, ad, [@var{mode}]}
3755 Set adjusting mode.
3757 Activation and deactivation of adjusting will be implicitly done with
3758 calls to the @code{fi} resp.@: @code{nf} requests.
3760 @var{mode} can have one of the following values:
3762 @table @code
3763 @item l
3764 @cindex ragged-right
3765 Adjust text to the left margin.  This produces what is traditionally
3766 called ragged-right text.
3768 @item r
3769 @cindex ragged-left
3770 Adjust text to the right margin, producing ragged-left text.
3772 @item c
3773 @cindex centered text
3774 @findex ce
3775 Center filled text.  This is different to the @code{ce} request which
3776 only centers text without filling.
3778 @item b
3779 @itemx n
3780 Justify to both margins.  This is default of @code{gtroff}.
3781 @end table
3783 With no argument, @code{gtroff} will adjust lines the same way before
3784 adjusting has been deactivated (with a call to @code{na}, for example).
3786 @example
3787 text
3788 .ad r
3789 text
3790 .ad c
3791 text
3793 text
3794 .ad  \" back to centering
3795 text
3796 @end example
3798 @vindex .j
3799 The current adjustment mode is available in the number register
3800 @code{.j}; it can be stored and subsequently used to set adjustment.
3802 The adjustment mode status is associated with the current environment
3803 (@pxref{Environments}).
3804 @end_Deffn
3806 @Deffn{Request, na, }
3807 Disable adjusting.  This request won't change the current adjustment
3808 mode: A call to @code{ad} afterwards will use the previous adjustment
3809 setting.
3811 The adjustment mode status is associated with the current environment
3812 (@pxref{Environments}).
3813 @end_Deffn
3815 @Deffn{Escape, \\p, }
3816 Adjust the current line and cause a break.
3818 In most cases this will produce very ugly results, since @code{gtroff}
3819 doesn't have a sophisticated paragraph building algorithm (as @TeX{}
3820 have, for example); instead, @code{gtroff} fills and adjusts a paragraph
3821 line by line:
3823 @example
3824   This is an uninteresting sentence.
3825   This is an uninteresting sentence.\p
3826   This is an uninteresting sentence.
3827 @end example
3829 is formatted as
3831 @example
3832   This is  an uninteresting  sentence.   This  is an
3833   uninteresting                            sentence.
3834   This is an uninteresting sentence.
3835 @end example
3836 @end_Deffn
3838 @cindex word space size
3839 @cindex size of word space
3840 @cindex space between words
3841 @cindex sentence space size
3842 @cindex size of sentence space
3843 @cindex space between sentences
3844 @Deffn{Request, ss, word_space_size [@var{sentence_space_size}]}
3845 Change the minimum size of a space between filled words.  It takes its
3846 units as one twelfth of the space width parameter for the current font.
3847 Initially both the @var{word_space_size} and @var{sentence_space_size}
3848 are@w{ }12.
3850 @cindex fill mode
3851 @cindex mode, fill
3852 If two arguments are given to the @code{ss} request, the second argument
3853 sets the sentence space size.  If the second argument is not given,
3854 @var{sentence_space_size} will be the same as @var{word_space_size}.
3855 The sentence space size is used in two circumstances: If the end of a
3856 sentence occurs at the end of a line in fill mode, then both an
3857 inter-word space and a sentence space will be added; if two spaces
3858 follow the end of a sentence in the middle of a line, then the second
3859 space will be a sentence space.  Note that the behaviour of
3860 @acronym{UNIX} @code{troff} will be exactly that exhibited by GNU
3861 @code{troff} if a second argument is never given to the @code{ss}
3862 request.  In GNU @code{troff}, as in @acronym{UNIX} @code{troff}, a
3863 sentence should always be followed with either a newline or two spaces.
3865 @vindex .ss
3866 @vindex .sss
3867 The number registers @code{.ss} and @code{.sss} are the values of the
3868 parameters set by the first and second arguments of the @code{ss}
3869 request.
3871 The space and sentence space values are associated with the current
3872 environment (@pxref{Environments}).
3874 This request is ignored in nroff mode; it is also ignored if there is no
3875 parameter.
3876 @end_Deffn
3878 @cindex centering lines
3879 @cindex lines, centering
3880 @Deffn{Request, ce, [@var{nnn}]}
3881 Center text.  While the @w{@samp{ad c}} request will also center text,
3882 it has the side effect of filling the text.  @code{ce} will not fill the
3883 text it affects.  This request causes a break.
3885 With no arguments, @code{ce} will center the next line of text.
3886 @var{nnn} is a number indicating the number of lines to be centered.  If
3887 the argument is zero or negative, centering is disabled.
3889 @findex ll
3890 @findex in
3891 @findex ti
3892 The basic length for centering text is the line length (as set with the
3893 @code{ll} request) minus the indentation (as set with the @code{in}
3894 request).  Temporary indentation is ignored.
3896 A common idiom is to turn on centering for a large number of lines, and
3897 to turn off centering after text to be centered.  This is useful for any
3898 request which takes a number of lines as an argument.
3900 @example
3901 .ce 1000
3902 replace this
3903 with
3904 something
3905 more interesting
3906 @dots{}
3907 .ce 0
3908 @end example
3910 @vindex .ce
3911 The @code{.ce} number register contains the number of lines remaining to
3912 be centered, as set by the @code{ce} request.
3913 @end_Deffn
3915 @cindex justifying text
3916 @cindex text, justifying
3917 @cindex right-justifying
3918 @vindex .rj
3919 @Deffn{Request, rj, [@var{nnn}]}
3920 Justify unfilled text to the right margin.  Its arguments are identical
3921 to the @code{ce} request.  The @code{.rj} number register is the number
3922 of lines to be right-justified as set by the @code{rj} request.  This
3923 request causes a line break.
3924 @end_Deffn
3927 @c =====================================================================
3929 @node Manipulating Hyphenation, Manipulating Spacing, Manipulating Filling and Adjusting, Programming Tutorial
3930 @section Manipulating Hyphenation
3931 @cindex manipulating hyphenation
3932 @cindex hyphenation, manipulating
3934 As discussed in @ref{Hyphenation}, @code{gtroff} will hyphenate words.
3935 There are a number of ways to influence how hyphenation is done.
3937 @Deffn{Request, hy, [@var{mode}]}
3938 Enable hyphenation.  The request has an optional numeric argument,
3939 @var{mode}, to restrict hyphenation if necessary:
3941 @table @code
3942 @item 1
3943 The default argument if @var{mode} is omitted.  Hyphenate without
3944 restrictions.  This is also the start-up value of @code{gtroff}.
3946 @item 2
3947 Do not hyphenate the last word on a page or column.
3949 @item 4
3950 Do not hyphenate the last two characters of a word.
3952 @item 8
3953 Do not hyphenate the first two characters of a word.
3954 @end table
3956 Values in the previous table are additive.  For example, the value@w{
3957 }12 causes @code{gtroff} to neither hyphenate the last two nor the first
3958 two characters of a word.
3960 @vindex .hy
3961 The current hyphenation restrictions can be found in the number register
3962 @samp{.hy}.
3964 The hyphenation mode is associated with the current environment
3965 (@pxref{Environments}).
3966 @end_Deffn
3968 @Deffn{Request, nh, }
3969 Disable hyphenation (i.e., set the hyphenation mode to zero).  Note that
3970 the hyphenation mode of the last call to @code{hy} is not remembered.
3972 The hyphenation mode is associated with the current environment
3973 (@pxref{Environments}).
3974 @end_Deffn
3976 @vindex .hlc
3977 @vindex .hlm
3978 @findex \%
3979 @cindex explicit hyphens
3980 @cindex hyphen, explicit
3981 @cindex consecutive hyphenated lines
3982 @cindex lines, consecutive hyphenated
3983 @cindex hyphenated lines, consecutive
3984 @Deffn{Request, hlm, [@var{nnn}]}
3985 Set the maximum number of consecutive hyphenated lines to @var{nnn}.  If
3986 this number is negative, there is no maximum.  The default value is@w{
3987 }-1 if @var{nnn} is omitted.  This value is associated with the current
3988 environment (@pxref{Environments}).  Only lines output from a given
3989 environment count towards the maximum associated with that environment.
3990 Hyphens resulting from @code{\%} are counted; explicit hyphens are not.
3992 The current setting of @code{hlm} is available in the @code{.hlm}
3993 register.  Also the number of immediately preceding consecutive
3994 hyphenated lines are available in the number register @samp{.hlc}.
3995 @end_Deffn
3997 @Deffn{Request, hw, word1 word2 @dots{}}
3998 Define how @var{word1}, @var{word2}, etc.@: are to be hyphenated.  The
3999 words must be given with hyphens at the hyphenation points.  For
4000 example:
4002 @example
4003 .hw in-sa-lub-rious
4004 @end example
4006 @noindent
4007 Besides the space character, any character which hyphenation code value
4008 is zero can be used to separate the arguments of @code{hw} (see the
4009 documentation for the @code{hcode} request below for more information).
4010 In addition, this request can be used more than once.
4012 Hyphenation exceptions specified with the @code{hw} request are
4013 associated with the current hyphenation language; it will cause an error
4014 if there is no current hyphenation language.
4016 This request is ignored if there is no parameter.
4018 In old versions of @code{troff} there was a limited amount of space to
4019 store such information; fortunately, with @code{gtroff}, this is no
4020 longer a restriction.
4021 @end_Deffn
4023 @cindex hyphenation character
4024 @cindex character, hyphenation
4025 @cindex disabling hyphenation
4026 @cindex hyphenation, disabling
4027 @Deffn{Escape, \\%, }
4028 To tell @code{gtroff} how to hyphenate words on the fly, the @code{\%}
4029 escape, also known as the @dfn{hyphenation character}, can be used.
4030 Preceding a word with this character will prevent it from being
4031 hyphenated, putting it in a word will indicate to @code{gtroff} that the
4032 word may be hyphenated at that point.  Note that this mechanism will
4033 only affect one word; to change the hyphenation of a word for the entire
4034 document, use the @code{hw} request.
4035 @end_Deffn
4037 @Deffn{Request, hc, [@var{char}]}
4038 Change the hyphenation character to @var{char}.  This character will
4039 then work the same as the @code{\%} escape, and, thus, no longer appear
4040 in the output.  Without an argument, @code{hc} will reset the
4041 hyphenation character to be @code{\%} (the default) only.
4043 The hyphenation character is associated with the current environment
4044 (@pxref{Environments}).
4045 @end_Deffn
4047 @cindex hyphenation patterns
4048 @cindex patterns for hyphenation
4049 @Deffn{Request, hpf, pattern_file}
4050 Read in a file of hyphenation patterns.  This file will be searched for
4051 in the same way as @file{tmac.@var{name}} is searched for if the
4052 @option{-m@var{name}} option is specified.
4054 It should have the same format as the argument to the @code{\patterns}
4055 primitive in @TeX{} (without using @TeX{}'s macro expansion); the
4056 letters appearing in this file are interpreted as hyphenation codes.  A
4057 @samp{%} character in the patterns file introduces a comment that
4058 continues to the end of the line.
4060 If no @code{hpf} request is specified (either in the document or in a
4061 macro package), @code{gtroff} won't hyphenate at all.
4063 @findex hla
4064 @pindex troffrc
4065 @pindex troffrc-end
4066 @pindex hyphen.us
4067 The set of hyphenation patterns is associated with the current language
4068 set by the @code{hla} request.  The @code{hpf} request is usually
4069 invoked by the @file{troffrc} or @file{troffrc-end} file; by default,
4070 @file{troffrc} loads hyphenation patterns for American English (in file
4071 @file{hyphen.us}).
4073 It will cause an error if there is no current hyphenation language.
4074 @end_Deffn
4076 @cindex hyphenation code
4077 @cindex code, hyphenation
4078 @Deffn{Request, hcode, c1 code1 c2 code2 @dots{}}
4079 Sets the hyphenation code of character @var{c1} to @var{code1}, that of
4080 @var{c2} to @var{code2}, etc.  A hyphenation code must be a single input
4081 character (not a special character) other than a digit or a space.
4082 Initially each lower-case letter (@samp{a}-@samp{z}) has a hyphenation
4083 code, which is itself, and each upper-case letter (@samp{A}-@samp{Z})
4084 has a hyphenation code which is the lower-case version of itself.
4086 This request will be ignored if it has no parameter.
4087 @end_Deffn
4089 @cindex hyphenation margin
4090 @cindex margin for hyphenation
4091 @findex ad
4092 @Deffn{Request, hym, [@var{length}]}
4093 Set the (right) hyphenation margin to @var{length}.  If the current
4094 adjustment mode is not@w{ }@samp{b}, the line will not be hyphenated if
4095 it is shorter than @var{length}.  Without argument, the hyphenation
4096 margin will be reset to its default value, which is@w{ }0.  The default
4097 scaling indicator for this request is@w{ }@code{m}.  The hyphenation
4098 margin is associated with the current environment
4099 (@pxref{Environments}).
4101 A negative argument will reset the hyphenation margin to zero, emitting
4102 a warning of type @samp{range}.
4104 @vindex .hym
4105 The current hyphenation margin is available in the @code{.hym} register.
4106 @end_Deffn
4108 @cindex hyphenation space
4109 @findex ad
4110 @Deffn{Request, hys, [@var{hyphenation_space}]}
4111 Set the hyphenation space to @var{hyphenation_space}.  If the current
4112 adjustment mode is@w{ }@samp{b}, don't hyphenate the line if the line
4113 can be justified by adding no more than @var{hyphenation_space} extra
4114 space to each word space.  Without argument, the hyphenation space is
4115 set to its default value, which is@w{ }0.  The default scaling indicator
4116 for this request is@w{ }@code{m}.  The hyphenation space is associated
4117 with the current environment (@pxref{Environments}).
4119 A negative argument will reset the hyphenation space to zero, emitting a
4120 warning of type @samp{range}.
4122 @vindex .hys
4123 The current hyphenation space is available in the @code{.hys} register.
4124 @end_Deffn
4126 @cindex soft hyphen character
4127 @cindex character, soft hyphen
4128 @glindex hy
4129 @findex char
4130 @findex tr
4131 @Deffn{Request, shc, [@var{char}]}
4132 Set the soft hyphen character to @var{char}.  If the argument is
4133 omitted, the soft hyphen character will be set to the default character
4134 @code{\(hy} (this is the start-up value of @code{gtroff} also).  The
4135 soft hyphen character is the character which will be inserted when a
4136 word is hyphenated at a line break.  If the soft hyphen character does
4137 not exist in the font of the character immediately preceding a potential
4138 break point, then the line will not be broken at that point.  Neither
4139 definitions (specified with the @code{char} request) nor translations
4140 (specified with the @code{tr} request) are considered when finding the
4141 soft hyphen character.
4142 @end_Deffn
4144 @findex hpf
4145 @findex hw
4146 @pindex troffrc
4147 @pindex troffrc-end
4148 @Deffn{Request, hla, language}
4149 Set the current hyphenation language to the string @var{language}.
4150 Hyphenation exceptions specified with the @code{hw} request and
4151 hyphenation patterns specified with the @code{hpf} request are both
4152 associated with the current hyphenation language.  The @code{hla}
4153 request is usually invoked by the @file{troffrc} or the
4154 @file{troffrc-end} files; @file{troffrc} sets the default language to
4155 @samp{us}.
4157 @vindex .hla
4158 The current hyphenation language is available as a string in the
4159 read-only number register @samp{.hla}.
4161 @example
4162 .ds curr_language \n[.hla]
4163 \*[curr_language]
4164     @result{} us
4165 @end example
4166 @end_Deffn
4169 @c =====================================================================
4171 @node Manipulating Spacing, Tabs and Fields, Manipulating Hyphenation, Programming Tutorial
4172 @section Manipulating Spacing
4173 @cindex manipulating spacing
4174 @cindex spacing, manipulating
4176 @Deffn{Request, sp, [@var{distance}]}
4177 Space downwards @var{distance}.  With no argument it will advance 1@w{
4178 }line.  A negative argument will cause @code{gtroff} to move up the page
4179 the specified distance.  If the argument is preceded by a @samp{|}
4180 @code{gtroff} will move that distance from the top of the page.  This
4181 request causes a line break.  The default scaling indicator is@w{
4182 }@code{v}.
4183 @end_Deffn
4185 @cindex double-spacing
4186 @Deffn{Request, ls, [@var{nnn}]}
4187 Output @w{@var{nnn}-1} blank lines after each line of text.  With no
4188 argument @code{gtroff} will use the previous value before the last
4189 @code{ls} call.
4191 @example
4192 .ls 2    \" This causes double-spaced output
4193 .ls 3    \" This causes triple-spaced output
4194 .ls      \" Again double spaced
4195 @end example
4197 The line spacing is associated with the current environment
4198 (@pxref{Environments}).
4200 @vindex .L
4201 The number register @code{.L} contains the current line spacing setting.
4202 @end_Deffn
4204 @Deffn{Escape, \\x, spacing}
4205 Sometimes, extra vertical spacing is only needed occasionally, e.g.@: to
4206 allow space for a tall construct (like an equation).  The @code{\x}
4207 escape will do this.  The escape is given a numerical argument, usually
4208 enclosed in quotes (like @samp{\x'3p'}); the default scaling indicator
4209 is@w{ }@code{v}.  If this number is positive extra vertical space will
4210 be inserted below the current line.  A negative number will add space
4211 above.  If this escape is used multiple times on the same line, the
4212 maximum of the values is used.
4214 @xref{Escapes}, for details on parameter delimiting characters.
4216 @vindex .a
4217 The @code{.a} number register contains the most recent (nonnegative)
4218 extra vertical line space.
4220 @c XXX
4221 @example
4222 ... example of inline equation ...
4223 @end example
4224 @end_Deffn
4226 @findex sp
4227 @cindex no-space mode
4228 @cindex mode, no-space
4229 @cindex blank lines
4230 @cindex lines, blank
4231 @Deffn{Request, ns, }
4232 Enable @dfn{no-space mode}.  In this mode, spacing (either via @code{sp}
4233 or via blank lines) is disabled.  The @code{bp} request to advance to
4234 the next page is also disabled, except if it is accompanied by a page
4235 number (@pxref{Page Control}, for more information).  This mode will end
4236 when actual text is output or the @code{rs} request is encountered.
4238 This request is useful for macros which want to avoid that subsequent
4239 macros inadvertently insert some vertical space before the text starts
4240 (for example, to set up the first paragraph after a section header).  It
4241 is associated with the current diversion level.
4243 @c XXX xref
4244 @end_Deffn
4246 @Deffn{Request, rs, }
4247 Disable no-space mode.  This request is associated with the current
4248 diversion level.
4250 @c XXX xref
4251 @end_Deffn
4254 @c =====================================================================
4256 @node Tabs and Fields, Character Translations, Manipulating Spacing, Programming Tutorial
4257 @section Tabs and Fields
4258 @cindex tabs and fields
4259 @cindex fields and tabs
4261 @cindex @acronym{EBCDIC} encoding
4262 A tab character (@acronym{ASCII} char@w{ }9, @acronym{EBCDIC} char@w{
4263 }5) causes a horizontal movement to the next tab stop (which is much
4264 like that on a typewriter).
4266 @Deffn{Escape, \\t, }
4267 This escape is a non-interpreted tab character.  In copy mode
4268 (@pxref{Copy-in Mode}), @code{\t} is the same as a real tab character.
4269 @end_Deffn
4271 @Deffn{Request, ta, [@var{n1} @var{n2} @dots{} @var{nn} @t{T} @var{r1} @var{r2} @dots{} @var{rn}]}
4272 Change tab stop positions.  This request takes a series of tab
4273 specifiers as arguments (optionally divided into two groups with the
4274 letter @samp{T}) which indicate where each tab stop is to be (overriding
4275 any previous settings).
4277 Tab stops can be specified absolutely, i.e., as the distance from the
4278 left margin.  For example, the following will set 6@w{ }tab stops every
4279 one inch.
4281 @example
4282 .ta 1i 2i 3i 4i 5i 6i
4283 @end example
4285 Tab stops can also be specified relatively (using a leading @samp{+})
4286 which means that the specified tab stop will be set that distance from
4287 the previous tab stop.  For example, the following is equivalent to the
4288 previous example.
4290 @example
4291 .ta 1i +1i +1i +1i +1i +1i
4292 @end example
4294 @code{gtroff} supports an extended syntax to specify repeat values after
4295 the @samp{T} mark (these values are always taken as relative) -- this is
4296 the usual way to specify tabs set at equal intervals.  The following is,
4297 yet again, the same as the previous examples.  It does even more since
4298 it defines an infinite number of tab stops separated by one inch.
4300 @example
4301 .ta T 1i
4302 @end example
4304 Now we are ready to interpret the full syntax given at the beginning:
4305 Set tabs at positions @var{n1}, @var{n2}, @dots{}, @var{nn} and then set
4306 tabs at @var{nn}+@var{r1}, @var{nn}+@var{r2}, @dots{}, @var{nn}+@var{rn}
4307 and then at @var{nn}+@var{rn}+@var{r1}, @var{nn}+@var{rn}+@var{r2},
4308 @dots{}, @var{nn}+@var{rn}+@var{rn}, and so on.
4310 Example: @samp{4c +6c T 3c 5c 2c} is equivalent to @samp{4c 10c 13c 18c
4311 20c 23c 28c 30c @dots{}}.
4313 The material in each tab column (i.e., the column between two tab stops)
4314 may be justified to the right or left or centered in the column.  This
4315 is specified by appending @samp{R}, @samp{L}, or @samp{C} to the tab
4316 specifier.  The default justification is @samp{L}.  Example:
4318 @example
4319 .ta 1i 2iC 2iR
4320 @end example
4322 Some notes:
4324 @itemize @bullet
4325 @item
4326 The default unit of the @code{ta} request is @samp{m}.
4328 @item
4329 A tab stop is converted into a non-breakable horizontal movement which
4330 can be neither stretched nor squeezed.  For example,
4332 @example
4333 .ds foo a\tb\tc
4334 .ta T 5i
4335 \*[foo]
4336 @end example
4338 @noindent
4339 creates a single line which is a bit longer than 10@w{ }inches (a string
4340 is used to show exactly where the tab characters are).  Now consider the
4341 following:
4343 @example
4344 .ds bar a\tb b\tc
4345 .ta T 5i
4346 \*[bar]
4347 @end example
4349 @noindent
4350 @code{gtroff} first converts the tab stops of the line into unbreakable
4351 horizontal movements, then splits the line after the second @samp{b}
4352 (assuming a sufficiently short line length).  Usually, this isn't what
4353 the user wants.
4355 @item
4356 Superfluous tabs (i.e., tab characters which do not correspond to a tab
4357 stop) are ignored except the first one which delimits the characters
4358 belonging to the last tab stop for right-justifying resp.@: centering.
4359 Consider the following example
4361 @example
4362 .ds Z   foo\tbar\tfoo
4363 .ds ZZ  foo\tbar\tfoobar
4364 .ds ZZZ foo\tbar\tfoo\tbar
4365 .ta 2i 4iR
4366 \*[Z]
4368 \*[ZZ]
4370 \*[ZZZ]
4372 @end example
4374 @noindent
4375 which produces the following output:
4377 @example
4378 foo                 bar              foo
4379 foo                 bar           foobar
4380 foo                 bar              foobar
4381 @end example
4383 @noindent
4384 The first line right-justifies the second `foo' relative to the tab
4385 stop.  The second line right-justifies `foobar'.  The third line finally
4386 right-justifies only `foo' because of the additional tab character which
4387 marks the end of the string belonging to the last defined tab stop.
4389 @item
4390 Tab stops are associated with the current environment
4391 (@pxref{Environments}).
4393 @item
4394 Calling @code{ta} without an argument will unset all tab stops.
4396 @item
4397 The start-up value of @code{gtroff} is @w{@samp{T 0.5i}}.  Even in nroff
4398 mode this value is used (contrary to @acronym{UNIX} @code{nroff} which
4399 has tab stops preset every 0.8@dmn{i}).
4400 @end itemize
4402 @vindex .tabs
4403 The number register @code{.tabs} contains a string representation of the
4404 current tab settings suitable for use as an argument to the @code{ta}
4405 request.
4407 @example
4408 .ds tab-string \n[.tabs]
4409 \*[tab-string]
4410     @result{} T120u
4411 @end example
4412 @end_Deffn
4414 @cindex tab repitition character
4415 @cindex character, tab repitition
4416 @Deffn{Request, tc, [@var{fill-char}]}
4417 Normally @code{gtroff} will fill the space to the next tab stop with
4418 space.  This can be changed with the @code{tc} request.  With no
4419 argument @code{gtroff} will revert to using space, which is the default.
4420 The value of this @dfn{tab repitition} character is associated with the
4421 current environment (@pxref{Environments}).
4422 @end_Deffn
4424 @menu
4425 * Leaders::                     
4426 * Fields::                      
4427 @end menu
4429 @c ---------------------------------------------------------------------
4431 @node Leaders, Fields, Tabs and Fields, Tabs and Fields
4432 @subsection Leaders
4433 @cindex leaders
4435 Sometimes it may may be desirable to use the @code{tc} request to fill a
4436 particular tab stop with a given character (for example dots in a table
4437 of contents), but also normal tab stops on the rest of the line.  For
4438 this @code{gtroff} provides an alternate tab mechanism, called
4439 @dfn{leaders} which will do just that.
4441 @cindex leader character
4442 A leader character (character code@w{ }1) behaves similarly to a tab
4443 character: It moves to the next tab stop.  The only difference is that
4444 for this movement, the fill character defaults to a period character and
4445 not to space.
4447 @Deffn{Escape, \\a, }
4448 This escape is a non-interpreted leader character.  In copy mode
4449 (@pxref{Copy-in Mode}), @code{\a} is the same as a real leader
4450 character.
4451 @end_Deffn
4453 @cindex leader repitition character
4454 @cindex character, leader repitition
4455 @Deffn{Request, lc, [@var{fill-char}]}
4456 The character that will be repeated can be declared with the @code{lc}
4457 request.  Without an argument, leaders will act the same as tabs (i.e.,
4458 using space for filling).  @code{gtroff}'s start-up value is @samp{.}.
4459 The value of this @dfn{leader repitition} character is associated with
4460 the current environment (@pxref{Environments}).
4461 @end_Deffn
4463 @cindex table of contents
4464 @cindex contents, table of
4465 For a table of contents, to name an example, tab stops may be defined so
4466 that the section number is one tab stop, the title is the second with
4467 the remaining space being filled with a line of dots, and then the page
4468 number slightly separated from the dots.
4470 @example
4471 .ds entry 1.1\tFoo\a\t12
4472 .lc .
4473 .ta 1i 5i +.25i
4474 \*[entry]
4475 @end example
4477 @noindent
4478 This produces
4480 @example
4481 1.1  Foo..........................................  12
4482 @end example
4484 @c ---------------------------------------------------------------------
4486 @node Fields,  , Leaders, Tabs and Fields
4487 @subsection Fields
4488 @cindex fields
4490 @cindex field delimiting character
4491 @cindex delimiting character for fields
4492 @cindex character, field delimiting
4493 @cindex field padding character
4494 @cindex padding character for fields
4495 @cindex character, field padding
4496 @dfn{Fields} are a more general way of laying out tabular data.  A field
4497 is defined as the data between a pair of @dfn{delimiting characters}.
4498 It contains substrings which are separated by @dfn{padding characters}.
4499 The width of a field is the distance on the @emph{input} line from the
4500 position where the field starts to the next tab stop.  A padding
4501 character inserts stretchable space similar to @TeX{}'s @code{\hss}
4502 command (thus it can even be negative) to make the sum of all substring
4503 lengths plus the stretchable space equal to the field width.  If more
4504 than one padding character is inserted, the available space is evenly
4505 distributed among them.
4507 @Deffn{Request, fc, [@var{delim-char} [@var{padding-char}]]}
4508 Define a delimiting and a padding character for fields.  If the latter
4509 is missing, the padding character defaults to a space character.  If
4510 there is no argument at all, the field mechanism is disabled (which is
4511 the default).  Note that contrary to e.g.@: the tab repitition
4512 character, delimiting and padding characters are not associated to the
4513 current environment (@pxref{Environments}).
4515 Example:
4517 @example
4518 .fc # ^
4519 .ta T 3i
4520 #foo^bar^smurf#
4522 #foo^^bar^smurf#
4523 @end example
4525 @noindent
4526 and here the result:
4528 @example
4529 foo         bar          smurf
4530 foo            bar       smurf
4531 @end example
4532 @end_Deffn
4535 @c =====================================================================
4537 @node Character Translations, Troff and Nroff Mode, Tabs and Fields, Programming Tutorial
4538 @section Character Translations
4539 @cindex character translations
4540 @cindex translations of characters
4542 @findex .
4543 @findex '
4544 @cindex control character
4545 @cindex character, control
4546 @cindex no-break control character
4547 @cindex character, no-break control
4548 @cindex control character, no-break
4549 The control character (@samp{.}) and the no-break control character
4550 (@samp{'}) can be changed with the @code{cc} and @code{c2} requests,
4551 respectively.
4553 @Deffn{Request, cc, [@var{c}]}
4554 Set the control character to @var{c}.  With no argument the default
4555 control character @samp{.} is restored.  The value of the control
4556 character is associated with the current environment
4557 (@pxref{Environments}).
4558 @end_Deffn
4560 @Deffn{Request, c2, [@var{c}]}
4561 Set the no-break control character to @var{c}.  With no argument the
4562 default control character @samp{'} is restored.  The value of the
4563 no-break control character is associated with the current environment
4564 (@pxref{Environments}).
4565 @end_Deffn
4567 @findex \
4568 @Deffn{Request, eo, }
4569 Disable the escape mechanism completely.  After executing this request,
4570 the backslash character @samp{\} no longer starts an escape sequence.
4572 This request can be very helpful in writing macros since it is not
4573 necessary then to double the escape character.  Here an example:
4575 @example
4576 .\" This is a simplified version of the
4577 .\" .BR request from the man macro package
4579 .de BR
4580 .  ds result \&
4581 .  while (\n[.$] >= 2) \{\
4582 .    as result \fB\$1\fR\$2
4583 .    shift 2
4584 .  \}
4585 .  if \n[.$] .as result \fB\$1
4586 \*[result]
4587 .  ft R
4590 @end example
4591 @end_Deffn
4593 @cindex escape character
4594 @cindex character, escape
4595 @Deffn{Request, ec, [@var{c}]}
4596 Set the escape character to @var{c}.  With no argument the default
4597 escape character @samp{\} is restored.  It can be also used to re-enable
4598 the escape mechanism after an @code{eo} request.
4600 Note that changing the escape character globally will likely break macro
4601 packages since @code{gtroff} has no mechanism (like @TeX{}) to `intern'
4602 macros, i.e., to convert a macro definition into an internal form which
4603 is independent of its representation.  If a macro is called, it will be
4604 executed literally.
4605 @end_Deffn
4607 @Deffn{Escape, \\e, }
4608 This escape sequence prints the current escape character (which is the
4609 backslash character @samp{\} by default).
4610 @end_Deffn
4612 A @dfn{translation} is a mapping of an input character to an output
4613 character.  The default mappings are given in the font definition files
4614 for the specific output device (@pxref{Font Files}); all mappings (both
4615 with @code{tr} and in the font definition files) occur at output time,
4616 i.e., the input character gets assigned the metric information of the
4617 mapped output character.
4619 @Deffn{Request, tr, @var{a}@var{b}@var{c}@var{d}@dots{}}
4620 Translate character @var{a} to @var{b}, character @var{c} to @var{d},
4621 etc.  If there is an odd number of arguments, the last one will be
4622 translated to the space character.
4624 Some notes:
4626 @itemize @bullet
4627 @item
4628 @findex \(
4629 @findex \[
4630 @findex \'
4631 @findex \`
4632 @findex \-
4633 @findex \_
4634 @findex \C
4635 @findex \N
4636 @findex char
4637 @cindex special character
4638 @cindex character, special
4639 @cindex numbered character
4640 @cindex character, numbered
4641 Special characters (@code{\(@var{xx}}, @code{\[@var{xxx}]},
4642 @code{\C'@var{xxx}'}, @code{\'}, @code{\`}, @code{\-}, @code{\_}),
4643 characters defined with the @code{char} request, and numbered characters
4644 (@code{\N'@var{xxx}'}) can be translated also.
4646 @item
4647 @findex \e
4648 The @code{\e} escape can be translated also.
4650 @item
4651 @findex \%
4652 Characters can be mapped onto the @code{\%} escape (but @code{\%} can't
4653 be mapped onto another character).
4655 @item
4656 @cindex backspace character
4657 @cindex character, backspace
4658 @cindex leader character
4659 @cindex character, leader
4660 @cindex newline character
4661 @cindex character, newline
4662 @cindex tab character
4663 @cindex character, tab
4664 @findex \a
4665 @findex \t
4666 The following characters can't be translated: space (with one exception,
4667 see below), backspace, newline, leader (and @code{\a}), tab (and
4668 @code{\t}).
4670 @item
4671 @findex shc
4672 Translations are not considered for finding the soft hyphen character
4673 set with the @code{shc} request.
4675 @item
4676 @findex \&
4677 The character pair @samp{@var{c}\&} (this is an arbitrary character@w{
4678 }@var{c} followed by the zero width space character) will map this
4679 character to nothing.
4681 @example
4682 .tr a\&
4683 foo bar
4684     @result{} foo br
4685 @end example
4687 @noindent
4688 It is even possible to map the space character to nothing:
4690 @example
4691 .tr aa \&
4692 foo bar
4693     @result{} foobar
4694 @end example
4696 @noindent
4697 As shown in the example, the space character can't be the first
4698 character pair as an argument of @code{tr}.  Additionally, it is not
4699 possible to map the space character to any other character; requests
4700 like @w{@samp{.tr aa x}} will undo @w{@samp{.tr aa \&}} instead.
4702 If justification is active, lines will be justified inspite of the
4703 `empty' space character (but there is no minimal distance, i.e.@: the
4704 space character, between words).
4706 @item
4707 After an output character has been constructed (this happens at the
4708 moment immediately before the character is appended to an output
4709 character list, either by direct output, in a macro, diversion, or
4710 string), it is no longer affected by @code{tr}.
4712 @c XXX xref
4714 @item
4715 Without an argument, the @code{tr} request is ignored.
4716 @end itemize
4717 @end_Deffn
4719 @findex \!
4720 @Deffn{Request, trnt, @var{a}@var{b}@var{c}@var{d}@dots{}}
4721 @code{trnt} is the same as the @code{tr} request except that the
4722 translations do not apply to text that is transparently throughput into
4723 a diversion with @code{\!}.  @xref{Diversions}, for more information.
4725 For example,
4727 @example
4728 .tr ab
4729 .di x
4730 \!.tm a
4733 @end example
4735 @noindent
4736 will print @samp{b}; if @code{trnt} is used instead of @code{tr} it will
4737 print @samp{a}.
4738 @end_Deffn
4741 @c =====================================================================
4743 @node Troff and Nroff Mode, Line Layout, Character Translations, Programming Tutorial
4744 @section Troff and Nroff Mode
4745 @cindex troff mode
4746 @cindex mode, troff
4747 @cindex nroff mode
4748 @cindex mode, nroff
4750 Originally, @code{nroff} and @code{troff} were two separate programs,
4751 the former for tty output, the latter for everything else.  With GNU
4752 @code{troff}, both programs are merged into one executable.
4754 Usually, a macro package can be used with both @code{nroff} and
4755 @code{troff}.  Nevertheless, it is sometimes necessary to make a
4756 distinction between the two programs (resp.@: modes), and @code{gtroff}
4757 provides two built-in conditions @samp{n} and @samp{t} for the
4758 @code{if}, @code{ie}, and @code{while} requests to decide whether
4759 @code{gtroff} shall behave like @code{nroff} or like @code{troff}.
4761 @pindex troffrc
4762 @pindex troffrc-end
4763 @Deffn{Request, troff, }
4764 Make the @samp{t} built-in condition true (and the @samp{n} built-in
4765 condition false) for @code{if}, @code{ie}, and @code{while} conditional
4766 requests.  This is the default if @code{gtroff} (@emph{not}
4767 @code{groff}) is started with the @option{-R} switch to avoid loading of
4768 the start-up files @file{troffrc} and @file{troffrc-end}.  Without
4769 @option{-R}, @code{gtroff} stays in troff mode if the output device is
4770 not a tty (e.g.@: `ps').
4771 @end_Deffn
4773 @pindex tmac.tty
4774 @Deffn{Request, nroff, }
4775 Make the @samp{n} built-in condition true (and the @samp{t} built-in
4776 condition false) for @code{if}, @code{ie}, and @code{while} conditional
4777 requests.  This is the default if @code{gtroff} uses a tty output
4778 device; the code for switching to nroff mode is in the file
4779 @file{tmac.tty} which will be loaded by the start-up file
4780 @code{troffrc}.
4781 @end_Deffn
4783 @xref{Conditionals and Loops}, for more details on built-in conditions.
4786 @c =====================================================================
4788 @node Line Layout, Page Layout, Troff and Nroff Mode, Programming Tutorial
4789 @section Line Layout
4790 @cindex line layout
4791 @cindex layout, line
4793 @cindex dimensions, line
4794 @cindex line dimensions
4795 The following drawing shows the dimensions which @code{gtroff} uses for
4796 placing a line of output onto the page.  They are labeled with the
4797 request which manipulates that dimension.
4799 @example
4800 @group
4801                 -->| in |<--
4802                    |<-----------ll------------>|
4803               +----+----+----------------------+----+
4804               |    :    :                      :    |
4805               +----+----+----------------------+----+
4806            -->| po |<--
4807               |<--------paper width---------------->|
4808 @end group
4809 @end example
4811 @noindent
4812 These dimensions are:
4814 @ftable @code
4815 @item po
4816 @cindex left margin
4817 @cindex margin, left
4818 @cindex page offset
4819 @cindex offset, page
4820 @dfn{Page offset} -- This is the leftmost position of text on the final
4821 output, defining the @dfn{left margin}.
4823 @item in
4824 @cindex indentation
4825 @cindex line indentation
4826 @dfn{Indentation} -- This is the distance from the left margin where
4827 text will be printed.
4829 @item ll
4830 @cindex line length
4831 @cindex length of line
4832 @dfn{Line length} -- This is the distance from the left margin to right
4833 margin.
4834 @end ftable
4836 @c XXX improve example
4838 @example
4839 .in +.5i
4840 .ll -.5i
4841 A bunch of really boring text which should
4842 be indented from both margins.
4843 Replace me with a better (and more) example!
4844 .in -.5i
4845 .ll +.5i
4846 @end example
4848 @cindex troff mode
4849 @cindex mode, troff
4850 @cindex nroff mode
4851 @cindex mode, nroff
4852 @Deffn{Request, po, [@var{offset}]}
4853 @Deffnx{Request, po, +offset}
4854 @Deffnx{Request, po, -offset}
4855 Set horizontal page offset to @var{offset} (resp.@: increment or
4856 decrement the current value by @var{offset}).  Note that this request
4857 does not cause a break, so changing the page offset in the middle of
4858 text being filled may not yield the expected result.  The initial value
4859 is 1@dmn{i} if in troff mode, and 0 if in nroff mode (@pxref{Troff and
4860 Nroff Mode}); the default scaling indicator is@w{ }@code{m} (and not@w{
4861 }@code{v} as incorrectly documented in the original @acronym{UNIX} troff
4862 manual).
4864 @vindex .o
4865 The current page offset can be found in the built-in number register
4866 @samp{.o}.
4868 If @code{po} is called without an argument, the page offset is reset to
4869 the previous value before the last call to @code{po}.
4871 @example
4872 .po 3i
4873 \n[.o]
4874     @result{} 720
4875 .po -1i
4876 \n[.o]
4877     @result{} 480
4879 \n[.o]
4880     @result{} 720
4881 @end example
4882 @end_Deffn
4884 @Deffn{Request, in, [@var{indent}]}
4885 @Deffnx{Request, in, +indent}
4886 @Deffnx{Request, in, -indent}
4887 Set indentation to @var{indent} (resp.@: increment or decrement the
4888 current value by @var{indent}).  This request causes a break.
4889 Initially, there is no indentation.
4891 If @code{in} is called without an argument, the indentation is reset to
4892 the previous value before the last call to @code{in}.  The default
4893 scaling indicator is@w{ }@code{m}.
4895 The indentation is associated with the current environment.
4897 If a negative indentation value is specified (which is not allowed),
4898 @code{gtroff} emits a warning of type @samp{range} and sets the
4899 indentation to zero.
4901 The effect of @code{in} is delayed until a partially collected line (if
4902 it exists) is output.
4904 @vindex .i
4905 The current indentation (as set by @code{in}) can be found in the
4906 built-in number register @samp{.i}.
4907 @end_Deffn
4909 @Deffn{Request, ti, offset}
4910 @Deffnx{Request, ti, +offset}
4911 @Deffnx{Request, ti, -offset}
4912 Temporarily indent the next output line by @var{offset}.  If an
4913 increment or decrement value is specified, adjust the temporary
4914 indentation relative to the value set by the @code{in} request.
4916 This request causes a break; its value is associated with the current
4917 environment.  The default scaling indicator is@w{ }@code{m}.  A call of
4918 @code{ti} without an argument is ignored.
4920 If the total indentation value is negative (which is not allowed),
4921 @code{gtroff} emits a warning of type @samp{range} and sets the
4922 temporary indentation to zero.  `Total indentation' is either
4923 @var{offset} if specified as an absolute value, or the temporary plus
4924 normal indentation, if @var{offset} is given as a relative value.
4926 The effect of @code{ti} is delayed until a partially collected line (if
4927 it exists) is output.
4929 @vindex .in
4930 The number register @code{.in} is the indentation that applies to the
4931 current output line.
4933 The difference between @code{.i} and @code{.in} is that the latter takes
4934 into account whether a partially collected line still uses the old
4935 indentation value resp.@: a temporary indentation value is active.
4936 @end_Deffn
4938 @Deffn{Request, ll, [@var{length}]}
4939 @Deffnx{Request, ll, +length}
4940 @Deffnx{Request, ll, -length}
4941 Set the line length to @var{length} (resp.@: increment or decrement the
4942 current value by @var{length}).  Initially, the line length is set to
4943 6.5@dmn{i}.  The effect of @code{ll} is delayed until a partially
4944 collected line (if it exists) is output.  The default scaling indicator
4945 is@w{ }@code{m}.
4947 If @code{ll} is called without an argument, the line length is reset to
4948 the previous value before the last call to @code{ll}.  If a negative
4949 line length is specified (which is not allowed), @code{gtroff} emits a
4950 warning of type @samp{range} and sets the line length to zero.
4952 The line length is associated with the current environment.
4954 @vindex .l
4955 @vindex .ll
4956 The current line length (as set by @code{ll}) can be found in the
4957 built-in number register @code{.l}.  The number register @code{.ll} is
4958 the line length that applies to the current output line.
4960 Similar to @code{.i} and @code{.in}, the difference between @code{.l}
4961 and @code{.ll} is that the latter takes into account whether a partially
4962 collected line still uses the old line length value.
4963 @end_Deffn
4966 @c =====================================================================
4968 @node Page Layout, Page Control, Line Layout, Programming Tutorial
4969 @section Page Layout
4970 @cindex page layout
4971 @cindex layout, page
4973 @code{gtroff} provides some very primitive operations for controlling
4974 page layout.
4976 @cindex page length
4977 @cindex length of page
4978 @Deffn{Request, pl, [@var{length}]}
4979 @Deffnx{Request, pl, +length}
4980 @Deffnx{Request, pl, -length}
4981 Set the @dfn{page length} to @var{length} (resp.@: increment or
4982 decrement the current value by @var{length}).  This is the length of the
4983 physical output page.  The default scaling indicator is@w{ }@code{v}.
4985 @vindex .p
4986 The current setting can be found in the built-in number register
4987 @samp{.p}.
4989 @cindex top margin
4990 @cindex margin, top
4991 @cindex bottom margin
4992 @cindex margin, bottom
4993 Note that this only specifies the size of the page, not the top and
4994 bottom margins.  Those are not set by groff directly.  @xref{Traps}, for
4995 further information on how to do this.
4997 Negative @code{pl} values are possible also, but not very useful: No
4998 trap is sprung, and each line is output on a single page (thus
4999 suppressing all vertical spacing).
5000 @end_Deffn
5002 @cindex headers
5003 @cindex footers
5004 @cindex titles
5005 @code{gtroff} provides several operations which help in setting up top
5006 and bottom titles (or headers and footers).
5008 @cindex title line
5009 @cindex three-part title
5010 @findex tl
5011 @vindex %
5012 The @code{tl} request will print a @dfn{title line}, which consists of
5013 three parts: a left justified portion, a centered portion and a right
5014 justified portion.  The argument to @code{tl} is specified as
5015 @code{'@var{left}'@var{center}'@var{right}'}.  The @samp{%} character is
5016 replaced with the current page number.  This character can be changed
5017 with the @code{pc} request (see below).
5019 @cindex length of title line
5020 @cindex title line, length
5021 @findex lt
5022 @vindex .lt
5023 The title line is printed using its own line length, which is specified
5024 with the @code{lt} request.  The current setting of this is available in
5025 the @code{.lt} number register.
5027 @cindex page number
5028 @cindex number, page
5029 @findex pn
5030 The @code{pn} request will change the page number of the @emph{next}
5031 page.  The only argument is the page number.
5033 @vindex %
5034 @vindex .pn
5035 The current page number is stored in the number register @code{%}.  The
5036 number register @code{.pn} contains the number of the next page: either
5037 the value set by a @code{pn} request, or the number of the current page
5038 plus@w{ }1.
5040 @cindex changing the page number character
5041 @cindex page number character, changing
5042 @findex pc
5043 The @code{pc} request will change the page number character (used by the
5044 @code{tl} request) to a different character.  With no argument, this
5045 mechanism is disabled.
5047 @xref{Traps}.
5050 @c =====================================================================
5052 @node Page Control, Fonts, Page Layout, Programming Tutorial
5053 @section Page Control
5054 @cindex page control
5055 @cindex control, page
5057 @findex bp
5058 @findex pn
5059 To stop processing the current page, and move to the next page, invoke
5060 the @code{bp} request.  This request will also cause a break.  It can
5061 also take an argument of what the next page should be numbered.  The
5062 only difference between @code{bp} and @code{pn} is that @code{pn} does
5063 not cause a break or actually eject a page.
5065 @example
5066 .de newpage
5068 'sp .5i
5069 .tl 'left top'center top'right top'
5070 'sp .3i
5072 @end example
5074 @cindex orphan
5075 @findex ne
5076 It is often necessary to force a certain amount of space before a new
5077 page occurs.  This is most useful to make sure that there is not a
5078 single @dfn{orphan} line left at the bottom of a page.  The @code{ne}
5079 request will ensure that there is a certain distance, specified by the
5080 first argument, before the next page is triggered (@pxref{Traps}, for
5081 further information).  The default unit for @code{ne} is @code{v} and
5082 the default argument is@w{ }1@dmn{v}.
5084 For example, to make sure that no fewer than 2@w{ }lines get orphaned,
5085 do the following before each paragraph:
5087 @example
5088 .ne 2
5089 .ti +5n
5090 text
5091 @end example
5093 @findex sv
5094 @findex os
5095 @findex ne
5096 @code{sv} is similar to the @code{ne} request; it reserves the specified
5097 amount of vertical space.  If the desired amount of space exists before
5098 the next trap (bottom page boundary), the space will be output
5099 immediately.  If there is not enough space, it is stored for later
5100 output via the @code{os} request.  The default argument is@w{ }1@dmn{v}
5101 and the default unit is @code{v}.
5104 @c =====================================================================
5106 @node Fonts, Sizes, Page Control, Programming Tutorial
5107 @section Fonts
5108 @cindex fonts
5110 @findex ft
5111 @findex \f
5112 @code{gtroff} has the ability to switch fonts at any point in the text.
5113 There are two ways to do this, via the @code{ft} request and the
5114 @code{\f} escape.
5116 Fonts are generally specified as upper-case strings, which are usually
5117 1@w{ }to 4 characters representing an abbreviation or acronym of the font
5118 name.
5120 The basic set of fonts are @samp{R}, @samp{I}, @samp{B}, and @samp{BI}.
5121 These are Times Roman, Italic, Bold, and Bold Italic.  There is also at
5122 least one symbol font which contains various special symbols (Greek,
5123 mathematics).  Such symbols fonts cannot be used directly, but should be
5124 used via an escape.
5126 @menu
5127 * Changing Fonts::              
5128 * Font Families::               
5129 * Font Positions::              
5130 * Using Symbols::               
5131 * Artificial Fonts::            
5132 * Ligatures and Kerning::       
5133 @end menu
5135 @c ---------------------------------------------------------------------
5137 @node Changing Fonts, Font Families, Fonts, Fonts
5138 @subsection Changing Fonts
5139 @cindex changing fonts
5140 @cindex fonts, changing
5142 @findex ft
5143 @cindex previous font
5144 @cindex font, previous
5145 Font changes can be done either with the @code{ft} request or the
5146 @code{\f} request.  With no arguments it will switch to the previous
5147 font (also known as @samp{P}).
5149 @example
5150 eggs, bacon,
5151 .ft B
5152 spam
5154 and sausage.
5155 @end example
5157 @findex \f
5158 The @code{\f} escape is useful for changing fonts in the middle of
5159 words:
5161 @example
5162 eggs, bacon, \fBspam\fP and sausage.
5163 @end example
5165 @noindent
5166 Both of the above examples will produce the same output.  Note the usage
5167 of @samp{P} to indicate the previous font -- using @code{\f} it is not
5168 possible to omit this parameter.
5170 Sometimes when putting letters of different fonts, more or less space at
5171 such boundaries are needed.  There are two escapes to help with this.
5173 @findex \/
5174 @cindex italic correction
5175 @cindex correction, italic
5176 The @code{\/} escape increases the width of the preceding character so
5177 that the spacing between that character and the following character will
5178 be correct if the following character is a Roman character.  For
5179 example, if an italic@w{ }f is immediately followed by a Roman right
5180 parenthesis, then in many fonts the top right portion of the f will
5181 overlap the top left of the right parenthesis.  It is a good idea to use
5182 this escape sequence whenever an italic character is immediately
5183 followed by a Roman character without any intervening space.  This small
5184 amount of space is also called @dfn{italic correction}.
5186 @c XXX example
5187 @c producing @i{f}), which is ugly.  Inserting \/ produces f) and avoids
5188 @c this problem.
5190 @findex \,
5191 @cindex left italic correction
5192 @cindex correction, left italic
5193 The @code{\,} escape modifies the spacing of the following character so
5194 that the spacing between that character and the preceding character will
5195 be correct if the preceding character is a Roman character.  It is a
5196 good idea to use this escape sequence whenever a Roman character is
5197 immediately followed by an italic character without any intervening
5198 space.  In analogy to above, this space could be called @dfn{left italic
5199 correction}, but this term isn't used widely.
5201 @c XXX example
5202 @c For example, inserting \, between the parenthesis and the f changes
5203 @c (f to (f.
5205 @findex ftr
5206 @findex ft
5207 @findex ul
5208 @findex bd
5209 @findex \f
5210 @findex cs
5211 @findex tkf
5212 @findex special
5213 @findex fspecial
5214 @findex fp
5215 @findex code
5216 The @code{ftr} request will translate fonts; its syntax is
5218 @example
5219 .ftr @var{F} @var{G}
5220 @end example
5222 @noindent
5223 which translates font@w{ }@var{F} to font@w{ }@var{G}.  Whenever a font
5224 named @var{F} is referred to in a @code{\f} escape sequence, or in the
5225 @code{ft}, @code{ul}, @code{bd}, @code{cs}, @code{tkf}, @code{special},
5226 @code{fspecial}, @code{fp}, or @code{code} requests, font@w{ }@var{G} will
5227 be used.  If @var{G} is missing, or equal to @var{F} then font@w{
5228 }@var{F} will not be translated.
5230 @c ---------------------------------------------------------------------
5232 @node Font Families, Font Positions, Changing Fonts, Fonts
5233 @subsection Font Families
5234 @cindex font families
5235 @cindex families, font
5237 Due to the variety of fonts available, @code{gtroff} has added the
5238 concept of font families.  Each of these families has four styles
5239 (@samp{R}, @samp{I}, @samp{B} and @samp{BI}).
5241 The fonts are specified as the concatenation of the font family and
5242 style.  Specifying a font without the family part will cause
5243 @code{gtroff} to use that style of the current family.  By default,
5244 @code{gtroff} uses the Times family.
5246 This way, it is possible to use the basic four fonts and to select a
5247 different font family on the command line.
5249 @findex fam
5250 @vindex .fam
5251 Font families can be switched with the @code{fam} request.  The current
5252 font family is available in the number register @code{.fam}.  This is a
5253 string-valued register.
5255 @example
5256 spam,
5257 .fam H
5258 spam,
5259 .ft B
5260 spam,
5261 .fam T
5262 spam,
5263 .ft AR
5264 baked beans,
5265 .ft R
5266 and spam.
5267 @end example
5269 @c ---------------------------------------------------------------------
5271 @node Font Positions, Using Symbols, Font Families, Fonts
5272 @subsection Font Positions
5273 @cindex font positions
5274 @cindex positions, font
5276 For the sake of old phototypesetters and compatability with old versions
5277 of @code{troff}, @code{gtroff} has the concept of font @dfn{positions},
5278 on which various fonts are mounted.  The last one or two are reserved
5279 for the symbol font(s).
5281 @findex fp
5282 New fonts can be mounted with the @code{fp} request.  These numeric
5283 positions can then be referred to with font changing commands.  When
5284 @code{gtroff} starts it is using font number one.
5286 @example
5287 .fp 1 H
5288 .fp 2 HI
5289 .fp 3 HB
5290 wink, wink,
5291 .ft 2
5292 nudge, nudge,
5294 .ft 3
5295 say no more!
5297 @end example
5299 @noindent
5300 Note that after these font changes have taken place the original font
5301 is restored.
5303 @vindex .f
5304 The current font in use, as a font position, is available in number
5305 register @code{.f}.  This can be useful to remember the current font,
5306 for later recall.
5308 @example
5309 .nr save-font \n(.f
5310 ... lots 'o text ...
5311 .ft \n[save-font]
5312 @end example
5314 @vindex .fp
5315 The number of the next free font position is available in the number
5316 register @code{.fp}.  This is useful when mounting a new font, like so:
5318 @example
5319 .fp \n[.fp] NEATOFONT
5320 @end example
5322 @pindex DESC
5323 Fonts not listed in the @file{DESC} file are automatically mounted on
5324 the next available font position when they are referenced.  If a font is
5325 to be mounted explicitly with the @code{fp} request on an unused font
5326 position, it should be mounted on the first unused font position, which
5327 can be found in the @code{.fp} register.  Although @code{gtroff} does
5328 not enforce this strictly, it will not allow a font to be mounted at a
5329 position whose number is much greater than that of any currently used
5330 position.
5332 @findex fp
5333 The @code{fp} request has an optional third argument.  This argument
5334 gives the external name of the font, which is used for finding the font
5335 description file.  The second argument gives the internal name of the
5336 font which is used to refer to the font in @code{gtroff} after it has
5337 been mounted.  If there is no third argument then the internal name will
5338 be used as the external name.  This feature make it possible to use
5339 fonts with long names in compatibility mode.
5341 @c ---------------------------------------------------------------------
5343 @node Using Symbols, Artificial Fonts, Font Positions, Fonts
5344 @subsection Using Symbols
5345 @cindex using symbols
5346 @cindex symbols, using
5348 @findex \(
5349 @findex \[
5350 Symbols can be inserted by using a special escape sequence.  This escape
5351 is simply the escape character (usually a backslash) followed by an
5352 identifier.  The symbol identifiers have to be two or more characters,
5353 since single characters conflict with all the other escapes.  The
5354 identifier can be either preceded by a parenthesis if it is two
5355 characters long, or surrounded by square brackets.  So, the symbol for
5356 the mathematical Greek letter `pi' can be produced either by @code{\(*p}
5357 or @code{\[*p]}.
5359 @example
5360 area = \(*p\fIr\fP\u2\d
5361 @end example
5363 @findex \C
5364 The escape @code{\C'@var{xxx}'} will typeset the character named
5365 @var{xxx}.  Normally it is more convenient to use @code{\[@var{xxx}]}.
5366 But @code{\C} has the advantage that it is compatible with recent
5367 versions of @code{ditroff} and is available in compatibility mode.
5369 @findex \N
5370 @findex char
5371 The escape @code{\N'@var{n}'} will typeset the character with code@w{
5372 }@var{n} in the current font.  @var{n} can be any integer.  Most devices
5373 only have characters with codes between 0 and@w{ }255.  If the current
5374 font does not contain a character with that code, special fonts will
5375 @emph{not} be searched.  The @code{\N} escape sequence can be
5376 conveniently used on conjunction with the @code{char} request:
5378 @example
5379 .char \[phone] \f(ZD\N'37'
5380 @end example
5382 @noindent
5383 @pindex DESC
5384 @cindex unnamed characters
5385 @cindex characters, unnamed
5386 The code of each character is given in the fourth column in the font
5387 description file after the charset command.  It is possible to include
5388 unnamed characters in the font description file by using a name of
5389 @samp{---}; the @code{\N} escape sequence is the only way to use these.
5391 @c XXX should be `glyph', not `character'
5393 @findex cflags
5394 @cindex character properties
5395 @cindex properties of characters
5396 Each character has certain properties associated with it.  These
5397 properties can be modified with the @code{cflags} request.  The first
5398 argument is the the sum of the desired flags and the remaining arguments
5399 are the characters to have those properties.
5401 @table @code
5402 @item 1
5403 @cindex end of sentence characters
5404 @cindex characters, end of sentence
5405 the character ends sentences (initially characters @samp{.?!} have this
5406 property)
5408 @item 2
5409 @cindex hyphenating characters
5410 @cindex characters, hyphenation
5411 lines can be broken before the character (initially no characters have
5412 this property)
5414 @item 4
5415 @glindex hy
5416 @glindex em
5417 lines can be broken after the character (initially the characters
5418 @samp{-\(hy\(em} have this property)
5420 @item 8
5421 @cindex overlapping characters
5422 @cindex characters, overlapping
5423 @glindex ul
5424 @glindex rn
5425 @glindex ru
5426 the character overlaps horizontally (initially the characters
5427 @samp{\(ul\(rn\(ru} have this property)
5429 @item 16
5430 @glindex br
5431 the character overlaps vertically (initially character @samp{\(br} has
5432 this property)
5434 @item 32
5435 @cindex transparent characters
5436 @cindex character, transparent
5437 @cindex '
5438 @cindex "
5439 @cindex ]
5440 @cindex )
5441 @cindex *
5442 @glindex dg
5443 @glindex rq
5444 an end of sentence character followed by any number of characters with
5445 this property will be treated as the end of a sentence if followed by a
5446 newline or two spaces; in other words the character is @dfn{transparent}
5447 for the purposes of end of sentence recognition -- this is the same as
5448 having a zero space factor in @TeX{} (initially characters
5449 @samp{"')]*\(dg\(rq} have this property).
5450 @end table
5452 @findex char
5453 @cindex defining characters
5454 @cindex characters, defining
5455 New characters can be created with the @code{char} request.  It is
5456 called as
5458 @example
5459 .char @var{c} @var{string}
5460 @end example
5462 @findex tr
5463 @findex lc
5464 @findex \l
5465 @findex \L
5466 @findex hcode
5467 @noindent
5468 This defines character@w{ }@var{c} to be @var{string}.  Every time
5469 character@w{ }@var{c} needs to be printed, @var{string} will be
5470 processed in a temporary environment and the result will be wrapped up
5471 into a single object.  Compatibility mode will be turned off and the
5472 escape character will be set to @samp{\} while @var{string} is being
5473 processed.  Any emboldening, constant spacing or track kerning will be
5474 applied to this object rather than to individual characters in
5475 @var{string}.  A character defined by this request can be used just like
5476 a normal character provided by the output device.  In particular other
5477 characters can be translated to it with the @code{tr} request; it can be
5478 made the leader character by the @code{lc} request; repeated patterns
5479 can be drawn with the character using the @code{\l} and @code{\L} escape
5480 sequences; words containing the character can be hyphenated correctly,
5481 if the @code{hcode} request is used to give the character a hyphenation
5482 code.  There is a special anti-recursion feature: use of character
5483 within the character's definition will be handled like normal characters
5484 not defined with @code{char}.
5486 @findex rchar
5487 @cindex removing character definition
5488 @cindex character, removing definition
5489 A character definition can be removed with the @code{rchar} request.
5490 Its arguments are the characters to be removed.  This undoes the effect
5491 of a @code{char} request.
5493 @xref{Special Characters}.
5495 @c ---------------------------------------------------------------------
5497 @node Artificial Fonts, Ligatures and Kerning, Using Symbols, Fonts
5498 @subsection Artificial Fonts
5499 @cindex artificial fonts
5500 @cindex fonts, artificial
5502 There are a number of requests for artificially creating fonts.  These
5503 are largely vestigial remains from the days when output devices did not
5504 have a wide variety of fonts, and when @code{nroff} and @code{troff}
5505 were separate programs.  These are no longer necessary in GNU
5506 @code{troff}.
5508 @findex ul
5509 @cindex underlining
5510 The @code{ul} request will print subsequent lines in italics on a device
5511 capable of it, or underline the text on an character output device.  The
5512 single argument is the number of lines to be ``underlined,'' with no
5513 argument, the next line will be underlined.
5515 @findex cu
5516 @cindex continuous underlining
5517 @cindex underlining, continuous
5518 The @code{cu} request is similar to @code{ul} ...
5520 @c XXX more info
5522 @findex uf
5523 @cindex underline font
5524 @cindex font for underlining
5525 The @code{uf} request will set the underline font used by @code{ul} and
5526 @code{cu}.
5528 @findex bd
5529 @cindex imitating bold face
5530 @cindex bold face, imitating
5531 The @code{bd} request artificially creates a bold font by printing each
5532 character twice, slightly offset.  The first argument specifies the font
5533 to embolden, and the second is the number of basic units, minus one, by
5534 which the two characters will be offset.  If the second argument is
5535 missing, emboldening will be turned off.
5537 @c ---------------------------------------------------------------------
5539 @node Ligatures and Kerning,  , Artificial Fonts, Fonts
5540 @subsection Ligatures and Kerning
5541 @cindex ligatures and kerning
5542 @cindex kerning and ligatures
5544 What are ligatures?
5546 @c XXX more info
5548 @findex lg
5549 @vindex .lg
5550 The ligature mechanism can be switched on or off with the @code{lg}
5551 request; if the parameter is non-zero or missing, ligatures are enabled,
5552 otherwise disabled.  Default is on.  The current ligature mode can be
5553 found in the number register @code{.lg} (set to@w{ }1 if ligatures are
5554 enabled, 0@w{ }otherwise).
5556 What is kerning?
5558 @c XXX more info
5560 @cindex zero width space character
5561 @cindex character, zero width space
5562 @cindex space character, zero width
5563 If the font description file contains pairwise kerning information,
5564 characters from that font will be kerned.  Kerning between two
5565 characters can be inhibited by placing @code{\&} between them.
5567 @findex kern
5568 @vindex .kern
5569 Kerning can be activated with the @code{kern} request.  If the parameter
5570 is non-zero or missing, enable pairwise kerning, otherwise disable it.
5571 The number register @code{.kern} is set to@w{ }1 if pairwise kerning is
5572 enabled, 0@w{ }otherwise.
5574 @findex tkf
5575 @cindex track kerning
5576 @cindex kerning, track
5577 What is track kerning?
5579 @c XXX more info
5581 Track kerning must be used with great care since it is usually
5582 considered bad typography if the reader notices the effect.  The syntax
5583 of the @code{tkf} request is
5585 @example
5586 .tkf @var{f} @var{s1} @var{n1} @var{s2} @var{n2}
5587 @end example
5589 @noindent
5590 Enable track kerning for font@w{ }@var{f}.  If the current font is@w{
5591 }@var{f} the width of every character will be increased by an amount
5592 between @var{n1} and @var{n2}; if the current point size is less than or
5593 equal to @var{s1} the width will be increased by @var{n1}; if it is
5594 greater than or equal to @var{s2} the width will be increased by
5595 @var{n2}; if the point size is greater than or equal to @var{s1} and
5596 less than or equal to @var{s2} the increase in width is a linear
5597 function of the point size.
5600 @c =====================================================================
5602 @node Sizes, Strings, Fonts, Programming Tutorial
5603 @section Sizes
5604 @cindex sizes
5606 @cindex baseline
5607 @cindex type size
5608 @cindex size of type
5609 @cindex vertical spacing
5610 @cindex spacing, vertical
5611 @code{gtroff} uses two dimensions with each line of text, type size and
5612 vertical spacing.  The @dfn{type size} is the height from the text
5613 @dfn{baseline} to the top of the tallest character (descenders may drop
5614 below this baseline).  @dfn{Vertical spacing} is the amount of space
5615 @code{gtroff} allows for a line of text; normally, this is about 20%@w{
5616 }larger than the current type size.  Ratios smaller than this can result
5617 in hard-to-read text; larger that this, it will spread the text out more
5618 vertically (useful for term papers).  By default, @code{gtroff} uses
5619 10@w{ }point type on 12@w{ }point spacing.
5621 @cindex leading
5622 The difference between type size and vertical spacing is known, by
5623 typesetters, as @dfn{leading}.
5625 @menu
5626 * Changing Type Sizes::         
5627 * Fractional Type Sizes::       
5628 @end menu
5630 @c ---------------------------------------------------------------------
5632 @node Changing Type Sizes, Fractional Type Sizes, Sizes, Sizes
5633 @subsection Changing Type Sizes
5634 @cindex changing type sizes
5635 @cindex type sizes, changing
5637 @findex ps
5638 @findex vs
5639 @findex \s
5640 @vindex .s
5641 @vindex .v
5642 Using the @code{ps} request and the @code{\s} escape the type size can
5643 be changed.  The @code{vs} request will change the vertical spacing.
5644 The default unit for the @code{ps} and @code{vs} requests are points.
5645 The number registers @code{.s} and @code{.v} contain the current type
5646 size and vertical spacing.
5648 These requests take parameters in units of points.  It is possible to
5649 specify sizes as an absolute size, or as a relative change from the
5650 current size.  The size@w{ }0 means go back to the previous size.  With
5651 no argument it will also revert to the previous size.
5653 @example
5654 snap, snap,
5655 .ps +2
5656 grin, grin,
5657 .ps +2
5658 wink, wink, \s+2nudge, nudge,\s+8 say no more!
5659 .ps 10
5660 @end example
5662 The @code{\s} escape may be called in a variety of ways.  Much like
5663 other escapes there must be a way to determine where the argument ends
5664 and the text begins.  Any of the following forms are valid:
5666 @table @code
5667 @item \s@var{n}
5668 Set the point size to @var{n}@w{ }points.  @var{n}@w{ }must be either 0
5669 or in the range 4 to@w{ }39.
5671 @item \s+@var{n}
5672 @itemx \s-@var{n}
5673 Increase resp.@: decrease the point size by @var{n}@w{ }points.
5674 @var{n}@w{ }must be exactly one digit.
5676 @item \s(@var{nn}
5677 Set the point size to @var{nn}@w{ }points.  @var{nn} must be exactly two
5678 digits.
5680 @item \s+(@var{nn}
5681 @itemx \s-(@var{nn}
5682 @itemx \s(+@var{nn}
5683 @itemx \s(-@var{nn}
5684 Increase resp.@: decrease the point size by @var{nn}@w{ }points.
5685 @var{nn} must be exactly two digits.
5686 @end table
5688 @xref{Fractional Type Sizes}, for yet another syntactical form of using
5689 the @code{\s} escape.
5691 Some devices may only have certain permissible sizes, in which case
5692 @code{gtroff} will round to the nearest permissible size.
5694 @c XXX example
5696 @example
5697 ... .sz macro example?? ...
5698 @end example
5700 @c ---------------------------------------------------------------------
5702 @node Fractional Type Sizes,  , Changing Type Sizes, Sizes
5703 @subsection Fractional Type Sizes
5704 @cindex fractional type sizes
5705 @cindex type sizes, fractional
5707 @cindex @code{s} unit
5708 @cindex unit, @code{s}
5709 @cindex @code{z} unit
5710 @cindex unit, @code{z}
5711 @findex ps
5712 @findex cs
5713 @findex tkf
5714 @findex \H
5715 @findex \s
5716 A @dfn{scaled point} is equal to 1/@var{sizescale} points, where
5717 @var{sizescale} is specified in the @file{DESC} file (1@w{ }by default.)
5718 There is a new scale indicator @samp{z} which has the effect of
5719 multiplying by @var{sizescale}.  Requests and escape sequences in
5720 @code{gtroff} interpret arguments that represent a point size as being in
5721 units of scaled points, but they evaluate each such argument using a
5722 default scale indicator of @samp{z}.  Arguments treated in this way are
5723 the argument to the @code{ps} request, the third argument to the
5724 @code{cs} request, the second and fourth arguments to the @code{tkf}
5725 request, the argument to the @code{\H} escape sequence, and those
5726 variants of the @code{\s} escape sequence that take a numeric expression
5727 as their argument (see below).
5729 For example, suppose @var{sizescale} is@w{ }1000; then a scaled point
5730 will be equivalent to a millipoint; the request @w{@samp{.ps 10.25}} is
5731 equivalent to @w{@samp{.ps 10.25z}} and thus sets the point size to 10250
5732 scaled points, which is equal to 10.25@w{ }points.
5734 It would make no sense to use the @samp{z} scale indicator in a numeric
5735 expression whose default scale indicator was neither @samp{u} nor
5736 @samp{z}, and so @code{gtroff} disallows this.  Similarly it would make
5737 no sense to use a scaling indicator other than @samp{z} or @samp{u} in a
5738 numeric expression whose default scale indicator was @samp{z}, and so
5739 @code{gtroff} disallows this as well.
5741 There is also new scale indicator @samp{s} which multiplies by the
5742 number of units in a scaled point.  So, for example, @samp{\n[.ps]s} is
5743 equal to @samp{1m}.  Be sure not to confuse the @samp{s} and @samp{z}
5744 scale indicators.
5746 @vindex .s
5747 @vindex .ps
5748 The number register @code{.s} returns the point size in points as decimal
5749 fraction.  There is also a new number register @code{.ps} that returns
5750 the point size in scaled points.
5752 @vindex .psr
5753 @vindex .sr
5754 The last-requested point size in scaled points is contained in the
5755 @code{.psr} number register.  The last requested point size in points as
5756 a decimal fraction can be found in @code{.psr}.  This is a string-valued
5757 register.
5759 @table @code
5760 @item \s[@var{n}]
5761 @itemx \s'@var{n}'
5762 Set the point size to @var{n} scaled points; @var{n}@w{ }is a numeric
5763 expression with a default scale indicator of @samp{z}.
5765 @item \s[+@var{n}]
5766 @itemx \s[-@var{n}]
5767 @itemx \s+[@var{n}]
5768 @itemx \s-[@var{n}]
5769 @itemx \s'+@var{n}'
5770 @itemx \s'-@var{n}'
5771 @itemx \s+'@var{n}'
5772 @itemx \s-'@var{n}'
5773 Increases resp.@: decreases the point size by @var{n} scaled points;
5774 @var{n} is a numeric expression with a default scale indicator of
5775 @samp{z}.
5776 @end table
5778 @xref{Font Files}.
5781 @c =====================================================================
5783 @node Strings, Conditionals and Loops, Sizes, Programming Tutorial
5784 @section Strings
5785 @cindex strings
5787 @findex ds
5788 @code{gtroff} has string variables, which are entirely for user
5789 convenience (i.e.@: there are no built-in strings).  They are defined
5790 via the @code{ds} request.
5792 @example
5793 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d
5794 @end example
5796 @findex \*
5797 @cindex string interpolation
5798 @cindex string expansion
5799 @cindex interpolation of strings
5800 @cindex expansion of strings
5801 They are interpolated, or expanded in-place, via the @code{\*} escape:
5803 @example
5804 The \*(UX Operating System
5805 @end example
5807 If the string named by the @code{\*} does not exist, the escape will be
5808 replaced by nothing.
5810 @cindex comments, with @code{ds}
5811 @strong{Caution:} Unlike other requests, the second argument to the
5812 @code{ds} request takes up the entire line including trailing spaces.
5813 This means that comments on a line with such a request can introduce
5814 unwanted space into a string.
5816 @example
5817 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d \" UNIX trademark
5818 @end example
5820 @noindent
5821 Instead the comment should be put on another line or have the comment
5822 escape adjacent with the end of the string.
5824 @example
5825 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d\"  UNIX trademark
5826 @end example
5828 @cindex trailing quotes
5829 @cindex quotes, trailing
5830 @cindex leading spaces with @code{ds}
5831 @cindex spaces with @code{ds}
5832 To produce leading space the string can be started with a double quote.
5833 No trailing quote is needed; in fact, any trailing quote is included in
5834 your string.
5836 @example
5837 .ds sign "           Yours in a white wine sauce,
5838 @end example
5840 @findex as
5841 @cindex appending to strings
5842 @cindex strings, appending
5843 The @code{as} request will append a string to another string.  It works
5844 similar to the @code{ds} request except that it appends the second
5845 argument onto the string named by the first argument.
5847 @example
5848 .as sign " with shallots, onions and garlic,
5849 @end example
5851 @findex \@key{RET}
5852 @cindex multi-line strings
5853 @cindex strings, multi-line
5854 @cindex newline character, escaping
5855 @cindex escaping newline characters
5856 Strings are not limited to a single line of text.  A string can span
5857 several lines by escaping the newlines with a backslash.  The resulting
5858 string will be stored @emph{without} the newlines.
5860 @example
5861 .ds foo lots and lots \
5862 of text are on these \
5863 next several lines
5864 @end example
5866 @findex substring
5867 @cindex substrings
5868 Rudimentary string manipulation routines are given with the
5869 @code{substring} and @code{length} requests.  The former has the
5870 following syntax:
5872 @example
5873 .substring @var{xx} @var{n1} [@var{n2}]
5874 @end example
5876 @noindent
5877 It replaces the string in register@w{ }@var{xx} with the substring
5878 defined by the indices @var{n1} and@w{ }@var{n2}.  The first character
5879 in the string has index one.  If @var{n2} is omitted, it is taken to be
5880 equal to the string's length.  If the index value @var{n1} or @var{n2}
5881 is negative or zero, it will be counted from the end of the string,
5882 going backwards: The last character has index@w{ }0, the character
5883 before the last character has index@w{ }-1, etc.
5885 @findex length
5886 @cindex length of a string
5887 @cindex string, length of
5888 Here the syntax of the @code{length} request:
5890 @example
5891 .length @var{xx} @var{string}
5892 @end example
5894 @noindent
5895 It computes the length of @var{string} and returns it in the number
5896 register@w{ }@var{xx} (which is not necessarily defined before).
5898 @findex rn
5899 @code{rn}
5901 @c XXX
5903 @findex rm
5904 @code{rm}
5906 @c XXX
5908 @findex als
5909 @code{als}
5911 @c XXX
5913 @findex chop
5914 @code{chop}
5916 @c XXX
5918 @xref{Identifiers}, and @ref{Comments}.
5921 @c =====================================================================
5923 @node Conditionals and Loops, Writing Macros, Strings, Programming Tutorial
5924 @section Conditionals and Loops
5925 @cindex conditionals and loops
5926 @cindex loops and conditionals
5928 @findex if
5929 @findex while
5930 In @code{if} and @code{while} requests, there are several more operators
5931 available:
5933 @table @code
5934 @item e
5935 @itemx o
5936 True if the current page is even or odd numbered (respectively).
5938 @item n
5939 @findex nroff
5940 True if the document is being processed in nroff mode.
5942 @item t
5943 @findex troff
5944 True if the document is being processed in troff mode.
5946 @item '@var{xxx}'@var{yyy}'
5947 True if the string @var{xxx} is equal to the string @var{yyy}.  Other
5948 characters can be used in place of the single quotes.
5949 @c XXX (Which?)
5950 The strings are `formatted' before being compared.
5951 @c XXX (?)
5953 @item r@var{xxx}
5954 True if there is a number register named @var{xxx}.
5956 @item d@var{xxx}
5957 True if there is a string, macro, diversion, or request named @var{xxx}.
5959 @item c@var{ch}
5960 @findex char
5961 True if there is a character @var{ch} available; @var{ch} is either an
5962 @acronym{ASCII} character or a special character (@code{\(@var{ch}} or
5963 @code{\[@var{ch}]}); the condition will also be true if @var{ch} has
5964 been defined by the @code{char} request.
5965 @end table
5967 @menu
5968 * if-else::                     
5969 * while::                       
5970 @end menu
5972 @c ---------------------------------------------------------------------
5974 @node if-else, while, Conditionals and Loops, Conditionals and Loops
5975 @subsection if-else
5976 @cindex if-else
5978 @code{gtroff} has if-then-else constructs like other languages, although
5979 the formatting can be painful.
5981 @findex if
5982 The @code{if} request has the following syntax:
5984 @example
5985 .if @var{expr} @var{anything}
5986 @end example
5988 @noindent
5989 where @var{expr} is the expression to be evaluated; @var{anything} (the
5990 remainder of the line) will be executed if @var{expr} evaluates to
5991 non-zero (true).  @var{anything} will be interpreted as though it was on
5992 a line by itself.  @xref{Expressions}, for more info.
5994 Here are some examples:
5996 @example
5997 .if t .ls 2                             \" double spacing in troff
5998 .if 0 .ab how'd this happen?
5999 @end example
6001 @findex ie
6002 @findex el
6003 An if-then-else is written using two requests @code{ie} and @code{el}.
6004 The first request is the `if' part and the latter is the `else' part.
6006 @c XXX example
6008 @example
6011 @end example
6013 @findex \@{
6014 @findex \@}
6015 In many cases more than one request is to be executed as a result of any
6016 of these requests.  This can be done using the @code{\@{} and @code{\@}}
6017 escapes.  The following example shows the possible ways to use these
6018 escapes (note the position of the opening and closing braces).
6020 @example
6021 .ie t \@{\
6022 .    ds lq ``
6023 .    ds rq ''
6024 .\@}
6025 .el \
6026 .\@{\
6027 .    ds lq "
6028 .    ds rq "\@}
6029 .ds qq "
6030 @end example
6032 @xref{Expressions}.
6034 @c ---------------------------------------------------------------------
6036 @node while,  , if-else, Conditionals and Loops
6037 @subsection while
6038 @cindex while
6040 @findex while
6041 @code{gtroff} provides a looping construct using the @code{while}
6042 request, which is used much like the @code{if} (and related) requests.
6043 The first argument is an expression which will be evaluated.  The
6044 @code{while} request will interpret the remainder of the line until the
6045 expression evaluates to 0 or false.
6047 @example
6048 .nr a 0 1
6049 .while (\na<9) \&\n+a,
6050 \&\n+a
6051 @end example
6053 @noindent
6054 The preceding example produces:
6056 @example
6057 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
6058 @end example
6060 @cindex zero width space character
6061 @cindex character, zero width space
6062 @cindex space character, zero width
6063 @findex \&
6064 @noindent
6065 Note the usage of the @code{\&} escape to avoid a control character at
6066 the beginning of a line.
6068 @findex break
6069 @findex continue
6070 The @code{break} request will @dfn{break} out of a while loop.  Be sure
6071 not to confuse this with the @code{br} request (causing a line break).
6072 The @code{continue} request will finish the current iteration of a while
6073 loop, immediately restarting the next iteration.
6075 @xref{Expressions}.
6078 @c =====================================================================
6080 @node Writing Macros, Page Motions, Conditionals and Loops, Programming Tutorial
6081 @section Writing Macros
6082 @cindex writing macros
6083 @cindex macros, writing
6085 @findex de
6086 A @dfn{macro} is a collection of text and embedded commands which can be
6087 invoked multiple times.  Macros are used for defining common operations.
6088 Macros are defined using the @code{de} request.  This request takes a
6089 name for the macro as the first argument.  Subsequent lines are copied
6090 into an internal buffer until the line @code{..} is encountered.  The
6091 optional second argument to @code{de} can change this ending token.
6093 Here a small example macro called @samp{P} which will cause a break and
6094 the insertion of some vertical space.  It could be used to separate
6095 paragraphs.
6097 @example
6098 .de P
6100 .sp .8v
6102 @end example
6104 @findex am
6105 The @code{am} request works similarly to @code{de} except it appends
6106 onto the macro named by the first argument.  So, to make the previously
6107 defined @samp{P} macro actually do indented instead of block paragraphs,
6108 is is possible to add the necessary code to the existing macro like
6109 this:
6111 @example
6112 .am P
6113 .ti +5n
6115 @end example
6117 @findex als
6118 @cindex aliases, macro
6119 @cindex macro aliases
6120 Macros can be aliased with the @code{als} request.
6122 @c XXX example
6124 @menu
6125 * Copy-in Mode::                
6126 * Parameters::                  
6127 @end menu
6129 @c ---------------------------------------------------------------------
6131 @node Copy-in Mode, Parameters, Writing Macros, Writing Macros
6132 @subsection Copy-in Mode
6133 @cindex copy-in mode
6134 @cindex mode, copy-in
6136 @findex \n
6137 @findex \$
6138 @findex \*
6139 @findex \\
6140 @findex \@key{RET}
6141 When @code{gtroff} reads in the text for a macro or diversion it copies
6142 the text (including request lines, but excluding escapes) into an
6143 internal buffer.  Escapes will be converted into an internal form,
6144 except for @code{\n}, @code{\$}, @code{\*}, @code{\\} and
6145 @code{\@key{RET}} which are evaluated and inserted into the text where
6146 the escape was located.  This is known as @dfn{copy-in} mode or
6147 @dfn{copy} mode.
6149 What this means is that you can specify when these escapes are to be
6150 evaluated (either at copy-in time or at the time of use) by insulating
6151 the escapes with an extra backslash.  Compare this to the @code{\def}
6152 and @code{\edef} commands in @TeX{}.
6154 For example, the following will result in the numbers 20 and@c{ }10
6155 being printed:
6157 @example
6158 .nr x 20
6159 .de y
6160 .nr x 10
6161 \&\nx
6162 \&\\nx
6165 @end example
6167 @c ---------------------------------------------------------------------
6169 @node Parameters,  , Copy-in Mode, Writing Macros
6170 @subsection Parameters
6171 @cindex parameters
6173 @findex \$
6174 @vindex .$
6175 The arguments to a macro can be examined using a variety of escapes.
6176 The number of arguments is available in the @code{.$} number register.
6177 Any individual argument can be retrieved with one of the following
6178 escapes:
6180 @cindex copy-in mode
6181 The escapes @code{\$@var{n}}, @code{\$(@var{nn}} and
6182 @code{\$[@var{nnn}]} will result in the @var{n}th, @var{nn}th or
6183 @var{nnn}th argument.  As usual, the first form only accepts a single
6184 number (larger than zero), the second only a two-digit number (larger or
6185 equal to@w{ }10), and the third any positive integer value (larger than
6186 zero).  Macros can have an unlimited number of arguments.  Note that due
6187 to copy-in mode, two backslashes should be used on these in actual use
6188 to prevent interpolation until the macro is actually invoked.
6190 @findex shift
6191 The request @code{shift} will shift the arguments 1@w{ }position, or as
6192 many positions as specified by its argument.  After executing this
6193 request, argument@w{ }@var{i} will become argument @var{i}-@var{n};
6194 arguments 1 to@w{ }@var{n} will no longer be available.  Shifting by
6195 negative amounts is currently undefined.
6197 @findex \$*
6198 @findex \$@@
6199 In some cases it is convenient to use all of the arguments at once (for
6200 example, to pass the arguments along to another macro).  The @code{\$*}
6201 escape is the concatenation of all the arguments separated by spaces.  A
6202 similar escape is @code{\$@@}, which is the concatenation of all the
6203 arguments with each surrounded by double quotes, and separated by
6204 spaces.
6206 @findex \$0
6207 @findex als
6208 The @code{\$0} escape is the name by which the current macro was
6209 invoked.  The @code{als} request can make a macro have more than one
6210 name.
6212 @example
6213 .de vl
6214 .ie \\n(.$=1 .ds Vl Pre-Release Version
6215 .el          .ds Vl Version \\$3, \\$4.
6217 @end example
6219 This would be called as
6221 @example
6222 .vl $Id$
6223 @end example
6225 @xref{Request Arguments}.
6228 @c =====================================================================
6230 @node Page Motions, Drawing Requests, Writing Macros, Programming Tutorial
6231 @section Page Motions
6232 @cindex page motions
6233 @cindex motions, page
6235 @findex sp
6236 Motions up and down the page can be done with the @code{sp} request.
6237 However, this causes a break so that the actual effect is to move to the
6238 left margin and then to the specified location.
6240 @findex mk
6241 @findex rt
6242 The request @code{mk} can be used to mark a location on a page, for
6243 movement to later.  This request takes a register name as an argument in
6244 which to store the current page location.  With no argument it will
6245 store the location in an internal register.  The results of this can be
6246 used later by the @code{rt} or the @code{sp} request.  The @code{rt}
6247 request will return @emph{upwards} to the location given in the register
6248 name given as an argument, with no argument it will return to the
6249 location marked with the @code{mk} request
6251 @c XXX example
6253 @example
6254 ... dual column example ...
6255 @end example
6257 The following escapes give fine control of movements about the page.
6259 @findex \v
6260 @cindex vertical motion
6261 @cindex motion, vertical
6262 The @code{\v'@var{e}'} enables arbitrary vertical motion from the
6263 current location on the page.  The argument@w{ }@var{e} specifies the
6264 distance to move; positive is downwards and negative upwards.  The
6265 default unit for this escape is vertical spaces, @code{v}'s.  Beware,
6266 however, that @code{gtroff} will leave text processing to continue
6267 wherever the motion ends, so to avoid interference with text processing,
6268 motions should be balanced.
6270 There are some special case escapes for vertical motion.
6272 @ftable @code
6273 @item \r
6274 move upwards@w{ }1@dmn{v}.
6276 @item \u
6277 move upwards@w{ }.5@dmn{v}.
6279 @item \d
6280 move down@w{ }.5@dmn{v}.
6281 @end ftable
6283 @findex \h
6284 Horizontal motions can be done via the @code{\h'@var{e}'} escape.  The
6285 expression@w{ }@var{e} indicates how far to move: positive is rightwards
6286 and negative leftwards.
6288 There are a number of special case escapes for horizontal motion:
6290 @ftable @code
6291 @item \@key{SP}
6292 an unbreakable and unpaddable (i.e.@: not expanded during filling)
6293 space.  (Note: It is a backslash followed by a space.)
6295 @item \~
6296 an unbreakable space that stretches like a normal inter-word space when a
6297 line is adjusted.
6299 @item \|
6300 a 1/6th em space.
6302 @item \^
6303 a 1/12th em space.
6305 @item \0
6306 a space the size of a digit.
6308 @item \&
6309 @cindex zero width space character
6310 @cindex character, zero width space
6311 @cindex space character, zero width
6312 A zero width space.
6314 @item \)
6315 Like @code{\&} except that it behaves like a character declared with the
6316 @code{cflags} request to be transparent for the purposes of end of
6317 sentence recognition.
6318 @end ftable
6320 @c XXX example
6322 @example
6323 ... tex logo example ...
6324 @end example
6326 @findex \w
6327 @cindex width escape
6328 @cindex escape, width
6329 A frequent need is to do horizontal movement based on the width of some
6330 arbitrary text (e.g.@: given as an argument to a macro).  For that,
6331 there is the escape @code{\w'@var{text}'} which will interpolate to the
6332 width of the given @var{text} in basic units.
6334 @c XXX example
6336 @example
6337 ... strlen example ...
6338 @end example
6340 Font changes may occur in @var{text} which don't affect current
6341 settings.
6343 After use, @code{\w} sets several registers:
6345 @table @code
6346 @item st
6347 @itemx sb
6348 @vindex st
6349 @vindex sb
6350 The highest and lowest point, respectively, in @var{text}.
6352 @item rst
6353 @itemx rsb
6354 @vindex rst
6355 @vindex rsb
6356 Like the @code{st} and @code{sb} registers, but takes account of the
6357 heights and depths of characters.
6359 @item ct
6360 @vindex ct
6361 is set according to what kinds of characters occur in @var{text}:
6362 @table @asis
6363 @item 0
6364 only short characters, no descenders or tall characters.
6366 @item 1
6367 descender
6369 @item 2
6370 tall character
6372 @item 3
6373 both a descender and a tall character
6374 @end table
6376 @item ssc
6377 @vindex ssc
6378 The amount of horizontal space (possibly negative) that should be added
6379 to the last character before a subscript.
6381 @item skw
6382 @vindex skw
6383 How far to right of the center of the last character in the @code{\w}
6384 argument, the center of an accent from a Roman font should be placed
6385 over that character.
6386 @end table
6388 @findex \k
6389 @vindex .k
6390 @code{\k}
6392 @code{.k}
6394 @c XXX documentation
6397 @c =====================================================================
6399 @node Drawing Requests, Traps, Page Motions, Programming Tutorial
6400 @section Drawing Requests
6401 @cindex drawing requests
6402 @cindex requests for drawing
6404 @code{gtroff} provides a number of ways to draw lines and other figures
6405 on the page.  Used in combination with the page motion commands
6406 (@pxref{Page Motions}, for more info), a wide variety of figures can be
6407 drawn.  However, for complex drawings these operations can be quite
6408 cumbersome, and it may be wise to use graphic preprocessors like
6409 @code{gpic} or @code{ggrn}.  @xref{gpic}, and @ref{ggrn}, for more
6410 information.
6412 All drawing is done via escapes.
6414 @findex \l
6415 @cindex horizontal line
6416 @cindex line, horizontal
6417 The @code{\l} escape will draw a line rightwards from the current
6418 location.  The full syntax for this escape is
6420 @example
6421 \l'@var{l}@var{c}'
6422 @end example
6424 @noindent
6425 where @var{l} is the length of the line to be drawn, starting at the
6426 current location; positive numbers will draw to the right, and negative
6427 will draw towards the left.  This can also be specified absolutely
6428 (i.e.@: with a leading @samp{|}) which will draw back to the beginning
6429 of the line.
6431 @cindex underscore character
6432 @cindex character, underscore
6433 @cindex line drawing character
6434 @cindex character for line drawing
6435 The optional second parameter @var{c} is a character to draw the line
6436 with.  If this second argument is not specified, @code{gtroff} will use
6437 the underscore character.
6439 @cindex zero width space character
6440 @cindex character, zero width space
6441 @cindex space character, zero width
6442 @findex \&
6443 To separate the two arguments (to prevent @code{gtroff} from
6444 interpreting a drawing character as a scaling indicator) use @code{\&}.
6446 Here a small useful example:
6448 @example
6449 .de box
6450 \(br\\$*\(br\l'|0\(rn'\l'|0\(ul'
6452 @end example
6454 @noindent
6455 @opindex |
6456 Note that this works by outputting a box rule (a vertical line), then
6457 the text given as an argument and then another box rule.  Then the line
6458 drawing escapes both draw from the current location to the beginning of
6459 the @emph{input} line.
6461 @findex \L
6462 @cindex vertical line
6463 @cindex line, vertical
6464 @cindex line drawing character
6465 @cindex character for line drawing
6466 @cindex box rule character
6467 @cindex character, box rule
6468 Vertical lines are drawn using the @code{\L} escape.  Its parameters are
6469 specified similar to the @code{\l} escape.  If the length is positive,
6470 the movement will be downwards, and upwards for negative values.  The
6471 default character is the box rule character.  As with the vertical
6472 motion escapes, text processing will blindly continue where the line
6473 ends.
6475 @c XXX example
6477 @example
6478 ...box macro...
6479 @end example
6481 @findex \D
6482 More flexible drawing functions are available via the @code{\D} escape.
6483 While the previous escapes will work on a character device, these
6484 escapes will not.
6486 @table @code
6487 @item \D'l @var{dx} @var{dy}'
6488 Draw a line from the current location to the relative point specified by
6489 (@var{dx},@var{dy}).
6491 @c XXX example
6493 @example
6494 ...revised box macro...
6495 @end example
6497 @item \D'c @var{d}'
6498 @cindex circles
6499 Draw a circle with a diameter of @var{d} with the leftmost point at the
6500 current position.
6502 @item \D'C @var{d}'
6503 Draw a solid circle with the same parameters as an outlined circle.
6505 @item \D'e @var{dx} @var{dy}'
6506 @cindex ellipses
6507 Draw an ellipse with a horizontal diameter of @var{dx} and a vertical
6508 diameter of @var{dy} with the leftmost point at the current position.
6510 @item \D'E @var{dx} @var{dy}'
6511 Draw a solid ellipse with the same parameters as an outlined ellipse.
6513 @item \D'a @var{dx1} @var{dy1} @var{dx2} @var{dy2}'
6514 @cindex arcs
6515 Draw an arc clockwise from the current location through the two
6516 specified locations (@var{dx1},@var{dy1}) and (@var{dx2},@var{dy2}).
6518 @item \D'~ @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
6519 @cindex splines
6520 Draw a spline from the current location to (@var{dx1},@var{dy1}) and
6521 then to (@var{dx2},@var{dy2}), and so on.
6523 @item \D'f @var{n}'
6524 @cindex gray shading
6525 @cindex shading
6526 Set the shade of gray to be used for filling solid objects to@w{
6527 }@var{n}; @var{n}@w{ }must be an integer between 0 and@w{ }1000, where 0
6528 corresponds solid white and 1000 to solid black, and values in between
6529 correspond to intermediate shades of gray.  This applies only to solid
6530 circles, solid ellipses and solid polygons.  By default, a level of@w{
6531 }1000 will be used.
6533 @item \D'p @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
6534 @cindex polygons
6535 Draw a polygon from the current location to (@var{dx1},@var{dy1}) and
6536 then to (@var{dx2},@var{dy2}) and so on.  When the specified data points
6537 are exhausted, a line is drawn back to the starting point.
6539 @c XXX example
6541 @example
6542 ... box example (yes, again)...
6543 @end example
6545 @item \D'P @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
6546 Draw a solid polygon with the same parameters as an outlined polygon.
6548 @c XXX example
6550 @example
6551 ... shaded box example ...
6552 @end example
6554 @item \D't @var{n}'
6555 @cindex line thickness
6556 @cindex thickness of lines
6557 Set the current line thickness to @var{n} machine units.  A value of
6558 zero selects the smallest available line thickness.  A negative value
6559 makes the line thickness proportional to the current point size (this is
6560 the default behaviour of @code{ditroff}).
6561 @end table
6563 @findex \b
6564 @cindex pile, character
6565 @cindex character pile
6566 The @code{\b} escape will @dfn{pile} a sequence of characters
6567 vertically, and center it vertically on the current line.  This can be
6568 used to build large brackets and braces.
6570 @example
6571 \b'\(lt\(bv\(lk\(bv\(lb'
6572 @end example
6574 @xref{Drawing Functions}.
6577 @c =====================================================================
6579 @node Traps, Diversions, Drawing Requests, Programming Tutorial
6580 @section Traps
6581 @cindex traps
6583 @dfn{Traps} are locations, which, when reached, will call a specified
6584 macro.  These traps can occur at a given location on the page, at a
6585 given location in the current diversion, after a certain number of input
6586 lines or at the end of input.
6588 @menu
6589 * Page Location Traps::         
6590 * Diversion Traps::             
6591 * Input Line Traps::            
6592 * End-of-input Traps::          
6593 @end menu
6595 @c ---------------------------------------------------------------------
6597 @node Page Location Traps, Diversion Traps, Traps, Traps
6598 @subsection Page Location Traps
6599 @cindex page location traps
6600 @cindex traps, page location
6602 @c XXX definition of wh request
6604 @cindex page headers
6605 @cindex page footers
6606 @cindex headers
6607 @cindex footers
6608 Page location traps are frequently used for page headers and footers.
6609 The following is a simple example of this.
6611 @example
6612 .de hd                \" Page header
6613 'sp .5i
6614 .tl 'Title''date'
6615 'sp .3i
6617 .de fo                \" Page footer
6618 'sp 1v
6619 .tl ''%''
6622 .wh 0   hd            \" trap at top of the page
6623 .wh -1i fo            \" trap one inch from bottom
6624 @end example
6626 @vindex .t
6627 @cindex distance to next trap
6628 @cindex trap, distance
6629 The number register @code{.t} is the distance to the next trap.
6631 @findex ch
6632 @cindex changing trap location
6633 @cindex trap, changing location
6634 The location of a trap can be changed later on with the @code{ch}
6635 request.  The first argument is the name of the macro to be invoked at
6636 the trap, and the second argument is the new location for the trap.
6637 This is useful for building up footnotes in a diversion to allow more
6638 space at the bottom of the page for them.
6640 @c XXX
6642 @example
6643 ... (simplified) footnote example ...
6644 @end example
6646 @findex vpt
6647 @findex wh
6648 @findex dt
6649 @vindex .vpt
6650 The @code{vpt} request will enable vertical position traps if the
6651 argument is non-zero, disable them otherwise.  Vertical position traps
6652 are traps set by the @code{wh} or @code{dt} requests.  Traps set by the
6653 @code{it} request are not vertical position traps.  The parameter that
6654 controls whether vertical position traps are enabled is global.
6655 Initially vertical position traps are enabled.  The current setting of
6656 this is available in the number register @code{.vpt}.
6658 @vindex .trunc
6659 @findex ne
6660 The number register @code{.trunc} contains the amount of vertical space
6661 truncated by the most recently sprung vertical position trap, or, if the
6662 trap was sprung by a @code{ne} request, minus the amount of vertical
6663 motion produced by the @code{ne} request.  In other words, at the point
6664 a trap is sprung, it represents the difference of what the vertical
6665 position would have been but for the trap, and what the vertical
6666 position actually is.
6668 @vindex .ne
6669 The number register @code{.ne} contains the amount of space that was
6670 needed in the last @code{ne} request that caused a trap to be sprung.
6671 Useful in conjunction with the @code{.trunc} register.  @xref{Page
6672 Control}, for more information.
6674 @c ---------------------------------------------------------------------
6676 @node Diversion Traps, Input Line Traps, Page Location Traps, Traps
6677 @subsection Diversion Traps
6678 @cindex diversion traps
6679 @cindex traps, diversion
6681 @findex dt
6682 @vindex .t
6683 Traps can also be set @emph{within} a diversion using the @code{dt}
6684 request.  Like @code{wh} the first argument is the location of the trap
6685 and the second argument is the name of the macro to be invoked.  The
6686 number register @code{.t} will still work within diversions.
6687 @xref{Diversions}, for more information.
6689 @c ---------------------------------------------------------------------
6691 @node Input Line Traps, End-of-input Traps, Diversion Traps, Traps
6692 @subsection Input Line Traps
6693 @cindex input line traps
6694 @cindex traps, input line
6696 @findex it
6697 The @code{it} request will set an input line trap.  The format for
6698 calling this is
6700 @example
6701 .it @var{n} @var{name}
6702 @end example
6704 @noindent
6705 where @var{n} is the number of lines of input which may be read before
6706 @dfn{springing} the trap, @var{name} is the macro to be invoked.
6707 Request lines are not counted as input lines.
6709 For example, one possible use is to have a macro which will print the
6710 next @var{n}@w{ }lines in a bold font.
6712 @example
6713 .de B
6714 .it B-end \\$1
6715 .ft B
6717 .de B-end
6718 .ft R
6720 @end example
6722 @c ---------------------------------------------------------------------
6724 @node End-of-input Traps,  , Input Line Traps, Traps
6725 @subsection End-of-input Traps
6726 @cindex end-of-input traps
6727 @cindex traps, end-of-input
6729 @findex em
6730 The @code{em} request will set a trap at the end of input.  The macro
6731 specified as an argument will be executed after the last line of the
6732 input file has been processed.
6734 For example, if the document had to have a section at the bottom of the
6735 last page for someone to approve it, the @code{em} request could be
6736 used.
6738 @example
6739 .de approval
6740 .ne 5v
6741 .sp |(\\n(.t-6v)
6742 .in +4i
6743 .lc _
6745 Approved:\t\a
6747 Date:\t\t\a
6749 .em approval
6750 @end example
6753 @c =====================================================================
6755 @node Diversions, Environments, Traps, Programming Tutorial
6756 @section Diversions
6757 @cindex diversions
6759 In @code{gtroff} it is possible to @dfn{divert} text into a named
6760 storage area.  Due to the similarity to defining macros it is sometimes
6761 said to be stored in a macro.  This is used for saving text for output
6762 at a later time, which is useful for keeping blocks of text on the same
6763 page, footnotes, tables of contents and indices.
6765 @findex di
6766 @findex da
6767 A diversion is initiated by the @code{di} request.  Like the @code{de}
6768 request, it takes an argument of a macro name to divert subsequent text
6769 into.  The @code{da} macro will append to an existing diversion.
6771 @code{di} (resp.@: @code{da}) without an argument ends the diversion.
6773 @c XXX example
6775 @example
6776 ... end-note example ...
6777 @end example
6779 @vindex .z
6780 @vindex .d
6781 @vindex nl
6782 @vindex .h
6783 @cindex nested diversions
6784 @cindex diversion, nested
6785 Diversions may be nested.  The number register @code{.z} contains the
6786 name of the current diversion.  The number register @code{.d} contains
6787 the current vertical place in the diversion.  If not in a diversion it
6788 is the same as the register @code{nl}.
6790 @c XXX more info
6792 @code{.h}
6794 @vindex dn
6795 @vindex dl
6796 After completing a diversion, the built-in number registers @code{dn}
6797 and @code{dl} contain the vertical and horizontal size of the diversion.
6799 @example
6800 .\" Center text both horizontally & vertically
6801 .de (c
6804 .di @@c
6806 .de )c
6809 .nr @@s (((\\n(.tu-\\n(dnu)/2u)-1v)
6810 .sp \\n(@@su
6811 .ce 1000
6815 .ce 0
6816 .sp \\n(@@su
6819 .rr @@s
6821 @end example
6823 @findex \!
6824 @cindex transparent output
6825 @cindex output, transparent
6826 Requests, macros and escapes are interpreted when read into a diversion.
6827 There are two ways to prevent this; either way will take the given text
6828 and @dfn{transparently} embed it into the diversion.  The first method
6829 is to prefix the line with @code{\!}.  This will cause the entire line
6830 to be transparently inserted into the diversion.  This is useful for
6831 macros which shouldn't be invoked until the diverted text is actually
6832 output.
6834 @c XXX anything is read in copy mode. (what about \! ??)
6836 @findex \?
6837 The other way is to surround the text by the @code{\?} escape, i.e.
6839 @example
6840 \?@var{anything}\?
6841 @end example
6843 @noindent
6844 @var{anything} may not contain newlines; use @code{\!}  to embed
6845 newlines in a diversion.  The escape sequence @code{\?} is also
6846 recognized in copy mode and turned into a single internal code; it is
6847 this code that terminates anything.  Thus the following example will
6848 print@w{ }4.
6850 @example
6851 .nr x 1
6853 .di d
6854 \?\\?\\\\?\\\\\\\\nx\\\\?\\?\?
6856 .nr x 2
6857 .di e
6860 .nr x 3
6861 .di f
6864 .nr x 4
6866 @end example
6868 @findex asciify
6869 @cindex unformatting diversions
6870 @cindex diversion, unformatting
6871 The @code{asciify} request only exists in order to make certain gross
6872 hacks work with GNU @code{troff}.  It @dfn{unformats} the diversion
6873 specified as an argument in such a way that @acronym{ASCII} characters
6874 that were formatted and diverted will be treated like ordinary input
6875 characters when the diversion is reread.  For example, the following
6876 will set register @code{n} to@w{ }1.
6878 @example
6879 .tr @@.
6880 .di x
6881 @@nr\ n\ 1
6884 .tr @@@@
6885 .asciify x
6887 @end example
6889 @xref{Copy-in Mode}.
6892 @c =====================================================================
6894 @node Environments, I/O, Diversions, Programming Tutorial
6895 @section Environments
6896 @cindex environments
6898 It happens frequently that some text should be printed in a certain
6899 format regardless of what may be in effect at the time, for example, in
6900 a trap invoked macro to print headers and footers.  To solve this
6901 @code{gtroff} has @dfn{environments} in which text is processed.  An
6902 environment contains most of the parameters that control text
6903 processing.  It is possible to switch amongst these environments; by
6904 default @code{gtroff} processes text in environment@w{ }0.  The
6905 following is the information kept in an environment.
6907 @itemize @bullet
6908 @item
6909 font parameters (size, family, style, character height and slant, space
6910 and sentence space size)
6912 @item
6913 page parameters (line length, title length, vertical spacing,
6914 line spacing, indentation, line numbering, hyphenation data)
6916 @item
6917 fill and adjust mode
6919 @item
6920 tab stops, tab and leader characters, escape character, no-break and
6921 hyphen indicators, margin character data
6923 @item
6924 partially collected lines
6925 @end itemize
6927 These environments may be given arbitrary names (@pxref{Identifiers},
6928 for more info).  Old versions of @code{troff} only had environments
6929 named @samp{0}, @samp{1} and@w{ }@samp{2}.
6931 @findex ev
6932 @vindex .ev
6933 The @code{ev} request will switch among environments.  The single
6934 argument is the name of the environment to switch to.  With no argument
6935 @code{gtroff} will switch back to the previous environment.  There is no
6936 limit on the number of named environments; they will be created the
6937 first time that they are referenced.  The @code{.ev} register contains
6938 the name or number of the current environment.  This is a string-valued
6939 register.
6941 Note that a call to @code{ev} (with argument) will push the previously
6942 active environment onto a stack.  If, say, environments @samp{foo},
6943 @samp{bar}, and @samp{zap} are called (in that order), the first
6944 @code{ev} request without parameter will switch back to environment
6945 @samp{bar} (which will be popped off the stack), and a second call will
6946 switch back to environment @samp{foo}.
6948 @c XXX example
6950 @example
6951 ... page break macro, revised ...
6952 @end example
6954 Here another example:
6956 @example
6957 .ev footnote-env
6958 .fam N
6959 .ps 6
6960 .vs 8
6961 .ll -.5i
6964 .ev footnote-env
6965 \(dg Note the large, friendly letters.
6967 @end example
6969 @findex evc
6970 To copy an environment into the current one, use the @code{evc} request,
6971 which takes the name of the environment to copy from as an argument.
6974 @c =====================================================================
6976 @node I/O, Postprocessor Access, Environments, Programming Tutorial
6977 @section I/O
6978 @cindex i/o
6979 @cindex input and output requests
6980 @cindex requests for input and output
6981 @cindex output and input requests
6983 @findex so
6984 The @code{so} request will read in the file given as an argument and
6985 include it in place of the @code{so} request.  This is quite useful for
6986 large documents, i.e.@: keeping each chapter in a separate file.
6987 @xref{gsoelim}, for more information.
6989 @findex mso
6990 The @code{mso} request is the same as the @code{so} request except that
6991 the file is searched for in the same directories as
6992 @file{tmac.@var{name}} is searched for when the @option{-m@var{name}}
6993 option is specified.
6995 @findex cf
6996 @cindex transparent output
6997 @cindex output, transparent
6998 The @code{cf} and @code{trf} requests are to include a file.  It will
6999 transparently output the contents of file filename.  Each line is output
7000 as it were preceded by @code{\!}; however, the lines are not subject to
7001 copy mode interpretation.  If the file does not end with a newline, then
7002 a newline will be added.  For example, to define a macro@w{ }@code{x}
7003 containing the contents of file@w{ }@file{f}, use
7005 @example
7006 .di x
7007 .trf f
7009 @end example
7011 The request @w{@code{.cf @var{filename}}}, when used in a diversion,
7012 will embed in the diversion an object which, when reread, will cause the
7013 contents of @var{filename} to be transparently copied through to the
7014 output.  In @acronym{UNIX} @code{troff}, the contents of @var{filename}
7015 is immediately copied through to the output regardless of whether there
7016 is a current diversion; this behaviour is so anomalous that it must be
7017 considered a bug.  This request causes a line break.
7019 @findex trf
7020 With @code{trf}, unlike @code{cf}, the file cannot contain characters
7021 such as NUL that are not legal @code{gtroff} input characters.  This
7022 request causes a line break.
7024 @c XXX xref to illegal input characters
7026 @findex nx
7027 The @code{nx} request will force @code{gtroff} to continue processing of
7028 the file specified as an argument.
7030 @findex rd
7031 The @code{rd} request will read from standard input, and include what is
7032 read as though it were part of the input file.  Text is read until a
7033 blank line is encountered.
7035 @cindex form letters
7036 @cindex letters, form
7037 Using these two requests it is easy to set up form letters.  The form
7038 letter template is constructed like this:
7040 @example
7042 \*(td
7043 .sp 2
7049 Body of letter.
7051 .nx repeat.let
7052 @end example
7054 @findex ex
7055 @noindent
7056 When this is run, the following file should be redirected in.  Note that
7057 requests included in this file are executed as though they were part of
7058 the form letter.  The last block of input is the @code{ex} requests
7059 which tells groff to stop processing.  If this was not there, groff
7060 would not know when to stop.
7062 @example
7063 Trent A. Fisher
7064 708 NW 19th Av., #202
7065 Portland, OR  97209
7067 Dear Trent,
7069 Len Adollar
7070 4315 Sierra Vista
7071 San Diego, CA  92103
7073 Dear Mr. Adollar,
7076 @end example
7078 @findex pi
7079 @code{pi}
7081 @c XXX documentation
7083 @findex sy
7084 The @code{sy} request will allow arbitrary system commands to be
7085 executed from within a @code{gtroff} document.  The output is not saved
7086 anyplace, so it is up to the user to do so.
7088 @c XXX add info about safer and unsafe mode
7090 For example, the following example will introduce the current time
7091 into a document:
7093 @cindex time, current
7094 @cindex current time
7095 @pindex perl
7096 @example
7097 .sy perl -e 'printf ".nr H %d\\n.nr M %d\\n.nr S %d\\n",\
7098              (localtime(time))[2,1,0]' > /tmp/x\n[$$]
7099 .so /tmp/x\n[$$]
7100 .sy rm /tmp/x\n[$$]
7101 \nH:\nM:\nS
7102 @end example
7104 @noindent
7105 Note that this works by having the @code{perl} script (run by @code{sy})
7106 print out the @code{nr} requests which will set the number registers
7107 @samp{H}, @samp{M} and @samp{S}, and then reads those commands in with
7108 the @code{so} request.
7110 @vindex systat
7111 The @code{systat} number register contains the return value of the
7112 @code{system()} function executed by the last @code{sy} request.
7114 @findex open
7115 The @code{open} request will open a file (specified as the second
7116 argument) for writing and associate the stream (specified as the first
7117 argument) with it.
7119 @findex opena
7120 The @code{opena} is like @code{open}, but if the file exists, append to
7121 it instead of truncating it.
7123 @findex write
7124 @findex ds
7125 @cindex copy-in mode
7126 @cindex mode, copy-in
7127 The @code{write} request will write to the file associated with the
7128 stream specified by the first argument.  The stream must previously have
7129 been the subject of an open request.  The remainder of the line is
7130 interpreted as the @code{ds} request reads its second argument: A
7131 leading @samp{"} will be stripped, and it will be read in copy-in mode.
7133 @findex close
7134 The @code{close} request will close the stream specified by the first
7135 argument; stream will no longer be an acceptable argument to the
7136 @code{write} request.
7138 @c XXX example
7140 @example
7141 ... example of open write &c...
7142 @end example
7144 @findex \V
7145 The @code{\V} escape will interpolate the contents of the specified
7146 environment variable, as returned by @code{getenv()}.  The argument to
7147 @code{\V} is specified as an identifier, i.e.@: @samp{\V@var{x}},
7148 @samp{\V(@var{xx}} or @samp{\V[@var{xxx}]}.  @code{\V} is interpreted in
7149 copy-in mode.
7152 @c =====================================================================
7154 @node Postprocessor Access, Miscellaneous, I/O, Programming Tutorial
7155 @section Postprocessor Access
7156 @cindex postprocessor access
7157 @cindex access of postprocessor
7159 There are two escapes which will allow information to be directly given
7160 to the postprocessor.  This is particularly useful for embedding
7161 @sc{PostScript} into the final document.
7163 @findex \X
7164 The @code{\X} escape will embed its argument into the @code{gtroff}
7165 output preceded with @w{@samp{x X}}.
7167 @findex \Y
7168 The @code{\Y} escape is called with an identifier (i.e.@:
7169 @code{\Y@var{x}}, @code{\Y(@var{xx}} or @code{\Y[@var{xxx}]}).  This is
7170 approximately equivalent to @samp{\X'\*[@var{xxx}]'}.  However, the
7171 contents of the string or macro @var{xxx} are not interpreted; also it
7172 is permitted for @var{xxx} to have been defined as a macro and thus
7173 contain newlines (it is not permitted for the argument to @code{\X} to
7174 contain newlines).  The inclusion of newlines requires an extension to
7175 the @acronym{UNIX} @code{troff} output format, and will confuse drivers
7176 that do not know about this extension.
7178 @xref{Output Devices}.
7181 @c =====================================================================
7183 @node Miscellaneous, Debugging, Postprocessor Access, Programming Tutorial
7184 @section Miscellaneous
7185 @cindex miscellaneous
7187 This section contains parts of @code{gtroff} which cannot (yet) be
7188 categorized elsewhere in this manual.
7190 @findex nm
7191 @cindex line numbers
7192 @cindex numbers, line
7193 Line numbers can be printed in the left margin using the @code{nm}
7194 request.  The first argument is the line number of the @emph{next}
7195 output line; this defaults to@w{ }1.  The second argument indicates on
7196 which lines numbers will be printed, i.e.@: 5 means put line numbers on
7197 every 5@w{ }lines; this defaults to@w{ }1.  The third argument is the
7198 space to be left between the number and the text; this defaults to@w{
7199 }1.  The fourth argument is the indentation of the line numbers.
7200 Without arguments, line numbers are turned off.
7202 @c XXX xref ln register
7204 @findex nn
7205 The @code{nn} request will temporarily turn off line numbering.  The
7206 first argument is the number of lines not to be numbered; this defaults
7207 to@w{ }1.
7209 @c XXX (does this disable incrementing or display?)
7211 @c XXX example
7213 @example
7214 ... line numbering example ...
7215 @end example
7217 @findex mc
7218 @cindex margin characters
7219 @cindex characters for margins
7220 Margin characters can be automatically printed to the right of the text
7221 with the @code{mc} request.  The first argument is the character to be
7222 printed, and the second argument is the distance away from the main body
7223 text.  With no arguments the margin characters are turned off.  If this
7224 occurs before a break, no margin character will be printed.
7226 @pindex nrchbar
7227 @pindex changebar
7228 This is quite useful for indicating text that has changed, and, in fact,
7229 there are programs available for doing this (they are called
7230 @code{nrchbar} and @code{changebar} and can be found in any
7231 @samp{comp.sources.unix} archive.
7233 @c XXX example
7235 @example
7236 ... margin char example ...
7237 @end example
7239 @findex lf
7240 @pindex soelim
7241 @cindex multi-file documents
7242 @cindex documents, multi-file
7243 The primary reason for the existence of @code{lf} is to make debugging
7244 documents which are split into many files, which are then put together
7245 with @code{soelim} and other preprocessors.  The first argument is the
7246 name of the file and the second argument is the input line number in
7247 that file.  This way @code{gtroff} can produce error messages which are
7248 intelligible to the user.
7250 @c XXX example
7252 @example
7253 ... example of soelim'ed doc ...
7254 @end example
7257 @c =====================================================================
7259 @node Debugging, Implementation Differences, Miscellaneous, Programming Tutorial
7260 @section Debugging
7261 @cindex debugging
7263 @code{gtroff} is not easy to debug, but there are some useful features
7264 and strategies for debugging.
7266 @itemize @bullet
7267 @item
7268 @findex tm
7269 The @code{tm} request will send output to stderr; this is very useful
7270 for printing debugging output.
7272 @item
7273 When doing something involved it is useful to leave the debugging
7274 statements in the code and have them turned on by a command line flag.
7276 @example
7277 .if \n(DB .tm debugging output
7278 @end example
7280 @noindent
7281 To activate these statements say
7283 @example
7284 groff -rDB=1 file
7285 @end example
7287 @item
7288 @findex ab
7289 @cindex aborting
7290 The @code{ab} request is similar to the @code{tm} request, except that
7291 it will cause @code{gtroff} to stop processing.  With no argument it
7292 will print @samp{User Abort}.
7294 @item
7295 @findex ex
7296 @cindex exiting
7297 The @code{ex} request will also cause @code{gtroff} to stop processing
7298 (if encountered at the topmost level; see also @ref{I/O}.
7300 @item
7301 If it is known in advance that there will be many errors and no useful
7302 output, @code{gtroff} can be forced to suppress formatted output with
7303 the @option{-z} flag.
7305 @item
7306 @findex pm
7307 @cindex dumping symbol table
7308 @cindex symbol table, dumping
7309 The @code{pm} request will dump out the entire symbol table.
7311 @item
7312 @findex pnr
7313 @cindex dumping number registers
7314 @cindex number registers, dumping
7315 The @code{pnr} request will print the names and contents of all
7316 currently defined number registers on stderr.
7318 @item
7319 @findex ptr
7320 @cindex dumping traps
7321 @cindex traps, dumping
7322 The @code{ptr} request will print the names and positions of all traps
7323 (not including input line traps and diversion traps) on stderr.  Empty
7324 slots in the page trap list are printed as well, because they can affect
7325 the priority of subsequently planted traps.
7327 @item
7328 @findex fl
7329 @cindex flush output
7330 @cindex output, flush
7331 @cindex interactive use of @code{gtroff}
7332 @cindex @code{gtroff}, interactive use
7333 The @code{fl} request instructs @code{gtroff} to flush its output
7334 immediately.  The intention is that this be used when using
7335 @code{gtroff} interactively.  There is little other use for it.  This
7336 request causes a line break.
7338 @item
7339 @findex backtrace
7340 @cindex backtrace of input stack
7341 @cindex input stack, backtrace
7342 The @code{backtrace} request will print a backtrace of the input stack
7343 on stderr.
7345 @item
7346 @cindex warnings
7347 @code{gtroff} has command line options for printing out more warnings
7348 (@option{-w}) and for printing backtraces (@option{-b}) when a warning
7349 or an error occurs.  The most verbose level of warnings is @option{-ww}.
7351 @item
7352 @findex warn
7353 @vindex .warn
7354 @cindex level of warnings
7355 @cindex warnings, level
7356 The @code{warn} request controls the level of warnings checked for.  The
7357 only argument is the sum of the numbers associated with each warning
7358 that is to be enabled; all other warnings will be disabled.  The number
7359 associated with each warning is listed below.  For example,
7360 @w{@code{.warn 0}} will disable all warnings, and @w{@code{.warn 1}}
7361 will disable all warnings except that about missing characters.  If an
7362 argument is not given, all warnings will be enabled.  The number
7363 register @code{.warn} contains the current warning level.
7364 @end itemize
7366 @c ---------------------------------------------------------------------
7368 @menu
7369 * Warnings::                    
7370 @end menu
7372 @node Warnings,  , Debugging, Debugging
7373 @subsection Warnings
7374 @cindex warnings
7376 The warnings that can be given to @code{gtroff} are divided into the
7377 following categories.  The name associated with each warning is used by
7378 the @option{-w} and @option{-W} options; the number is used by the
7379 @code{warn} request and by the @code{.warn} register.
7381 @table @samp
7382 @item char
7383 @itemx 1
7384 Non-existent characters.  This is enabled by default.
7386 @item number
7387 @itemx 2
7388 Invalid numeric expressions.  This is enabled by default.
7389 @xref{Expressions}.
7391 @item break
7392 @itemx 4
7393 @cindex fill mode
7394 @cindex mode, fill
7395 In fill mode, lines which could not be broken so that their length was
7396 less than the line length.  This is enabled by default.
7398 @item delim
7399 @itemx 8
7400 Missing or mismatched closing delimiters.
7402 @item el
7403 @itemx 16
7404 @findex ie
7405 @findex el
7406 Use of the @code{el} request with no matching @code{ie} request.
7407 @xref{if-else}.
7409 @item scale
7410 @itemx 32
7411 Meaningless scaling indicators.
7413 @item range
7414 @itemx 64
7415 Out of range arguments.
7417 @item syntax
7418 @itemx 128
7419 Dubious syntax in numeric expressions.
7421 @item di
7422 @itemx 256
7423 @findex di
7424 @findex da
7425 Use of @code{di} or @code{da} without an argument when there is no
7426 current diversion.
7428 @item mac
7429 @itemx 512
7430 @findex de
7431 @c XXX more findex entries
7432 Use of undefined strings, macros and diversions.  When an undefined
7433 string, macro or diversion is used, that string is automatically defined
7434 as empty.  So, in most cases, at most one warning will be given for each
7435 name.
7437 @item  reg
7438 @itemx 1024
7439 @findex nr
7440 @c XXX more findex entries
7441 Use of undefined number registers.  When an undefined number register is
7442 used, that register is automatically defined to have a value of@w{ }0.
7443 A definition is automatically made with a value of@w{ }0.  So, in most
7444 cases, at most one warning will be given for use of a particular name.
7446 @item  tab
7447 @itemx 2048
7448 Use of a tab character where a number was expected.
7450 @item  right-brace
7451 @itemx 4096
7452 @findex \@}
7453 Use of @code{\@}} where a number was expected.
7455 @item  missing
7456 @itemx 8192
7457 Requests that are missing non-optional arguments.
7459 @item  input
7460 @itemx 16384
7461 Illegal input characters.
7463 @item  escape
7464 @itemx 32768
7465 Unrecognized escape sequences.  When an unrecognized escape sequence is
7466 encountered, the escape character is ignored.
7468 @item  space
7469 @itemx 65536
7470 @cindex compatibility mode
7471 Missing space between a request or macro and its argument.  This warning
7472 will be given when an undefined name longer than two characters is
7473 encountered, and the first two characters of the name make a defined
7474 name.  The request or macro will not be invoked.  When this warning is
7475 given, no macro is automatically defined.  This is enabled by default.
7476 This warning will never occur in compatibility mode.
7478 @item  font
7479 @itemx 131072
7480 Non-existent fonts.  This is enabled by default.
7482 @item all
7483 All warnings except @samp{di}, @samp{mac} and @samp{reg}.  It is
7484 intended that this covers all warnings that are useful with traditional
7485 macro packages.
7487 @item w
7488 All warnings.
7489 @end table
7492 @c =====================================================================
7494 @node Implementation Differences, Summary, Debugging, Programming Tutorial
7495 @section Implementation Differences
7496 @cindex implementation differences
7497 @cindex differences in implementation
7498 @cindex compatibility mode
7499 @cindex mode, compatibility
7501 GNU @code{troff} has a number of features which cause incompatibilities
7502 with documents written with old versions of @code{troff}.
7504 @cindex long names
7505 @cindex names, long
7506 Long names cause some incompatibilities.  @acronym{UNIX} @code{troff}
7507 will interpret
7509 @example
7510 .dsabcd
7511 @end example
7513 @findex \*
7514 @findex \n
7515 @findex cp
7516 @vindex .C
7517 @noindent
7518 as defining a string @samp{ab} with contents @samp{cd}.  Normally, GNU
7519 @code{troff} will interpret this as a call of a macro named
7520 @code{dsabcd}.  Also @acronym{UNIX} @code{troff} will interpret
7521 @code{\*[} or @code{\n[} as references to a string or number register
7522 called @samp{[}.  In GNU @code{troff}, however, this will normally be
7523 interpreted as the start of a long name.  In compatibility mode GNU
7524 @code{troff} will interpret these things in the traditional way.  In
7525 compatibility mode, however, long names are not recognized.
7526 Compatibility mode can be turned on with the @option{-C} command line
7527 option, and turned on or off with the @code{cp} request.  The number
7528 register @code{.C} is@w{ }1 if compatibility mode is on, 0@w{
7529 }otherwise.
7531 @findex \A
7532 @findex \|
7533 @findex \^
7534 @findex \&
7535 @findex \@}
7536 @findex \@{
7537 @findex \@key{SP}
7538 @findex \'
7539 @findex \`
7540 @findex \-
7541 @findex \_
7542 @findex \!
7543 @findex \%
7544 @findex \c
7545 GNU @code{troff} does not allow the use of the escape sequences
7546 @code{\|}, @code{\^}, @code{\&}, @code{\@}}, @code{\@{},
7547 @code{\@key{SP}}, @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!},
7548 @code{\%}, and @code{\c} in names of strings, macros, diversions, number
7549 registers, fonts or environments; @acronym{UNIX} @code{troff} does.  The
7550 @code{\A} escape sequence (@pxref{Identifiers}) may be helpful in
7551 avoiding use of these escape sequences in names.
7553 @cindex fractional point sizes
7554 @cindex point sizes, fractional
7555 @findex ps
7556 Fractional point sizes cause one noteworthy incompatibility.  In
7557 @acronym{UNIX} @code{troff} the @code{ps} request ignores scale
7558 indicators and thus
7560 @example
7561 .ps 10u
7562 @end example
7564 @noindent
7565 will set the point size to 10@w{ }points, whereas in GNU @code{troff} it
7566 will set the point size to 10@w{ }scaled points.  @xref{Fractional Type
7567 Sizes}, for more information.
7569 @findex bd
7570 @findex cs
7571 @findex tkf
7572 @findex tr
7573 @findex fp
7574 @cindex input and output characters
7575 @cindex output characters
7576 @cindex characters, input and output
7577 In GNU @code{troff} there is a fundamental difference between
7578 unformatted, input characters, and formatted, output characters.
7579 Everything that affects how an output character will be output is stored
7580 with the character; once an output character has been constructed it is
7581 unaffected by any subsequent requests that are executed, including
7582 @code{bd}, @code{cs}, @code{tkf}, @code{tr}, or @code{fp} requests.
7583 Normally output characters are constructed from input characters at the
7584 moment immediately before the character is added to the current output
7585 line.  Macros, diversions and strings are all, in fact, the same type of
7586 object; they contain lists of input characters and output characters in
7587 any combination.  An output character does not behave like an input
7588 character for the purposes of macro processing; it does not inherit any
7589 of the special properties that the input character from which it was
7590 constructed might have had.  For example,
7592 @example
7593 .di x
7594 \\\\
7598 @end example
7600 @findex \e
7601 @findex \!
7602 @findex \?
7603 @cindex transparent output
7604 @cindex output, transparent
7605 @noindent
7606 will print @samp{\\} in GNU @code{troff}; each pair of input backslashes
7607 is turned into one output backslash and the resulting output backslashes
7608 are not interpreted as escape characters when they are reread.
7609 @acronym{UNIX} @code{troff} would interpret them as escape characters
7610 when they were reread and would end up printing one @samp{\}.  The
7611 correct way to obtain a printable backslash is to use the @code{\e}
7612 escape sequence: This will always print a single instance of the current
7613 escape character, regardless of whether or not it is used in a
7614 diversion; it will also work in both GNU @code{troff} and @acronym{UNIX}
7615 @code{troff}.  To store, for some reason, an escape sequence in a
7616 diversion that will be interpreted when the diversion is reread, either
7617 use the traditional @code{\!} transparent output facility, or, if this
7618 is unsuitable, the new @code{\?} escape sequence.
7620 @xref{Diversions}, for more information.
7623 @c =====================================================================
7625 @node Summary,  , Implementation Differences, Programming Tutorial
7626 @section Summary
7627 @cindex summary
7629 @c XXX documentation
7633 @c =====================================================================
7634 @c =====================================================================
7636 @node Preprocessors, Output Devices, Programming Tutorial, Top
7637 @chapter Preprocessors
7638 @cindex preprocessors
7640 This chapter describes all preprocessors that come with @code{groff} or
7641 which are freely available.
7643 @menu
7644 * geqn::                        
7645 * gtbl::                        
7646 * gpic::                        
7647 * ggrn::                        
7648 * grap::                        
7649 * grefer::                      
7650 * gsoelim::                     
7651 @end menu
7654 @c =====================================================================
7656 @node geqn, gtbl, Preprocessors, Preprocessors
7657 @section @code{geqn}
7658 @cindex @code{eqn}
7659 @cindex @code{geqn}
7661 @c XXX
7663 @menu
7664 * Invoking geqn::               
7665 @end menu
7667 @c ---------------------------------------------------------------------
7669 @node Invoking geqn,  , geqn, geqn
7670 @subsection Invoking @code{geqn}
7671 @cindex invoking @code{geqn}
7672 @cindex @code{geqn}, invoking
7674 @c XXX
7677 @c =====================================================================
7679 @node gtbl, gpic, geqn, Preprocessors
7680 @section @code{gtbl}
7681 @cindex @code{tbl}
7682 @cindex @code{gtbl}
7684 @c XXX
7686 @menu
7687 * Invoking gtbl::               
7688 @end menu
7690 @c ---------------------------------------------------------------------
7692 @node Invoking gtbl,  , gtbl, gtbl
7693 @subsection Invoking @code{gtbl}
7694 @cindex invoking @code{gtbl}
7695 @cindex @code{gtbl}, invoking
7697 @c XXX
7700 @c =====================================================================
7702 @node gpic, ggrn, gtbl, Preprocessors
7703 @section @code{gpic}
7704 @cindex @code{pic}
7705 @cindex @code{gpic}
7707 @c XXX
7709 @menu
7710 * Invoking gpic::               
7711 @end menu
7713 @c ---------------------------------------------------------------------
7715 @node Invoking gpic,  , gpic, gpic
7716 @subsection Invoking @code{gpic}
7717 @cindex invoking @code{gpic}
7718 @cindex @code{gpic}, invoking
7720 @c XXX
7723 @c =====================================================================
7725 @node ggrn, grap, gpic, Preprocessors
7726 @section @code{ggrn}
7727 @cindex @code{grn}
7728 @cindex @code{ggrn}
7730 @c XXX
7732 @menu
7733 * Invoking ggrn::               
7734 @end menu
7736 @c ---------------------------------------------------------------------
7738 @node Invoking ggrn,  , ggrn, ggrn
7739 @subsection Invoking @code{ggrn}
7740 @cindex invoking @code{ggrn}
7741 @cindex @code{ggrn}, invoking
7743 @c XXX
7746 @c =====================================================================
7748 @node grap, grefer, ggrn, Preprocessors
7749 @section @code{grap}
7750 @cindex @code{grap}
7752 A freely available implementation of @code{grap}, written by Ted Faber,
7753 is available as an extra package from the following address:
7755 @display
7756 @url{http://www.lunabase.org/~faber/Vault/software/grap/}
7757 @end display
7760 @c =====================================================================
7762 @node grefer, gsoelim, grap, Preprocessors
7763 @section @code{grefer}
7764 @cindex @code{refer}
7765 @cindex @code{grefer}
7767 @c XXX
7769 @menu
7770 * Invoking grefer::             
7771 @end menu
7773 @c ---------------------------------------------------------------------
7775 @node Invoking grefer,  , grefer, grefer
7776 @subsection Invoking @code{grefer}
7777 @cindex invoking @code{grefer}
7778 @cindex @code{grefer}, invoking
7780 @c XXX
7783 @c =====================================================================
7785 @node gsoelim,  , grefer, Preprocessors
7786 @section @code{gsoelim}
7787 @cindex @code{soelim}
7788 @cindex @code{gsoelim}
7790 @c XXX
7792 @menu
7793 * Invoking gsoelim::            
7794 @end menu
7796 @c ---------------------------------------------------------------------
7798 @node Invoking gsoelim,  , gsoelim, gsoelim
7799 @subsection Invoking @code{gsoelim}
7800 @cindex invoking @code{gsoelim}
7801 @cindex @code{gsoelim}, invoking
7803 @c XXX
7807 @c =====================================================================
7808 @c =====================================================================
7810 @node Output Devices, File formats, Preprocessors, Top
7811 @chapter Output Devices
7812 @cindex output devices
7813 @cindex devices for output
7815 @c XXX
7817 @menu
7818 * Special Characters::          
7819 * grotty::                      
7820 * grops::                       
7821 * grodvi::                      
7822 * grolj4::                      
7823 * grolbp::                      
7824 * grohtml::                     
7825 * gxditview::                   
7826 @end menu
7829 @c =====================================================================
7831 @node Special Characters, grotty, Output Devices, Output Devices
7832 @section Special Characters
7833 @cindex special characters
7834 @cindex characters, special
7836 @c XXX
7838 @xref{Font Files}.
7841 @c =====================================================================
7843 @node grotty, grops, Special Characters, Output Devices
7844 @section @code{grotty}
7845 @cindex @code{grotty}
7847 @c XXX
7849 @menu
7850 * Invoking grotty::             
7851 @end menu
7853 @c ---------------------------------------------------------------------
7855 @node Invoking grotty,  , grotty, grotty
7856 @subsection Invoking @code{grotty}
7857 @cindex invoking @code{grotty}
7858 @cindex @code{grotty}, invoking
7860 @c XXX
7863 @c =====================================================================
7865 @node grops, grodvi, grotty, Output Devices
7866 @section @code{grops}
7867 @cindex @code{grops}
7869 @c XXX
7871 @menu
7872 * Invoking grops::              
7873 * Embedding PostScript::        
7874 @end menu
7876 @c ---------------------------------------------------------------------
7878 @node Invoking grops, Embedding PostScript, grops, grops
7879 @subsection Invoking @code{grops}
7880 @cindex invoking @code{grops}
7881 @cindex @code{grops}, invoking
7883 @c XXX
7885 @c ---------------------------------------------------------------------
7887 @node Embedding PostScript,  , Invoking grops, grops
7888 @subsection Embedding @sc{PostScript}
7889 @cindex embedding postscript
7890 @cindex postscript, embedding
7892 @c XXX
7895 @c =====================================================================
7897 @node grodvi, grolj4, grops, Output Devices
7898 @section @code{grodvi}
7899 @cindex @code{grodvi}
7901 @c XXX
7903 @menu
7904 * Invoking grodvi::             
7905 @end menu
7907 @c ---------------------------------------------------------------------
7909 @node Invoking grodvi,  , grodvi, grodvi
7910 @subsection Invoking @code{grodvi}
7911 @cindex invoking @code{grodvi}
7912 @cindex @code{grodvi}, invoking
7914 @c XXX
7917 @c =====================================================================
7919 @node grolj4, grolbp, grodvi, Output Devices
7920 @section @code{grolj4}
7921 @cindex @code{grolj4}
7923 @c XXX
7925 @menu
7926 * Invoking grolj4::             
7927 @end menu
7929 @c ---------------------------------------------------------------------
7931 @node Invoking grolj4,  , grolj4, grolj4
7932 @subsection Invoking @code{grolj4}
7933 @cindex invoking @code{grolj4}
7934 @cindex @code{grolj4}, invoking
7936 @c XXX
7939 @c =====================================================================
7941 @node grolbp, grohtml, grolj4, Output Devices
7942 @section @code{grolbp}
7943 @cindex @code{grolbp}
7945 @c XXX
7947 @menu
7948 * Invoking grolbp::             
7949 @end menu
7951 @c ---------------------------------------------------------------------
7953 @node Invoking grolbp,  , grolbp, grolbp
7954 @subsection Invoking @code{grolbp}
7955 @cindex invoking @code{grolbp}
7956 @cindex @code{grolbp}, invoking
7958 @c XXX
7961 @c =====================================================================
7963 @node grohtml, gxditview, grolbp, Output Devices
7964 @section @code{grohtml}
7965 @cindex @code{grohtml}
7967 @c XXX
7969 @menu
7970 * Invoking grohtml::            
7971 @end menu
7973 @c ---------------------------------------------------------------------
7975 @node Invoking grohtml,  , grohtml, grohtml
7976 @subsection Invoking @code{grohtml}
7977 @cindex invoking @code{grohtml}
7978 @cindex @code{grohtml}, invoking
7980 @c XXX
7983 @c =====================================================================
7985 @node gxditview,  , grohtml, Output Devices
7986 @section @code{gxditview}
7987 @cindex @code{gxditview}
7989 @c XXX
7991 @menu
7992 * Invoking gxditview::          
7993 @end menu
7995 @c ---------------------------------------------------------------------
7997 @node Invoking gxditview,  , gxditview, gxditview
7998 @subsection Invoking @code{gxditview}
7999 @cindex invoking @code{gxditview}
8000 @cindex @code{gxditview}, invoking
8002 @c XXX
8003 @c X11's xditview
8007 @c =====================================================================
8008 @c =====================================================================
8010 @node File formats, Installation, Output Devices, Top
8011 @chapter File formats
8012 @cindex file formats
8013 @cindex formats, file
8015 @c XXX
8017 @menu
8018 * gtroff Output::               
8019 * Font Files::                  
8020 @end menu
8023 @c =====================================================================
8025 @node gtroff Output, Font Files, File formats, File formats
8026 @section @code{gtroff} Output
8027 @cindex @code{gtroff} output
8028 @cindex output, @code{gtroff}
8030 This section describes the format output of GNU @code{troff}.  The
8031 output format used by GNU @code{troff} is very similar to that used by
8032 @acronym{UNIX} device-independent @code{troff} (@code{ditroff}).
8034 @menu
8035 * Output Format::               
8036 * Device Control::              
8037 * Drawing Functions::           
8038 * Line Continuation::           
8039 @end menu
8041 @c ---------------------------------------------------------------------
8043 @node Output Format, Device Control, gtroff Output, gtroff Output
8044 @subsection Output Format
8045 @cindex output format
8046 @cindex format of output
8048 @cindex 8-bit input
8049 @cindex input, 8-bit
8050 The output format is text based, as opposed to a binary format (like
8051 @TeX{} DVI).  The output format is @w{8-bit} clean, thus single
8052 characters can have the eighth bit set, as can the names of fonts and
8053 special characters.
8055 The output format consists of single command characters with attached
8056 parameters which are separated from subsequent text by whitespace or a
8057 newline.
8059 The names of characters and fonts can be of arbitrary length; drivers
8060 should not assume that they will be only two characters long (as
8061 @code{ditroff} does).
8063 When a character is to be printed, that character will always be in the
8064 current font.  Unlike @code{ditroff}, it is not necessary for drivers to
8065 search special fonts to find a character.
8067 @table @code
8068 @item H@var{n}
8069 @c XXX
8071 @item V@var{n}
8072 @c XXX
8074 @item h@var{n}
8075 @c XXX
8077 @item v@var{n}
8078 @c XXX
8080 @item c@var{n}
8081 @c XXX
8083 @item C@var{n}
8084 @c XXX
8086 @item @var{nn}@var{c}
8087 @c XXX
8089 @item t@var{xxx}
8090 @var{xxx} is any sequence of characters terminated by a space or a
8091 newline; the first character should be printed at the current position,
8092 the the current horizontal position should be increased by the width of
8093 the first character, and so on for each character.  The width of the
8094 character is that given in the font file, appropriately scaled for the
8095 current point size, and rounded so that it is a multiple of the
8096 horizontal resolution.  Special characters cannot be printed using this
8097 command.
8099 @kindex tcommand
8100 @pindex DESC
8101 This command is only allowed if the @samp{tcommand} line is present in
8102 the @file{DESC} file.
8104 @item u@var{n} @var{xxx}
8105 This is same as the @samp{t} command except that after printing each
8106 character, the current horizontal position is increased by the sum of
8107 the width of that character and@w{ }@var{n}.
8109 This command is only allowed if the @samp{tcommand} line is present in
8110 the @file{DESC} file.
8112 @item n@var{a}@var{b}
8113 @c XXX
8115 @item p@var{n}
8116 @c XXX
8118 @item s@var{n}
8119 @kindex sizescale
8120 @pindex DESC
8121 The argument to the @samp{s} command is in scaled points (units of
8122 points/@var{n}, where @var{n} is the argument to the @samp{sizescale}
8123 command in the @file{DESC} file).
8125 @item f@var{n}
8126 @item x @dots{} \n
8127 Device control.
8128 @c XXX more info
8130 @item D@var{c} @var{x}@dots{}\n
8131 @c XXX
8132 @end table
8134 @c ---------------------------------------------------------------------
8136 @node Device Control, Drawing Functions, Output Format, gtroff Output
8137 @subsection Device Control
8138 @cindex device control
8139 @cindex control of devices
8141 The @samp{x} command is normally followed by a letter or word indicating
8142 the function to perform, followed by white space separated arguments.
8144 The first argument can be abbreviated to the first letter.
8146 @table @code
8147 @item x init
8148 @c XXX
8150 @item x T
8151 @c XXX
8153 @item x res @var{n} @var{h} @var{v}
8154 @c XXX
8156 @item x H
8157 @c XXX more info
8158 The argument to the @w{@samp{x Height}} command is also in scaled
8159 points.
8160 @end table
8162 The first three output commands are guaranteed to be:
8164 @example
8165 x T device
8166 x res n h v
8167 x init
8168 @end example
8170 @noindent
8171 For example, the input
8173 @example
8174 crunchy \fH\s+2frog\s0\fP!?
8175 @end example
8177 @noindent
8178 will produce
8180 @c XXX example
8182 @example
8183 ... sample output here ...
8184 @end example
8186 @c ---------------------------------------------------------------------
8188 @node Drawing Functions, Line Continuation, Device Control, gtroff Output
8189 @subsection Drawing Functions
8190 @cindex drawing functions
8191 @cindex functions for drawing
8193 @pindex gpic
8194 The @samp{D} drawing command has been extended.  These extensions will
8195 only be used by GNU @code{pic} if the @option{-x} option is given.
8197 @xref{Drawing Requests}.
8199 @table @code
8200 @c XXX ...
8201 @item Df @var{n}
8202 Set the shade of gray to be used for filling solid objects to@w{
8203 }@var{n}; @var{n}@w{ }must be an integer between 0 and@w{ }1000, where 0
8204 corresponds solid white and 1000 to solid black, and values in between
8205 correspond to intermediate shades of gray.  This applies only to solid
8206 circles, solid ellipses and solid polygons.  By default, a level of@w{
8207 }1000 will be used.  Whatever color a solid object has, it should
8208 completely obscure everything beneath it.  A value greater than@w{ }1000
8209 or less than@w{ }0 can also be used: this means fill with the shade of
8210 gray that is currently being used for lines and text.  Normally this
8211 will be black, but some drivers may provide a way of changing this.
8213 @item DC @var{d}
8214 Draw a solid circle with a diameter of@w{ }@var{d} with the leftmost
8215 point at the current position.
8217 @item DE @var{dx} @var{dy}
8218 Draw a solid ellipse with a horizontal diameter of@w{ }@var{dx} and a
8219 vertical diameter of@w{ }@var{dy} with the leftmost point at the current
8220 position.
8222 @item Dp @var{dx1} @var{dy1} @var{dx2} @var{dy2} @dots{} @var{dxn} @var{dyn}
8223 Draw a polygon with.  The first vertex is at the current position, the
8224 second vertex at an offset (@var{dx1},@var{dy1}) from the current
8225 position, the second vertex at an offset (@var{dx2},@var{dy2}) from the
8226 first vertex, and so on up to the @var{n}-th vertex.  At the moment, GNU
8227 @code{pic} only uses this command to generate triangles and rectangles.
8229 @item DP @var{dx1} @var{dy1} @var{dx2} @var{dy2} @dots{} @var{dxn} @var{dyn}
8230 Like @code{Dp} but draw a solid rather than outlined polygon.
8232 @item Dt @var{n}
8233 @cindex line thickness
8234 @cindex thickness of lines
8235 Set the current line thickness to @var{n}@w{ }machine units.
8236 Traditionally, @acronym{UNIX} @code{troff} drivers use a line thickness
8237 proportional to the current point size; drivers should continue to do
8238 this if no @code{Dt} command has been given, or if a @code{Dt} command
8239 has been given with a negative value of@w{ }@var{n}.  A zero value of@w{
8240 }@var{n} selects the smallest available line thickness.
8241 @end table
8243 @findex \D
8244 A difficulty arises in how the current position should be changed after
8245 the execution of these commands.  This is not of great importance since
8246 the code generated by GNU @code{pic} does not depend on this.  Given a
8247 drawing command of the form
8249 @example
8250 \D'@var{c} @var{x1} @var{y1} @var{x2} @var{y2} @dots{} @var{xn} @var{yn}'
8251 @end example
8253 @findex \w
8254 @vindex st
8255 @findex sb
8256 @noindent
8257 where @var{c} is not one of @samp{c}, @samp{e}, @samp{l}, @samp{a} or
8258 @samp{~}, @acronym{UNIX} @code{troff} will treat each of the x@w{ }value
8259 as a horizontal quantity, and each of the y@w{ }values as a vertical
8260 quantity and will assume that the width of the drawn object is sum if
8261 all x@w{ }values, and that the height is the sum of all y@w{ }values.
8262 (The assumption about the height can be seen by examining the @code{st}
8263 and @code{sb} registers after using such a @code{D}@w{ }command in a
8264 @code{\w} escape sequence.)  This rule also holds for all the original
8265 drawing commands with the exception of @code{De}.  For the sake of
8266 compatibility GNU @code{troff} also follows this rule, even though it
8267 produces an ugly result in the case of the @code{Df}, @code{Dt}, and, to
8268 a lesser extent, @code{DE}@w{ }commands.  Thus after executing a
8269 @code{D}@w{ }command of the form
8271 @example
8272 D@var{c} @var{x1} @var{y1} @var{x2} @var{y2} @dots{} @var{xn} @var{yn}
8273 @end example
8275 @noindent
8276 the current position should be increased horizontally by the sum of all
8277 x@w{ }values and vertically by the sum of all y@w{ }values.
8279 @c ---------------------------------------------------------------------
8281 @node Line Continuation,  , Drawing Functions, gtroff Output
8282 @subsection Line Continuation
8283 @cindex line continuation in output commands
8284 @cindex output commands, line continuation
8286 There is a continuation convention which permits the argument to the
8287 @w{@samp{x X}} command to contain newlines: When outputting the argument
8288 to the @w{@samp{x X}} command, GNU @code{troff} will follow each newline
8289 in the argument with a @samp{+} character (as usual, it will terminate
8290 the entire argument with a newline); thus if the line after the line
8291 containing the @w{@samp{x X}} command starts with @samp{+}, then the
8292 newline ending the line containing the @w{@samp{x X}} command should be
8293 treated as part of the argument to the @w{@samp{x X}} command, the
8294 @samp{+} should be ignored, and the part of the line following the
8295 @samp{+} should be treated like the part of the line following the
8296 @w{@samp{x X}} command.
8299 @c =====================================================================
8301 @node Font Files,  , gtroff Output, File formats
8302 @section Font Files
8303 @cindex font files
8304 @cindex files, font
8306 The @code{gtroff} font format is roughly a superset of the
8307 @code{ditroff} font format.  Unlike the @code{ditroff} font format,
8308 there is no associated binary format; all files are text files.  The
8309 font files for device @var{name} are stored in a directory
8310 @file{dev@var{name}}.  There are two types of file: a device description
8311 file called @file{DESC} and for each font@w{ }@samp{F} a font file
8312 called@w{ }@file{F}.
8314 @menu
8315 * DESC file format::            
8316 * Font file format::            
8317 @end menu
8319 @c ---------------------------------------------------------------------
8321 @node DESC file format, Font file format, Font Files, Font Files
8322 @subsection @file{DESC} file format
8323 @cindex @file{DESC} file format
8324 @cindex font description file format
8325 @cindex format of font description file
8326 @pindex DESC
8328 The @file{DESC} file can contain the following types of line:
8330 @table @code
8331 @item res @var{n}
8332 @kindex res
8333 There are @var{n} machine units per inch.
8335 @item hor @var{n}
8336 @kindex hor
8337 The horizontal resolution is @var{n} machine units.
8339 @item vert @var{n}
8340 @kindex vert
8341 The vertical resolution is @var{n} machine units.
8343 @item sizescale @var{n}
8344 @kindex sizescale
8345 The scale factor for point sizes.  By default this has a value of@w{ }1.
8346 One scaled point is equal to one point/@var{n}.  The arguments to the
8347 @code{unitwidth} and @code{sizes} commands are given in scaled points.
8348 @xref{Fractional Type Sizes}, for more information.
8350 @item unitwidth @var{n}
8351 @kindex unitwidth
8352 Quantities in the font files are given in machine units for fonts whose
8353 point size is @var{n}@w{ }scaled points.
8355 @item tcommand
8356 @kindex tcommand
8357 This means that the postprocessor can handle the @samp{t} and @samp{u}
8358 output commands.
8360 @item sizes @var{s1} @var{s2} @dots{} @var{sn} 0
8361 @kindex sizes
8362 This means that the device has fonts at @var{s1}, @var{s2}, @dots{}
8363 @var{sn} scaled points.  The list of sizes must be terminated by a@w{
8364 }0.  Each @var{si} can also be a range of sizes @var{m}-@var{n}.  The
8365 list can extend over more than one line.
8367 @item styles @var{S1} @var{S2} @dots{} @var{Sm}
8368 @kindex styles
8369 The first @var{m}@w{ }font positions will be associated with styles
8370 @var{S1} @dots{} @var{Sm}.
8372 @item fonts @var{n} @var{F1} @var{F2} @var{F3} @dots{} @var{Fn}
8373 @kindex fonts
8374 Fonts @var{F1} @dots{} @var{Fn} will be mounted in the font positions
8375 @var{m}+1, @dots{}, @var{m}+@var{n} where @var{m} is the number of
8376 styles.  This command may extend over more than one line.  A font name
8377 of@var{ }0 will cause no font to be mounted on the corresponding font
8378 position.
8380 @item family @var{fam}
8381 @kindex family
8382 The default font family is @var{fam}.
8384 @item charset
8385 @kindex charset
8386 This line and everything following in the file are ignored.  It is
8387 allowed for the sake of backwards compatibility.
8388 @end table
8390 The @code{res}, @code{unitwidth}, @code{fonts} and @code{sizes} lines
8391 are compulsory.  Other commands are ignored by @code{gtroff} but may be
8392 used by postprocessors to store arbitrary information about the device
8393 in the @file{DESC} file.
8395 @c XXX add other commands resp. xrefs to output devices
8396 @c XXX add obsolete commands
8398 @c ---------------------------------------------------------------------
8400 @node Font file format,  , DESC file format, Font Files
8401 @subsection Font file format
8402 @cindex font file format
8403 @cindex format of font files
8405 A font file has two sections.  The first section is a sequence of lines
8406 each containing a sequence of blank delimited words; the first word in
8407 the line is a key, and subsequent words give a value for that key.
8409 @table @code
8410 @item name @var{F}
8411 @kindex name
8412 The name of the font is@w{ }@var{F}.
8414 @item spacewidth @var{n}
8415 @kindex spacewidth
8416 The normal width of a space is@w{ }@var{n}.
8418 @item slant @var{n}
8419 @kindex slant
8420 The characters of the font have a slant of @var{n}@w{ }degrees.
8421 (Positive means forward.)
8423 @item ligatures @var{lig1} @var{lig2} @dots{} @var{lign} [0]
8424 @kindex ligatures
8425 Characters @var{lig1}, @var{lig2}, @dots{}, @var{lign} are ligatures;
8426 possible ligatures are @samp{ff}, @samp{fi}, @samp{fl}, @samp{ffi} and
8427 @samp{ffl}.  For backwards compatibility, the list of ligatures may be
8428 terminated with a@w{ }0.  The list of ligatures may not extend over more
8429 than one line.
8431 @item special
8432 @kindex special
8433 The font is special; this means that when a character is requested that
8434 is not present in the current font, it will be searched for in any
8435 special fonts that are mounted.
8436 @end table
8438 Other commands are ignored by @code{gtroff} but may be used by
8439 postprocessors to store arbitrary information about the font in the font
8440 file.
8442 @cindex comments in font files
8443 @cindex font files, comments
8444 @kindex #
8445 The first section can contain comments which start with the @samp{#}
8446 character and extend to the end of a line.
8448 The second section contains one or two subsections.  It must contain a
8449 @code{charset} subsection and it may also contain a @code{kernpairs}
8450 subsection.  These subsections can appear in any order.  Each
8451 subsection starts with a word on a line by itself.
8453 @kindex charset
8454 The word @code{charset} starts the character set subsection.  The
8455 @code{charset} line is followed by a sequence of lines.  Each line gives
8456 information for one character.  A line comprises a number of fields
8457 separated by blanks or tabs.  The format is
8459 @c XXX fix it for new HTML additions
8461 @example
8462 @var{name} @var{metrics} @var{type} @var{code} @var{comment}
8463 @end example
8465 @cindex 8-bit input
8466 @cindex input, 8-bit
8467 @findex \N
8468 @kindex ---
8469 @noindent
8470 @var{name} identifies the character: If @var{name} is a single
8471 character@w{ }@var{c} then it corresponds to the @code{gtroff} input
8472 character @var{c}; if it is of the form @samp{\@var{c}} where @var{c} is
8473 a single character, then it corresponds to the @code{gtroff} input
8474 character@w{ }\@var{c}; otherwise it corresponds to the groff input
8475 character @samp{\[@var{name}]}.  (If it is exactly two characters
8476 @var{xx} it can be entered as @samp{\(@var{xx}}.)  @code{gtroff}
8477 supports 8-bit characters; however some utilities have difficulties with
8478 eight-bit characters.  For this reason, there is a convention that the
8479 name @samp{char@var{n}} is equivalent to the single character whose code
8480 is@w{ }@var{n}.  For example, @samp{char163} would be equivalent to the
8481 character with code@w{ }163 which is the pounds sterling sign in @w{ISO
8482 Latin-1} character set.  The name @samp{---} is special and indicates
8483 that the character is unnamed; such characters can only be used by means
8484 of the @code{\N} escape sequence in @code{gtroff}.
8486 @c XXX input encodings vs. output encodings
8488 The @var{type} field gives the character type:
8490 @table @code
8491 @item 1
8492 the character has an descender, for example, `p';
8494 @item 2
8495 the character has an ascender, for example, `b';
8497 @item 3
8498 the character has both an ascender and a descender, for example, `('.
8499 @end table
8501 The @var{code} field gives the code which the postprocessor uses to
8502 print the character.  The character can also be input to @code{gtroff}
8503 using this code by means of the @code{\N} escape sequence.  The code can
8504 be any integer.  If it starts with @samp{0} it will be interpreted as
8505 octal; if it starts with @samp{0x} or @samp{0X} it will be interpreted as
8506 hexadecimal.
8508 Anything on the line after the @var{code} field will be ignored.
8510 The @var{metrics} field has the form:
8512 @example
8513 @var{width}[,@var{height}[,@var{depth}[,@var{italic_correction}
8514   [,@var{left_italic_correction}[,@var{subscript_correction}]]]]]
8515 @end example
8517 @noindent
8518 There must not be any spaces between these subfields (it has been split
8519 here into two lines for better legibility only).  Missing subfields are
8520 assumed to be@w{ }0.  The subfields are all decimal integers.  Since
8521 there is no associated binary format, these values are not required to
8522 fit into a variable of type @samp{char} as they are in @code{ditroff}.
8523 The @var{width} subfield gives the width of the character.  The
8524 @var{height} subfield gives the height of the character (upwards is
8525 positive); if a character does not extend above the baseline, it should
8526 be given a zero height, rather than a negative height.  The @var{depth}
8527 subfield gives the depth of the character, that is, the distance below
8528 the lowest point below the baseline to which the character extends
8529 (downwards is positive); if a character does not extend below above the
8530 baseline, it should be given a zero depth, rather than a negative depth.
8531 The @var{italic_correction} subfield gives the amount of space that
8532 should be added after the character when it is immediately to be
8533 followed by a character from a Roman font.  The
8534 @var{left_italic_correction} subfield gives the amount of space that
8535 should be added before the character when it is immediately to be
8536 preceded by a character from a Roman font.  The
8537 @var{subscript_correction} gives the amount of space that should be
8538 added after a character before adding a subscript.  This should be less
8539 than the italic correction.
8541 A line in the @code{charset} section can also have the format
8543 @example
8544 @var{name} "
8545 @end example
8547 @noindent
8548 This indicates that @var{name} is just another name for the character
8549 mentioned in the preceding line.
8551 @kindex kernpairs
8552 The word @code{kernpairs} starts the kernpairs section.  This contains a
8553 sequence of lines of the form:
8555 @example
8556 @var{c1} @var{c2} @var{n}
8557 @end example
8559 This means that when character @var{c1} appears next to character
8560 @var{c2} the space between them should be increased by@w{ }@var{n}.
8561 Most entries in kernpairs section will have a negative value for@w{
8562 }@var{n}.
8566 @c =====================================================================
8567 @c =====================================================================
8569 @node Installation, Request and Escape Index, File formats, Top
8570 @chapter Installation
8571 @cindex installation
8573 @c XXX
8577 @c =====================================================================
8578 @c =====================================================================
8580 @node Request and Escape Index, Operator Index, Installation, Top
8581 @chapter Request and Escape Index
8583 In this index, escapes are listed with a leading backslash (@samp{\}) to
8584 distinguish them from requests which appear without the leading control
8585 character (normally either @samp{.} or @samp{'}).
8587 @printindex fn
8591 @c =====================================================================
8592 @c =====================================================================
8594 @node Operator Index, Register Index, Request and Escape Index, Top
8595 @chapter Operator Index
8597 @printindex op
8601 @c =====================================================================
8602 @c =====================================================================
8604 @node Register Index, Macro and String Index, Operator Index, Top
8605 @chapter Register Index
8607 @printindex vr
8611 @c =====================================================================
8612 @c =====================================================================
8614 @node Macro and String Index, Glyph Name Index, Register Index, Top
8615 @chapter Macro and String Index
8617 In this index, strings are listed with the calling escape sequence
8618 (@samp{\*}) to distinguish them from macros which appear without the
8619 leading control character (normally either @samp{.} or @samp{'}).
8621 @printindex ma
8625 @c =====================================================================
8626 @c =====================================================================
8628 @node Glyph Name Index, Font File Keyword Index, Macro and String Index, Top
8629 @chapter Glyph Name Index
8631 A glyph name @code{xx} consisting of exactly two characters can be
8632 accessed as @samp{\(xx}.  Glyph names @code{xxx} of any length can be
8633 accessed as @samp{\[xxx]}.
8635 @printindex gl
8639 @c =====================================================================
8640 @c =====================================================================
8642 @node Font File Keyword Index, Program and File Index, Glyph Name Index, Top
8643 @chapter Font File Keyword Index
8645 @printindex ky
8649 @c =====================================================================
8650 @c =====================================================================
8652 @node Program and File Index, Concept Index, Font File Keyword Index, Top
8653 @chapter Program  and File Index
8655 @printindex pg
8659 @c =====================================================================
8660 @c =====================================================================
8662 @node Concept Index,  , Program and File Index, Top
8663 @chapter Concept Index
8665 @printindex cp
8669 @summarycontents
8670 @contents
8671 @bye