* src/include/lib.h: Added xtmptemplate and made xtmpfile
[s-roff.git] / doc / groff.texinfo
blob2165b4298e8580708c10d4067c5dc3b658b418ed
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header (This is for running Texinfo on a region.)
3 @setfilename  groff
4 @settitle The GNU Troff Manual
5 @setchapternewpage odd
6 @footnotestyle separate
7 @c %**end of header (This is for running Texinfo on a region.)
10 @dircategory Miscellaneous
11 @direntry
12 * Groff: (groff).   The GNU troff document formatting system.
13 @end direntry
16 @smallbook
19 @iftex
20 @finalout
21 @end iftex
24 @ifinfo
25 This Info file documents GNU troff version 1.16.
27 Published by the Free Software Foundation
28 59 Temple Place, Suite 330
29 Boston, MA  02111-1307  USA
31 Copyright (C) 1994-2000 Free Software Foundation, Inc.
33 Permission is granted to make and distribute verbatim copies of this
34 manual provided the copyright notice and this permission notice are
35 preserved on all copies.
37 @ignore
38 Permission is granted to process this file through TeX and print the
39 results, provided the printed document carries copying permission notice
40 identical to this one except for the removal of this paragraph (this
41 paragraph not being relevant to the printed manual).
43 @end ignore
44 Permission is granted to copy and distribute modified versions of this
45 manual under the conditions for verbatim copying, provided that the
46 entire resulting derived work is distributed under the terms of a
47 permission notice identical to this one.
49 Permission is granted to copy and distribute translations of this manual
50 into another language, under the above conditions for modified versions,
51 except that this permission notice may be stated in a translation
52 approved by the Foundation.
54 Permission is granted to copy and distribute modified versions of this
55 manual under the conditions for verbatim copying, provided also that the
56 section entitled ``GNU General Public License'' is included exactly as
57 in the original, and provided that the entire resulting derived work is
58 distributed under the terms of a permission notice identical to this
59 one.
61 Permission is granted to copy and distribute translations of this manual
62 into another language, under the above conditions for modified versions,
63 except that the section entitled ``GNU General Public License'' may be
64 included in a translation approved by the Free Software Foundation
65 instead of in the original English.
66 @end ifinfo
69 @titlepage
70 @title groff
71 @subtitle The GNU implementation of @code{groff}
72 @subtitle Edition 1.16
73 @subtitle Spring 2000
74 @author by Trent A.@w{ }Fisher
75 @author and the maintainer of groff
77 @c Include the Distribution inside the titlepage environment so
78 @c that headings are turned off.  Headings on and off do not work.
80 @page
81 @vskip 0pt plus 1filll
82 Copyright @copyright{} 1994-2000 Free Software Foundation, Inc.
84 @sp 2
85 Version 1.16 of @code{groff}, @*
86 Spring 2000
87 @sp 2
88 Published by the Free Software Foundation @*
89 59 Temple Place, Suite 330 @*
90 Boston, MA  02111-1307  USA
93 Permission is granted to make and distribute verbatim copies of this
94 manual provided the copyright notice and this permission notice are
95 preserved on all copies.
97 Permission is granted to copy and distribute modified versions of this
98 manual under the conditions for verbatim copying, provided also that the
99 section entitled ``GNU General Public License'' is included
100 exactly as in the original, and provided that the entire resulting
101 derived work is distributed under the terms of a permission notice
102 identical to this one.
104 Permission is granted to copy and distribute translations of this manual
105 into another language, under the above conditions for modified versions,
106 except that the section entitled ``GNU General Public License'' may be
107 included in a translation approved by the Free Software Foundation
108 instead of in the original English.
110 Cover art by Etienne Suvasa.
111 @end titlepage
112 @page
116 @node Top, Copying, (dir), (dir)
118 @ifinfo
119 This Info file documents groff version 1.16, the GNU implementation of
120 the troff typesetting system.
122 This is an in-progress document; contributions, comments, or
123 contributions are welcome.  Send them to bug-groff@@gnu.org.
124 @end ifinfo
126 @menu
127 * Copying::                     
128 * Introduction::                
129 * Invoking groff::              
130 * Tutorial for Macro Users::    
131 * -man::                        
132 * -ms::                         
133 * -me::                         
134 * -mm::                         
135 * Programming Tutorial::        
136 * geqn::                        
137 * gtbl::                        
138 * gpic::                        
139 * grap::                        
140 * grefer::                      
141 * gsoelim::                     
142 * Devices::                     
143 * File formats::                
144 * Installation::                
145 * Request Index::               
146 * Register Index::              
147 * String Index::                
148 * Macro Index::                 
149 * Program Index::               
150 * Concept Index::               
151 @end menu
155 @node Copying, Introduction, Top, Top
156 @cindex copying
157 @unnumbered GNU GENERAL PUBLIC LICENSE
158 @center Version 2, June 1991
160 @display
161 Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
162 59 Temple Place, Suite 330, Boston, MA 02111, USA
164 Everyone is permitted to copy and distribute verbatim copies of this
165 license document, but changing it is not allowed.
166 @end display
168 @unnumberedsec Preamble
170 The licenses for most software are designed to take away your freedom to
171 share and change it.  By contrast, the GNU General Public License is
172 intended to guarantee your freedom to share and change free software --
173 to make sure the software is free for all its users.  This General
174 Public License applies to most of the Free Software Foundation's
175 software and to any other program whose authors commit to using it.
176 (Some other Free Software Foundation software is covered by the GNU
177 Library General Public License instead.)  You can apply it to your
178 programs, too.
180 When we speak of free software, we are referring to freedom, not price.
181 Our General Public Licenses are designed to make sure that you have the
182 freedom to distribute copies of free software (and charge for this
183 service if you wish), that you receive source code or can get it if you
184 want it, that you can change the software or use pieces of it in new
185 free programs; and that you know you can do these things.
187 To protect your rights, we need to make restrictions that forbid anyone
188 to deny you these rights or to ask you to surrender the rights.  These
189 restrictions translate to certain responsibilities for you if you
190 distribute copies of the software, or if you modify it.
192 For example, if you distribute copies of such a program, whether gratis
193 or for a fee, you must give the recipients all the rights that you have.
194 You must make sure that they, too, receive or can get the source code.
195 And you must show them these terms so they know their rights.
197 We protect your rights with two steps: (1)@w{ }copyright the software,
198 and (2)@w{ }offer you this license which gives you legal permission to
199 copy, distribute and/or modify the software.
201 Also, for each author's protection and ours, we want to make certain
202 that everyone understands that there is no warranty for this free
203 software.  If the software is modified by someone else and passed on, we
204 want its recipients to know that what they have is not the original, so
205 that any problems introduced by others will not reflect on the original
206 authors' reputations.
208 Finally, any free program is threatened constantly by software patents.
209 We wish to avoid the danger that redistributors of a free program will
210 individually obtain patent licenses, in effect making the program
211 proprietary.  To prevent this, we have made it clear that any patent
212 must be licensed for everyone's free use or not licensed at all.
214 The precise terms and conditions for copying, distribution and
215 modification follow.
217 @iftex
218 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
219 @end iftex
220 @ifinfo
221 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
222 @end ifinfo
224 @enumerate 0
225 @item
226 This License applies to any program or other work which contains a
227 notice placed by the copyright holder saying it may be distributed under
228 the terms of this General Public License.  The ``Program'', below,
229 refers to any such program or work, and a ``work based on the Program''
230 means either the Program or any derivative work under copyright law:
231 that is to say, a work containing the Program or a portion of it, either
232 verbatim or with modifications and/or translated into another language.
233 (Hereinafter, translation is included without limitation in the term
234 ``modification''.)  Each licensee is addressed as ``you''.
236 Activities other than copying, distribution and modification are not
237 covered by this License; they are outside its scope.  The act of running
238 the Program is not restricted, and the output from the Program is
239 covered only if its contents constitute a work based on the Program
240 (independent of having been made by running the Program).  Whether that
241 is true depends on what the Program does.
243 @item
244 You may copy and distribute verbatim copies of the Program's source code
245 as you receive it, in any medium, provided that you conspicuously and
246 appropriately publish on each copy an appropriate copyright notice and
247 disclaimer of warranty; keep intact all the notices that refer to this
248 License and to the absence of any warranty; and give any other
249 recipients of the Program a copy of this License along with the Program.
251 You may charge a fee for the physical act of transferring a copy, and
252 you may at your option offer warranty protection in exchange for a fee.
254 @item
255 You may modify your copy or copies of the Program or any portion of it,
256 thus forming a work based on the Program, and copy and distribute such
257 modifications or work under the terms of Section@w{ }1 above, provided
258 that you also meet all of these conditions:
260 @enumerate a
261 @item
262 You must cause the modified files to carry prominent notices stating
263 that you changed the files and the date of any change.
265 @item
266 You must cause any work that you distribute or publish, that in whole or
267 in part contains or is derived from the Program or any part thereof, to
268 be licensed as a whole at no charge to all third parties under the terms
269 of this License.
271 @item
272 If the modified program normally reads commands interactively when run,
273 you must cause it, when started running for such interactive use in the
274 most ordinary way, to print or display an announcement including an
275 appropriate copyright notice and a notice that there is no warranty (or
276 else, saying that you provide a warranty) and that users may
277 redistribute the program under these conditions, and telling the user
278 how to view a copy of this License.  (Exception: if the Program itself
279 is interactive but does not normally print such an announcement, your
280 work based on the Program is not required to print an announcement.)
281 @end enumerate
283 These requirements apply to the modified work as a whole.  If
284 identifiable sections of that work are not derived from the Program, and
285 can be reasonably considered independent and separate works in
286 themselves, then this License, and its terms, do not apply to those
287 sections when you distribute them as separate works.  But when you
288 distribute the same sections as part of a whole which is a work based on
289 the Program, the distribution of the whole must be on the terms of this
290 License, whose permissions for other licensees extend to the entire
291 whole, and thus to each and every part regardless of who wrote it.
293 Thus, it is not the intent of this section to claim rights or contest
294 your rights to work written entirely by you; rather, the intent is to
295 exercise the right to control the distribution of derivative or
296 collective works based on the Program.
298 In addition, mere aggregation of another work not based on the Program
299 with the Program (or with a work based on the Program) on a volume of a
300 storage or distribution medium does not bring the other work under the
301 scope of this License.
303 @item
304 You may copy and distribute the Program (or a work based on it, under
305 Section@w{ }2) in object code or executable form under the terms of
306 Sections 1 and 2 above provided that you also do one of the following:
308 @enumerate a
309 @item
310 Accompany it with the complete corresponding machine-readable source
311 code, which must be distributed under the terms of Sections 1 and 2
312 above on a medium customarily used for software interchange; or,
314 @item
315 Accompany it with a written offer, valid for at least three years, to
316 give any third party, for a charge no more than your cost of physically
317 performing source distribution, a complete machine-readable copy of the
318 corresponding source code, to be distributed under the terms of Sections
319 1 and 2 above on a medium customarily used for software interchange; or,
321 @item
322 Accompany it with the information you received as to the offer to
323 distribute corresponding source code.  (This alternative is allowed only
324 for noncommercial distribution and only if you received the program in
325 object code or executable form with such an offer, in accord with
326 Subsection b above.)
327 @end enumerate
329 The source code for a work means the preferred form of the work for
330 making modifications to it.  For an executable work, complete source
331 code means all the source code for all modules it contains, plus any
332 associated interface definition files, plus the scripts used to control
333 compilation and installation of the executable.  However, as a special
334 exception, the source code distributed need not include anything that is
335 normally distributed (in either source or binary form) with the major
336 components (compiler, kernel, and so on) of the operating system on
337 which the executable runs, unless that component itself accompanies the
338 executable.
340 If distribution of executable or object code is made by offering access
341 to copy from a designated place, then offering equivalent access to copy
342 the source code from the same place counts as distribution of the source
343 code, even though third parties are not compelled to copy the source
344 along with the object code.
346 @item
347 You may not copy, modify, sublicense, or distribute the Program except
348 as expressly provided under this License.  Any attempt otherwise to
349 copy, modify, sublicense or distribute the Program is void, and will
350 automatically terminate your rights under this License.  However,
351 parties who have received copies, or rights, from you under this License
352 will not have their licenses terminated so long as such parties remain
353 in full compliance.
355 @item
356 You are not required to accept this License, since you have not signed
357 it.  However, nothing else grants you permission to modify or distribute
358 the Program or its derivative works.  These actions are prohibited by
359 law if you do not accept this License.  Therefore, by modifying or
360 distributing the Program (or any work based on the Program), you
361 indicate your acceptance of this License to do so, and all its terms and
362 conditions for copying, distributing or modifying the Program or works
363 based on it.
365 @item
366 Each time you redistribute the Program (or any work based on the
367 Program), the recipient automatically receives a license from the
368 original licensor to copy, distribute or modify the Program subject to
369 these terms and conditions.  You may not impose any further restrictions
370 on the recipients' exercise of the rights granted herein.  You are not
371 responsible for enforcing compliance by third parties to this License.
373 @item
374 If, as a consequence of a court judgment or allegation of patent
375 infringement or for any other reason (not limited to patent issues),
376 conditions are imposed on you (whether by court order, agreement or
377 otherwise) that contradict the conditions of this License, they do not
378 excuse you from the conditions of this License.  If you cannot
379 distribute so as to satisfy simultaneously your obligations under this
380 License and any other pertinent obligations, then as a consequence you
381 may not distribute the Program at all.  For example, if a patent license
382 would not permit royalty-free redistribution of the Program by all those
383 who receive copies directly or indirectly through you, then the only way
384 you could satisfy both it and this License would be to refrain entirely
385 from distribution of the Program.
387 If any portion of this section is held invalid or unenforceable under
388 any particular circumstance, the balance of the section is intended to
389 apply and the section as a whole is intended to apply in other
390 circumstances.
392 It is not the purpose of this section to induce you to infringe any
393 patents or other property right claims or to contest validity of any
394 such claims; this section has the sole purpose of protecting the
395 integrity of the free software distribution system, which is implemented
396 by public license practices.  Many people have made generous
397 contributions to the wide range of software distributed through that
398 system in reliance on consistent application of that system; it is up to
399 the author/donor to decide if he or she is willing to distribute
400 software through any other system and a licensee cannot impose that
401 choice.
403 This section is intended to make thoroughly clear what is believed to be
404 a consequence of the rest of this License.
406 @item
407 If the distribution and/or use of the Program is restricted in certain
408 countries either by patents or by copyrighted interfaces, the original
409 copyright holder who places the Program under this License may add an
410 explicit geographical distribution limitation excluding those countries,
411 so that distribution is permitted only in or among countries not thus
412 excluded.  In such case, this License incorporates the limitation as if
413 written in the body of this License.
415 @item
416 The Free Software Foundation may publish revised and/or new versions of
417 the General Public License from time to time.  Such new versions will be
418 similar in spirit to the present version, but may differ in detail to
419 address new problems or concerns.
421 Each version is given a distinguishing version number.  If the Program
422 specifies a version number of this License which applies to it and ``any
423 later version'', you have the option of following the terms and
424 conditions either of that version or of any later version published by
425 the Free Software Foundation.  If the Program does not specify a version
426 number of this License, you may choose any version ever published by the
427 Free Software Foundation.
429 @item
430 If you wish to incorporate parts of the Program into other free programs
431 whose distribution conditions are different, write to the author to ask
432 for permission.  For software which is copyrighted by the Free Software
433 Foundation, write to the Free Software Foundation; we sometimes make
434 exceptions for this.  Our decision will be guided by the two goals of
435 preserving the free status of all derivatives of our free software and
436 of promoting the sharing and reuse of software generally.
438 @iftex
439 @heading NO WARRANTY
440 @end iftex
441 @ifinfo
442 @center NO WARRANTY
443 @end ifinfo
445 @item
446 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
447 THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW@.  EXCEPT WHEN
448 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
449 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER
450 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
451 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE@.
452 THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH
453 YOU@.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
454 NECESSARY SERVICING, REPAIR OR CORRECTION.
456 @item
457 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
458 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
459 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
460 DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
461 DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM
462 (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
463 INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
464 THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR
465 OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
466 @end enumerate
468 @iftex
469 @heading END OF TERMS AND CONDITIONS
470 @end iftex
471 @ifinfo
472 @center END OF TERMS AND CONDITIONS
473 @end ifinfo
476 @page
477 @unnumberedsec How to Apply These Terms to Your New Programs
479 If you develop a new program, and you want it to be of the greatest
480 possible use to the public, the best way to achieve this is to make it
481 free software which everyone can redistribute and change under these
482 terms.
484 To do so, attach the following notices to the program.  It is safest to
485 attach them to the start of each source file to most effectively convey
486 the exclusion of warranty; and each file should have at least the
487 ``copyright'' line and a pointer to where the full notice is found.
489 @smallexample
490 @var{one line to give the program's name and an idea of what it does.}
491 Copyright (C) 19@var{yy} @var{name of author}
493 This program is free software; you can redistribute it and/or modify it
494 under the terms of the GNU General Public License as published by the
495 Free Software Foundation; either version 2 of the License, or (at your
496 option) any later version.
498 This program is distributed in the hope that it will be useful, but
499 WITHOUT ANY WARRANTY; without even the implied warranty of
500 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE@.  See the GNU
501 General Public License for more details.
503 You should have received a copy of the GNU General Public License along
504 with this program; if not, write to the Free Software Foundation, Inc.,
505 59 Temple Place, Suite 330, Boston, MA 02111, USA.
506 @end smallexample
508 Also add information on how to contact you by electronic and paper mail.
510 If the program is interactive, make it output a short notice like this
511 when it starts in an interactive mode:
513 @smallexample
514 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
515 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type
516 `show w'.  This is free software, and you are welcome to redistribute it
517 under certain conditions; type `show c' for details.
518 @end smallexample
520 The hypothetical commands @samp{show w} and @samp{show c} should show
521 the appropriate parts of the General Public License.  Of course, the
522 commands you use may be called something other than @samp{show w} and
523 @samp{show c}; they could even be mouse-clicks or menu items---whatever
524 suits your program.
526 You should also get your employer (if you work as a programmer) or your
527 school, if any, to sign a ``copyright disclaimer'' for the program, if
528 necessary.  Here is a sample; alter the names:
530 @smallexample
531 @group
532 Yoyodyne, Inc., hereby disclaims all copyright
533 interest in the program `Gnomovision'
534 (which makes passes at compilers) written 
535 by James Hacker.
537 @var{signature of Ty Coon}, 1 April 1989
538 Ty Coon, President of Vice
539 @end group
540 @end smallexample
542 This General Public License does not permit incorporating your program
543 into proprietary programs.  If your program is a subroutine library, you
544 may consider it more useful to permit linking proprietary applications
545 with the library.  If this is what you want to do, use the GNU Library
546 General Public License instead of this License.
550 @node Introduction, Invoking groff, Copying, Top
551 @chapter Introduction
552 @cindex introduction
554 GNU @code{troff} (or @code{groff}) is a system for typesetting
555 documents.  @code{troff} is very flexible and has been in existence (and
556 use) for about 3@w{ }decades.  It is quite widespread and firmly
557 entrenched in the @sc{Unix} community.
561 @menu
562 * What Is groff?::              
563 * History::                     
564 * groff Capabilities::          
565 * Macro Packages::              
566 * Preprocessors::               
567 * Postprocessors::              
568 * Credits::                     
569 @end menu
571 @node What Is groff?, History, Introduction, Introduction
572 @section What Is @code{groff}?
573 @cindex what is @code{groff}?
574 @cindex @code{groff} -- what is it?
577 @code{groff} is of an older generation of document preparation systems,
578 which operate more like compilers than the more recent interactive
579 WYSIWYG @footnote{What You See Is What You Get} systems.  @code{groff}
580 and its contemporary counterpart, @TeX{}, both work using a @dfn{batch}
581 paradigm: The input (or @dfn{source}) files are normal text files with
582 embedded formatting commands.  These files can then be processed by
583 @code{groff} to produce a typeset document on a variety of devices.
585 Likewise, @code{groff} should not be confused with a @dfn{word
586 processor}, since that term connotes an integrated system which includes
587 an editor and a text formatter.  Also, many word processors follow the
588 WYSIWYG paradigm which was discussed earlier.
590 Although WYSIWYG systems may be easier to use, they have a number of
591 disadvantages compared to @code{troff}:
593 @itemize @bullet{}
594 @item
595 They must be used on a bitmapped display to do any operations on your
596 document.
597 @item
598 Most of the WYSIWYG systems are either non-free or are not very
599 portable.
600 @item
601 @code{troff} is firmly entrenched in all @sc{Unix} systems.
602 @item
603 It is difficult to have a wide range of capabilities available within
604 the confines of a GUI/window system.
605 @item
606 It is more difficult to make global changes to a document.
607 @end itemize
609 @quotation
610 ``GUIs normally make it simple to accomplish simple actions and
611 impossible to accomplish complex actions.''  --Doug Gwyn (22/Jun/91 in
612 @code{comp.unix.wizards})
613 @end quotation
617 @node History, groff Capabilities, What Is groff?, Introduction
618 @section History
619 @cindex history
621 @code{troff} can trace its origins back to a formatting program called
622 @code{runoff} which ran on MIT's CTSS system.  This name came from the
623 common phrase of the time ``I'll run off a document.''
625 The first version of @sc{Unix} was developed on a PDP-7 which was
626 sitting around Bell Labs.  In 1971 the developers wanted to get a PDP-11
627 for further work on the operating system.  In order to justify the cost
628 for this system, they proposed that they would implement a document
629 formatting system for the AT&T patents division.  This first formatting
630 program was a reimplementation of @code{runoff}.  In accordance with
631 @sc{Unix}'s penchant for abreviations, it was named @code{roff} (an
632 abreviation of @code{runoff}).
634 When they needed a more flexible language, a new version of @code{roff}
635 called @code{nroff} (Newer @code{roff}) was written.  It had a much more
636 complicated syntax, but provided the basis for all future versions.
637 When they got a Graphic Systems CAT Phototypesetter, J.@w{ }F.@w{
638 }Ossanna wrote a version of @code{nroff} which would drive it.  It was
639 dubbed @code{troff} for typesetter @code{roff}, although many people
640 have speculated that it actually means Times @code{roff} because of
641 @code{troff}'s use of the Times font family by default.  As such, the
642 name @code{troff} is pronounced t-roff rather than trough.
644 With @code{troff} came @code{nroff} (they were actually the same program
645 except for some @samp{#ifdefs}), which was for producing output for line
646 printers and ascii terminals.  It understood everything @code{troff}
647 did, and ignored the commands which were not aplicable (i.e.@: font
648 changes).
650 Since there are several things which cannot be done easily in
651 @code{troff}, work on several preprocessors began.  These programs would
652 transform certain parts of a document into @code{troff}, which made a
653 very natural use of pipes in @sc{Unix}.
655 The @code{eqn} preprocessor allowed mathematical formul@ae{} to be
656 specified in a much simpler and more intuitive manner.  @code{tbl} is a
657 preprocessor for formatting tables.  The @code{refer} preprocessor (and
658 the similar program, @code{bib}) processes citations in a document
659 according to a bibliographic database.
661 Unfortunately, Ossanna's @code{troff} was written in PDP-11 assembly
662 language and produced output specifically for the CAT phototypesetter.
663 He rewrote it in C, although it was now 7000@w{ }lines of uncommented
664 code and still dependent on the CAT.  As the CAT became less common, and
665 was no longer supported by the manufacturer, the need to make it support
666 other devices became a priority.  However, before this could be done, he
667 was killed in an auto accident.
669 @pindex ditroff
670 So, Brian Kernighan took on the task of rewriting @code{troff}.  The
671 newly rewritten version produced a device independent code which was
672 very easy for postprocessors to read and translate to the appropriate
673 printer codes.  Also, this new version of @code{troff} (called
674 @code{ditroff}) had several extentions, which included drawing
675 functions.
677 Due to the additional abilities of the new version of @code{troff},
678 several new preprocessors appeared.  The @code{pic} preprocessor
679 provides a wide range of drawing functions.  Likewise the @code{ideal}
680 preprocessor did the same, although via a much different paradigm.  The
681 @code{grap} preprocessor took specifications for graphs, but, unlike
682 other preprocessors, produced @code{pic} code.
684 James Clark began work on a GNU implementation of @code{ditroff} in
685 early@w{ }1989.  The first version, @code{groff}@w{ }0.3.1, was released
686 June@w{ }1990.  @code{groff} included
688 @itemize @bullet{}
689 @item
690 A replacement for @code{ditroff} with many extentions.
691 @item
692 The @code{soelim}, @code{pic}, @code{tbl}, and @code{eqn} preprocessors.
693 @item
694 Postprocessors for ascii devices, PostScript, @TeX{} DVI, and X@w{
695 }windows.  GNU @code{troff} also eliminated the need for a separate
696 @code{nroff} program with a postprocessor which would produce ascii
697 output.
698 @item
699 A version of the @code{-me} macros and an implementation of the
700 @code{-man} macros.
701 @end itemize
703 Also, a front-end was included which could construct the, sometimes
704 painfully long, pipelines required for all the post- and preprocessors.
706 Development of GNU @code{troff} progressed rapidly, and saw the
707 additions of a replacement for @code{refer}, an implementation of the
708 @code{-ms} and @code{-mm} macros, and a program to deduce how to format
709 a document (@code{grog}).
711 It was declared a stable (i.e.@: non beta) package with the release of
712 version@w{ }1.04 around November@w{ }1991.
716 @node groff Capabilities, Macro Packages, History, Introduction
717 @section @code{groff} Capabilities
718 @cindex @code{groff} capabilities
719 @cindex capabilities of @code{groff}
721 So what exactly is @code{groff} capable of doing?  @code{groff} provides
722 a wide range of low-level text formatting operations.  Using these, you
723 can perform a wide range of formatting tasks, such as footnotes, table
724 of contents, multiple columns, etc.
726 @itemize @bullet{}
727 @item
728 Text filling, adjusting, and centering
729 @item
730 Hyphenation
731 @item
732 Page control
733 @item
734 Font and character size control
735 @item
736 Vertical spacing (i.e.@: double spacing)
737 @item
738 Line length and indenting
739 @item
740 Macros, strings, diversions, and traps
741 @item
742 Number registers
743 @item
744 Tabs, leaders, and fields
745 @item
746 Input and output conventions and character translation
747 @item
748 Overstrike, bracket, line drawing, and zero-width functions
749 @item
750 Local horizontal and vertical motions and the width function
751 @item
752 Three-part titles
753 @item
754 Output line numbering
755 @item
756 Conditional acceptance of input
757 @item
758 Environment switching
759 @item
760 Insertions from the standard input
761 @item
762 Input/output file switching
763 @item
764 Output and error messages
765 @end itemize
768 @node Macro Packages, Preprocessors, groff Capabilities, Introduction
769 @section Macro Packages
770 @cindex macro packages
772 Since @code{groff} provides such low level facilities, it can be quite
773 difficult to use by itself.  However, @code{groff} provides a
774 @dfn{macro} facility which allows you to specify how certain routine
775 operations (e.g.@w{ }starting paragraphs, printing headers and footers,
776 etc.)@: should be done.  These macros can be collected together into a
777 @dfn{macro package}.  There are a number of macro packages available;
778 the most common (and the ones described in this manual) are @code{-man},
779 @code{-me}, @code{-ms}, and @code{-mm}.
782 @node Preprocessors, Postprocessors, Macro Packages, Introduction
783 @section Preprocessors
784 @cindex preprocessors
786 Although @code{groff} provides most functions needed to format a
787 document, some operations would be unwieldy (i.e.@: drawing pictures).
788 Therefore, programs called preprocessors were written which understand
789 their own language and produce the necessary groff operations.  These
790 preprocessors are able to differentiate their own input from the rest of
791 the document via markers.
793 To use a preprocessor, @sc{Unix} pipes are used to feed the output from
794 the preprocessor into @code{groff}.  Any number of preprocessors may be
795 used on a given document; in this case, the preprocessors are linked
796 together into one pipeline.  However, in @code{groff}, the user does not
797 need to construct the pipe, but only tell @code{groff} what
798 preprocessors to use.
800 @code{groff} currently has preprocessors for producing tables
801 (@code{tbl}), typesetting equations (@code{eqn}), drawing pictures
802 (@code{pic}), and for processing bibliographies (@code{refer}).  An
803 associated program which is useful when dealing with preprocessors is
804 @code{soelim}.
806 There are other preprocessors in existence, but there are,
807 unfortunately, no free implementations available.  They are for drawing
808 pictures (@code{ideal} and @code{gremlin}), for drawing graphs
809 (@code{grap}), and chemical structures (@code{chem}).
812 @node Postprocessors, Credits, Preprocessors, Introduction
813 @section Postprocessors
814 @cindex postprocessors
816 @code{groff} actually produces device independent code which may be fed
817 into a postprocessor which will produce output for a particular device.
818 Currently, @code{groff} has postprocessors for PostScript, ascii
819 terminals, X@w{ }windows (for previewing), @TeX{} DVI format, and HTML.
822 @node Credits,  , Postprocessors, Introduction
823 @section Credits
824 @cindex credits
827 Large portions of this manual were taken from existing documents, most
828 notably, the manual pages for the @code{groff} package by James Clark,
829 and Eric Allman's papers on the @code{-me} macro package.
833 @node Invoking groff, Tutorial for Macro Users, Introduction, Top
834 @chapter Invoking @code{groff}
835 @cindex invoking @code{groff}
836 @cindex @code{groff} invocation
839 @pindex groff
840 @pindex gtroff
841 This section focuses on how to invoke the @code{groff} front end.  This
842 front end takes care of the details of constructing the pipeline among
843 the preprocessors, @code{gtroff} and the postprocessor.
845 It has become a tradition that GNU programs get the prefix @dfn{g} to
846 distinguish it from its original counterparts provided by the host
847 (@pxref{Environment}, for more details).  Thus, for example, @code{geqn}
848 is GNU @code{eqn}.  On operating systems like Linux or the Hurd, which
849 don't contain proprietary software, this prefix is omitted since GNU
850 @code{troff} is the only used incarnation of @code{troff}.  Exception:
851 @code{groff} is never replaced by `roff'.
854 @menu
855 * Options::                     
856 * Environment::                 
857 * Invocation Examples::         
858 @end menu
860 @node Options, Environment, Invoking groff, Invoking groff
861 @section Options
862 @cindex options
865 @pindex groff
866 @pindex gtroff
867 @pindex gpic
868 @pindex geqn
869 @pindex gtbl
870 @pindex grefer
871 @pindex gsoelim
872 @code{groff} is a front-end to the groff document formatting system.
873 Normally it runs the @code{gtroff} program and a postprocessor
874 appropriate for the selected device.  The default device is @samp{ps}.
875 It can optionally preprocess with any of @code{gpic}, @code{geqn},
876 @code{gtbl}, @code{grefer}, or @code{gsoelim}.
878 This section only documents options to the @code{groff} front end.  Many
879 of the arguments to @code{groff} are passed on to @code{gtroff},
880 therefore those are also included.  Arguments to pre- or postprocessors
881 can be found in @ref{Invoking gpic}, @ref{Invoking geqn}, @ref{Invoking
882 gtbl}, @ref{Invoking grefer}, @ref{Invoking gsoelim}, @ref{Invoking
883 grotty}, @ref{Invoking grops}, @ref{Invoking grohtml}, @ref{Invoking
884 grodvi}, and @ref{Invoking gxditview}
886 The command line format for @code{groff} is:
888 @example
889 groff [ -abehilpstvzCENRSVXZ ] [ -F@var{dir} ] [ -m@var{name} ]
890       [ -T@var{def} ] [ -f@var{fam} ] [ -w@var{name} ] [ -W@var{name} ]
891       [ -M@var{dir} ] [ -d@var{cs} ] [ -r@var{cn} ] [ -n@var{num} ]
892       [ -o@var{list} ] [ -P@var{arg} ] [ -L@var{arg} ]
893       [ @var{files}@dots{} ]
894 @end example
896 The command line format for @code{gtroff} is as follows.  As you can
897 see, many of the options to @code{groff} are actually passed on to
898 @code{gtroff}.
900 @example
901 gtroff [ -abivzCER ] [ -w@var{name} ] [ -W@var{name} ] [ -d@var{cs} ]
902        [ -f@var{fam} ] [ -m@var{name} ] [ -n@var{num} ]
903        [ -o@var{list} ] [ -r@var{cn} ] [ -T@var{name} ]
904        [ -F@var{dir} ] [ -M@var{dir} ] [ @var{files}@dots{} ]
905 @end example
907 Options without an argument can be grouped behind a single @samp{-}.  A
908 filename of @samp{-} denotes the standard input.
910 @pindex grog
911 The @code{grog} command can be used to guess the correct @code{groff}
912 command to use to format a file.
914 @table @samp
915 @item -h
916 Print a help message.
917 @item -e
918 Preprocess with @code{geqn}.
919 @item -t
920 Preprocess with @code{gtbl}.
921 @item -p
922 Preprocess with @code{gpic}.
923 @item -s
924 Preprocess with @code{gsoelim}.
925 @item -R
926 Preprocess with @code{grefer}.  No mechanism is provided for passing
927 arguments to @code{grefer} because most @code{grefer} options have
928 equivalent commands which can be included in the file.  @xref{grefer},
929 for more details.
931 @pindex troffrc
932 Note that @code{gtroff} also accepts a @samp{-R} option, which is not
933 accessible via @code{groff}.  This option prevents the loading of the
934 @file{troffrc} file.
935 @item -v
936 Make programs run by @code{groff} print out their version number.
937 @item -V
938 Print the pipeline on stdout instead of executing it.
939 @item -z
940 Suppress output from @code{gtroff}.  Only error messages will be printed.
941 @item -Z
942 Do not postprocess the output of @code{gtroff}.  Normally @code{groff}
943 will automatically run the appropriate postprocessor.
944 @item -P@var{arg}
945 Pass @var{arg} to the postprocessor.  Each argument should be passed
946 with a separate @samp{-P} option. Note that groff does not prepend
947 @samp{-} to @var{arg} before passing it to the postprocessor.
948 @item -l
949 Send the output to a printer.  The command used for this is specified by
950 the print command in the device description file.
951 @item -L@var{arg}
952 Pass @var{arg} to the spooler.  Each argument should be passed with a
953 separate @samp{-L} option.  Note that @code{groff} does not prepend a
954 @samp{-} to @var{arg} before passing it to the postprocessor.
955 @item -T@var{dev}
956 Prepare output for device @var{dev}.  The default device is @samp{ps}.
957 The following are the output devices currently available:
958 @table @samp
959 @item ps
960 For PostScript printers and previewers.
961 @item dvi
962 For TeX dvi format.
963 @item X75
964 For a 75 dpi X11 previewer.
965 @item X100
966 For a 100dpi X11 previewer.
967 @item ascii
968 For typewriter-like devices.
969 @item latin1
970 For typewriter-like devices using the ISO Latin-1 (ISO 8859-1) character set.
971 @item utf8
972 For typewriter-like devices using the Unicode (ISO 10646) character set with
973 UTF-8 encoding.
974 @item lj4
975 For an HP LaserJet4-compatible (or other PCL5-compatible) printer.
976 @item html
977 To produce HTML output.
978 @end table
980 The postprocessor to be used for a device is specified by the
981 @code{postpro} command in the device description file.  (@xref{Font
982 Files}, for more info.)  This can be overridden with the @samp{-X}
983 option.
984 @item -X
985 Preview with @code{gxditview} instead of using the usual postprocessor.
986 This is unlikely to produce good results except with @samp{-Tps}.
987 @item -N
988 Don't allow newlines with @code{eqn} delimiters.  This is the same as
989 the @samp{-N} option in @code{geqn}.
990 @item -S
991 Safer mode.  Pass the @samp{-S} option to @code{gpic} and use the
992 @samp{-msafer} macros with @code{gtroff}.
993 @item -a
994 Generate an ASCII approximation of the typeset output.
995 @item -b
996 Print a backtrace with each warning or error message.  This backtrace
997 should help track down the cause of the error.  The line numbers given
998 in the backtrace may not always be correct: @code{troff}'s idea of line
999 numbers gets confused by @code{as} or @code{am} requests.
1000 @item -i
1001 Read the standard input after all the named input files have been
1002 processed.
1003 @item -w@var{name}
1004 Enable warning @var{name}.  Available warnings are described in
1005 @ref{Debugging}.  Multiple @samp{-w} options are allowed.
1006 @item -W@var{name}
1007 Inhibit warning @var{name}.  Multiple @samp{-W} options are allowed.
1008 @item -E
1009 Inhibit all error messages.
1010 @item -C
1011 Enable compatibility mode.
1012 @item -d@var{cs}
1013 @itemx -d@var{name}=s
1014 Define @var{c} or @var{name} to be a string @var{s}; @var{c} must be a
1015 one-letter @var{name}.
1016 @item -f@var{fam}
1017 Use @var{fam} as the default font family.
1018 @item -m@var{name}
1019 Read in the file @file{tmac.@var{name}}.  Normally this will be searched
1020 for in @code{groff}'s lib directory.
1021 @item -n@var{num}
1022 Number the first page @var{num}.
1023 @item -o@var{list}
1024 Output only pages in @var{list}, which is a comma-separated list of page
1025 ranges; @var{n} means print page @var{n}, @samp{@var{m}-@var{n}} means
1026 print every page between @var{m} and @var{n}, @samp{-@var{n}} means
1027 print every page up to @var{n}, @samp{@var{n}-} means print every page
1028 from @var{n}.  @code{troff} will exit after printing the last page in
1029 the list.
1030 @item -r@var{cn}
1031 @itemx -r@var{name}=@var{n}
1032 Set number register @var{c} or @var{name} to @var{n}; @var{c} must be a
1033 one-letter @var{name}; @var{n} can be any troff numeric expression.
1034 @item -F@var{dir}
1035 Search @var{dir} for subdirectories dev@var{name} (@var{name} is the
1036 name of the device) for the @file{DESC} file and font files before the
1037 normal directory.
1038 @item -M@var{dir}
1039 Search directory @var{dir} for macro files before the normal directory.
1040 @end table
1044 @node Environment, Invocation Examples, Options, Invoking groff
1045 @section Environment
1046 @cindex environment
1049 There are also several environment variables which can modify groff's
1050 behavior.
1052 @table @code
1053 @item GROFF_COMMAND_PREFIX
1054 If this is set to @var{X}, then @code{groff} will run
1055 @var{X}@code{troff} instead of @code{gtroff}.  This also applies to
1056 @code{tbl}, @code{pic}, @code{eqn}, @code{refer}, and @code{soelim}.  It
1057 does not apply to @code{grops}, @code{grodvi}, @code{grotty},
1058 @code{grohtml}, @code{grolj4}, and @code{gxditview}.
1059 @item GROFF_TMAC_PATH
1060 A colon separated list of directories in which to search for macro
1061 files.
1062 @item GROFF_TYPESETTER
1063 Default device.
1064 @item GROFF_FONT_PATH
1065 A colon separated list of directories in which to search for the
1066 @code{dev}@var{name} directory.
1067 @item PATH
1068 The search path for commands executed by groff.
1069 @item GROFF_TMPDIR
1070 The directory in which temporary files will be created.  If this is not
1071 set and @code{TMPDIR} is set, temporary files will be created in that
1072 directory.  Otherwise temporary files will be created in @code{/tmp}.
1073 The @code{grops} and @code{grefer} commands can create temporary files.
1074 @end table
1077 @node Invocation Examples,  , Environment, Invoking groff
1078 @section Invocation Examples
1079 @cindex invocation examples
1080 @cindex examples of invocation
1083 This section will list several common uses of @code{groff} and the
1084 command line which will accomplish it.
1086 @example
1087 groff file
1088 groff -X -me file
1089 groff -mm -rD1 -z file
1090 groff -tps -me file | lpr -Plw2
1091 ... any more?? ...
1092 @end example
1094 @subsection @code{grog}
1096 @code{grog} reads files and guesses which of the @code{groff}
1097 preprocessors and/or macro packages are are required for formatting
1098 them, and prints the @code{groff} command including those options on the
1099 standard output.  The options generated are one of @samp{-e},
1100 @samp{-man}, @samp{-me}, @samp{-mm}, @samp{-ms}, @samp{-p}, @samp{-s},
1101 and @samp{-t}.
1103 A filename of @samp{-} is taken to refer to the standard input.  If no
1104 files are specified the standard input will be read.  Any specified
1105 options will be included in the printed command.  No space is allowed
1106 between options and their arguments.  For example,
1108 @example
1109 grog -Tdvi paper.ms
1110 @end example
1112 will guess the approriate command to print @file{paper.ms} and then run
1113 it after adding the @samp{-Tdvi} option.
1116 @node Tutorial for Macro Users, -man, Invoking groff, Top
1117 @chapter Tutorial for Macro Users
1118 @cindex tutorial for macro users
1119 @cindex macro tutorial for users
1120 @cindex user's tutorial for macros
1121 @cindex user's macro tutorial
1123 Most users tend to use a macro package to format their papers.  This
1124 means that the whole breadth of @code{groff} is not neccessary for most
1125 people.  This chapter covers the material needed to efficiently use a
1126 macro package.
1129 @menu
1130 * Basics::                      
1131 * Common Features::             
1132 @end menu
1134 @node Basics, Common Features, Tutorial for Macro Users, Tutorial for Macro Users
1135 @section Basics
1136 @cindex basics
1139 This section covers some of the basic concepts you will need to
1140 understand to use a macro package.@footnote{This section is derived from
1141 @cite{Writing Papers with nroff using -me} by Eric P.@w{ }Allman}
1142 References are made throughout to more detailed information, if desired.
1144 @code{groff} reads an input file prepared by the user and outputs a
1145 formatted paper suitable for publication or framing.  The input consists
1146 of text, or words to be printed, and embedded commands (@dfn{requests}
1147 and @dfn{escapes}), which tell @code{groff} how to format the printed
1148 copy.  For more detail on this @pxref{Embedded Commands}.
1150 The word @dfn{argument} is used in this manual to mean a word or number
1151 which appears on the same line as a request which modifies the meaning
1152 of that request.  For example, the request
1154 @example
1156 @end example
1158 @noindent
1159 spaces one line, but
1161 @example
1162 .sp 4
1163 @end example
1165 @noindent
1166 spaces four lines.  The number@w{ }4 is an argument to the @code{sp}
1167 request which says to space four lines instead of one.  Arguments are
1168 separated from the request and from each other by spaces.  More details
1169 on this can be found in @ref{Request Arguments}.
1171 The primary function of @code{groff} is to collect words from input
1172 lines, fill output lines with those words, justify the right hand margin
1173 by inserting extra spaces in the line, and output the result.  For
1174 example, the input:
1176 @example
1177 Now is the time
1178 for all good men
1179 to come to the aid
1180 of their party.
1181 Four score and seven
1182 years ago,...
1183 @end example
1185 @noindent
1186 will be read, packed onto output lines, and justified to produce:
1188 @quotation
1189 Now is the time for all good men to come to the aid of their party.
1190 Four score and seven years ago,...
1191 @end quotation
1193 @cindex break
1194 @cindex line break
1195 Sometimes you may want to start a new output line even though the line
1196 you are on is not yet full; for example, at the end of a paragraph.  To
1197 do this you can cause a @dfn{break}, which starts a new output line.
1198 Some requests cause a break automatically, as do blank input lines and
1199 input lines beginning with a space.
1201 Not all input lines are text to be formatted.  Some of the input lines
1202 are requests which describe how to format the text.  Requests always
1203 have a period or an apostrophe (@samp{'}) as the first character of the
1204 input line.
1206 The text formatter also does more complex things, such as automatically
1207 numbering pages, skipping over page boundaries putting footnotes in the
1208 correct place, and so forth.
1210 Here a few hints for preparing text for input to @code{groff}.  First,
1211 keep the input lines short.  Short input lines are easier to edit, and
1212 @code{groff} will pack words onto longer lines for you anyhow.  In
1213 keeping with this, it is helpful to begin a new line after every period,
1214 comma, or phrase, since common corrections are to add or delete
1215 sentences or phrases.  Secondly, do not hyphenate words at the end of
1216 lines -- @code{groff} is smart enough to hyphenate words for you as
1217 needed, but is not smart enough to take hyphens out and join a word back
1218 together.  Also, words such as ``mother-in-law'' should not be broken
1219 over a line, since then you will get a space where not wanted, such as
1220 ``mother- in-law''.
1222 @findex ls
1223 @cindex double spacing
1224 @cindex spacing
1225 Groff will double space output text automatically if you use the request
1226 @samp{.ls 2}.  You can revert to single spaced mode by typing @samp{.ls
1229 A number of requests allow you to change the way the printed copy looks,
1230 sometimes called the @dfn{layout} of the output page.  Most of these
1231 requests adjust the placing of @dfn{white space} (blank lines or
1232 spaces).
1234 @findex bp
1235 @cindex new page
1236 The @samp{.bp} request starts a new page.
1238 @findex sp
1239 @cindex blank lines
1240 @cindex empty lines
1241 The request @samp{.sp @var{N}} leaves @var{N} lines of blank space.
1242 @var{N} can be omitted (meaning skip a single line) or can be of the
1243 form @var{N}i (for @var{N} inches) or @var{N}c (for @var{N}
1244 centimeters).  For example, the input:
1246 @example
1247 .sp 1.5i
1248 My thoughts on the subject
1250 @end example
1252 @noindent
1253 leaves one and a half inches of space, followed by the line ``My
1254 thoughts on the subject'', followed by a single blank line.
1256 @findex ce
1257 @cindex centering lines
1258 Text lines can be centered by using the @samp{.ce} request.  The line
1259 after @samp{.ce} is centered (horizontally) on the page.  To center more
1260 than one line, use @samp{.ce @var{N}} (where @var{N} is the number of
1261 lines to center), followed by the @var{N} lines.  If you want to center
1262 many lines but don't want to count them, type:
1264 @example
1265 .ce 1000
1266 lines to center
1267 .ce 0
1268 @end example
1270 @noindent
1271 The @samp{.ce 0} request tells @code{groff} to center zero more lines,
1272 in other words, stop centering.
1274 @findex br
1275 @cindex line break
1276 @cindex break
1277 All of these requests cause a break; that is, they always start a new
1278 line.  If you want to start a new line without performing any other
1279 action, use @samp{.br}.
1282 @node Common Features,  , Basics, Tutorial for Macro Users
1283 @section Common Features
1284 @cindex common features
1285 @cindex features, common
1288 Groff provides very low level operations for formatting a document.
1289 There are many common routine operations which are done in all documents.
1290 These common operations are written into @dfn{macros} and collected into a
1291 @dfn{macro package}.
1293 All macro packages provide certain common capabilities which fall
1294 into the following categories.
1296 @subsection Paragraphs
1297 @cindex paragraphs
1299 One of the most common and most used capability is starting a
1300 paragraph.  There are a number of different types of paragraphs,
1301 any of which can be initiated with macros supplied by the macro
1302 package.  Normally paragraphs start with a blank line and the first
1303 line indented, like the text in this manual.  There are also block
1304 style paragraphs, which omit the indentation:
1306 @example
1307 Some   men  look   at  constitutions   with  sanctimonious
1308 reverence, and deem them like the ark of the covenant, too
1309 sacred to be touched.
1310 @end example
1312 And there are also indented paragraphs which begin with a tag or label
1313 at the margin and the remaining text indented.
1315 @example
1316 one   This is  the first paragraph.  Notice  how the first
1317       line of  the resulting  paragraph lines up  with the
1318       other lines in the paragraph.
1319 longlabel
1320       This  paragraph   had  a  long   label.   The  first
1321       character of text on the first line will not line up
1322       with  the  text  on  second  and  subsequent  lines,
1323       although they will line up with each other.
1324 @end example
1326 A variation of this is a bulleted list....
1328 @subsection Sections and Chapters
1330 Most macro packages supply some form of section headers.
1331 The simplest kind is simply the heading on a line by itself in bold
1332 type.  Others supply automatically numbered section heading or
1333 different heading styles at different levels.
1334 Some, more sophisticated, macro packages supply macros for starting
1335 chapters and appendicies.
1337 @subsection Headers and Footers
1339 Every macro packages gives you some way to manipulate the headers and
1340 footers (or @dfn{titles} on each page.  Some packages will allow you
1341 to have different ones on the even and odd pages (for material
1342 printed in a book form).
1343 The titles are called three-part titles, that is, there is a
1344 left-justified part, a centered part, and a right-justified part.
1345 An automatically generated page number may be put in any of these
1346 fields with the @samp{%} character.
1348 @subsection Page Layout
1350 Most macro packages let you specify top and bottom margins and other
1351 details about the appearance of the printed pages.
1353 @subsection Displays
1354 @cindex displays
1356 Displays are sections of text to be set off from the body
1357 of the paper.  Major quotes, tables, and figures are types of
1358 displays, as are all the examples used in this document.
1360 @cindex quotes, major
1361 @cindex major quotes
1362 Major quotes are quotes which are several lines long,
1363 and hence are set in from the rest of the text without
1364 quote marks around them.
1366 @cindex list
1367 A list is an indented, single spaced, unfilled display.  Lists should
1368 be used when the material to be printed
1369 should not be filled and justified like normal text, such
1370 as columns of figures or the examples used in this paper.
1372 @cindex keep
1373 A keep is a display of lines which are kept on a single page if
1374 possible.  An example of where you would use a
1375 keep might be a diagram.  Keeps differ from lists in that
1376 lists may be broken over a page boundary whereas keeps will
1377 not.
1379 @cindex keep, floating
1380 @cindex floating keep
1381 Floating keeps move relative to the text.  Hence, they
1382 are good for things which will be referred to by name, such
1383 as ``See figure 3''.  A floating keep will appear at the bottom of the
1384 current page if it will fit; otherwise, it will
1385 appear at the top of the next page.  Meanwhile, the surrounding text
1386 will `flow' around the keep, thus leaving now blank areas.
1388 @subsection Footnotes and annotations
1389 @cindex footnotes
1390 @cindex annotations
1392 There are a number of requests to save text for later
1393 printing.  Footnotes are printed at the bottom of the current
1394 page.  Delayed text is intended to be a variant form of foot-
1395 note; the text is printed only when explicitly called for,
1396 such as at the end of each chapter.
1398 Delayed text is very similar to a footnote except that
1399 it is printed when called for explicitly.  This allows a
1400 list of references to appear (for example) at the end of
1401 each chapter, as is the convention in some disciplines.
1403 Most macro packages which supply this functionality also supply a
1404 means of automatically numbering either type of annotation.
1406 @subsection Table of Contents
1408 Tables of contents are a type of
1409 delayed text having a tag (usually the page number) attached
1410 to each entry after a row of dots.  The table accumulates
1411 throughought the paper until printed, usually after the paper has
1412 ended.  Many macro packages will provide the abilitly to have several
1413 tables of contents (i.e. one standard one, one for tables, &c.)
1415 @subsection Indexes
1417 While some macro packages will use the term @dfn{index}, none
1418 actually provide that functionality.  The facilities they call
1419 indexes are actually more appropriate for tables of contents.
1421 @subsection Paper formats
1423 Some macro packages provide stock formats for various kinds of
1424 documents.  Many of them provide a common format for the title and
1425 opening pages of a technical paper.  The -mm macros in particular
1426 provide formats for letters and memorandums.
1428 @subsection Multiple Columns
1430 Some macro packages (except -man) provide the ability to have two or
1431 more columns on a page.
1433 @subsection Font and Size changes
1435 The builtin font and size functions are not always intuitive, so all
1436 macro packages provide macros to make these operations simpler.
1438 @subsection Predefined Strings
1440 Most macro packages provide various predefined strings for a variety
1441 of uses, examples are sub- and super-scripts, printable dates, quotes
1442 and various special characters.
1444 @subsection Preprocessor Support
1446 All macro packages provide support for the various preprocessors.
1448 @subsection Configuration and Customization
1450 Some macro packages provide means of customizing many of details of
1451 how the package behaves.  This ranges from setting the default type
1452 size to changing the appearance of section headers.
1455 @node -man, -ms, Tutorial for Macro Users, Top
1456 @chapter -man
1457 @cindex @code{-man}
1461 @node -ms, -me, -man, Top
1462 @chapter -ms
1463 @cindex @code{-ms}
1467 @node -me, -mm, -ms, Top
1468 @chapter -me
1469 @cindex @code{-me}
1473 @node -mm, Programming Tutorial, -me, Top
1474 @chapter -mm
1475 @cindex @code{-mm}
1479 @node Programming Tutorial, geqn, -mm, Top
1480 @chapter Programming Tutorial
1481 @cindex programming tutorial
1482 @cindex tutorial for programming
1484 This chapter covers @strong{all} of the facilities of groff.
1485 If you are intending to use a macro package, you probably do not want
1486 to read this chapter.
1489 @menu
1490 * Text::                        
1491 * Input Conventions::           
1492 * Measurements::                
1493 * Expressions::                 
1494 * Identifiers::                 
1495 * Embedded Commands::           
1496 * Registers::                   
1497 * Manipulating Filling and Adjusting::  
1498 * Manipulating Hyphenation::    
1499 * Manipulating Spacing::        
1500 * Tabs and Fields::             
1501 * Character Translations::      
1502 * Line Layout::                 
1503 * Page Layout::                 
1504 * Page Control::                
1505 * Fonts::                       
1506 * Sizes::                       
1507 * Strings::                     
1508 * Conditionals and Loops::      
1509 * Writing Macros::              
1510 * Page Motions::                
1511 * Drawing Functions::           
1512 * Traps::                       
1513 * Diversions::                  
1514 * Environments::                
1515 * I/O::                         
1516 * Postprocessor Access::        
1517 * Miscellany::                  
1518 * Debugging::                   
1519 * Implementation Differences::  
1520 * Summary::                     
1521 @end menu
1523 @node Text, Input Conventions, Programming Tutorial, Programming Tutorial
1524 @section Text
1525 @cindex text
1527 @code{groff} input files contain text with control commands
1528 interspersed throughout.  But, even without control codes,
1529 @code{groff} will still do several things with your text:
1530 filling and adjusting,
1531 adding additional space after sentences,
1532 hyphenating
1534 inserting implicit line breaks.
1537 @menu
1538 * Filling and Adjusting::       
1539 * Hyphenation::                 
1540 * Sentences::                   
1541 * Tab Stops::                   
1542 * Implicit Line Breaks::        
1543 @end menu
1545 @node Filling and Adjusting, Hyphenation, Text, Text
1546 @subsection Filling and Adjusting
1547 @cindex filling and adjusting
1548 @cindex adjusting and filling
1551 When troff reads in text it collects words from input and fits as many
1552 of them together on one output line as it can.  This is known as
1553 @dfn{filling}.
1555 Once troff has a @dfn{filled} line it will try to @dfn{adjust} it.
1556 which means it will widen the spacing between words until
1557 the text reaches the right margin (in the default adjustment mode).
1558 Extra spaces between words are preserved, but
1559 spaces at the end of lines are ignored.
1560 Spaces at the front of a line will cause a @dfn{break}
1561 (breaks will be explained in @ref{Implicit Line Breaks})
1563 @c distribute these through the text
1564 @xref{Manipulating Filling and Adjusting}
1566 @node Hyphenation, Sentences, Filling and Adjusting, Text
1567 @subsection Hyphenation
1568 @cindex hyphenation
1571 Since the odds of finding a set of words, for every output line,
1572 which will fit nicely on a
1573 line without inserting excessive amounts of space between words
1574 is not great,
1575 troff will hyphenate words so that lines can be justified
1576 without there being too much space between words.
1577 It uses an internal hyphenation algorithm, to indicate which words can
1578 be hyphenated and how to do so.
1579 When a word is hyphenated the first part of the word will be added
1580 to the current filled line being output (with an attached hyphen),
1581 and the other portion will be added to the next line to be filled.
1583 @c distribute these through the text
1584 @xref{Manipulating Hyphenation}
1586 @node Sentences, Tab Stops, Hyphenation, Text
1587 @subsection Sentences
1588 @cindex sentences
1591 Although it is often debated,
1592 some typesetting rules say there should be different amounts of space
1593 after various puctuation marks.
1594 For example, a period at the end of a sentence
1595 should have twice as much space following it
1596 as would a comma or a period as part of an abbreviation.
1598 @cindex sentence spaces
1599 @cindex spaces between sentences
1600 Troff does this by flagging certain characters (normally
1601 @samp{!},  @samp{?} and @samp{.})
1602 as @dfn{end of sentence} characters.
1603 When troff encounters one of these characters at the end of a line it
1604 will append two @dfn{sentence spaces} in the formatted output.
1605 (thus, one of the conventions mentioned in @ref{Input Conventions}).
1607 @c also describe how characters like ) are treated here -jjc
1608 @c gotta do some research on this -trent
1612 @node Tab Stops, Implicit Line Breaks, Sentences, Text
1613 @subsection Tab Stops
1614 @cindex tab stops
1615 @cindex stops, tabulator
1618 Groff translates tabs in the input into movements to the next tab
1619 stop.  These tab stops are initially located every half inch across
1620 the page.
1621 Using this you can make simple tables.  However, this can often be
1622 deceptive as the appearance (and width) of your text on a terminal and
1623 the results from groff can vary greatly.
1625 Also, a possible sticking point is that lines beginning with tab
1626 characters will still be filled, again producing unexpected results.
1627 For example, the following input
1629 @example
1630         1       2       3
1631                 4       5
1632 @end example
1634 @noindent
1635 will produce
1637 @example
1638         1       2       3               4       5
1639 @end example
1641 @c Tab stops are with respect to the input line.  -jjc
1642 @c did that last section address that?? -trent
1646 @c distribute these through the text
1647 @xref{Tabs and Fields}
1649 @node Implicit Line Breaks,  , Tab Stops, Text
1650 @subsection Implicit Line Breaks
1651 @cindex implicit line breaks
1652 @cindex implicit breaks of lines
1653 @cindex line, implicit breaks
1654 @cindex break
1655 @cindex break, implicit
1656 @cindex line break
1658 An important concept in troff is the @dfn{break}.  When a @dfn{break}
1659 occurs, troff will output the partially filled line (unadjusted),
1660 and resume collecting and filling text on the next output line.
1662 @cindex blank line
1663 @cindex empty line
1664 @cindex line, blank
1665 There are several ways to cause a break in troff.
1666 A blank line will not only cause a break, but it will also cause a
1667 one line vertical space (effectively a blank line) to be output.
1669 A line which begins with a space will cause a break and the space
1670 will be output at the beginning of the next line.
1671 Note that this space isn't adjusted, even in fill mode.
1673 The end of file will also cause a break (otherwise the last line of
1674 your document may vanish!)
1676 Certain @dfn{requests} also cause breaks, implicitly or explicity.
1677 This will be discussed later.
1679 @c distribute these through the text
1680 @xref{Manipulating Filling and Adjusting}
1682 @node Input Conventions, Measurements, Text, Programming Tutorial
1683 @section Input Conventions
1684 @cindex input conventions
1685 @cindex conventions for input
1688 Since groff does filling automatically, it is traditional in groff not
1689 to try and type things in as nicely formatted paragraphs.  These are
1690 some conventions commonly used when typing groff text:
1692 @itemize @bullet{}
1693 @item
1694 Break lines after punctuation, particularily at the ends of
1695 sentences, and in other logical places.  Keep separate phrases on
1696 lines by themselves, as entire phrases are often added or deleted
1697 when editing.
1698 @item
1699 Try to keep lines less than 40-60 characters,
1700 to allow space for inserting more text.
1701 @item
1702 Do not try to do any formatting in a WYSIWYG manner (i.e. don't
1703 try and use spaces to get proper indentation).
1704 @end itemize
1707 @node Measurements, Expressions, Input Conventions, Programming Tutorial
1708 @section Measurements
1709 @cindex measurements
1712 @cindex units of measurement
1713 @cindex basic units
1714 @cindex machine units
1715 Troff (like any other programs) requires numeric parameters to
1716 specify various measurements.  Most numeric parameters
1717 @footnote{those that specify vertical or horizontal motion or a type
1718 size} may have a measurement unit attached.
1719 These units are specified as a single
1720 character which immediately follows the number or expression.
1721 Each of these units are understood, by troff, to be a multiple of its
1722 @dfn{basic unit}.  So, whenever a different measurement unit is
1723 specified troff converts this into its basic units.
1724 This basic unit, represented by a @samp{u} is a
1725 device dependent measurement which is quite small, ranging from
1726 1/75th to 1/72000th of an inch.
1728 Some of the measurement units are compleatly independent of any of
1729 the current settings (e.g. type size) of groff.
1731 @table @samp
1732 @item i
1733 @cindex inch
1734 Inches.  An antiquated measurement unit still in use in certain
1735 backwards countries.
1736 @item c
1737 @cindex centimeter
1738 Centimeters.
1739 @item p
1740 @cindex points
1741 Points.  This is a typesetter's measurement used for measure type size.
1742 It is 72 points to an inch.
1743 @item P
1744 @cindex pica
1745 Pica.  Another typesetting measurement.  6 Picas to an inch.
1746 @item s
1747 @item z
1748 @end table
1750 The other measurements understood by troff are dependent on settings
1751 currently in effect in troff.  These are very useful for specifying
1752 measurements which should look proper with any size of text.
1754 @table @samp
1755 @item m
1756 @cindex em
1757 Ems.  This unit is equal to the current font size in points.
1758 So called because it is @emph{approximately} the width of the letter
1759 @samp{m} in the current font.
1760 @item n
1761 @cindex en
1762 Ens.  This is half of an em.
1763 @item v
1764 @cindex vertical space
1765 @cindex space, vertical
1766 Vertical space.  This is equivalent to the current line spacing.
1767 @xref{Sizes}, for more information about this.
1768 @item M
1769 100ths of an em.
1770 @end table
1772 @c distribute these through the text
1773 @xref{Fractional Type Sizes}
1775 @menu
1776 * Default Units::               
1777 @end menu
1779 @node Default Units,  , Measurements, Measurements
1780 @subsection Default Units
1781 @cindex default units
1782 @cindex units, default
1785 Many requests take a default unit.  While this can be helpful at
1786 times, it can cause strange errors in some expressions.
1787 For example, the line  length  request  expects  em's.
1788 Here are several attempts to get 3.5 inches and the results:
1790 @example
1791 3.5i      @result{}   3.5i
1792 7/2       @result{}   0i
1793 7/2i      @result{}   0i
1794 7i/2      @result{}   .1i
1795 7i/2u     @result{}   3.5i
1796 @end example
1798 As you can see, the safest way to specify measurements is to always
1799 attach a scaling indicator.
1801 @node Expressions, Identifiers, Measurements, Programming Tutorial
1802 @section Expressions
1803 @cindex expressions
1806 Troff has most of operators common to other languages:
1808 @itemize @bullet
1809 @item
1810 Arithmetic: +, -, /, *, %
1811 @item
1812 Comparison: <, >, >=, <=, =, ==  (the last two are the same)
1813 @item
1814 Logical: &, :
1815 @item
1816 Unary operators: -, +, ! (if/while only??)
1817 @item
1818 Maximum and minimum: >?, <?
1819 @item
1820 Scaling: (@var{c};@var{e})
1821 Evaluate @var{e} using @var{c} as the default scaling indicator.
1822 If @var{c} is missing, ignore scaling indicators in the
1823 evaluation of @var{e}.
1824 @end itemize
1826 Parenthesis may be used as in any other language.
1827 However, in groff they are necessary to ensure order of evaluation.
1828 Groff has no operator precedence,
1829 expressions are evaluated left to right.
1830 This means that @samp{3+5*4} is evaluated as if it were parenthesized
1831 like @samp{(3+5)*4}, not as @samp{3+(5*4)}, like you may expect.
1833 For many requests which cause a motion on the page, the unary
1834 operators work differently.
1835 The @samp{+} and @samp{-} operators indicate a motion relative to the
1836 current position (down or up, respectively).  The @samp{|} operator
1837 indicates an absolute position on the page or input line. (????)
1838 @code{+} and @code{-} are also treated differently by @code{nr} (?)
1840 Due to the way arguments are parsed, spaces are not allowed in
1841 expressions, unless the entire expression is surrounded by parenthesis.
1843 @c distribute these through the text
1844 @xref{Request Arguments}
1845 @c distribute these through the text
1846 @xref{Conditionals and Loops}
1848 @node Identifiers, Embedded Commands, Expressions, Programming Tutorial
1849 @section Identifiers
1850 @cindex identifiers
1852 Like any other language troff, has rules for properly formed
1853 identifiers.
1854 In troff an identifier can be made up of most any printable
1855 character.
1856 The only exception is characters which are interpreted by troff
1857 (backslash, square bracket and ?).  So, for example, any of the following
1858 are valid.
1860 @example
1864 end-list
1866 @end example
1868 You can test whether an identifier is valid in groff with the
1869 @code{\A} escape.  It expands to 1 or 0 according whether its argument
1870 (given in quotes) is or is not acceptable as the name of a string,
1871 macro, diversion, number register, environment or font. It will return
1872 0 if no argument is given. This is useful if you want to lookup user
1873 input in some sort of associative table.
1875 Identifiers in groff can be any length, but, in some contexts,
1876 groff needs to told
1877 where identifiers end and text begins (and in different ways
1878 depending on their length)
1880 @itemize @bullet{}
1881 @item
1882 Single character
1883 @item
1884 Two characters
1885 Must be prefixed with @samp{(} in some situations.
1886 @item
1887 Arbitrary length (groff only)
1888 Must be bracketed with @samp{[}, @samp{]} in some situations.
1889 Any length identifier can be put in brackets.
1890 @end itemize
1892 Unlike many other programming languages, undefined identifiers are
1893 silently ignored or expanded to nothing.
1896 @c distribute these through the text
1897 @xref{Interpolating Registers}
1898 @c distribute these through the text
1899 @xref{Strings}
1901 @node Embedded Commands, Registers, Identifiers, Programming Tutorial
1902 @section Embedded Commands
1903 @cindex embedded commands
1904 @cindex commands, embedded
1907 With most documents you need more funtionality beyond filling,
1908 adjusting and implicit line breaking.
1909 In order to gain further functionality, groff allows commands to be
1910 embeded into your text, in two ways.
1912 The first is a @dfn{request} which takes up an entire line, and does
1913 some large scale operation (e.g. break lines, start new pages).
1915 The other is an @dfn{escape} which can be embedded anywhere
1916 in your text, or even as an argument to a request. (Not always?)
1917 Escapes generally do more minor operations like sub- and super-
1918 scripts, print a symbol, &c.
1922 @menu
1923 * Requests::                    
1924 * Macros::                      
1925 * Escapes::                     
1926 @end menu
1928 @node Requests, Macros, Embedded Commands, Embedded Commands
1929 @subsection Requests
1930 @cindex requests
1933 @cindex control character
1934 @cindex character, control
1935 A request line begins with a control character,
1936 which is either a single quote (@samp{'}) or a period (@samp{.}).
1937 These can be changed @pxref{Character Translations}, for details.
1938 After this there may be optional tabs or spaces followed by an
1939 identifier which is the name of the request.
1940 This may be followed by any number of space separated arguments.
1942 @findex \&
1943 If you want to begin a line with a control character without it being
1944 interpreted, precede it with a @code{\&}.  This represents a zero
1945 width space, which means it will not affect you output.
1947 In most cases you will use the period as a control character.
1948 Several requests will cause a break, using the single quote control
1949 character will prevent this.
1952 @menu
1953 * Request Arguments::           
1954 @end menu
1956 @node Request Arguments,  , Requests, Requests
1957 @subsubsection Request Arguments
1958 @cindex request arguments
1959 @cindex arguments to requests
1962 Argument to requests (and macros) are processed much like the shell:
1963 The line is split into arguments according to spaces.
1964 An argument which is intended to contain spaces can either be enclosed
1965 in quotes (single or double), or have the spaces @dfn{escaped} with
1966 backslashes.
1968 So, for example:
1970 @example
1971 .uh The Mouse Problem
1972 .uh "The Mouse Problem"
1973 .uh The\ Mouse\ Problem
1974 @end example
1976 The first line is the @code{.uh} macro being called with 3 arguments,
1977 @samp{The}, @samp{Mouse}, and @samp{Problem}.
1978 The latter two have the same effect or calling the @code{.uh} macro
1979 with one argument @samp{The Mouse Problem}.
1981 Note, however, that the @code{.ds} request works differently.
1983 @c distribute these through the text
1984 @xref{Strings}
1986 @node Macros, Escapes, Requests, Embedded Commands
1987 @subsection Macros
1988 @cindex macros
1991 Troff has a @dfn{macro} facility for defining a series of lines which
1992 can be invoked by name.
1993 They are called in the same manner as requests
1994 and arguments may be passed in the same manner.
1997 @c distribute these through the text
1998 @xref{Writing Macros}
1999 @c distribute these through the text
2000 @xref{Request Arguments}
2002 @node Escapes,  , Macros, Embedded Commands
2003 @subsection Escapes
2004 @cindex escapes
2007 @findex \e
2008 @findex \\
2009 Escapes may occur anywhere in the input to groff.
2010 They begin with a backslash and are followed by a single character
2011 which indicates the function to be performed.
2012 If you want to have a backslash appear in your document, you should
2013 use the escape sequence @code{\e}.  Merely escaping the backslash
2014 with another backslash will work in @emph{some} curcumstances.
2016 Many escapes have no parameters, those that do, do so in one of two
2017 ways.  For escapes which require an identifier there must be a way for
2018 groff to tell where the identifier ends and the text begins.
2019 It assumes that the next single character is the identifier, but if
2020 that character is an open parenthesis, it takes the next two
2021 characters as the identifier; and if the next character is an open
2022 bracket, all characters until a close bracket are taken as the
2023 identifier.  Note that in the second case there is no closing
2024 parenthesis.  For example:
2026 @example
2028 \n(XX
2029 \*[TeX]
2030 @end example
2032 Other escapes may require several arguments and/or some special
2033 format.  In these cases the @dfn{argument} is enclosed in single
2034 quotes (not required??) and the enclosing text is decoded according
2035 to what that escape expects.
2037 @example
2038 \l'1.5i\(bu'
2039 @end example
2041 @findex \\
2042 @findex \e
2043 @findex \E
2044 If you want to have a backslash appear in your output, you can use several
2045 escapes: @code{\\}, @code{\e} or @code{\E}.
2046 These are very similar, and only differ with respect to being used in
2047 macros or diversions (@xref{Copy-in Mode}, and @ref{Diversions}, for
2048 more information)
2052 @c distribute these through the text
2053 @xref{Identifiers}
2055 @menu
2056 * Comments::                    
2057 @end menu
2059 @node Comments,  , Escapes, Escapes
2060 @subsubsection Comments
2061 @cindex comments
2064 @findex \"
2065 Probably one of the most@footnote{Unfortunately, this is a lie.  But
2066 hopefully future troff hackers will believe it :-)}
2067 common forms of escapes is the comment.
2068 They begin with the @code{\"} escape and end at the end of the input
2069 line.
2071 This may sound simple, but it can be tricky to keep the comments from
2072 interfering with the apperarance of your final outupt.
2074 If the escape is to the right of some text or a request, that portion
2075 of the line will be ignored, but the space leading up to it will be
2076 noticed by groff.  This only affects the @code{.ds} request (any
2077 others?).
2079 One possibly irritating idiosyncracy is that you mustn't use tabs to
2080 line up your comments.
2081 Tabs are not treated as white space between request and macro
2082 arguments.
2084 If you have a comment on a line by itself, it will be treated as a
2085 blank line, because after eliminating the comment, that is all that
2086 remains.  So, it is common to start the line with @code{.\"} which
2087 will cause the line to be treated as an undefined request.
2089 Another commenting scheme seen sometimes is three consecutive single
2090 quotes (@code{'''}) at the begining of a line.  This works, but groff
2091 will give a warning about an undefined macro, which is harmless, but
2092 irritating.
2094 @findex \#
2095 Now to avoid all this groff has a new comment mechanism using the
2096 @code{\#} escape.  This escape works the same as @code{\"} except
2097 that the newline is also ignored.
2099 @findex ig
2100 For large blocks of text, the @code{ig} request may be useful.
2101 @c distribute these through the text
2102 @xref{Strings}
2104 @node Registers, Manipulating Filling and Adjusting, Embedded Commands, Programming Tutorial
2105 @section Registers
2106 @cindex registers
2109 Registers are groff's numeric variables.  groff has a number of
2110 builtin registers, supplying anything from the date to details of
2111 formatting parameters.
2113 @c distribute these through the text
2114 @xref{Identifiers}
2116 @menu
2117 * Setting Registers::           
2118 * Interpolating Registers::     
2119 * Auto-increment::              
2120 * Assigning Formats::           
2121 * Builtin Registers::           
2122 @end menu
2124 @node Setting Registers, Interpolating Registers, Registers, Registers
2125 @subsection Setting Registers
2126 @cindex setting registers
2127 @cindex registers, setting
2130 @findex nr
2131 @findex \R
2132 Registers are defined/set via the @code{nr}
2133 request or the @code{\R} escape, for example, the following two lines
2134 are equivalent:
2136 @example
2137 .nr a 1
2138 \R'a 1'
2139 @end example
2141 @findex rr
2142 The @code{rr} request will
2143 remove the register specified by the argument.
2145 @findex rnn
2146 The @code{rnn} request will rename a number register.
2147 The format is @samp{.rnn @var{x} @var{y}}, which will
2148 rename number register  @var{x} to @var{y}.
2150 @findex aln
2151 Aliases can be created for a number register.  The format is
2152 @samp{.aln @var{xx} @var{yy}}, which will create an alias @var{xx} for
2153 number register object named @var{yy}.  The new name and the old name
2154 will be exactly equivalent.  If @var{yy} is undefined, a warning of
2155 type @samp{reg} will be generated, and the request will be ignored.
2156 @xref{Debugging}, for information about warnings.
2159 @node Interpolating Registers, Auto-increment, Setting Registers, Registers
2160 @subsection Interpolating Registers
2161 @cindex interpolating registers
2162 @cindex registers, interpolating
2165 @findex \n
2166 Numeric registers are @dfn{interpolated} via the @code{\n} escape.
2167 @c the following is wrong.  Should I say any more than the above??
2168 @c This means that the value of the number register in expanded in-place
2169 @c on the input line before any other actions, i.e. before requests and
2170 @c escapes are interpreted.
2172 @example
2173 .nr as \na+\na
2174 \n(as
2175 @end example
2178 @node Auto-increment, Assigning Formats, Interpolating Registers, Registers
2179 @subsection Auto-increment
2180 @cindex auto-increment
2181 @cindex increment, automatic
2183 Number registers can also be auto incremented/decremented.  You can
2184 specify the increment/decrement factor with third argument to the
2185 @code{nr} request.  The default value is 0.  For example:
2187 @example
2188 .nr a 0 1
2189 .nr xx 0 5
2190 \n+a, \n+a, \n+a, \n+a, \n+a
2192 \n+(xx, \n+(xx, \n+(xx, \n+(xx, \n+(xx
2193 @end example
2195 Produces:
2197 @example
2198 1, 2, 3, 4, 5
2199 5, 10, 15, 20, 25
2200 @end example
2202 If you want to change the increment factor without changing the value
2203 of a register, the following can be used.
2205 @example
2206 .nr a \na 10
2207 @end example
2210 @node Assigning Formats, Builtin Registers, Auto-increment, Registers
2211 @subsection Assigning Formats
2212 @cindex assigning formats
2213 @cindex formats, assigning
2216 @findex af
2217 When a register is used in the text of an input file
2218 (as opposed to part of an expression)
2219 it is textually replaced (or interpolated) with a representation of
2220 that number.
2221 This output format can be changed to a variety of formats
2222 (numbers, roman numerals, etc)
2223 This is done using the @code{af} request.
2224 The first argument to @code{af} is the name of the number register to
2225 be changed,
2226 and the second argument is the output format.
2227 The following output formats are available:
2229 @table @samp
2230 @item 1
2231 This is the default format, decimal numbers:
2232 1, 2, 3, @dots{}
2233 @item 001
2234 Decimal numbers with as many leading zeros as specified.
2235 So, @samp{001} would result in 001, 002, 003, @dots{}
2236 @item I
2237 @cindex roman numerals
2238 @cindex numerals, roman
2239 Upper-case roman numerals:
2240 0, I, II, III, IV, @dots{}
2241 @item i
2242 Lower-case roman numerals:
2243 0, i, ii, iii, iv, @dots{}
2244 @item A
2245 Upper-case letters:
2246 A, B, C, @dots{}, Z, AA, AB, @dots{}
2247 @item a
2248 Lower-case letters:
2249 a, b, c, @dots{}, z, aa, ab, @dots{}
2250 @end table
2252 The following example will produce @samp{10, X, j, 010}.
2254 @example
2255 .nr a 10
2256 .af a 1           \" the default format
2257 \na,
2258 .af a I
2259 \na,
2260 .af a a
2261 \na,
2262 .af a 001
2264 @end example
2266 @findex \g
2267 The @code{\g} escape returns the current format of the specified
2268 register.  For example, @samp{\ga} after the following example would
2269 produce @samp{001}.
2273 @node Builtin Registers,  , Assigning Formats, Registers
2274 @subsection Builtin Registers
2275 @cindex builtin registers
2276 @cindex registers, builtin
2279 The following are some builtin registers, which are not listed
2280 elsewhere in this manual.  Any registers which begin with a @samp{.}
2281 are read-only.  A compleat listing of all builtin registers can be
2282 found in @ref{Register Index}.
2284 @table @code
2285 @item .H
2286 @vindex .H
2287 Horizontal resolution in basic units.
2288 @item .V
2289 @vindex .V
2290 Vertical resolution in basic units.
2291 @item dw
2292 @vindex dw
2293 Day of the week (1-7).
2294 @item dy
2295 @vindex dy
2296 Day of the year (1-31).
2297 @item mo
2298 @vindex mo
2299 Current month (1-12).
2300 @item year
2301 @vindex year
2302 The year.
2303 @item yr
2304 @vindex yr
2305 The year minus 1900.  Unfortunately, the Unix Version 7 troff
2306 documentation had a year 2000 bug: it incorrectly claimed that
2307 @samp{\n(yr} was the last two digits of the year.  That claim has never
2308 been true of either traditional troff or GNU troff.  If you see old
2309 troff input that looks like this:
2311 @example
2312 '\" (The following line stopped working after 1999.)
2313 This document was formatted in 19\n(yr.
2314 @end example
2316 you can correct it as follows:
2318 @example
2319 This document was formatted in \n[year].
2320 @end example
2322 or, if you want to be portable to older troff versions, as follows:
2324 @example
2325 .nr y4 1900+\n(yr
2326 This document was formatted in \n(y4.
2327 @end example
2329 @item .c
2330 @vindex .c
2331 @itemx c.
2332 @vindex c.
2333 The current @emph{input} line number.
2334 @item ln
2335 @vindex ln
2336 The current @emph{output} line number.
2337 @item .x
2338 @vindex .x
2339 The  major  version  number.  For example, if the version number is 1.03
2340 then @code{.x} will contain 1.
2341 @item .y
2342 @vindex .y
2343 The minor version number.  For example, if the version number is 1.03
2344 then @code{.y} will contain 03.
2345 @item .Y
2346 @vindex .Y
2347 The revision number of groff.
2348 @item .g
2349 @vindex .g
2350 Always 1.
2351 Macros should use this to determine whether they are running
2352 under GNU troff.
2353 @item .A
2354 @vindex .A
2355 If the current output device is ascii, this is set to 1,
2356 zero otherwise.
2357 @item .P
2358 @vindex .P
2359 This register indicates whether the current page is actualy being
2360 printed, i.e. if the @samp{-o} option is being used to only print
2361 selected pages.
2362 @xref{Options}, for more information.
2363 @end table
2365 @node Manipulating Filling and Adjusting, Manipulating Hyphenation, Registers, Programming Tutorial
2366 @section Manipulating Filling and Adjusting
2367 @cindex manipulating filling and adjusting
2368 @cindex filling and adjusting, manipulating
2369 @cindex adjusting and filling, manipulating
2372 @findex br
2373 @cindex break
2374 @cindex line break
2375 Several ways of causing @dfn{breaks} were given in
2376 @ref{Implicit Line Breaks}.
2377 The @code{br} request will likewise cause a break.
2378 Several other requests will also cause breaks, implicitly.
2379 They are
2380 @code{bp},
2381 @code{ce},
2382 @code{fi},
2383 @code{fl},
2384 @code{in},
2385 @code{nf},
2386 @code{sp} and
2387 @code{ti}.
2389 @findex nf
2390 @findex fi
2391 @vindex .u
2392 Initially, groff will fill and ajust text to both margins.
2393 Filling can be disabled via the @code{nf} request
2394 and re-enabled with the @code{fi} request.
2395 These implicitly disable and re-enable adjusting.
2396 Both of these will cause break in text currently being filled.
2397 The number register @code{.u} is equal to 1 in fill mode and 0 in
2398 no-fill mode.
2400 @findex ad
2401 @findex na
2402 @vindex .j
2403 Adjusting can be disabled with the @code{ad} request and re-enabled
2404 with the @code{na} request.
2405 The @code{ad} request takes a single argument to indicate how to
2406 adjust text.
2407 The current adjustment mode is available in the number register
2408 @code{.j}.
2410 @table @samp
2411 @item l
2412 @cindex ragged-right
2413 Adjust text to the left margin.  This produces what is traditionally
2414 called ragged-right text.
2415 @item r
2416 Adjust text to the right margin.
2417 @item c
2418 Center filled text.
2419 @item b
2420 @itemx n
2421 Justify to both margins.  This is groff's default.
2422 @end table
2424 With no argument to @code{ad}, troff will adjust lines the same way
2425 it was the last time it was filling.  For example:
2427 @example
2428 text
2429 .ad r
2430 text
2431 .ad c
2432 text
2434 text
2435 .ad  \" back to centering
2436 text
2437 @end example
2439 @findex \p
2440 The escape @code{\p} will cause a break and cause the remaining text
2441 to be adjusted.
2443 @findex ss
2444 The @code{ss} request allows you to change the minimum size of a
2445 space between filled words.
2446 This request takes it's units as one twelfth of the
2447 spacewidth parameter for the current font.  Initially both the word
2448 space size and the sentence space size are 12.
2450 When two arguments are given to the @code{ss} request, the second argument
2451 gives the sentence space size. If the second argument is not given, the
2452 sentence space size will be the same as the word space size.
2453 The sentence space size
2454 is used in two circumstances: if the end of a sentence occurs at the end
2455 of a line in fill mode, then both an inter-word space and a sentence
2456 space will be added; if two spaces follow the end of a sentence in the
2457 middle of a line, then the second space will be a sentence space. Note
2458 that the behaviour of @sc{Unix} troff will be exactly that exhibited by GNU
2459 troff if a second argument is never given to the @code{ss} request. In GNU
2460 troff, as in @sc{Unix} troff, you should always follow a sentence with either
2461 a newline or two spaces.
2463 @vindex .ss
2464 @vindex .sss
2465 The number registers @code{.ss} and @code{.sss} are
2466 the values of the parameters set by the first and second
2467 arguments of the @code{ss} request.
2469 @findex ce
2470 The @code{ce} request will center text.
2471 While the @samp{ad c} request will also center text, it has the side
2472 effect of filling the text.  The @code{.ce} request will not fill the
2473 text it affects.
2474 This request causes a break.
2476 With no arguments, @code{ce} will fill the next line of text.
2477 The single argument @code{ce} takes is a number indicating the
2478 number of lines to be centered.  With no argument centering is
2479 disabled.
2481 A common idiom is to turn on centering for a large number of lines,
2482 and then turn off centering when you are done with the centered text.
2483 This is useful for any request which takes a number of lines as an
2484 argument.
2486 @example
2487 .ce 1000
2488 replace this
2489 with
2490 something
2491 more interesting
2492 @dots{}
2493 .ce 0
2494 @end example
2496 @vindex .ce
2497 The @code{.ce} number register contains the number of lines remaining
2498 to be centered, as set by the @code{ce} request.
2501 @findex rj
2502 @vindex .rj
2503 A similar request is @code{rj} request which will justify unfilled
2504 text to the right margin.  Its arguments are identical to the
2505 @code{ce} request.
2506 The @code{.rj} number register is
2507 the number of lines to be right-justified as set by the @code{rj}
2508 request.
2512 @node Manipulating Hyphenation, Manipulating Spacing, Manipulating Filling and Adjusting, Programming Tutorial
2513 @section Manipulating Hyphenation
2514 @cindex manipulating hyphenation
2515 @cindex hyphenation, manipulating
2518 As discussed in @ref{Hyphenation}, groff will hyphenate words.
2519 There are a number of ways to modify the how hyphenation is done.
2521 @findex nh
2522 @findex hy
2523 @vindex .hy
2524 This hyphenation can be turned off with the @code{nh} request, and
2525 turned back on with the @code{hy} request.  However, troff's
2526 hyphenation facilities are far more flexible than this.  The @code{hy}
2527 request can be used to tell troff to restrict hypenation to certain
2528 cases.  The request takes a single numeric argument.
2529 The current hyphenation restrictions can be found in the number
2530 register @code{.hy}
2532 @table @samp
2533 @item 1
2534 The default argument, which
2535 indicates to hyphenate without restrictions.
2536 @item 2
2537 Do not hyphenate the last word on a page or column.
2538 @item 4
2539 Do not hyphenate the last two characters of a word.
2540 @item 8
2541 Do not hyphenate the first two characters of a word.
2542 @end table
2544 @findex hlm
2545 @vindex .hlc
2546 @vindex .hlm
2547 The @code{hlm} request will
2548 set the maximum number of consecutive hyphenated lines to the value
2549 given as the first argument.
2550 If this number is
2551 negative, there is no maximum.  The default value is -1.
2552 This value is
2553 associated with the current environment.  Only lines output from an
2554 environment count towards the maximum associated with that environment.
2555 Hyphens resulting from @code{\%} are counted; explicit hyphens are not.
2556 The current setting of this is available in the @code{.hlm} request.
2557 Also the number of immediately preceding consecutive hyphenated lines
2558 are available in the number register @code{.hlc}.
2560 @findex hw
2561 The @code{hw} request allows you to specify how a specific word is
2562 to be hyphenated.  It takes only one argument which is the word with
2563 hyphens at the hyphenation points.  For example:
2564 @samp{.hw in-sa-lub-rious}.
2565 @c In old versions of troff there was a
2566 @c limited amount of space to store such information, fortunately,
2567 @c with groff, this is no longer a restriction.
2569 @findex \%
2570 @cindex hyphenation character
2571 @cindex character, hyphenation
2572 You can also tell troff how to hyphenate words on the fly with the
2573 use of the @code{\%} escape, also known as the @dfn{hyphenation
2574 character}.  Preceding a word with this character will prevent it
2575 from being hyphenated, putting it in a word will indicate to troff
2576 that the word may be hyphenated at that point.  Note that this
2577 mechanism will only affect one word, if you want to change the
2578 hyphenation of a word for the entire document, use the @code{hw}
2579 request.
2581 @findex hc
2582 The @code{hc} request allows you to change the hyphenation character.
2583 The character specified as an argument will then work the same as the
2584 @code{\%} escape, and, thus, no longer appear in the output.  Without
2585 an argument it will return the hyphenation character to @code{\%}.
2587 @findex hpf
2588 To further customize hyphenation the @code{hpf} request will read in
2589 a file of hyphenation patterns.
2590 This file will be searched for in the
2591 same way that @file{tmac.@var{name}} is searched for when the
2592 @samp{-m@var{name}} option is specified.
2594 It should have the same format as the argument to the
2595 \patterns primitive in @TeX{}; the letters appearing in this file are
2596 interpreted as hyphenation codes.
2597 A @samp{%} character in the patterns file
2598 introduces a comment that continues to the end of the line.
2600 @findex hla
2601 @findex hpf
2602 @pindex troffrc
2603 The set of
2604 hyphenation patterns is associated with the current language set by the
2605 @code{hla} request.  The @code{hpf} request is usually invoked by the
2606 @file{troffrc} file.
2608 @findex hcode
2609 @code{.hcode @var{c1 code1 c2 code2...}}
2610 Set the hyphenation code of character @var{c1} to code1 and that of
2611 @var{c2} to @var{code2}.
2612 A hyphenation code must be a single input character (not a
2613 special character) other than a digit or a space.  Initially each
2614 lower-case letter has a hyphenation code, which is itself, and each
2615 upper-case letter has a hyphenation code which is the lower case
2616 version of itself.
2618 @findex hym
2619 @vindex .hym
2620 The @code{hym} request will set the hyphenation margin to the value
2621 given as the first argument: when the current adjustment mode is not
2622 @samp{b}, the line will not be hyphenated if the line is no more than
2623 that amount short.
2624 The default hyphenation margin is 0.  The default scaling
2625 indicator for this request is m.  The hyphenation margin is associated
2626 with the current environment.  The current hyphenation margin is
2627 available in the @code{.hym} register.
2629 @findex hys
2630 @vindex .hys
2631 The @code{hys} request set the hyphenation space to the value given as
2632 the first argument: when the current adjustment mode is b, don't
2633 hyphenate the line if the line can be justified by adding no more than
2634 that amount of extra space to each word space.  The default
2635 hyphenation space is 0.  The default scaling indicator for this
2636 request is m.  The hyphenation space is associated with the current
2637 environment.  The current hyphenation space is available in the
2638 @code{.hys} register.
2640 @findex shc
2641 The @code{shc} request will set the soft hyphen character to the
2642 argument given as an argument.  If the argument is omitted, the soft
2643 hyphen character will be set to the default @code{\(hy}. The soft
2644 hyphen character is the character which will be inserted when a word
2645 is hyphenated at a line break.  If the soft hyphen character does not
2646 exist in the font of the character immediately preceding a potential
2647 break point, then the line will not be broken at that point.  Neither
2648 definitions (specified with the @code{char} request) nor translations
2649 (specified with the @code{tr} request) are considered when finding the soft
2650 hyphen character.
2652 @findex hla
2653 @vindex .hla
2654 @pindex troffrc
2655 The @code{hla} request will set the current hyphenation language to
2656 that given by the first argument.  Hyphenation exceptions specified
2657 with the @code{hw} request and hyphenation patterns specified with the
2658 @code{hpf} request are both associated with the current hyphenation
2659 language.  The @code{hla} request is usually invoked by the
2660 @file{troffrc} file.  The current hyphenation language is available
2661 in the number register @code{.hla}.
2665 @node Manipulating Spacing, Tabs and Fields, Manipulating Hyphenation, Programming Tutorial
2666 @section Manipulating Spacing
2667 @cindex manipulating spacing
2668 @cindex spacing, manipulating
2671 @findex sp
2672 The @code{sp} request will cause troff to space downwards the
2673 distance specified as the first argument.  With no argument it will
2674 advance 1 line.
2675 A negative argument will cause troff to move up the page the
2676 specified distance.
2677 If the argument is preceded by a @samp{|} troff will move that
2678 distance from the top of the page.
2680 @findex ls
2681 @vindex .L
2682 Often you may want your output to be double or triple spaced.
2683 The @code{ls} request will cause troff to output @var{n}-1 blank
2684 lines after each line of text, where @var{n} is the argument given to
2685 the @code{ls} request.  With no argument troff will go back to single
2686 spacing.  The number register @code{.L} contains the current line
2687 spacing setting.
2689 @findex \x
2690 @vindex .a
2691 Sometimes, extra vertical spacing is only needed occasionaly,
2692 i.e. to allow space for a tall construct (like an equation).
2693 The @code{\x} escape will do this.
2694 The escape is given a numerical argument (like @samp{\x'3p'}).
2695 If this number is positive extra vertical space will be inserted
2696 below the current line.  A negative number will add space above.
2697 If this escape is used multiple times on the same line, the maximum
2698 values are used.
2699 The @code{.a} number register contains the most recent
2700 extra vertical @strong{emph} line space.
2702 @example
2703 ... example of inline equation ...
2704 @end example
2706 @findex ns
2707 @findex rs
2708 @cindex no-space mode
2709 @cindex mode, no-space
2710 Spacing (via either @code{sp} or via blank lines) can be disabled
2711 with the @code{ns} request.  This will enable @dfn{no-space mode}.
2712 This mode will end when actual text is output or the @code{rs}
2713 request is encountered.  No-space mode will also prevent requests to
2714 advance to the next page unless they are accompanied by a page number
2715 (@pxref{Page Control}, for more information.)
2718 @node Tabs and Fields, Character Translations, Manipulating Spacing, Programming Tutorial
2719 @section Tabs and Fields
2720 @cindex tabs and fields
2721 @cindex fields and tabs
2724 @findex \t
2725 Tab stops are much like those on a typewriter: a tab character (or the
2726 @code{\t} escape) on input will cause horizontal motion to the next
2727 tab stop.
2729 @findex ta
2730 Tab stops can be changed with the @code{ta} request.
2731 This request takes a series of numbers as arguments which indicate
2732 where each tab stop is to be (overriding any previous settings).
2733 These can be specified absolutely,
2734 i.e. as the distance from the left margin.
2735 For example, the following wil set tab stops every one inch.
2737 @example
2738 .ta 1i 2i 3i 4i 5i 6i
2739 @end example
2741 Tab stops can also be specified relatively (using a leading @samp{+})
2742 which means that the specified tab stop will be set that distance
2743 from the previous tab stop.  For example the following is equivalent
2744 to the previous example.
2746 @example
2747 .ta 1i +1i +1i +1i +1i +1i
2748 @end example
2750 After the specified tab stops repeat values may be set for tabs beyond
2751 the last one specified.  This is most commonly used to specify tabs
2752 set at equal intervals.  The compleat syntax for setting tabs is
2753 @code{ta @var{n1} @var{n2} @dots{} @var{nn} T @var{r1} @var{r2}
2754 @dots{} @var{rn}} This will set tabs at positions @var{n1}, @var{n2},
2755 @dots{}, @var{nn} and then set tabs at @var{nn}+@var{r1},
2756 @var{nn}+@var{r2}, @dots{}, @var{nn}+@var{rn} and then at
2757 @var{nn}+@var{rn}+@var{r1}, @var{nn}+@var{rn}+@var{r2}, @dots{},
2758 @var{nn}+@var{rn}+@var{rn}, and so on.  For example the following is,
2759 yet again, the same as the previous examples.
2761 @example
2762 .ta T 1i
2763 @end example
2765 The material in each tab column may be justified to the right or left
2766 or centered in the column.  This is specified by appending an
2767 @samp{R}, @samp{L} or @samp{C} to the number specifying that tab stop.
2768 The default justification is @samp{L}.
2770 @example
2771 .ta 1i 2iC 2iR
2772 @end example
2774 @vindex .tabs
2775 The number register @code{.tabs} contains
2776 a string representation of the current tab settings suitable for use as
2777 an argument to the @code{ta} request.
2779 @findex tc
2780 Normally troff will fill the space to the next tab stop with spaces.
2781 In some cases you may wish to change this.  The @code{tc} request
2782 will do this.  With no argument troff will revert to using spaces.
2784 @subsection Leaders
2785 @cindex leaders
2787 @findex lc
2788 Sometimes you may wish to use the @code{tc} request to fill a tab
2789 stop with a given character, but also, you want to use normal tab
2790 stops on the rest of the line.  For this groff provides an alternate
2791 tab mechanism, called @dfn{leaders} which will do just that.
2792 They are used exclusively to produce a repeated run of characters to
2793 the next tab stop.
2795 You can declare what character will be repeated with the @code{lc}
2796 request.  If you do not give it an argument, the leaders will act the
2797 same as tabs.
2799 @findex \a
2800 The difference is that a leader is invoked by using the @code{\a}
2801 escape.
2803 @cindex table of contents
2804 @cindex contents, table of
2805 So for a table of contents you may want to have tab stops defined so
2806 that the section number is one tab stop, the title is the second with
2807 the remaining space being filled with a line of dots and then the
2808 page number slightly separated from the dots.
2810 @example
2811 .lc .
2812 .ta .5iR 5i +.25i
2813 1.1\tFoo\a\t12
2814 @end example
2816 @subsection Fields
2817 @cindex fields
2819 @findex fc
2820 Fields are a more general way of laying out tabular data.
2821 @code{fc}
2823 @node Character Translations, Line Layout, Tabs and Fields, Programming Tutorial
2824 @section Character Translations
2825 @cindex character translations
2826 @cindex translations of characters
2829 @findex cc
2830 @findex c2
2831 The control character (@samp{.}) and the no-break control character
2832 (@samp{'}) can be changed with the @code{cc} and @code{c2} requests,
2833 respectively.
2834 The single argument is the new character to be used, with no argument
2835 the normal control character is restored.
2837 @findex ec
2838 @findex eo
2839 The @code{eo} request will compleatly disable the escape mechanism.
2840 The @code{ec} request can be used to change the escape character from
2841 the default @samp{\} to what is specified as an argument.
2843 @findex tr
2844 The @code{tr} request will translate characters.
2846 @findex trnt
2847 @findex \!
2848 @code{trnt}
2849 This is the same as the @code{tr} request except that the
2850 translations do not
2851 apply to text that is transparently throughput into a diversion with
2852 @code{\!}.  @xref{Diversions}, for more information.
2853 For example,
2855 @example
2856 .tr ab
2857 .di x
2858 \!.tm a
2861 @end example
2863 will print @samp{b}; if @code{trnt} is used instead of @code{tr} it
2864 will print @samp{a}.
2867 @node Line Layout, Page Layout, Character Translations, Programming Tutorial
2868 @section Line Layout
2869 @cindex line layout
2870 @cindex layout, line
2873 @cindex dimensions, line
2874 @cindex line dimensions
2875 The following drawing shows the dimensions which troff uses for
2876 placing a line of output onto the page.  They are labeled with the
2877 request which manipulates that dimension.
2879 @example
2880 @group
2881               | -->| in |<--                   |
2882            -->| po |<-----------ll------------>|
2883               +----+----+----------------------+----+
2884               |    :    :                      :    |
2885               +----+----+----------------------+----+
2886 @end group
2887 @end example
2889 These dimensions are:
2891 @ftable @code
2892 @item po
2893 @vindex .o
2894 @dfn{Page offset}--This is the leftmost postition of text on the final
2895 output.  This can be adjusted with the @code{po} request, and the
2896 current setting can be found in the builtin number register @code{.o}
2897 Note, that this request does not cause a break, so changing the page
2898 offset in the middle of text being filled may not do what you expect.
2899 @item in
2900 @vindex .i
2901 @dfn{Indentation}--This is the distance from the left margin where text
2902 will be printed.  This can be adjusted with the @code{in} request, and
2903 the current setting can be found in the builtin number register.
2904 @code{.i}
2905 This request causes a break.
2907 @findex ti
2908 @findex .in
2909 There is also the request @code{ti} which will cause one output line
2910 to be indented, after which the indentation returns to 0.
2911 This request causes a break.
2912 The number register @code{.in} is the indent that applies to the
2913 current output line.
2914 @item ll
2915 @findex .l
2916 @findex .ll
2917 @dfn{Line length}--This is the distance from the left margin to right
2918 margin.  This can be adjusted with the @code{.ll} request, and the
2919 current setting can be found in the builtin number register @code{.l}
2920 Note, as the figure implies, line length is not affected by the current
2921 indentation.
2922 The number register @code{.ll} is
2923 the line length that applies to the current output line.
2924 @end ftable
2926 @example
2927 .in +.5i
2928 .ll -.5i
2929 A bunch of really boring text which should
2930 be indented from both margins.
2931 replace me with a better (and more) example!
2932 .in -.5i
2933 .ll +.5i
2934 @end example
2937 @node Page Layout, Page Control, Line Layout, Programming Tutorial
2938 @section Page Layout
2939 @cindex page layout
2940 @cindex layout, page
2943 Troff provides some very primitive operations for controlling page
2944 layout.
2946 @findex pl
2947 @vindex .p
2948 Troff lets you specify the @dfn{page length} via the @code{pl} request.
2949 This is the length of the physical output page.
2950 The current setting can
2951 be found in the builtin number register @code{.p}.  Note that this only
2952 specifies the size of the page, not the not the top and bottom margins.
2953 Those are not done by groff directly, @xref{Traps}, for further
2954 information on how to do this.
2956 @cindex headers
2957 @cindex footers
2958 @cindex titles
2959 Troff provides several operations which help in setting up top and
2960 bottom titles (or headers and footers)
2962 @findex tl
2963 The @code{tl} request will print a @dfn{title line}, which consists
2964 of three parts: a left justified portion, a centered portion and a
2965 right justified portion.  The argument to @code{tl} is specified as
2966 @code{'@var{left}'@var{center}'@var{right}'}
2967 The @samp{%} character is replaced with the current page number.
2969 @findex lt
2970 @vindex .lt
2971 The title line is printed using its own line length, which is
2972 specified with the @code{lt} request.  The current setting of this is
2973 available in the @code{.lt} number register.
2975 @findex pn
2976 The @code{pn} request will change the page number of the @emph{next}
2977 page.  The only argument is the page number.
2979 @vindex %
2980 @vindex .pn
2981 The current page number is stored in the number register @code{%}.
2982 The number register @code{.pn} contains the
2983 number of the next page:
2984 either the value set by a @code{pn} request, or
2985 the number of the current page plus 1.
2987 @findex pc
2988 The @code{pc} request will change the page number character (used by
2989 the @code{tl} request) to a different character.  With no argument,
2990 this mechanism is disabled.
2993 @c distribute these through the text
2994 @xref{Traps}
2996 @node Page Control, Fonts, Page Layout, Programming Tutorial
2997 @section Page Control
2998 @cindex page control
2999 @cindex control, page
3002 @findex bp
3003 To stop processing the current page, and move to the next page, you
3004 can invoke the @code{bp} request.  This request will also cause a
3005 break.  This request can also take an argument of what the next page
3006 should be numbered.
3007 The only difference
3008 between @code{bp} and @code{pn} is that @code{pn} does not cause a
3009 break or actually eject a page.
3011 @example
3012 .de newpage
3014 'sp .5i
3015 .tl 'left top'center top'right top'
3016 'sp .3i
3018 @end example
3020 @cindex orphan
3021 @findex ne
3022 Often you may want to make sure that you have a certain amount of
3023 space before a new page occurs.  This is most useful to make sure
3024 that there is not a single @dfn{orphan} line left at the bottom of a
3025 page.  The @code{ne} request will ensure that there is a certain
3026 distance, specified by the first argument, before the next page is
3027 triggered (@pxref{Traps}, for further information).
3028 The default unit for @code{ne} is v's and the default argument
3029 is 1v.
3031 For example, to make sure that no fewer than 2 lines get orphaned,
3032 you can do the following before each paragraph.
3034 @example
3035 .ne 2
3036 .ti +5n
3037 text
3038 @end example
3040 @findex sv
3041 @findex os
3042 The @code{sv} is similar to the @code{ne} request, it reserves the
3043 specified amount of vertical space.  If the desired amount of space
3044 exists before the next trap (bottom page boundary), the space will be
3045 output immediately.  If there is not enough space, it is stored for
3046 later output via the @code{os} request.
3047 The default argument is 1v and the default units are v's.
3050 @node Fonts, Sizes, Page Control, Programming Tutorial
3051 @section Fonts
3052 @cindex fonts
3055 @findex ft
3056 @findex \f
3057 Groff gives you the ability to switch fonts at any point in your
3058 text.  There are two ways to do this, via the @code{ft} request and
3059 the @code{\f} escape.
3061 Fonts are generaly specified as uppercase strings, which are usually
3062 1 to 4 characters representing an abreviation of acronym of the font
3063 name.
3065 The basic set of fonts are R, I, B, and BI.  These are Times Roman,
3066 Italic, Bold, and Bold Italic.  There is also at least one symbol
3067 font which contains various special symbols (greek, mathematics).
3068 These latter fonts cannot be used directly, but should be used via an
3069 escape.
3072 @menu
3073 * Changing Fonts::              
3074 * Font Families::               
3075 * Font Positions::              
3076 * Using Symbols::               
3077 * Artificial Fonts::            
3078 * Ligatures and Kerning::       
3079 @end menu
3081 @node Changing Fonts, Font Families, Fonts, Fonts
3082 @subsection Changing Fonts
3083 @cindex changing fonts
3084 @cindex fonts, changing
3087 @findex ft
3088 You can change fonts with both the @code{ft} request.
3089 With no arguments it
3090 will switch to the previous font (also known as P).
3092 @example
3093 eggs, bacon,
3094 .ft B
3095 spam
3097 and sausage.
3098 @end example
3100 @findex \f
3101 The @code{\f} escape is useful for changing fonts in the middle of words
3103 @example
3104 eggs, bacon, \fBspam\fP and sausage.
3105 @end example
3107 Both of the above examples will produce the same output.
3109 Sometimes when putting letters of different fonts, you need more or
3110 less space at such boundaries.  There are two escapes to help with
3111 this.
3113 @findex \/
3114 The @code{\/} escape
3115 increases the width of the preceding character so that the spacing
3116 between that character and the following character will be correct if
3117 the following character is a roman character.  For example, if an italic
3118 f is immediately followed by a roman right parenthesis,  then in many
3119 fonts the top right portion of the f will overlap the top left of the
3120 right parenthesis.
3121 It is a good idea to use this escape sequence
3122 whenever an italic character is immediately followed by a roman
3123 character without any intervening space.
3125 @c producing @i{f}), which is ugly.  Inserting \/ produces f) and avoids this problem.
3127 @findex \,
3128 The @code{\,} escape
3129 modifies the spacing of the following character so that the spacing
3130 between that character and the preceding character will correct if the
3131 preceding character is a roman character.
3132 It is a good idea
3133 to use this escape sequence whenever a roman character is immediately
3134 followed by an italic character without any intervening space.
3136 @c For example, inserting \, between the parenthesis and the f changes (f to (f.
3138 @findex ftr
3139 The @code{ftr} request will translate fonts, it is called as
3140 @samp{.ftr @var{F G}}, which
3141 Translate font @var{F} to @var{G}.
3142 Whenever a font named @var{F} is referred to in @code{\f}
3143 escape sequence,
3144 or in the @code{ft}, @var{ul}, @var{bd}, @var{cs}, @var{tkf},
3145 @var{special}, @var{fspecial}, @var{fp},
3146 or @var{sty} requests, font @var{G} will be used.  If @var{G} is
3147 missing, or equal to @var{F} then font @var{F} will not be translated.
3150 @node Font Families, Font Positions, Changing Fonts, Fonts
3151 @subsection Font Families
3152 @cindex font families
3153 @cindex families, font
3156 Due to the variety of fonts available, groff has added the concept of
3157 font families.  Each of these families has four styles (R, I, B and BI),
3159 The fonts are specified as the concatenation of the font family and
3160 style.  Specifying a font without the family part will cause groff to
3161 use that style of the current family.
3162 By default, groff uses the Times family.
3164 This way, you can just use the basic four fonts and select a
3165 different font family on the command line.
3167 @findex fam
3168 @vindex .fam
3169 You can also switch font families with the @code{fam} request
3170 The current font family is available in the number register
3171 @code{.fam}.
3172 This is a string-valued register.
3174 @example
3175 spam,
3176 .fam H
3177 spam,
3178 .ft B
3179 spam,
3180 .fam T
3181 spam,
3182 .ft AR
3183 baked beans,
3184 .ft R
3185 and spam.
3186 @end example
3190 @node Font Positions, Using Symbols, Font Families, Fonts
3191 @subsection Font Positions
3192 @cindex font positions
3193 @cindex positions, font
3196 For the sake of old phototypesetters and compatability with old
3197 versions of troff, groff has the concept of font
3198 @dfn{positions}, on which various fonts are mounted.
3199 The last one or two are reserved for the symbol font(s).
3201 @findex fp
3202 New fonts can be mounted with the @code{fp} request.
3203 These numeric positions can then be referred to with font changing commands.
3204 When groff starts it is using font number one.
3206 @example
3207 .fp 1 H
3208 .fp 2 HI
3209 .fp 3 HB
3210 wink, wink,
3211 .ft 2
3212 nudge, nudge,
3214 .ft 3
3215 say no more!
3217 @end example
3219 (note that after these font changes have taken place the original
3220 font is restored.)
3222 @vindex .f
3223 The current font in use, as a font position.
3224 This can be useful to remember the current font, for later recall.
3226 @example
3227 .nr save-font \n(.f
3228 ... lots 'o text ...
3229 .ft \n[save-font]
3230 @end example
3232 @vindex .fp
3233 The number of the next free font position is available in the number
3234 register @code{.fp}.  This is useful when mounting a new font, like so:
3236 @example
3237 .fp \n[.fp] NEATOFONT
3238 @end example
3240 @pindex DESC
3241 Fonts not listed in the @file{DESC} file are automatically mounted on
3242 the next available font position when they are referenced.
3243 If a font is to be
3244 mountfed explicitly with the @code{fp} request on an unused font position, it
3245 should be mounted on the first unused font position, which can be found
3246 in the @code{.fp} register; although troff does not enforce this strictly,
3247 it will not allow a font to be mounted at a position whose number is
3248 much greater than that of any currently used position.
3250 The @code{fp} request has an optional third argument.
3251 This argument gives the
3252 external name of the font, which is used for finding the font
3253 description file.  The second argument gives the internal name of the
3254 font which is used to refer to the font in troff after it has been
3255 mounted.  If there is no third argument then the internal name will be
3256 used as the external name.  This feature allows you to use fonts with
3257 long names in compatibility mode.
3261 @node Using Symbols, Artificial Fonts, Font Positions, Fonts
3262 @subsection Using Symbols
3263 @cindex using symbols
3264 @cindex symbols, using
3267 @findex \(
3268 @findex \[
3269 Symbols can be inserted by using a special escape sequence.
3270 This escape is simply the escape character (a backslash) followed by
3271 an identifier.  The symbol identifiers have to be two or more
3272 characters, since single characters conflict with all the other
3273 escapes.  The identifier can be either preceded by a parenthesis if
3274 it is two character, or surrounded by square brackets.
3275 So, the symbol for pi can be produced either by @code{\(*p} or
3276 @code{\[*p]}.
3278 @example
3279 area = \(*p\fIr\fP\u2\d
3280 @end example
3282 @findex \C
3283 The escape @code{\C'@var{xxx}'} will typeset character named
3284 @var{xxx}.  Normally it is more convenient to use @code{\[@var{xxx}]}.
3285 But @code{\C} has the advantage that it is compatible with recent
3286 versions of ditroff and is available in compatibility mode.
3288 @findex \N
3289 The escape @code{\N'@var{n}'} will typeset the character with code
3290 @var{n} in the current font.  @var{n} can be any integer.  Most devices only
3291 have characters with codes between 0 and 255.  If the current font
3292 does not contain a character with that code, special fonts will not be
3293 searched.  The @code{\N} escape sequence can be conveniently used on
3294 conjunction with the @code{char} request:
3296 @example
3297 .char \[phone] \f(ZD\N'37'
3298 @end example
3300 The code of each character is given in the fourth column in the font
3301 description file after the charset command.  It is possible to include
3302 unnamed characters in the font description file by using a name of
3303 @samp{---}; the @code{\N} escape sequence is the only way to use these.
3305 @findex cflags
3306 Each character has certain properties associated with it.
3307 These properties can be modified with the @code{cflags} request.
3308 The first argument is the the sum of the desired flags and the
3309 remaining arguments are the characters to have those properties.
3310 @table @code
3311 @item 1
3312 the character ends sentences (initially characters @samp{.?!} have this
3313 property);
3314 @item 2
3315 lines can be broken before the character (initially no characters have
3316 this property);
3317 @item 4
3318 lines can be broken after the character (initially characters
3319 @samp{-\(hy\(em} have this property);
3320 @item 8
3321 the character overlaps horizontally (initially characters
3322 @samp{\(ul\(rn\(ru} have this property);
3323 @item 16
3324 the character overlaps vertically (initially character @samp{\(br} has
3325 this property);
3326 @item 32
3327 an end of sentence character followed by any number of characters with
3328 this property will be treated as the end of a sentence if followed by a
3329 newline or two spaces; in other words the character is transparent for
3330 the purposes of end of sentence recognition; this is the same as having
3331 a zero space factor in @TeX{} (initially characters
3332 @samp{"')]*\(dg\(rq} have this property).
3333 @end table
3335 @findex char
3336 You can create new characters with the @code{char} request.  It is
3337 called as @samp{.char @var{c} @var{string}} Define character @var{c}
3338 to be @var{string}. Every time character @var{c} needs to be printed,
3339 @var{string} will be processed in a temporary environment and the
3340 result will be wrapped up into a single object.  Compatibility mode
3341 will be turned off and the escape character will be set to \ while
3342 @var{string} is being processed.  Any emboldening, constant spacing or
3343 track kerning will be applied to this object rather than to individual
3344 characters in @var{string}.  A character defined by this request can
3345 be used just like a normal character provided by the output device.
3346 In particular other characters can be translated to it with the
3347 @code{tr} request; it can be made the leader character by the
3348 @code{lc} request; repeated patterns can be drawn with the character
3349 using the @code{\l} and @code{\L} escape sequences;  words containing
3350 the character can be hyphenated correctly, if the @code{hcode} request
3351 is used to give the character a hyphenation code. There is a special
3352 anti-recursion feature: use of character within the character's
3353 definition will be handled like normal characters not defined with
3354 @code{char}.
3356 @findex rchar
3357 A character definition can be removed with the @code{rchar} request.  Its
3358 arguments are the characters to be removed.  This undoes the effect of
3359 a @code{char} request.
3361 @c distribute these through the text
3362 @xref{Special Characters}
3364 @node Artificial Fonts, Ligatures and Kerning, Using Symbols, Fonts
3365 @subsection Artificial Fonts
3366 @cindex artificial fonts
3367 @cindex fonts, artificial
3370 There are a number of requests for artificially creating fonts.
3371 These are largely vestigal remains from the days when output devices
3372 did not have a wide variety of fonts, and when nroff and troff were
3373 separate programs.
3374 These are no longer necessary in GNU Troff.
3376 @findex ul
3377 The @code{ul} request will print subsequent lines in italics on a
3378 device capable of it, or underline the text on an ascii output device.
3379 The single argument is the number of lines to be ``underlined,''
3380 with no argument, the next line will be underlined.
3382 @findex cu
3383 The @code{cu} request is similar to @code{ul} ...
3385 @findex uf
3386 The @code{uf} request will set the underline font used by @code{ul}
3387 and @code{cu}.
3389 @findex bd
3390 The @code{bd} request artificially creates a bold font by printing
3391 each character twice, slightly offset.
3392 The first argument specifies the font to embolden, and the second is
3393 the number of basic units, minus one, by which the two characters
3394 will be offset.  If the second argument is missing, emboldening will
3395 be turned off.
3398 @node Ligatures and Kerning,  , Artificial Fonts, Fonts
3399 @subsection Ligatures and Kerning
3400 @cindex ligatures and kerning
3401 @cindex kerning and ligatures
3404 @findex lg
3405 @vindex .lg
3406 @code{lg}
3407 @code{.lg}
3408 The current ligature mode.
3410 What is kerning??
3412 If the font description file contains pairwise kerning information,
3413 characters from that font will be kerned.  Kerning between two
3414 characters can be inhibited by placing a @code{\&} between them.
3416 @findex kern
3417 @vindex .kern
3418 @code{kern}
3419 If n is non-zero or missing, enable pairwise kerning, otherwise disable
3421 @code{.kern}
3422 1 if pairwise kerning is enabled, 0 otherwise.
3424 @findex tkf
3425 .tkf f s1 n1 s2 n2
3426 Enable track kerning for font f.  When the current font is f the width
3427 of every character will be increased by an amount between n1 and n2;
3428 when the current point size is less than or equal to s1 the width will
3429 be increased by n1; when it is greater than or equal to s2 the width
3430 will be increased by n2; when the point size is greater than or equal to
3431 s1 and less than or equal to s2 the increase in width is a linear
3432 function of the point size.
3435 @node Sizes, Strings, Fonts, Programming Tutorial
3436 @section Sizes
3437 @cindex sizes
3440 @cindex baseline
3441 Groff uses two dimensions with each line of text, type size and
3442 vertical spacing.  The type size is the height from the text
3443 @dfn{baseline} to the top of the tallest character (decenders may drop
3444 below this baseline).  Vertical spacing is the amount of space groff
3445 allows for a line of text, normally, this is about 20% larger than the
3446 current type size.  Ratios smaller than this can result in
3447 hard-to-read text, larger that this, it will spread your text out more
3448 vertically (useful for term papers).  By default, troff uses 10 point
3449 type on 12 point spacing.
3451 @cindex leading
3452 The difference between type size and vertical spacing is known, by
3453 typesetters, as @dfn{leading}.
3456 @menu
3457 * Changing Type Sizes::         
3458 * Fractional Type Sizes::       
3459 @end menu
3461 @node Changing Type Sizes, Fractional Type Sizes, Sizes, Sizes
3462 @subsection Changing Type Sizes
3463 @cindex changing type sizes
3464 @cindex type sizes, changing
3467 @findex ps
3468 @findex vs
3469 @findex \s
3470 @vindex .s
3471 @vindex .v
3472 Using the @code{ps} request and the @code{\s} escape you can change
3473 the type size.  The @code{vs} request will change the vertical
3474 spacing. The default unit for the @code{ps} and @code{vs} requests are
3475 points.
3476 The number registers @code{.s} and @code{.v} contain the current
3477 type size and vertical spacing.
3479 These requests take parameters in units of points.  You can specify
3480 sizes as an absolute size, or as a relative change from the current
3481 size.  The size 0 means go back to the previous size.  With no
3482 argument it will revert to the previous size.
3484 @example
3485 snap, snap,
3486 .ps +2
3487 grin, grin,
3488 .ps +2
3489 wink, wink, \s+2nudge, nudge,\s+8 say no more!
3490 .ps 10
3491 @end example
3493 The @code{\s} escape may be called in a variety of ways.
3494 Much like other escapes there must be a way to determine where the
3495 argument ends and the text begins.
3496 Any of the following forms are valid:
3497 @code{\s@var{n}},
3498 @code{\s+@var{n}},
3499 @code{\s-@var{n}},
3500 @code{\s(@var{nn}},
3501 @code{\s+(@var{nn}},
3502 @code{\s-(@var{nn}},
3503 @code{\s[+@var{nnn}]},
3504 @code{\s[-@var{nnn}]},
3505 @code{\s+[@var{nnn}]},
3506 @code{\s-[@var{nnn}]}.
3508 Some devices may only have certain permissible sizes, in which case
3509 groff will round to the nearest permissible size.
3511 @example
3512 ... .sz macro example?? ...
3513 @end example
3515 @node Fractional Type Sizes,  , Changing Type Sizes, Sizes
3516 @subsection Fractional Type Sizes
3517 @cindex fractional type sizes
3518 @cindex type sizes, fractional
3521 A @dfn{scaled point} is equal to 1/@var{sizescale} points, where
3522 @var{sizescale} is specified in the @file{DESC} file (1 by default.)
3523 There is a new scale indicator @samp{z} which has the effect of
3524 multiplying by @var{sizescale}.  Requests and escape sequences in
3525 troff interpret arguments that represent a pointsize as being in units
3526 of scaled points, but they evaluate each such argument using a default
3527 scale indicator of @samp{z}.  Arguments treated in this way are the
3528 argument to the @code{ps} request, the third argument to the @code{cs}
3529 request, the second and fourth arguments to the @code{tkf} request,
3530 the argument to the @code{\H} escape sequence, and those variants of
3531 the @code{\s} escape sequence that take a numeric expression as their
3532 argument.
3534 For example, suppose @var{sizescale} is 1000; then a scaled point will be
3535 equivalent to a millipoint; the request @samp{.ps 10.25} is equivalent to
3536 @samp{.ps 10.25z} and so sets the pointsize to 10250 scaled points, which is
3537 equal to 10.25 points.
3539 The number register @code{\n(.s} returns the pointsize in points as
3540 decimal fraction.  There is also a new number register @code{\n[.ps]}
3541 that returns the pointsize in scaled points.
3543 It would make no sense to use the @samp{z} scale indicator in a
3544 numeric expression whose default scale indicator was neither @samp{u}
3545 nor @samp{z}, and so troff disallows this.  Similarily it would make
3546 no sense to use a scaling indicator other than @samp{z} or @samp{u} in a
3547 numeric expression whose default scale indicator was @samp{z}, and so
3548 troff disallows this as well.
3550 There is also new scale indicator @samp{s} which multiplies by the
3551 number of units in a scaled point.  So, for example, @samp{\n[.ps]s}
3552 is equal to 1m.  Be sure not to confuse the @samp{s} and @samp{z}
3553 scale indicators.
3555 @code{\s'+@var{n}'}
3556 @code{\s'-@var{n}'}
3557 @code{\s+'@var{n}'}
3558 @code{\s-'@var{n}'}
3559 Set the point size to @var{n} scaled points; @var{n} is a numeric
3560 expression with a default scale indicator of @samp{z}.
3562 @code{\n[.ps]}
3563 The current pointsize in scaled points.
3565 @code{\n[.psr]}
3566 The last-requested pointsize in scaled points.
3568 @code{\n[.sr]}
3569 The last requested pointsize in points as a decimal fraction.  This is a
3570 string-valued register.
3573 @c distribute these through the text
3574 @xref{Font Files}
3576 @node Strings, Conditionals and Loops, Sizes, Programming Tutorial
3577 @section Strings
3578 @cindex strings
3581 @findex ds
3582 Groff has string variables, which are entirely for user convenience
3583 (i.e. there are no builtin strings).  They are defined via the
3584 @code{ds} request.
3586 @example
3587 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d
3588 @end example
3590 @findex \*
3591 They are interpolated, or expanded in-place, via the @code{\*} escape:
3593 @example
3594 The \*(UX Operating System
3595 @end example
3597 Will produce:
3599 @example
3600 The UNIXtm Operating System
3601 @end example
3603 If the string named by the @code{\*} does not exist, the escape will
3604 be replaced by nothing.
3606 @cindex comments, with @code{ds}
3607 NOTE:  Unlike other requests the third argument takes up the entire
3608 line including trailing spaces.  This means that comments on a line
3609 with such a request can introduce unwanted space into a string.
3611 @example
3612 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d \" trademark of you-know-who
3613 @end example
3615 Instead you should either put the comment on another line or
3616 have the comment escape adjacent with the end of the string.
3618 @example
3619 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d\"  trademark of you-know-who
3620 @end example
3622 If you need leading space you can start the string with a double
3623 quote.  No trailing quote is needed, in fact any trailing quote is
3624 included in your string.
3626 @cindex canibalism
3627 @example
3628 .ds sign "           Yours in a white wine sauce,
3629 @end example
3631 @findex as
3632 @cindex appending to strings
3633 @cindex strings, appending
3634 You can also append onto a string with the @code{as} request.
3635 It works the same as the @code{ds} request except that it appends the
3636 second argument onto the string named by the first argument.
3638 @example
3639 .as sign " with shallots, onions and garlic,
3640 @end example
3642 @findex \@key{ret}
3643 Strings are not limited to a sigle line of text.  A string can span
3644 several lines by escaping the newlines with a backslash.  The
3645 resulting string will be stored @emph{without} the newlines.
3647 @example
3648 .ds foo lots and lots \
3649 of text are on these \
3650 next several lines
3651 @end example
3653 @findex substring
3654 @cindex substrings
3655 @code{.substring xx n1 [n2]}
3656 Replace the string in register@w{ }xx with the substring defined by the
3657 indices n1 and@w{ }n2.  The first character in the string has index one.
3658 If n2 is omitted, it is taken to be equal to the string's length.  If
3659 the index value n1 or n2 is negative or zero, it will be counted from
3660 the end of the string, going backwards: The last character has index@w{
3661 }0, the character before the last character has index@w{ }-1, etc.
3663 @findex length
3664 @cindex length of a string
3665 @cindex string, length of
3666 @code{.length xx string}
3667 Compute the length of string and return it in the number register@w{ }xx
3668 (which is not necessarily defined before).
3670 @findex rn
3671 @code{rn}
3673 @findex rm
3674 @code{rm}
3676 @findex als
3677 @code{als}
3679 @findex chop
3680 @code{chop}
3682 @c distribute these through the text
3683 @xref{Identifiers}
3684 @c distribute these through the text
3685 @xref{Comments}
3687 @node Conditionals and Loops, Writing Macros, Strings, Programming Tutorial
3688 @section Conditionals and Loops
3689 @cindex conditionals and loops
3690 @cindex loops and conditionals
3693 @findex if
3694 @findex while
3695 In @code{if} and @code{while} requests, there are several more operators
3696 available:
3698 @table @code
3699 @item e
3700 @itemx o
3701 True if the current page is even or odd numbered (respectively)
3702 @item n
3703 @itemx t
3704 True if the document is being processed by
3705 nroff (or an ascii device) or troff.
3706 @item '@var{xxx}'@var{yyy}'
3707 True if the string @var{xxx} is equal to the string @var{yyy}.
3708 Other characters can be used in place of the single quotes.
3709 (Which?)
3710 The strings are `formatted' before being compared. (?)
3711 @item r@var{xxx}
3712 True if there is a number register named @var{xxx}.
3713 @item d@var{xxx}
3714 True if there is a string, macro, diversion, or request named @var{xxx}.
3715 @item c@var{ch}
3716 True if there is a character @var{ch} available;  @var{ch} is
3717 either an ASCII character or a special character @code{\(@var{ch}} or
3718 @code{\[@var{ch}]}; the condition will also be true if @var{ch} has been
3719 defined by the @code{char} request.
3720 @end table
3723 @menu
3724 * if-else::                     
3725 * while::                       
3726 @end menu
3728 @node if-else, while, Conditionals and Loops, Conditionals and Loops
3729 @subsection if-else
3730 @cindex if-else
3733 Troff has if-then-else constructs like other languages, although
3734 the formatting can be painful.
3736 @findex if
3737 The @code{if} request is troff's if statement, it is called as
3738 @samp{.if @var{expr} @var{anything}}, where @var{expr} is the
3739 expression to be evaluated,
3740 and @var{anything} (the remainder of the line)
3741 which will be executed if
3742 the @var{expr} evaluates to non-zero (true).
3743 @var{anything} will be interpreted as though it was on a line by
3744 itself.
3745 @xref{Expressions}, for more info.
3747 Here are some examples:
3749 @example
3750 .if t .ls 2                             \" double spacing in troff
3751 .if 0 .ab how'd this happen??
3752 @end example
3754 @findex ie
3755 @findex el
3756 An if-then-else is written using two requests @code{ie} and @code{el}
3757 the first request is the if part and the latter is the else part.
3759 @example
3762 @end example
3764 @findex \@{
3765 @findex \@}
3766 In many cases you will want more than one request to be executed as a
3767 result of any of these requests, this can be done using the \@{ and
3768 \@} escapes.
3769 The following example shows the possible ways to use these escapes.
3771 @example
3772 .ie t \@{\
3773 .    ds lq ``
3774 .    ds rq ''
3775 .\@}
3776 .el \
3777 .\@{\
3778 .    ds lq "
3779 .    ds rq "\@}
3780 .ds qq "
3781 @end example
3784 @c distribute these through the text
3785 @xref{Expressions}
3787 @node while,  , if-else, Conditionals and Loops
3788 @subsection while
3789 @cindex while
3792 @findex while
3793 Groff provides a looping construct using the @code{while} request,
3794 which is used much like the @code{if} (and related) requests.
3795 The first argument is an expression which will be evaluated.
3796 The @code{while} request will interpret the remainder of the line
3797 until the expression evaluates to 0 or false.
3799 @example
3800 .nr a 0 1
3801 .while (\na<9) \&\n+a,
3802 \&\n+a
3803 @end example
3805 The preceding example produces:
3807 @example
3808 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
3809 @end example
3811 @findex break
3812 @findex continue
3813 The @code{break} request will
3814 @dfn{break} out of a while loop.
3815 Be sure not to confuse this with the @code{.br} request.
3816 The @code{continue} request will
3817 finish the current iteration of a while loop.
3819 @c distribute these through the text
3820 @xref{Expressions}
3822 @node Writing Macros, Page Motions, Conditionals and Loops, Programming Tutorial
3823 @section Writing Macros
3824 @cindex writing macros
3825 @cindex macros, writing
3828 @findex de
3829 A macro is a collection of text and embedded commands which can be
3830 invoked multiple times.  Macros are used for defining common operations.
3831 Macros are defined using the @code{de} request.  This request takes
3832 a name for the macro as the first argument.  Subsequent lines are
3833 copied into an internal buffer until the line @code{..} is
3834 encountered.  The optional second argument to @code{de} can change
3835 this ending token.
3837 For example, suppose at the beginning of each paragraph, you want
3838 cause a break, move down a partial line and indent the first line.
3839 Such a macro could be defined as follows:
3841 @example
3842 .de P
3844 .sp .8v
3846 @end example
3848 @findex am
3849 The @code{am} request works similarily to @code{de} except it appends
3850 onto the macro named by the first argument.  So, if we decide we want
3851 our previously @code{P} macro to actually do indented instead of
3852 block paragraphs we can add the necessary code to our existing macro.
3854 @example
3855 .am P
3856 .ti +5n
3858 @end example
3860 @findex als
3861 @cindex aliases, macro
3862 @cindex macro aliases
3863 Macros can be aliased with the @code{als} request.
3865 @findex rn
3866 @code{rn}
3868 @findex rm
3869 @code{rm}
3871 @findex chop
3872 @code{chop}
3875 @menu
3876 * Copy-in Mode::                
3877 * Parameters::                  
3878 @end menu
3880 @node Copy-in Mode, Parameters, Writing Macros, Writing Macros
3881 @subsection Copy-in Mode
3882 @cindex copy-in mode
3883 @cindex mode, copy-in
3886 @findex \n
3887 @findex \$
3888 @findex \*
3889 @findex \\
3890 @findex \@key{RET}
3891 When troff reads in the test for a macro or diversion it copies the
3892 text (including request lines) into an internal buffer, except for
3893 escapes.  Escapes will be converted into an internal form, except for
3894 @code{\n}, @code{\$}, @code{\*}, @code{\\} and @code{\@key{RET}} which
3895 are evaluated and inserted into the text where the escape was located.
3896 This is known as @dfn{copy-in} mode.
3898 What this means is that you can specify when these escapes are to be
3899 evaluated (copy-in time or time of use) by insulating the escapes
3900 with an extra backslash.
3902 For example, the following will result in the numbers 20 and 10 being
3903 printed.
3905 @example
3906 .nr x 20
3907 .de y
3908 .nr x 10
3909 \&\nx
3910 \&\\nx
3913 @end example
3917 @node Parameters,  , Copy-in Mode, Writing Macros
3918 @subsection Parameters
3919 @cindex parameters
3922 @findex \$
3923 @vindex .$
3924 The arguments to a macro can be examined using a variety of escapes.
3925 The number of arguments is available in the @code{.$} number register.
3926 Any individual argument can be retrieved with one of the following
3927 escapes:
3929 The escapes @code{\$@var{n}}, @code{\$(@var{nn}}
3930 and @code{\$[@var{nnn}]}
3931 will result in the @var{n}th, @var{nn}th or @var{nnn}th
3932 argument.  Macros can have a unlimited number of arguments.
3933 Note that due to copy-in mode, you will want to have two backslashes
3934 on these in actual use, since you do not want them interpolated until
3935 the macro is actually invoked.
3937 @findex shift
3938 The request @code{shift} will shift the arguments 1 position, or as
3939 many positions as specified by the first argument.
3940 After executing this request, argument
3941 @var{i} will become argument @var{i}-@var{n}; arguments 1 to @var{n}
3942 will no longer be available.
3943 Shifting by negative amounts is currently undefined.
3945 @findex \$*
3946 @findex \$@@
3947 In some cases you will want to just use all of the arguments at once.
3948 For example if you pass the arguments along to another macro.
3949 The @code{\$*} escape is
3950 the concatenation of all the arguments separated by spaces.
3951 A similar escape is @code{\$@@},
3952 which is
3953 the concatenation of all the arguments with each surrounded
3954 by double quotes, and separated by spaces.
3956 @findex \$0
3957 @findex als
3958 The @code{\$0} escape is 
3959 the name by which the current macro was invoked.  The @code{als}
3960 request can make a macro have more than one name.
3962 @example
3963 .de vl
3964 .ie \\n(.$=1 .ds Vl Pre-Release Version
3965 .el          .ds Vl Version \\$3, \\$4.
3967 @end example
3969 This would be called as
3971 @example
3972 .vl $Id$
3973 @end example
3976 @c distribute these through the text
3977 @xref{Request Arguments}
3979 @node Page Motions, Drawing Functions, Writing Macros, Programming Tutorial
3980 @section Page Motions
3981 @cindex page motions
3982 @cindex motions, page
3985 @findex sp
3986 Motions up and down the page can be done with the @code{sp} request.
3987 However, this causes a break so that the actual effect is to move to
3988 the left margin and then to the specified location.
3990 @findex mk
3991 @findex rt
3992 The request @code{mk} can be used to mark a location on a page, for
3993 movement to later.  This request takes a register name as an
3994 argument in which to store the current page location, with no
3995 argument it will store the location in an internal register.
3996 The results of this can be used later by the @code{rt} or the
3997 @code{sp} request.  The @code{rt} request will return
3998 @strong{upwards} to the location given in the register name given as
3999 an argument, with no argument it will return to the location marked
4000 with the @code{mk} request
4002 @example
4003 ... dual column example ...
4004 @end example
4006 There are escapes which will give you much finer control of movements
4007 about the page.
4009 @findex \v
4010 The @code{\v'@var{e}'} will let you do arbitrary vertical motion from
4011 the current location on the page.  The argument @var{e} specifies the
4012 distance to move, positive is downwards and negative upwards.  The
4013 default unit for this escape is vertical spaces, @code{v}'s.  Beware,
4014 however, that troff will leave text processing to continue wherever
4015 the motion ends, so if you don't want to interfere with text
4016 processing, make sure your motions are balanced.
4018 There are some special case escapes for vertical motion.
4020 @ftable @code
4021 @item \r
4022 move upwards 1v.
4023 @item \u
4024 move upwards .5v.
4025 @item \d
4026 move down .5v.
4027 @end ftable
4029 @findex \h
4030 Horizontal motions can be done via the @code{\h'@var{e}'} escape.
4031 The expression @var{e} indicates how far to move: positive is
4032 rightwards and negative leftwards.
4034 There are a number of special case escapes for horizontal motion:
4036 @ftable @code
4037 @item \@key{SP}
4038 An unbreakable and unpadable (i.e. not expanded during filling) space.
4039 (Note: it is a backslash followed by a space.)
4040 @item \~
4041 This produces an unbreakable space that stretches like a normal
4042 interword space when a line is adjusted.
4043 @item \|
4044 a 1/6th em space.
4045 @item \^
4046 a 1/12th em space.
4047 @item \0
4048 a space the size of a digit.
4049 @item \&
4050 A zero width space.
4051 @item \)
4052 Like @code{\&} except that it behaves like a character declared with
4053 the @code{cflags} request to be transparent for the purposes of end
4054 of sentence recognition.
4055 @end ftable
4057 @example
4058 ... tex logo example ...
4059 @end example
4061 @findex \w
4062 @cindex width escape
4063 @cindex escape, width
4064 Often you will want to do horizontal movement based on the width of
4065 some arbitrary text (e.g. given as an argument to a macro).
4066 For that, there is the escape @code{\w'@var{text}'} which will
4067 interpolate to the width of the given @var{text} in basic units.
4069 @example
4070 ... strlen example ...
4071 @end example
4073 Font changes may occur in @var{text} and not affect current settings.
4075 Also after use, @code{\w} sets several registers:
4077 @table @code
4078 @item st
4079 @vindex st
4080 @itemx sb
4081 @vindex sb
4082 The highest and lowest point, respectively, in @var{text}.
4083 @item rst
4084 @vindex rst
4085 @itemx rsb
4086 @vindex rsb
4087 Like the @code{st} and @code{sb} registers, but takes account of the
4088 heights and depths of characters.
4089 @item ct
4090 @vindex ct
4091 is set according to what kinds of characters occur in @var{text}.
4092 @table @asis
4093 @item 0
4094 all short characters, no decenders or tall characters.
4095 @item 1
4096 decender
4097 @item 2
4098 tall character
4099 @item 3
4100 both a decender and a tall character
4101 @end table
4102 @item ssc
4103 @vindex ssc
4104 The amount of horizontal space (possibly negative) that should be
4105 added to the last character before a subscript.
4106 @item skw
4107 @vindex skw
4108 How far to right of the center of the last character in the @code{\w}
4109 argument, the center of an accent from a roman font should  be
4110 placed over that character.
4111 @end table
4113 @findex \k
4114 @vindex .k
4115 @code{\k}
4116 @code{.k}
4118 @node Drawing Functions, Traps, Page Motions, Programming Tutorial
4119 @section Drawing Functions
4120 @cindex drawing functions
4121 @cindex functions for drawing
4124 Groff provides a number of ways to draw lines, and other figures on
4125 the page.  Used in combination with the page motion commands
4126 (@pxref{Page Motions}, for more info) you can draw a wide variety of
4127 figures.  However, for complex drawings these operations can be quite
4128 cumbersome, and it may be wise to use the pic preprocessor.
4129 @xref{gpic}, for more information.
4131 All drawing is done via escapes.
4133 @findex \l
4134 The @code{\l} will draw a line rightwards from the current location.
4135 The full syntax for this escape is @samp{\l'@var{l}@var{c}'}, where
4136 @var{l} is the length of the line to be drawn, starting at the
4137 current location, positive numbers will draw to the right, and
4138 negative will draw towards the left.  This can also be specified
4139 absolutely (i.e. with a leading |) which will draw back to the
4140 begining of the line.
4142 The optional second parameter @var{c} is a character to draw the line
4143 with.  If this second argument is not specified, troff will use the
4144 underscore character.
4146 If you need to separate the two arguments (to prevent troff from
4147 interpreting a drawing character as a scaling indicator), you can
4148 separate them with @code{\&}.
4150 And now, for a useful example:
4152 @example
4153 .de box
4154 \(br\\$*\(br\l'|0\(rn'\l'|0\(ul'
4156 @end example
4158 Note that this works by outputing a box rule (a vertical line), then
4159 the text given as an argument and then another box rule.
4160 Then the line drawing escapes both draw from the current location to
4161 the beginning of the @emph{input} line.
4163 @findex \L
4164 Vertical lines are drawn using the @code{\L} escape.  It's parameters
4165 are specified the same as the @code{\l} escape.  If the length is
4166 positive, the movement will be downwards, and upwards for negative.
4167 The default character is the box rule character.
4168 As with the vertical motion escapes, text processing will blindly
4169 continue where the line ends.
4171 @example
4172 ...box macro...
4173 @end example
4175 @findex \D
4176 More flexible drawing functions are available via the @code{\D}
4177 escape.  While the previous escapes will work on an ascii device,
4178 these escapes will not.
4180 @table @code
4181 @item \D'l @var{x} @var{y}'
4182 Draw a line from the current location to the relative point specified
4183 by @var{x}, @var{y}.
4185 @example
4186 ...revised box macro...
4187 @end example
4189 @item \D'c @var{d}'
4190 Draw a circle with a diameter of @var{d} with the leftmost point at
4191 the current position.
4192 @item \D'C @var{d}'
4193 Draw a solid circle with the same parameters as an outlined circle.
4194 @item \D'e @var{dx} @var{dy}'
4195 Draw an ellipse with a horizontal diameter of @var{dx} and a vertical
4196 diameter of @var{dy} with the leftmost point at the current position.
4197 @item \D'E @var{dx} @var{dy}'
4198 Draw a solid elipse with the same parameters as an outlined elipse.
4199 @item \D'a @var{dx1} @var{dy1} @var{dx2} @var{dy2}'
4200 Draw an arc clockwise from the current location through the two
4201 specified locations.
4202 @item \D'~ @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
4203 Draw a spline from the current location to
4204 @var{dx1}, @var{dy1} and then to @var{dx2}, @var{dy2}, and so on.
4205 @item \D'f @var{n}'
4206 Set the shade of gray to be used for filling solid objects to @var{n};
4207 @var{n} must be an integer between 0 and 1000, where 0 corresponds
4208 solid white and 1000 to solid black, and values in between correspond
4209 to intermediate shades of gray.  This applies only to solid circles,
4210 solid ellipses and solid polygons.  By default, a level of 1000 will
4211 be used.
4212 @item  \D'p @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
4213 Draw a polygon from the current location to @var{dx1}, @var{dy1}
4214 and then to @var{dx2}, @var{dy2} and so on.  When the specified data
4215 points are exhausted, a line is drawn back to the starting point.
4217 @example
4218 ... box example (yes, again)...
4219 @end example
4221 @itemx \D'P @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
4222 Draw a solid polygon with the same parameters as an outlined polygon.
4224 @example
4225 ... shaded box example ...
4226 @end example
4228 @item \D't @var{n}'
4229 Set the current line thickness to @var{n} machine units.
4230 A value of zero selects the smallest available line thickness.
4232 @end table
4234 Current position
4236 @findex \b
4237 @cindex pile, character
4238 @cindex character pile
4239 The @code{\b} escape will @dfn{pile} a sequence of characters
4240 vertically, and center it vertically on the current line.
4241 This can be used to build large brackets and braces.
4243 @example
4244 \b'\(lt\(bv\(lk\(bv\(lb'
4245 @end example
4250 @node Traps, Diversions, Drawing Functions, Programming Tutorial
4251 @section Traps
4252 @cindex traps
4255 Traps are locations, which, when reached, will call a specified macro.
4256 These traps can occur at a given location on the page, at a given
4257 location in the current diversion, after a certain number of input
4258 lines or at the end of input.
4260 @findex ch
4261 Any of these traps can be changed after they have been set with the
4262 @code{ch} request.  The first arguemnt is the name of the trap or
4263 macro, and the second is the new value for that trap.
4266 @menu
4267 * Page Location Traps::         
4268 * Diversion Traps::             
4269 * Input Line Traps::            
4270 * End-of-input Traps::          
4271 @end menu
4273 @node Page Location Traps, Diversion Traps, Traps, Traps
4274 @subsection Page Location Traps
4275 @cindex page location traps
4276 @cindex traps, page location
4279 Page location traps are frequently used for page headers and
4280 footers.  The following is a simple example of this.
4282 @example
4283 .de hd                          \" Page header
4284 'sp .5i
4285 .tl 'Title''date'
4286 'sp .3i
4288 .de fo                          \" Page footer
4289 'sp 1v
4290 .tl ''%''
4293 .wh 0   hd                      \" top of the page
4294 .wh -1i fo                      \" one inch from bottom
4295 @end example
4297 @vindex .t
4298 The number register @code{.t} is the distance to the next trap.
4300 @findex ch
4301 The location of a trap can be changed later on with the @code{ch}
4302 request.
4303 The first argument is the name of the macro to be invoked at the trap
4304 and the second argument is the new location for the trap.
4305 This is useful when you are building up footnotes in a diversion, and
4306 you need to allow more space at the bottom of the page for them.
4308 @example
4309 ... (simplified) footnote example ...
4310 @end example
4312 @findex vpt
4313 @findex wh
4314 @findex dt
4315 @vindex .vpt
4316 The @code{vpt} request will enable vertical position traps if the argment is
4317 non-zero, disable them otherwise.  Vertical position traps are traps
4318 set by the @code{wh} or @code{dt} requests.  Traps set by the
4319 @code{it} request are not vertical position traps.  The parameter that
4320 controls whether vertical position traps are enabled is global.
4321 Initially vertical position traps are enabled.  The current setting of
4322 this is available in the number register @code{.vpt}.
4324 @vindex .trunc
4325 @findex ne
4326 The number register @code{.trunc} contains
4327 the amount of vertical space truncated by the most recently
4328 sprung vertical position trap, or, if the trap was sprung by a
4329 @code{ne} request, minus the amount of vertical motion produced by
4330 the @code{ne} request.  In other words, at the point a trap is
4331 sprung, it represents the difference of what the vertical position
4332 would have been but for the trap, and what the vertical position
4333 actually is.
4335 @vindex .ne
4336 The number register @code{.ne} contains
4337 the amount of space that was needed in the last @code{ne} request that caused
4338 a trap to be sprung.  Useful in conjunction with the @code{.trunc}
4339 register.  @xref{Page Control}, for more information.
4343 @node Diversion Traps, Input Line Traps, Page Location Traps, Traps
4344 @subsection Diversion Traps
4345 @cindex diversion traps
4346 @cindex traps, diversion
4349 @findex dt
4350 @vindex .t
4351 Traps can also be set @emph{within} a diversion using the @code{dt}
4352 request.  Like @code{wh} the first argument is the location of the
4353 trap and the second argument is the name of the macro to be invoked.
4354 The number register @code{.t} will still work within diversions.
4355 @xref{Diversions}, for more information.
4357 @node Input Line Traps, End-of-input Traps, Diversion Traps, Traps
4358 @subsection Input Line Traps
4359 @cindex input line traps
4360 @cindex traps, input line
4363 @findex it
4364 The @code{it} request will set an input line trap.  The format for
4365 calling this is @samp{.it @var{n} @var{name}}, where @var{n} is the
4366 number of lines of input which may be read before @dfn{springing} the
4367 trap, @var{name} is the macro to be invoked.  Request lines are not
4368 counted as input lines.
4370 For example, one possible use is to have a macro which will print the
4371 next @var{n} lines in a bold font.
4373 @example
4374 .de B
4375 .it B-end \\$1
4376 .ft B
4378 .de B-end
4379 .ft R
4381 @end example
4383 @node End-of-input Traps,  , Input Line Traps, Traps
4384 @subsection End-of-input Traps
4385 @cindex end-of-input traps
4386 @cindex traps, end-of-input
4389 @findex em
4390 The @code{em} request will set a trap at the end of input.
4391 The macro specified as an arguement will be executed after the last
4392 line of the input file has been processed.
4394 For example, if your document had to have a section at the bottom of
4395 the last page for someone to approve you document, you could set it
4396 up with @code{em}.
4398 @example
4399 .de approval
4400 .ne 5v
4401 .sp |(\\n(.t-6v)
4402 .in +4i
4403 .lc _
4405 Approved:\t\a
4407 Date:\t\t\a
4409 .em approval
4410 @end example
4413 @node Diversions, Environments, Traps, Programming Tutorial
4414 @section Diversions
4415 @cindex diversions
4418 In Troff you can divert text into a named storage area, due to the
4419 similarity to defining macros it is sometimes said to be stored in a
4420 macro.  This is used for saving text for output at a later time,
4421 which is useful for keeping blocks of text on the same page,
4422 footnotes, tables of contents and indexes.
4424 @findex di
4425 @findex da
4426 Diversion is initiated by the @code{di} request, like the @code{de}
4427 request it takes an argument of a macro name to divert subsequent
4428 text to into.  The @code{da} macro will append to an existing diversion.
4430 @example
4431 ... end-note example ...
4432 @end example
4434 @vindex .z
4435 @vindex .d
4436 @vindex nl
4437 @vindex .h
4438 Diversions may be nested.
4439 The number register @code{.z} contains the name of the current diversion.
4440 The number register @code{.d} contains the current vertical place in
4441 the diversion.  If not in a diversion it is the same as the register
4442 @code{nl}.
4443 @code{.h}
4445 @vindex dn
4446 @vindex dl
4447 After compleating a diversion, the builtin number registers @code{dn}
4448 and @code{dl} contain the vertical and horizontal size of the diversion.
4450 @example
4451 .\" Center text both horizontally & vertically
4452 .de (c
4455 .di @@c
4457 .de )c
4460 .nr @@s (((\\n(.tu-\\n(dnu)/2u)-1v)
4461 .sp \\n(@@su
4462 .ce 1000
4466 .ce 0
4467 .sp \\n(@@su
4470 .rr @@s
4472 @end example
4474 @findex \!
4475 Requests, macros and escapes are interpreted when read into a
4476 diversion.
4477 There are two ways to prevent this, either way will take the given
4478 text and @dfn{transparently} embed it into the diversion.
4479 The first method is to prefix the line with @code{\!}.  This will
4480 cause the entire line to be transparently inserted into the diversion.
4481 This is useful for macros you do not want invoked until the diverted
4482 text is actually output.
4484 @c anything  is  read  in  copy  mode. (what about \! ??)
4486 @findex \?
4487 The other way is to surround the text by the @code{\?} escape, i.e.
4488 @samp{\?@var{anything}\?}.
4489 @var{anything} may not  contain
4490 newlines; use @code{\!} if you want to embed newlines in a diversion.  The
4491 escape sequence @code{\?} is also recognised in copy mode and turned into a
4492 single internal code; it is this code that terminates anything.  Thus
4493 the followin example will print 4.
4495 @example
4496 .nr x 1
4498 .di d
4499 \?\\?\\\\?\\\\\\\\nx\\\\?\\?\?
4501 .nr x 2
4502 .di e
4505 .nr x 3
4506 .di f
4509 .nr x 4
4511 @end example
4513 @findex rn
4514 @code{rn}
4516 @findex rm
4517 @code{rm}
4519 @findex als
4520 @code{als}
4522 @findex chop
4523 @code{chop}
4525 @findex asciify
4526 @code{asciify}
4527 This request only exists in order to make it possible to make certain
4528 gross hacks work with GNU troff.  It @dfn{unformats} the diversion
4529 specified as an argument in
4530 such a way that ASCII characters that were formatted and diverted
4531 will be treated like ordinary input characters when the diversion is
4532 reread.  For example, the following will set register @code{n} to 1.
4534 @example
4535 .tr  @@.
4536 .di  x
4537 @@nr\  n\  1
4540 .tr  @@@@
4541 .asciify  x
4543 @end example
4546 @c distribute these through the text
4547 @xref{Copy-in Mode}
4549 @node Environments, I/O, Diversions, Programming Tutorial
4550 @section Environments
4551 @cindex environments
4554 Often you will need to print some text in a certain format regardless
4555 of what may be in effect at the time, for example, in a trap invoked
4556 macro to print headers and footers.
4557 To solve this groff has @dfn{environments} in which text is processed.
4558 An environment contains most of the parameters that control
4559 text processing.  You can switch amongst these environments, by
4560 default groff processes text in environment 0.
4561 The following is the information kept in an environment.
4563 @itemize @bullet{}
4564 @item
4565 Type size
4566 @item
4567 Font (family and style)
4568 @item
4569 Page parameters
4570 @item
4571 Fill/adjust mode
4572 @item
4573 Tab stops
4574 @item
4575 Partially collected lines
4576 @end itemize
4578 These environments may be given arbitrary names
4579 (@pxref{Identifiers}, for more info.)
4580 Old versions of troff only had environments named 0, 1 and 2.
4582 @findex ev
4583 @vindex .ev
4584 The @code{ev} request will switch among these environments.
4585 The single argument is the name of the environment to switch to, with
4586 no argument groff will switch back to the previous enviroment.
4587 There is no limit on the number of named environments;
4588 they will be created the first time that they are referenced.
4589 The @code{.ev} number register contains
4590 the name or number of the current environment.  This is a string-valued
4591 register.
4593 @example
4594 ... page break macro, revised ...
4595 @end example
4597 @example
4598 .ev footnote-env
4599 .fam N
4600 .ps 6
4601 .vs 8
4602 .ll -.5i
4605 .ev footnote-env
4606 \(dg Note the large, friendly letters.
4608 @end example
4613 @node I/O, Postprocessor Access, Environments, Programming Tutorial
4614 @section I/O
4615 @cindex i/o
4618 @findex so
4619 The @code{so} request will read in the file given as an argument and
4620 include it in place of the @code{so} request.  This is quite useful
4621 for large documents, i.e. keeping each chapter in a separate file.
4622 @xref{gsoelim}, for more information.
4624 @findex mso
4625 The @code{mso} request is
4626 the same as the @code{so} request except that file is searched for in
4627 the same way that @file{tmac.@var{name}} is searched for when the
4628 @samp{-m@var{name}} option is specified.
4630 @findex cf
4631 @findex trf
4632 The @code{cf} and @code{trf} requests are to include a file.
4633 It will transparently output the contents of file filename.  Each
4634 line is output
4635 as it would be were it preceded by @code{\!}; however, the lines are not
4636 subject to copy-mode interpretation.  If the file does not end with a
4637 newline, then a newline will be added.  For example, you can define a
4638 macro @code{x} containing the contents of file @file{f}, using
4640 @example
4641 .di x
4642 .trf f
4644 @end example
4646 .cf filename
4647 When  used  in  a  diversion, this will embed in the diversion an object
4648 which,  when  reread,  will  cause  the  contents  of  filename  to   be
4649 transparently copied through to the output.  In @sc{Unix} troff, the contents
4650 of filename is immediately copied through to the  output  regardless  of
4651 whether  there  is  a  current diversion; this behaviour is so anomalous
4652 that it must be considered a bug.
4655 With @code{trf}, unlike @code{cf}, the file cannot contain characters
4656 such as NUL that are not legal troff input characters.
4658 @findex nx
4659 The @code{nx} request will force groff to continue processing of the
4660 file specified as an argument.
4662 @findex rd
4663 The @code{rd} request will read from standard input, and include what
4664 is read as though it were part of the input file.  Text is read until
4665 a blank line is encountered.
4667 @cindex form letters
4668 @cindex letters, form
4669 Using these two requests you can set up form letters.
4670 The form letter template is constructed like this:
4672 @example
4674 \*(td
4675 .sp 2
4681 Body of letter.
4683 .nx repeat.let
4684 @end example
4686 @findex ex
4687 When this is run, the following file should be redirected in.
4688 Note that requests included in this file are executed as though they
4689 were part of the form letter.  The last block of input is the
4690 @code{ex} requests which tells groff to stop processing.  If this was
4691 not there, groff would not know when to stop.
4693 @cindex Beagle Brothers
4694 @example
4695 Trent A. Fisher
4696 708 NW 19th Av., #202
4697 Portland, OR  97209
4699 Dear Trent,
4701 Len Adollar
4702 4315 Sierra Vista
4703 San Diego, CA  92103
4705 Dear Mr. Adollar,
4708 @end example
4710 @findex pi
4711 @code{pi}
4713 @findex sy
4714 The @code{sy} request will allow arbitrary system commands to be
4715 executed from within a groff document.  The output is not saved
4716 anyplace, so it is up to you to do so.
4718 For example, the following example will introduce the current time
4719 into your document:
4721 @cindex time
4722 @pindex perl
4723 @example
4724 .sy perl -e 'printf ".nr H %d\\n.nr M %d\\n.nr S %d\\n",\
4725              (localtime(time))[2,1,0]' > /tmp/x\n[$$]
4726 .so /tmp/x\n[$$]
4727 .sy rm /tmp/x\n[$$]
4728 \nH:\nM:\nS
4729 @end example
4731 Note that this works by having the perl script (run by @code{sy})
4732 print out the @code{nr} requests which will set the number registers
4733 @samp{H}, @samp{M} and @samp{S}, and then reads those commands in
4734 with the @code{so} request.
4736 @vindex systat
4737 The @code{systat} number register contains
4738 The return value of the @code{system()} function executed by the last
4739 @code{sy} request.
4741 @findex open
4742 The @code{open} request will open
4743 a file (specified as the second argument) for writing and associate
4744 the stream (specified as the first argument) with it.
4746 @findex opena
4747 The @code{opena} is
4748 like open, but if filename exists, append to it instead of truncating
4751 @findex write
4752 @findex ds
4753 @cindex copy-in mode
4754 @cindex mode, copy-in
4755 The @code{write} request will write to the file associated with the
4756 stream specified by the first argument.  The stream must previously
4757 have been the subject of an open request.  The remainder of the line
4758 in interpreted as the @code{ds} request reads its second argument: a
4759 leading @code{"} will be stripped, and it will be read in copy-in mode.
4761 @findex close
4762 The @code{close} request will
4763 close the stream specified by the first argument; stream will no
4764 longer be an acceptable argument to the @code{write} request.
4766 @example
4767 ... example of open write &c...
4768 @end example
4770 @findex \v
4771 The @code{\V} escape will
4772 interpolate the contents of the specified environment variable, as returned
4773 by getenv(3).
4774 The argument to @code{\V} is specified as an identifier, i.e.
4775 @samp{\V@var{x}}, @samp{\V(@var{xx}} or @samp{\V[@var{xxx}]}.
4776 @code{\V} is interpreted in copy-in mode.
4779 @node Postprocessor Access, Miscellany, I/O, Programming Tutorial
4780 @section Postprocessor Access
4781 @cindex postprocessor access
4782 @cindex access of postprocessor
4785 There are two escapes which will allow you to give information
4786 directly to the postprocessor.  This is particularly useful for
4787 embedding PostScript into your final document.
4789 @findex \X
4790 The @code{\X} escape will embed its argument into the gtroff output
4791 preceded with @samp{x X}.
4793 @findex \Y
4794 The @code{\Y} escape is called with an identifier (i.e.
4795 @code{\Y@var{x}},
4796 @code{\Y(@var{xx}} or
4797 @code{\Y[@var{xxx}]}).
4798 This is approximately equivalent to @samp{\X'\*[@var{xxx}]'}.
4799 However the contents
4800 of the string or macro @var{xxx} are not interpreted; also it is
4801 permitted for
4802 @var{xxx} to have been defined as a macro and thus contain newlines
4803 (it is not permitted for the argument to @code{\X} to contain newlines).
4804 The inclusion of
4805 newlines requires an extetension to the @sc{Unix} troff output format, and will
4806 confuse drivers that do not know about this extension.
4809 @c distribute these through the text
4810 @xref{Devices}
4812 @node Miscellany, Debugging, Postprocessor Access, Programming Tutorial
4813 @section Miscellany
4814 @cindex miscellany
4817 This section contains parts of troff which cannot (yet) be
4818 categorized elsewhere in this manual.
4820 @findex nm
4821 Line numbers can be printed in the left margin
4822 using the @code{nm} request.
4823 The first argument is the line number of the @emph{next} output line,
4824 this defaults to 1.
4825 The second argument indicates on which lines numbers will be printed,
4826 i.e. 5 means put line numbers on every 5 lines, this defaults to 1.
4827 The third argument is the space to be left between the number and
4828 your text, this defaults to 1.
4829 The fourth argument is the indentation of the line numbers.
4830 Without arguments, line numbers are turned off.
4832 @findex nn
4833 The @code{nn} request will temporarily turn off line numbering.
4834 The first argument is the number of lines not to be numbered,
4835 this defaults to 1. (does this disable incrementing or display?)
4837 @example
4838 ... line numbering example ...
4839 @end example
4841 @findex mc
4842 margin characters can be automatically printed to the right of your
4843 text with the @code{mc} request.
4844 The first argument is the character to be printed and the second
4845 argument is the distance away from your text.
4846 With no arguments the margin characters are turned off.
4847 If this occurs before a break, no margin character will be printed.
4849 This is quite useful for indicating text that has changed, and, in
4850 fact, there are programs available for doing this (they are called
4851 @code{nrchbar} and @code{changebar} and can be found in any
4852 @samp{comp.sources.unix} archive.
4854 @example
4855 ... margin char example ...
4856 @end example
4858 @findex lf
4859 @pindex soelim
4860 The @code{lf} primary reason for existence is to make debugging
4861 documents which are split into many files, which are then put
4862 together with @code{soelim} and other preprocessors.
4863 The first argument is the name of the file and the second argument is
4864 the input line number in that file.
4865 This way troff can produce error messages which are intelligible to
4866 the user.
4868 @example
4869 ... example of soelim'ed doc ...
4870 @end example
4872 @node Debugging, Implementation Differences, Miscellany, Programming Tutorial
4873 @section Debugging
4874 @cindex debugging
4877 Troff is not easy to debug, but there are some useful features and
4878 strategies for debugging.
4880 @itemize @bullet{}
4881 @item
4882 @findex tm
4883 The @code{tm} request will send output to stderr, this is very useful for
4884 printing debugging output.
4885 @item
4886 When doing something involved it is useful to leave the debugging
4887 statements in the code and have them turned on by a command line
4888 flag.
4890 @example
4891 .if \n(DB .tm debugging output
4892 @end example
4894 Then you can activate these statements with:
4896 @example
4897 groff -rDB=1 file
4898 @end example
4900 @item
4901 @findex ab
4902 The @code{ab} request is similar to the @code{tm} request,
4903 except that it will cause groff to stop processing.
4904 With no argument it will print @samp{User Abort}.
4905 @item
4906 @findex ex
4907 The @code{ex} request will also cause groff to stop processing.
4908 @item
4909 If you know you are going to get many errors and no useful output,
4910 you can tell groff to suppress formatted output with the @samp{-z}
4911 flag.
4912 @item
4913 @findex pm
4914 The @code{pm} request will dump out the entire symbol table.
4915 @item
4916 @findex pnr
4917 The @code{pnr} request will print the names and contents of all
4918 currently defined number registers on stderr.
4919 @item
4920 @findex ptr
4921 The @code{ptr} request will
4922 print the names and positions of all traps (not including input line
4923 traps and diversion traps) on stderr.  Empty slots in the page trap list
4924 are printed as well, because they can affect the priority of
4925 subsequently planted traps.
4926 @item
4927 @findex fl
4928 The @code{fl} request instructs groff to flush its output immediately.
4929 The intention is that this be used when using troff interactively.
4930 There is little other use for it.
4931 @item
4932 @findex backtrace
4933 The @code{backtrace} request will
4934 print a backtrace of the input stack on stderr.
4935 @item
4936 Groff has command line options for printing out more warnings
4937 (@samp{-w}) and for printing backtraces (@samp{-b}) when a warning or
4938 an error occurs.  The most verbose level of warnings is @samp{-ww}.
4939 @item
4940 @findex warn
4941 @vindex .warn
4942 The @code{warn} request controls the level of warnings checked for.
4943 The one argument is the sum of the numbers associated with each
4944 warning that is to be enabled; all other warnings will be disabled.
4945 The number associated with each warning is listed below.
4946 For example, @code{.warn 0} will disable all warnings, and
4947 @code{.warn 1} will disable
4948 all warnings except that about missing characters.  If an argument
4949 is not given, all warnings will be enabled.
4950 The number register @code{.warn} contains the current warning level.
4951 @end itemize
4953 @subsection Warnings
4954 @cindex warnings
4956 The warnings that can be given by troff are divided into the
4957 following categories.  The name associated with each warning is used
4958 by the @samp{-w} and @samp{-W} options; the number is used by the
4959 @code{warn} request, and by the @code{.warn} register.
4961 @table @samp
4962 @item  char
4963 @itemx 1
4964 Non-existent characters.  This is enabled by default.
4965 @item  number
4966 @itemx 2
4967 Invalid numeric expressions.  This is enabled by default.
4968 @item  break
4969 @itemx 4
4970 In fill mode, lines which could not be broken so that
4971 their length was less than the line length.  This is
4972 enabled by default.
4973 @item  delim
4974 @itemx 8
4975 Missing or mismatched closing delimiters.
4976 @item  el
4977 @itemx 16
4978 Use of the @code{el} request with no matching @code{ie} request.
4979 @xref{if-else}, for more information.
4980 @item  scale
4981 @itemx 32
4982 Meaningless scaling indicators.
4983 @item  range
4984 @itemx 64
4985 Out of range arguments.
4986 @item  syntax
4987 @itemx 128
4988 Dubious syntax in numeric expressions.
4989 @item  di
4990 @itemx 256
4991 @findex di
4992 @findex da
4993 Use of @code{di} or @code{da} without an argument when there is no
4994 current diversion.
4995 @item  mac
4996 @itemx 512
4997 Use of undefined strings, macros and diversions.
4998 When an undefined string, macro or diversion is used,
4999 that string is automatically defined as empty.  So,
5000 in most cases, at most one warning will be given for
5001 each name.
5002 @item  reg
5003 @itemx 1024
5004 Use of undefined number registers.  When an undefined
5005 number register is used, that register is
5006 automatically defined to have a value of 0.  a
5007 definition is automatically made with a value of 0.
5008 So, in most cases, at most one warning will be given
5009 for use of a particular name.
5010 @item  tab
5011 @itemx 2048
5012 Use of a tab character where a number was expected.
5013 @item  right-brace
5014 @itemx 4096
5015 @findex \@}
5016 Use of @code{\@}} where a number was expected.
5017 @item  missing
5018 @itemx 8192
5019 Requests that are missing non-optional arguments.
5020 @item  input
5021 @itemx 16384
5022 Illegal input characters.
5023 @item  escape
5024 @itemx 32768
5025 Unrecognized escape sequences.  When an unrecognized
5026 escape sequence is encountered, the escape character
5027 is ignored.
5028 @item  space
5029 @itemx 65536
5030 Missing space between a request or macro and its
5031 argument.  This warning will be given when  an
5032 undefined name longer than two characters is
5033 encountered, and the first two characters of the name
5034 make a defined name.  The request or macro will not
5035 be invoked. When this warning is given, no macro is
5036 automatically defined.  This is enabled by default.
5037 This warning will never occur in compatibility mode.
5038 @item  font
5039 @itemx 131072
5040 Non-existent fonts. This is enabled by default.
5041 @item all
5042 All warnings except @samp{di}, @samp{mac} and @samp{reg}. It is
5043 intended that this covers
5044 all warnings that are useful with traditional macro packages.
5045 @item w
5046 All warnings.
5047 @end table
5050 @node Implementation Differences, Summary, Debugging, Programming Tutorial
5051 @section Implementation Differences
5052 @cindex implementation differences
5053 @cindex differences in implementation
5056 GNU troff has a number of features which cause incompatibilites with
5057 documents written with old versions of troff.
5059 Long names cause some incompatibilities.  @sc{Unix} troff will interpret
5061 @example
5062 .dsabcd
5063 @end example
5065 @findex \*
5066 @findex \n
5067 @findex cp
5068 @vindex .C
5069 as defining a string @samp{ab} with contents @samp{cd}.
5070 Normally, GNU troff will interpret this as a call of a macro named
5071 @code{dsabcd}.  Also @sc{Unix} troff will interpret @code{\*[} or
5072 @code{\n[} as references to a string or number register called
5073 @samp{[}.  In GNU troff, however, this will normally be interpreted as the
5074 start of a long name.  In compatibility mode GNU troff will interpret
5075 these things in the traditional way.  In compatibility mode, however,
5076 long names are not recognised.  Compatibility mode can be turned on with
5077 the @samp{-C} command line option, and turned on or off with the
5078 @code{cp} request.
5079 The number register @code{.C} is 1 if compatibility mode is on, 0 otherwise.
5081 @findex \A
5082 GNU troff does not allow the use of the escape sequences
5083 @samp{\| \^ \& \@} \@{ \@key{SP} \' \` \- \_ \! \% \c} in names of
5084 strings, macros,
5085 diversions, number registers, fonts or environments; @sc{Unix} troff does.
5086 The @code{\A} escape sequence may be helpful in avoiding use of these escape
5087 sequences in names.
5089 @cindex fractional point sizes
5090 @cindex point sizes, fractional
5091 @findex ps
5092 Fractional pointsizes cause one noteworthy incompatibility.  In @sc{Unix}
5093 troff the @code{ps} request ignores scale indicators and so
5095 @example
5096 .ps 10u
5097 @end example
5099 will set the pointsize to 10 points, whereas in GNU troff it will set
5100 the pointsize to 10 scaled points.
5101 @xref{Fractional Type Sizes}, for more information.
5103 @findex bd
5104 @findex cs
5105 @findex tkf
5106 @findex tr
5107 @findex fp
5108 In GNU troff there is a fundamental difference between unformatted,
5109 input characters, and formatted, output characters.  Everything that
5110 affects how an output character will be output is stored with the
5111 character; once an output character has been constructed it  is
5112 unaffected by any subsequent requests that are executed, including
5113 @code{bd}, @code{cs}, @code{tkf}, @code{tr}, or @code{fp}
5114 requests.  Normally output characters are constructed
5115 from input characters at the moment immediately before the character is
5116 added to the current output line.  Macros, diversions and strings are
5117 all, in fact, the same type of object; they contain lists of input
5118 characters and output characters in any combination.  An  output
5119 character does not behave like an input character for the purposes of
5120 macro processing; it does not inherit any of the special properties that
5121 the input character from which it was constructed might have had. For
5122 example,
5124 @example
5125 .di x
5126 \\\\
5130 @end example
5132 @findex \e
5133 @findex \!
5134 @findex \?
5135 will print @samp{\\} in GNU troff; each pair of input backslashes is
5136 turned into one
5137 output backslash and the resulting output backslashes are not
5138 interpreted as escape
5139 characters when they are reread. @sc{Unix} troff would interpret them as
5140 escape characters when they were reread and would end up printing one
5141 @samp{\}.
5142 The correct way to obtain a printable backslash is to use the
5143 @code{\e} escape
5144 sequence: this will always print a single instance of the current escape
5145 character, regardless of whether or not it is used in a diversion; it
5146 will also work in both GNU troff and @sc{Unix} troff. If you wish for some
5147 reason to store in a diversion an escape sequence that will be
5148 interpreted when the diversion is reread, you can either use the
5149 traditional @code{\!} transparent output facility, or, if this is unsuitable,
5150 the new @code{\?} escape sequence.  @xref{Diversions}, for more information.
5153 @node Summary,  , Implementation Differences, Programming Tutorial
5154 @section Summary
5155 @cindex summary
5158 @node geqn, gtbl, Programming Tutorial, Top
5159 @chapter @code{geqn}
5160 @cindex @code{eqn}
5161 @cindex @code{geqn}
5164 @menu
5165 * Invoking geqn::               
5166 @end menu
5168 @node Invoking geqn,  , geqn, geqn
5169 @section Invoking @code{geqn}
5170 @cindex invoking @code{geqn}
5171 @cindex @code{geqn}, invoking
5175 @node gtbl, gpic, geqn, Top
5176 @chapter @code{gtbl}
5177 @cindex @code{tbl}
5178 @cindex @code{gtbl}
5181 @menu
5182 * Invoking gtbl::               
5183 @end menu
5185 @node Invoking gtbl,  , gtbl, gtbl
5186 @section Invoking @code{gtbl}
5187 @cindex invoking @code{gtbl}
5188 @cindex @code{gtbl}, invoking
5191 @node gpic, grap, gtbl, Top
5192 @chapter @code{gpic}
5193 @cindex @code{pic}
5194 @cindex @code{gpic}
5197 @menu
5198 * Invoking gpic::               
5199 @end menu
5201 @node Invoking gpic,  , gpic, gpic
5202 @section Invoking @code{gpic}
5203 @cindex invoking @code{gpic}
5204 @cindex @code{gpic}, invoking
5208 @node grap, grefer, gpic, Top
5209 @chapter @code{grap}
5210 @cindex @code{grap}
5214 @node grefer, gsoelim, grap, Top
5215 @chapter @code{grefer}
5216 @cindex @code{refer}
5217 @cindex @code{grefer}
5220 @menu
5221 * Invoking grefer::             
5222 @end menu
5224 @node Invoking grefer,  , grefer, grefer
5225 @section Invoking @code{grefer}
5226 @cindex invoking @code{grefer}
5227 @cindex @code{grefer}, invoking
5231 @node gsoelim, Devices, grefer, Top
5232 @chapter @code{gsoelim}
5233 @cindex @code{soelim}
5234 @cindex @code{gsoelim}
5237 @menu
5238 * Invoking gsoelim::            
5239 @end menu
5241 @node Invoking gsoelim,  , gsoelim, gsoelim
5242 @section Invoking @code{gsoelim}
5243 @cindex invoking @code{gsoelim}
5244 @cindex @code{gsoelim}, invoking
5248 @node Devices, File formats, gsoelim, Top
5249 @chapter Devices
5250 @cindex devices
5254 @menu
5255 * Special Characters::          
5256 * grotty::                      
5257 * grops::                       
5258 * grodvi::                      
5259 * grolj4::                      
5260 * grohtml::                     
5261 * gxditview::                   
5262 @end menu
5264 @node Special Characters, grotty, Devices, Devices
5265 @section Special Characters
5266 @cindex special characters
5267 @cindex characters, special
5270 @c distribute these through the text
5271 @xref{Font Files}
5273 @node grotty, grops, Special Characters, Devices
5274 @section @code{grotty}
5275 @cindex @code{grotty}
5279 @menu
5280 * Invoking grotty::             
5281 @end menu
5283 @node Invoking grotty,  , grotty, grotty
5284 @subsection Invoking @code{grotty}
5285 @cindex invoking @code{grotty}
5286 @cindex @code{grotty}, invoking
5290 @node grops, grodvi, grotty, Devices
5291 @section @code{grops}
5292 @cindex @code{grops}
5296 @menu
5297 * Invoking grops::              
5298 * Embedding PostScript::        
5299 @end menu
5301 @node Invoking grops, Embedding PostScript, grops, grops
5302 @subsection Invoking @code{grops}
5303 @cindex invoking @code{grops}
5304 @cindex @code{grops}, invoking
5308 @node Embedding PostScript,  , Invoking grops, grops
5309 @subsection Embedding PostScript
5310 @cindex embedding postscript
5311 @cindex postscript, embedding
5315 @node grodvi, grolj4, grops, Devices
5316 @section @code{grodvi}
5317 @cindex @code{grodvi}
5321 @menu
5322 * Invoking grodvi::             
5323 @end menu
5325 @node Invoking grodvi,  , grodvi, grodvi
5326 @subsection Invoking @code{grodvi}
5327 @cindex invoking @code{grodvi}
5328 @cindex @code{grodvi}, invoking
5332 @node grolj4, grohtml, grodvi, Devices
5333 @section @code{grolj4}
5334 @cindex @code{grolj4}
5338 @menu
5339 * Invoking grolj4::             
5340 @end menu
5342 @node Invoking grolj4,  , grolj4, grolj4
5343 @subsection Invoking @code{grolj4}
5344 @cindex invoking @code{grolj4}
5345 @cindex @code{grolj4}, invoking
5349 @node grohtml, gxditview, grolj4, Devices
5350 @section @code{grohtml}
5351 @cindex @code{grohtml}
5355 @menu
5356 * Invoking grohtml::            
5357 @end menu
5359 @node Invoking grohtml,  , grohtml, grohtml
5360 @subsection Invoking @code{grohtml}
5361 @cindex invoking @code{grohtml}
5362 @cindex @code{grohtml}, invoking
5366 @node gxditview,  , grohtml, Devices
5367 @section @code{gxditview}
5368 @cindex @code{gxditview}
5372 @menu
5373 * Invoking gxditview::          
5374 @end menu
5376 @node Invoking gxditview,  , gxditview, gxditview
5377 @subsection Invoking @code{gxditview}
5378 @cindex invoking @code{gxditview}
5379 @cindex @code{gxditview}, invoking
5383 @node File formats, Installation, Devices, Top
5384 @chapter File formats
5385 @cindex file formats
5386 @cindex formats, file
5390 @menu
5391 * gtroff Output::               
5392 * Font Files::                  
5393 @end menu
5395 @node gtroff Output, Font Files, File formats, File formats
5396 @section @code{gtroff} Output
5397 @cindex @code{gtroff} output
5398 @cindex output, @code{gtroff}
5401 This section describes the format output by GNU troff.  The output
5402 format used by GNU troff is very similar to that used by @sc{Unix}
5403 device-independent troff.
5405 The output format is ascii based, as opposed to a binary format (like
5406 @TeX{} dvi).
5407 The output format is 8 bit clean, thus single characters can have the
5408 eighth bit set, as can the names of fonts and special characters.
5410 The output format consists of single command characters with attached
5411 parameters which are separated from subsequent text by whitespace, or
5412 a newline.
5414 The names of characters and fonts an be of arbitrary length; drivers
5415 should not assume that they will be only two characters long (as
5416 device-independent troff did).
5418 When a character is to be printed, that character will always be in the
5419 current font.
5420 Unlike device-independent troff, it is not necessary for
5421 drivers to search special fonts to find a character.
5423 @table @code
5424 @item H@var{n}
5425 @item V@var{n}
5426 @item h@var{n}
5427 @item v@var{n}
5428 @item c@var{n}
5429 @item C@var{n}
5430 @item @var{nn}@var{c}
5431 @item t@var{xxx}
5432 @var{xxx} is any sequence of characters terminated by a space or a
5433 newline; the first character should be printed at the current
5434 position, the the current horizontal position should be increased by
5435 the width of the first character, and so on for each character.
5436 The width of the character is that given in the font file,
5437 appropriately scaled for the current point size,
5438 and rounded so that it is a multiple of the horizontal resolution.
5439 Special characters cannot be printed using this command.
5441 This command is only allowed if the @samp{tcommand} line is present
5442 in the @file{DESC} file.
5443 @item u@var{n} @var{xxx}
5444 @pindex DESC
5445 This is same as the @code{t} command except that after printing each
5446 character, the current horizontal position is increased by the sum of
5447 the width of that character and @code{n}.
5449 This command is only allowed if the @samp{tcommand} line is present
5450 in the @file{DESC} file.
5451 @item n@var{a}@var{b}
5452 @item p@var{n}
5453 @item s@var{n}
5454 The argument to the s command is in scaled points (units of points/n,
5455 where n is the argument to the sizescale command  in the DESC file.)
5456 @item f@var{n}
5457 @item x @dots{} \n
5458 Device control.
5459 @item D@var{c} @var{x}@dots{}\n
5460 @end table
5462 @subsection Device Control
5464 The @code{x} command is normally followed by a letter or word
5465 indicating the function to perform, followed by white space separated
5466 arguments.
5468 The first argument can be abreviated to the first letter.
5470 @table @code
5471 @item x init
5472 @item x T
5473 @item x res @var{n} @var{h} @var{v}
5474 @item x H
5475 The argument to the x Height command is also in scaled points.
5476 @end table
5478 The first three output commands are guaranteed to be:
5480 @example
5481 x T device
5482 x res n h v
5483 x init
5484 @end example
5486 For example, the input @samp{crunchy \fH\s+2frog\s0\fP!?} will produce:
5488 @example
5489 ... sample output here ...
5490 @end example
5492 @subsection Drawing Functions
5494 The D drawing command has been extended.  These extensions will only be
5495 used by GNU pic if the -x option is given.
5497 @table @code
5499 @item Df n\n
5500 Set the shade of gray to be used for filling solid objects to n; n must
5501 be an integer between 0 and 1000, where 0 corresponds solid white and
5502 1000 to solid black, and values in between correspond to intermediate
5503 shades of gray.  This applies only to solid circles, solid ellipses and
5504 solid polygons.  By default, a level of 1000 will be used.  Whatever
5505 color a solid object has, it should completely obscure everything
5506 beneath it. A value greater than 1000 or less than 0 can also be used:
5507 this means fill with the shade of gray that is currently being used for
5508 lines and text.  Normally this will be black, but some drivers may
5509 provide a way of changing this.
5510 @item DC d\n
5511 Draw a solid circle with a diameter of d with the leftmost point at the
5512 current position.
5513 @item DE dx dy\n
5514 Draw a solid ellipse with a horizontal diameter of dx and a vertical
5515 diameter of dy with the leftmost point at the current position.
5516 @item Dp $dx sub 1$ $dy sub 1$ $dx sub 2$ $dy sub 2$ $...$ $dx sub n$ $dy sub
5517 n$\n
5518 Draw a polygon with, for $i = 1 ,..., n+1$, the i-th vertex at the
5519 current position $+ sum from j=1 to i-1 ( dx sub j , dy sub j )$. At
5520 the moment, GNU pic only uses this command to generate triangles and
5521 rectangles.
5522 @item DP $dx sub 1$ $dy sub 1$ $dx sub 2$ $dy sub 2$ $...$ $dx sub n$ $dy sub
5523 n$\n
5524 Like Dp but draw a solid rather than outlined polygon.
5525 @item Dt n\n
5526 Set the current line thickness to n machine units.  Traditionally @sc{Unix}
5527 troff drivers use a line thickness proportional to the current point
5528 size; drivers should continue to do this if no Dt command has been
5529 given, or if a Dt command has been given with a negative value of n.  A
5530 zero value of n selects the smallest available line thickness.
5531 @end table
5533 A difficulty arises in how the current position should be changed after
5534 the execution of these commands. This is not of great importance since
5535 the code generated by GNU pic does not depend on this. Given a drawing
5536 command of the form
5538 \D'c $x sub 1$ $y sub 1$ $x sub 2$ $y sub 2$ $...$ $x sub n$ $y sub n$'
5540 where c is not one of c, e, l, a or ~, @sc{Unix} troff will treat each of the
5541 $x sub i$ as a horizontal quantity, and each of the $y sub i$ as a
5542 vertical quantity and will assume that the width of the drawn object is
5543 $sum from i=1 to n x sub i$, and that the height is $sum from i=1 to n y
5544 sub i$.  (The assumption about the height can be seen by examining the
5545 st and sb registers after using such a D command in a \w escape
5546 sequence.)  This rule also holds for all the original drawing commands
5547 with the exception of De.  For the sake of compatibility GNU troff also
5548 follows this rule, even though it produces an ugly result in the case of
5549 the Df, Dt, and, to a lesser extent, DE commands.  Thus after executing
5550 a D command of the form
5552 Dc $x sub 1$ $y sub 1$ $x sub 2$ $y sub 2$ $...$ $x sub n$ $y sub n$\n
5554 the current position should be increased by $( sum from i=1 to n x sub i
5555 , sum from i=1 to n y sub i )$.
5557 @subsection Line Continuation
5559 There is a continuation convention which permits the argument to the x X
5560 command to contain newlines: when outputting the argument to the x X
5561 command,  GNU troff will follow each newline in the argument with a +
5562 character (as usual, it will terminate the entire argument with a
5563 newline); thus if the line after the line containing the x X command
5564 starts with +, then the newline ending the line containing the x X
5565 command should be treated as part of the argument to the x X command,
5566 the + should be ignored, and the part of the line following the + should
5567 be treated like the part of the line following the x X command.
5572 @node Font Files,  , gtroff Output, File formats
5573 @section Font Files
5574 @cindex font files
5575 @cindex files, font
5578 The groff font format is roughly a superset of the ditroff font
5579 format.  Unlike the ditroff font format, there is no associated binary
5580 format.  The font files for device name are stored in a directory
5581 @file{dev@var{name}}.  There are two types of file: a device
5582 description file called @file{DESC} and for each font @samp{F} a font
5583 file called @file{F}.  These are text files; there is no associated
5584 binary format.
5586 @subsection @file{DESC} file format
5587 @pindex DESC
5589 The @file{DESC} file can contain the following types of line:
5591 @table @code
5592 @item res @var{n}
5593 There are @var{n} machine units per inch.
5594 @item hor @var{n}
5595 The horizontal resolution is @var{n} machine units.
5596 @item vert @var{n}
5597 The vertical resolution is @var{n} machine units.
5598 @item sizescale @var{n}
5599 The scale factor for pointsizes.  By default this has a value of 1.  One
5600 scaled point is equal to one point/@var{n}.  The arguments to the
5601 @code{unitwidth} and @code{sizes} commands are given in scaled points.
5602 @xref{Fractional Type Sizes}, for more information.
5603 @item unitwidth @var{n}
5604 Quantities in the font files are given in machine units for fonts  whose
5605 point size is @var{n} scaled points.
5606 @item tcommand
5607 This means that the postprocessor can handle the @code{t} and
5608 @code{u} output commands.
5609 @item sizes @var{s1} @var{s2}@dots{}@var{sn} 0
5610 This means that the device has fonts at @var{s1}, @var{s2},
5611 @dots{}@var{sn} scaled points.  The list of sizes must be terminated
5612 by a 0.  Each @var{si} can also be a range of
5613 sizes @var{m}-@var{n}.  The list can extend over more than one line.
5614 @item styles @var{S1 S2@dots{}Sm}
5615 The first @var{m} font positions will be associated with styles
5616 @var{S1}@dots{}@var{Sm}.
5617 @item fonts @var{n} @var{F1 F2 F3@dots{}Fn}
5618 Fonts @var{F1@dots{}Fn} will be mounted in the font positions
5619 @var{m}+1, @dots{}, @var{m}+@var{n} where @var{m}
5620 is the number of styles.  This command may extend over more than one
5621 line. A font name of 0 will cause no font to be mounted on the
5622 corresponding font position.
5623 @item family @var{fam}
5624 The default font family is @var{fam}.
5625 @item charset
5626 This line and everything following in the file are ignored.  It is
5627 allowed for the sake of backwards compatibility.
5628 @end table
5630 The @code{res}, @code{unitwidth}, @code{fonts} and @code{sizes} lines
5631 are compulsory.  Other commands are ignored by troff but may be used
5632 by postprocessors to store arbitrary information about the device in
5633 the @file{DESC} file.
5636 @subsection Font file format
5638 A font file has two sections.  The first section is a sequence of lines
5639 each containing a sequence of blank delimited words; the first word in
5640 the line is a key, and subsequent words give a value for that key.
5642 @table @code
5643 @item name @var{F}
5644 The name of the font is @var{F}.
5645 @item spacewidth @var{n}
5646 The normal width of a space is @var{n}.
5647 @item slant @var{n}
5648 The characters of the font have a slant of @var{n} degrees.
5649 (Positive means forward.)
5650 @item ligatures @var{lig1} @var{lig2}@dots{}@var{lign} [0]
5651 Characters @var{lig1}, @var{lig2}, @dots{}, @var{lign} are ligatures;
5652 possible ligatures are ff, fi, fl and ffl.  For backwards
5653 compatibiliy, the list of ligatures may be terminated with a 0.  The
5654 list of ligatures may not extend over more than one line.
5655 @item special
5656 The font is special; this means that when a character is requested that
5657 is not present in the current font, it will be searched for in any
5658 special fonts that are mounted.
5659 @end table
5661 Other commands are ignored by troff but may be used by postprocessors to
5662 store arbitrary information about the font in the font file.
5664 The first section can contain comments which start with the # character
5665 and extend to the end of a line.
5667 The second section contains one or two subsections.  It must contain a
5668 @code{charset} subsection and it may also contain a @code{kernpairs}
5669 subsection.  These subsections can appear in any order.  Each
5670 subsection starts with a word on a line by itself.
5672 The word @code{charset} starts the @code{charset} subsection. The
5673 @code{charset} line is followed by a sequence of lines. Each line
5674 gives information for one character.  A line comprises a number of
5675 fields separated by blanks or tabs. The format is
5677 @display
5678 @var{name} @var{metrics} @var{type} @var{code} @var{comment}
5679 @end display
5681 @var{name} identifies the character: if @var{name} is a single
5682 character @var{c} then it corresponds to the groff input character
5683 @var{c}; if it is of the form @samp{\@var{c}} where @var{c} is a
5684 single character, then it corresponds to the groff input character
5685 @samp{\@var{c}}; otherwise it corresponds to the groff input character
5686 @samp{\[@var{name}]} (if it is exactly two characters @var{xx} it can
5687 be entered as @samp{\(@var{xx}}.) Groff supports eight bit characters;
5688 however some utilities has difficulties with eight bit characters.
5689 For this reason, there is a convention that the @var{name}
5690 @samp{char@var{n}} is equivalent to the single character whose code is
5691 @var{n}. For example, @samp{char163} would be equivalent to the
5692 character with @var{code} 163 which is the pounds sterling sign in ISO
5693 Latin-1 character set.  The name @samp{---} is special and indicates
5694 that the character is unnamed; such characters can only be used by
5695 means of the @code{\N} escape sequence in troff.
5697 The @var{type} field gives the character type:
5699 @table @code
5700 @item 1
5701 means the character has an descender, for example, p;
5702 @item 2
5703 means the character has an ascender, for example, b;
5704 @item 3
5705 means the character has both an ascender and a descender, for example,
5706 @samp{(}.
5707 @end table
5709 The @var{code} field gives the code which the postprocessor uses to
5710 print the character.  The character can also be input to groff using
5711 this code by means of the @code{\N} escape sequence. The code can be any
5712 integer.  If it starts with a 0 it will be interpreted as octal; if it
5713 starts with 0x or 0X it will be intepreted as hexdecimal.
5715 Anything on the line after the @var{code} field will be ignored.
5717 The @var{metrics} field has the form:
5719 @smallexample
5720 @var{width[,height[,depth[,italic_correction[,left_italic_correction[,subscript_correction]]]]]}
5721 @end smallexample
5723 There must not be any spaces between these subfields.  Missing
5724 subfields are assumed to be 0.  The subfields are all decimal
5725 integers.  Since there is no associated binary format, these values
5726 are not required to fit into a variable of type @samp{char} as they
5727 are in ditroff.  The @var{width} subfields gives the width of the
5728 character.  The @var{height} subfield gives the height of the
5729 character (upwards is positive); if a character does not extend above
5730 the baseline, it should be given a zero height, rather than a negative
5731 height.  The @var{depth} subfield gives the depth of the character,
5732 that is, the distance below the lowest point below the baseline to
5733 which the character extends (downwards is positive); if a character
5734 does not extend below above the baseline, it should be given a zero
5735 depth, rather than a negative depth.  The @var{italic_correction}
5736 subfield gives the amount of space that should be added after the
5737 character when it is immediately to be followed by a character from a
5738 roman font.  The @var{left_italic_correction} subfield gives the
5739 amount of space that should be added before the character when it is
5740 immediately to be preceded by a character from a roman font.  The
5741 @var{subscript_correction} gives the amount of space that should be
5742 added after a character before adding a subscript. This should be less
5743 than the italic correction.
5745 A line in the @code{charset} section can also have the format
5747 @example
5748 @var{name} "
5749 @end example
5751 This indicates that @var{name} is just another name for the character
5752 mentioned in the preceding line.
5754 The word @code{kernpairs} starts the kernpairs section.  This contains a
5755 sequence of lines of the form:
5757 @display
5758 @var{c1 c2 n}
5759 @end display
5761 This means that when character @var{c1} appears next to character
5762 @var{c2} the space between them should be increased by @var{n}.  Most
5763 entries in kernpairs section will have a negative value for @var{n}.
5767 @node Installation, Request Index, File formats, Top
5768 @chapter Installation
5769 @cindex installation
5773 @node Request Index, Register Index, Installation, Top
5774 @chapter Request Index
5776 @printindex fn
5779 @node Register Index, String Index, Request Index, Top
5780 @chapter Register Index
5782 @printindex vr
5785 @node String Index, Macro Index, Register Index, Top
5786 @chapter String Index
5790 @node Macro Index, Program Index, String Index, Top
5791 @chapter Macro Index
5795 @node Program Index, Concept Index, Macro Index, Top
5796 @chapter Program Index
5798 @printindex pg
5802 @node Concept Index,  , Program Index, Top
5803 @chapter Concept Index
5805 @printindex cp
5809 @summarycontents
5810 @contents
5811 @bye