Other minor fixes.
[s-roff.git] / doc / groff.texinfo
blob9853a7ff886a57898216c6faee09fe5e5a18df61
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 @c We use the following indices:
12 @c   cindex: concepts
13 @c   findex: requests, escapes, and functions
14 @c   vindex: registers
15 @c   kindex: commands in font files
16 @c   pindex: programs
17 @c   tindex: environment variables
19 @c tindex and cindex are merged.
21 @syncodeindex tp cp
24 @c XXX comment all examples
27 @dircategory Miscellaneous
28 @direntry
29 * Groff: (groff).   The GNU troff document formatting system.
30 @end direntry
33 @smallbook
36 @iftex
37 @finalout
38 @end iftex
41 @ifinfo
42 This Info file documents GNU troff version 1.16.
44 Published by the Free Software Foundation
45 59 Temple Place, Suite 330
46 Boston, MA  02111-1307  USA
48 Copyright (C) 1994-2000 Free Software Foundation, Inc.
50 Permission is granted to make and distribute verbatim copies of this
51 manual provided the copyright notice and this permission notice are
52 preserved on all copies.
54 @ignore
55 Permission is granted to process this file through TeX and print the
56 results, provided the printed document carries copying permission notice
57 identical to this one except for the removal of this paragraph (this
58 paragraph not being relevant to the printed manual).
60 @end ignore
61 Permission is granted to copy and distribute modified versions of this
62 manual under the conditions for verbatim copying, provided that the
63 entire resulting derived work is distributed under the terms of a
64 permission notice identical to this one.
66 Permission is granted to copy and distribute translations of this manual
67 into another language, under the above conditions for modified versions,
68 except that this permission notice may be stated in a translation
69 approved by the Foundation.
71 Permission is granted to copy and distribute modified versions of this
72 manual under the conditions for verbatim copying, provided also that the
73 section entitled ``GNU General Public License'' is included exactly as
74 in the original, and provided that the entire resulting derived work is
75 distributed under the terms of a permission notice identical to this
76 one.
78 Permission is granted to copy and distribute translations of this manual
79 into another language, under the above conditions for modified versions,
80 except that the section entitled ``GNU General Public License'' may be
81 included in a translation approved by the Free Software Foundation
82 instead of in the original English.
83 @end ifinfo
86 @titlepage
87 @title groff
88 @subtitle The GNU implementation of @code{groff}
89 @subtitle Edition 1.16
90 @subtitle Spring 2000
91 @author by Trent A.@w{ }Fisher
92 @author and the maintainer of groff
94 @c Include the Distribution inside the titlepage environment so
95 @c that headings are turned off.  Headings on and off do not work.
97 @page
98 @vskip 0pt plus 1filll
99 Copyright @copyright@w{ }1994-2000 Free Software Foundation,@w{ }Inc.
100 @sp 2
101 Version 1.16 of @code{groff}, @*
102 Spring 2000
103 @sp 2
104 Published by the Free Software Foundation @*
105 59 Temple Place, Suite 330 @*
106 Boston, MA  02111-1307  USA
109 Permission is granted to make and distribute verbatim copies of this
110 manual provided the copyright notice and this permission notice are
111 preserved on all copies.
113 Permission is granted to copy and distribute modified versions of this
114 manual under the conditions for verbatim copying, provided also that the
115 section entitled ``GNU General Public License'' is included exactly as
116 in the original, and provided that the entire resulting derived work is
117 distributed under the terms of a permission notice identical to this
118 one.
120 Permission is granted to copy and distribute translations of this manual
121 into another language, under the above conditions for modified versions,
122 except that the section entitled ``GNU General Public License'' may be
123 included in a translation approved by the Free Software Foundation
124 instead of in the original English.
126 Cover art by Etienne Suvasa.
127 @end titlepage
128 @page
132 @node Top, Copying, (dir), (dir)
134 @ifinfo
135 This Info file documents groff version 1.16, the GNU implementation of
136 the troff typesetting system.
138 This is an in-progress document; contributions, comments, or
139 contributions are welcome.  Send them to bug-groff@@gnu.org.
140 @end ifinfo
142 @menu
143 * Copying::                     
144 * Introduction::                
145 * Invoking groff::              
146 * Tutorial for Macro Users::    
147 * Macro Packages::              
148 * Programming Tutorial::        
149 * Preprocessors::               
150 * Output Devices::              
151 * File formats::                
152 * Installation::                
153 * Request and Operator Index::  
154 * Register Index::              
155 * Font File Keyword Index::     
156 * Program and File Index::      
157 * Concept Index::               
158 @end menu
162 @node Copying, Introduction, Top, Top
163 @cindex copying
164 @unnumbered GNU GENERAL PUBLIC LICENSE
165 @center Version 2, June 1991
167 @display
168 Copyright @copyright{}@w{ }1989, 1991 Free Software Foundation, Inc.
169 59@w{ }Temple Place, Suite@w{ }330, Boston, MA@w{ }02111, USA
171 Everyone is permitted to copy and distribute verbatim copies of this
172 license document, but changing it is not allowed.
173 @end display
175 @unnumberedsec Preamble
177 The licenses for most software are designed to take away your freedom to
178 share and change it.  By contrast, the GNU General Public License is
179 intended to guarantee your freedom to share and change free software --
180 to make sure the software is free for all its users.  This General
181 Public License applies to most of the Free Software Foundation's
182 software and to any other program whose authors commit to using it.
183 (Some other Free Software Foundation software is covered by the GNU
184 Library General Public License instead.)  You can apply it to your
185 programs, too.
187 When we speak of free software, we are referring to freedom, not price.
188 Our General Public Licenses are designed to make sure that you have the
189 freedom to distribute copies of free software (and charge for this
190 service if you wish), that you receive source code or can get it if you
191 want it, that you can change the software or use pieces of it in new
192 free programs; and that you know you can do these things.
194 To protect your rights, we need to make restrictions that forbid anyone
195 to deny you these rights or to ask you to surrender the rights.  These
196 restrictions translate to certain responsibilities for you if you
197 distribute copies of the software, or if you modify it.
199 For example, if you distribute copies of such a program, whether gratis
200 or for a fee, you must give the recipients all the rights that you have.
201 You must make sure that they, too, receive or can get the source code.
202 And you must show them these terms so they know their rights.
204 We protect your rights with two steps: (1)@w{ }copyright the software,
205 and (2)@w{ }offer you this license which gives you legal permission to
206 copy, distribute and/or modify the software.
208 Also, for each author's protection and ours, we want to make certain
209 that everyone understands that there is no warranty for this free
210 software.  If the software is modified by someone else and passed on, we
211 want its recipients to know that what they have is not the original, so
212 that any problems introduced by others will not reflect on the original
213 authors' reputations.
215 Finally, any free program is threatened constantly by software patents.
216 We wish to avoid the danger that redistributors of a free program will
217 individually obtain patent licenses, in effect making the program
218 proprietary.  To prevent this, we have made it clear that any patent
219 must be licensed for everyone's free use or not licensed at all.
221 The precise terms and conditions for copying, distribution and
222 modification follow.
224 @iftex
225 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
226 @end iftex
227 @ifinfo
228 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
229 @end ifinfo
231 @enumerate 0
232 @item
233 This License applies to any program or other work which contains a
234 notice placed by the copyright holder saying it may be distributed under
235 the terms of this General Public License.  The ``Program'', below,
236 refers to any such program or work, and a ``work based on the Program''
237 means either the Program or any derivative work under copyright law:
238 that is to say, a work containing the Program or a portion of it, either
239 verbatim or with modifications and/or translated into another language.
240 (Hereinafter, translation is included without limitation in the term
241 ``modification''.)  Each licensee is addressed as ``you''.
243 Activities other than copying, distribution and modification are not
244 covered by this License; they are outside its scope.  The act of running
245 the Program is not restricted, and the output from the Program is
246 covered only if its contents constitute a work based on the Program
247 (independent of having been made by running the Program).  Whether that
248 is true depends on what the Program does.
250 @item
251 You may copy and distribute verbatim copies of the Program's source code
252 as you receive it, in any medium, provided that you conspicuously and
253 appropriately publish on each copy an appropriate copyright notice and
254 disclaimer of warranty; keep intact all the notices that refer to this
255 License and to the absence of any warranty; and give any other
256 recipients of the Program a copy of this License along with the Program.
258 You may charge a fee for the physical act of transferring a copy, and
259 you may at your option offer warranty protection in exchange for a fee.
261 @item
262 You may modify your copy or copies of the Program or any portion of it,
263 thus forming a work based on the Program, and copy and distribute such
264 modifications or work under the terms of Section@w{ }1 above, provided
265 that you also meet all of these conditions:
267 @enumerate a
268 @item
269 You must cause the modified files to carry prominent notices stating
270 that you changed the files and the date of any change.
272 @item
273 You must cause any work that you distribute or publish, that in whole or
274 in part contains or is derived from the Program or any part thereof, to
275 be licensed as a whole at no charge to all third parties under the terms
276 of this License.
278 @item
279 If the modified program normally reads commands interactively when run,
280 you must cause it, when started running for such interactive use in the
281 most ordinary way, to print or display an announcement including an
282 appropriate copyright notice and a notice that there is no warranty (or
283 else, saying that you provide a warranty) and that users may
284 redistribute the program under these conditions, and telling the user
285 how to view a copy of this License.  (Exception: if the Program itself
286 is interactive but does not normally print such an announcement, your
287 work based on the Program is not required to print an announcement.)
288 @end enumerate
290 These requirements apply to the modified work as a whole.  If
291 identifiable sections of that work are not derived from the Program, and
292 can be reasonably considered independent and separate works in
293 themselves, then this License, and its terms, do not apply to those
294 sections when you distribute them as separate works.  But when you
295 distribute the same sections as part of a whole which is a work based on
296 the Program, the distribution of the whole must be on the terms of this
297 License, whose permissions for other licensees extend to the entire
298 whole, and thus to each and every part regardless of who wrote it.
300 Thus, it is not the intent of this section to claim rights or contest
301 your rights to work written entirely by you; rather, the intent is to
302 exercise the right to control the distribution of derivative or
303 collective works based on the Program.
305 In addition, mere aggregation of another work not based on the Program
306 with the Program (or with a work based on the Program) on a volume of a
307 storage or distribution medium does not bring the other work under the
308 scope of this License.
310 @item
311 You may copy and distribute the Program (or a work based on it, under
312 Section@w{ }2) in object code or executable form under the terms of
313 Sections@w{ }1 and@w{ }2 above provided that you also do one of the
314 following:
316 @enumerate a
317 @item
318 Accompany it with the complete corresponding machine-readable source
319 code, which must be distributed under the terms of Sections@w{ }1 and@w{
320 }2 above on a medium customarily used for software interchange; or,
322 @item
323 Accompany it with a written offer, valid for at least three years, to
324 give any third party, for a charge no more than your cost of physically
325 performing source distribution, a complete machine-readable copy of the
326 corresponding source code, to be distributed under the terms of
327 Sections@w{ }1 and@w{ }2 above on a medium customarily used for software
328 interchange; or,
330 @item
331 Accompany it with the information you received as to the offer to
332 distribute corresponding source code.  (This alternative is allowed only
333 for noncommercial distribution and only if you received the program in
334 object code or executable form with such an offer, in accord with
335 Subsection@w{ }b above.)
336 @end enumerate
338 The source code for a work means the preferred form of the work for
339 making modifications to it.  For an executable work, complete source
340 code means all the source code for all modules it contains, plus any
341 associated interface definition files, plus the scripts used to control
342 compilation and installation of the executable.  However, as a special
343 exception, the source code distributed need not include anything that is
344 normally distributed (in either source or binary form) with the major
345 components (compiler, kernel, and so on) of the operating system on
346 which the executable runs, unless that component itself accompanies the
347 executable.
349 If distribution of executable or object code is made by offering access
350 to copy from a designated place, then offering equivalent access to copy
351 the source code from the same place counts as distribution of the source
352 code, even though third parties are not compelled to copy the source
353 along with the object code.
355 @item
356 You may not copy, modify, sublicense, or distribute the Program except
357 as expressly provided under this License.  Any attempt otherwise to
358 copy, modify, sublicense or distribute the Program is void, and will
359 automatically terminate your rights under this License.  However,
360 parties who have received copies, or rights, from you under this License
361 will not have their licenses terminated so long as such parties remain
362 in full compliance.
364 @item
365 You are not required to accept this License, since you have not signed
366 it.  However, nothing else grants you permission to modify or distribute
367 the Program or its derivative works.  These actions are prohibited by
368 law if you do not accept this License.  Therefore, by modifying or
369 distributing the Program (or any work based on the Program), you
370 indicate your acceptance of this License to do so, and all its terms and
371 conditions for copying, distributing or modifying the Program or works
372 based on it.
374 @item
375 Each time you redistribute the Program (or any work based on the
376 Program), the recipient automatically receives a license from the
377 original licensor to copy, distribute or modify the Program subject to
378 these terms and conditions.  You may not impose any further restrictions
379 on the recipients' exercise of the rights granted herein.  You are not
380 responsible for enforcing compliance by third parties to this License.
382 @item
383 If, as a consequence of a court judgment or allegation of patent
384 infringement or for any other reason (not limited to patent issues),
385 conditions are imposed on you (whether by court order, agreement or
386 otherwise) that contradict the conditions of this License, they do not
387 excuse you from the conditions of this License.  If you cannot
388 distribute so as to satisfy simultaneously your obligations under this
389 License and any other pertinent obligations, then as a consequence you
390 may not distribute the Program at all.  For example, if a patent license
391 would not permit royalty-free redistribution of the Program by all those
392 who receive copies directly or indirectly through you, then the only way
393 you could satisfy both it and this License would be to refrain entirely
394 from distribution of the Program.
396 If any portion of this section is held invalid or unenforceable under
397 any particular circumstance, the balance of the section is intended to
398 apply and the section as a whole is intended to apply in other
399 circumstances.
401 It is not the purpose of this section to induce you to infringe any
402 patents or other property right claims or to contest validity of any
403 such claims; this section has the sole purpose of protecting the
404 integrity of the free software distribution system, which is implemented
405 by public license practices.  Many people have made generous
406 contributions to the wide range of software distributed through that
407 system in reliance on consistent application of that system; it is up to
408 the author/donor to decide if he or she is willing to distribute
409 software through any other system and a licensee cannot impose that
410 choice.
412 This section is intended to make thoroughly clear what is believed to be
413 a consequence of the rest of this License.
415 @item
416 If the distribution and/or use of the Program is restricted in certain
417 countries either by patents or by copyrighted interfaces, the original
418 copyright holder who places the Program under this License may add an
419 explicit geographical distribution limitation excluding those countries,
420 so that distribution is permitted only in or among countries not thus
421 excluded.  In such case, this License incorporates the limitation as if
422 written in the body of this License.
424 @item
425 The Free Software Foundation may publish revised and/or new versions of
426 the General Public License from time to time.  Such new versions will be
427 similar in spirit to the present version, but may differ in detail to
428 address new problems or concerns.
430 Each version is given a distinguishing version number.  If the Program
431 specifies a version number of this License which applies to it and ``any
432 later version'', you have the option of following the terms and
433 conditions either of that version or of any later version published by
434 the Free Software Foundation.  If the Program does not specify a version
435 number of this License, you may choose any version ever published by the
436 Free Software Foundation.
438 @item
439 If you wish to incorporate parts of the Program into other free programs
440 whose distribution conditions are different, write to the author to ask
441 for permission.  For software which is copyrighted by the Free Software
442 Foundation, write to the Free Software Foundation; we sometimes make
443 exceptions for this.  Our decision will be guided by the two goals of
444 preserving the free status of all derivatives of our free software and
445 of promoting the sharing and reuse of software generally.
447 @iftex
448 @heading NO WARRANTY
449 @end iftex
450 @ifinfo
451 @center NO WARRANTY
452 @end ifinfo
454 @item
455 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
456 THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW@.  EXCEPT WHEN
457 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
458 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER
459 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
460 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE@.
461 THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH
462 YOU@.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
463 NECESSARY SERVICING, REPAIR OR CORRECTION.
465 @item
466 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
467 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
468 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
469 DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
470 DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM
471 (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
472 INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
473 THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR
474 OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
475 @end enumerate
477 @iftex
478 @heading END OF TERMS AND CONDITIONS
479 @end iftex
480 @ifinfo
481 @center END OF TERMS AND CONDITIONS
482 @end ifinfo
485 @page
486 @unnumberedsec How to Apply These Terms to Your New Programs
488 If you develop a new program, and you want it to be of the greatest
489 possible use to the public, the best way to achieve this is to make it
490 free software which everyone can redistribute and change under these
491 terms.
493 To do so, attach the following notices to the program.  It is safest to
494 attach them to the start of each source file to most effectively convey
495 the exclusion of warranty; and each file should have at least the
496 ``copyright'' line and a pointer to where the full notice is found.
498 @smallexample
499 @var{one line to give the program's name and an idea of what it does.}
500 Copyright (C) 19@var{yy} @var{name of author}
502 This program is free software; you can redistribute it and/or modify
503 it under the terms of the GNU General Public License as published by
504 the Free Software Foundation; either version 2 of the License, or (at
505 your option) any later version.
507 This program is distributed in the hope that it will be useful, but
508 WITHOUT ANY WARRANTY; without even the implied warranty of
509 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE@.  See the GNU
510 General Public License for more details.
512 You should have received a copy of the GNU General Public License
513 along with this program; if not, write to the Free Software
514 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
515 @end smallexample
517 Also add information on how to contact you by electronic and paper mail.
519 If the program is interactive, make it output a short notice like this
520 when it starts in an interactive mode:
522 @smallexample
523 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
524 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type
525 `show w'.  This is free software, and you are welcome to redistribute
526 it under certain conditions; type `show c' for details.
527 @end smallexample
529 The hypothetical commands @samp{show@w{ }w} and @samp{show@w{ }c} should
530 show the appropriate parts of the General Public License.  Of course,
531 the commands you use may be called something other than @samp{show@w{
532 }w} and @samp{show@w{ }c}; they could even be mouse-clicks or menu
533 items---whatever suits your program.
535 You should also get your employer (if you work as a programmer) or your
536 school, if any, to sign a ``copyright disclaimer'' for the program, if
537 necessary.  Here is a sample; alter the names:
539 @smallexample
540 @group
541 Yoyodyne, Inc., hereby disclaims all copyright interest
542 in the program `Gnomovision' (which makes passes at compilers)
543 written by James Hacker.
545 @var{signature of Ty Coon}, 1 April 1989
546 Ty Coon, President of Vice
547 @end group
548 @end smallexample
550 This General Public License does not permit incorporating your program
551 into proprietary programs.  If your program is a subroutine library, you
552 may consider it more useful to permit linking proprietary applications
553 with the library.  If this is what you want to do, use the GNU Library
554 General Public License instead of this License.
558 @node Introduction, Invoking groff, Copying, Top
559 @chapter Introduction
560 @cindex introduction
562 GNU @code{troff} (or @code{groff}) is a system for typesetting
563 documents.  @code{troff} is very flexible and has been in existence (and
564 use) for about 3@w{ }decades.  It is quite widespread and firmly
565 entrenched in the @acronym{UNIX} community.
567 @menu
568 * What Is groff?::              
569 * History::                     
570 * groff Capabilities::          
571 * Macro Package Intro::         
572 * Preprocessor Intro::          
573 * Output device intro::         
574 * Credits::                     
575 @end menu
578 @node What Is groff?, History, Introduction, Introduction
579 @section What Is @code{groff}?
580 @cindex what is @code{groff}?
581 @cindex @code{groff} -- what is it?
583 @code{groff} is of an older generation of document preparation systems,
584 which operate more like compilers than the more recent interactive
585 @acronym{WYSIWYG}@footnote{What You See Is What You Get} systems.
586 @code{groff} and its contemporary counterpart, @TeX{}, both work using a
587 @dfn{batch} paradigm: The input (or @dfn{source}) files are normal text
588 files with embedded formatting commands.  These files can then be
589 processed by @code{groff} to produce a typeset document on a variety of
590 devices.
592 Likewise, @code{groff} should not be confused with a @dfn{word
593 processor}, since that term connotes an integrated system which includes
594 an editor and a text formatter.  Also, many word processors follow the
595 @acronym{WYSIWYG} paradigm which was discussed earlier.
597 Although @acronym{WYSIWYG} systems may be easier to use, they have a
598 number of disadvantages compared to @code{troff}:
600 @itemize @bullet{}
601 @item
602 They must be used on a graphics display to do any operations on a
603 document.
604 @item
605 Most of the @acronym{WYSIWYG} systems are either non-free or are not
606 very portable.
607 @item
608 @code{troff} is firmly entrenched in all @acronym{UNIX} systems.
609 @item
610 It is difficult to have a wide range of capabilities available within
611 the confines of a GUI/window system.
612 @item
613 It is more difficult to make global changes to a document.
614 @end itemize
616 @quotation
617 ``GUIs normally make it simple to accomplish simple actions and
618 impossible to accomplish complex actions.''  --Doug Gwyn (22/Jun/91 in
619 @code{comp.unix.wizards})
620 @end quotation
623 @node History, groff Capabilities, What Is groff?, Introduction
624 @section History
625 @cindex history
627 @cindex @code{runoff}
628 @code{troff} can trace its origins back to a formatting program called
629 @code{runoff} which ran on MIT's CTSS system.  This name came from the
630 common phrase of the time ``I'll run off a document.''
632 @cindex @code{roff}
633 The first version of @acronym{UNIX} was developed on a PDP-7 which was
634 sitting around Bell Labs.  In 1971 the developers wanted to get a PDP-11
635 for further work on the operating system.  In order to justify the cost
636 for this system, they proposed that they would implement a document
637 formatting system for the AT&T patents division.  This first formatting
638 program was a reimplementation of @code{runoff}.  In accordance with
639 @acronym{UNIX}'s penchant for abbreviations, it was named @code{roff}
640 (an abbreviation of @code{runoff}).
642 @cindex @code{nroff}
643 When they needed a more flexible language, a new version of @code{roff}
644 called @code{nroff} (Newer @code{roff}) was written.  It had a much more
645 complicated syntax, but provided the basis for all future versions.
646 When they got a Graphic Systems CAT Phototypesetter, J.@w{ }F.@w{
647 }Ossanna wrote a version of @code{nroff} which would drive it.  It was
648 dubbed @code{troff} for typesetter @code{roff}, although many people
649 have speculated that it actually means Times @code{roff} because of the
650 use of the Times font family in @code{troff} by default.  As such, the
651 name @code{troff} is pronounced `@w{t-roff}' rather than `trough'.
653 With @code{troff} came @code{nroff} (they were actually the same program
654 except for some @samp{#ifdefs}), which was for producing output for line
655 printers and character terminals.  It understood everything @code{troff}
656 did, and ignored the commands which were not applicable (e.g.@: font
657 changes).
659 Since there are several things which cannot be done easily in
660 @code{troff}, work on several preprocessors began.  These programs would
661 transform certain parts of a document into @code{troff}, which made a
662 very natural use of pipes in @acronym{UNIX}.
664 The @code{eqn} preprocessor allowed mathematical formul@ae{} to be
665 specified in a much simpler and more intuitive manner.  @code{tbl} is a
666 preprocessor for formatting tables.  The @code{refer} preprocessor (and
667 the similar program, @code{bib}) processes citations in a document
668 according to a bibliographic database.
670 Unfortunately, Ossanna's @code{troff} was written in PDP-11 assembly
671 language and produced output specifically for the CAT phototypesetter.
672 He rewrote it in C, although it was now 7000@w{ }lines of uncommented
673 code and still dependent on the CAT.  As the CAT became less common, and
674 was no longer supported by the manufacturer, the need to make it support
675 other devices became a priority.  However, before this could be done, he
676 was killed in an auto accident.
678 @pindex ditroff
679 @cindex @code{ditroff}
680 So, Brian Kernighan took on the task of rewriting @code{troff}.  The
681 newly rewritten version produced a device independent code which was
682 very easy for postprocessors to read and translate to the appropriate
683 printer codes.  Also, this new version of @code{troff} (called
684 @code{ditroff} for `device independent @code{troff}') had several
685 extensions, which included drawing functions.
687 Due to the additional abilities of the new version of @code{troff},
688 several new preprocessors appeared.  The @code{pic} preprocessor
689 provides a wide range of drawing functions.  Likewise the @code{ideal}
690 preprocessor did the same, although via a much different paradigm.  The
691 @code{grap} preprocessor took specifications for graphs, but, unlike
692 other preprocessors, produced @code{pic} code.
694 James Clark began work on a GNU implementation of @code{ditroff} in
695 early@w{ }1989.  The first version, @code{groff}@w{ }0.3.1, was released
696 June@w{ }1990.  @code{groff} included
698 @itemize @bullet{}
699 @item
700 A replacement for @code{ditroff} with many extensions.
701 @item
702 The @code{soelim}, @code{pic}, @code{tbl}, and @code{eqn} preprocessors.
703 @item
704 Postprocessors for character devices, @sc{PostScript}, @TeX{} DVI, and
705 X@w{ }windows.  GNU @code{troff} also eliminated the need for a separate
706 @code{nroff} program with a postprocessor which would produce
707 @acronym{ASCII} output.
708 @item
709 A version of the @option{-me} macros and an implementation of the
710 @option{-man} macros.
711 @end itemize
713 Also, a front-end was included which could construct the, sometimes
714 painfully long, pipelines required for all the post- and preprocessors.
716 Development of GNU @code{troff} progressed rapidly, and saw the
717 additions of a replacement for @code{refer}, an implementation of the
718 @option{-ms} and @option{-mm} macros, and a program to deduce how to
719 format a document (@code{grog}).
721 It was declared a stable (i.e.@: non-beta) package with the release of
722 version@w{ }1.04 around November@w{ }1991.
724 Beginning in@w{ }1999, @code{groff} has new maintainers (the package was
725 an orphan for a few years).  As a result, new features and programs like
726 @code{grn}, a preprocessor for gremlin images, and @code{grohtml}, an
727 output device to produce @acronym{HTML} output, have been added.
730 @node groff Capabilities, Macro Package Intro, History, Introduction
731 @section @code{groff} Capabilities
732 @cindex @code{groff} capabilities
733 @cindex capabilities of @code{groff}
735 So what exactly is @code{groff} capable of doing?  @code{groff} provides
736 a wide range of low-level text formatting operations.  Using these, it
737 is possible to perform a wide range of formatting tasks, such as
738 footnotes, table of contents, multiple columns, etc.
740 @itemize @bullet{}
741 @item
742 Text filling, adjusting, and centering
743 @item
744 Hyphenation
745 @item
746 Page control
747 @item
748 Font and character size control
749 @item
750 Vertical spacing (i.e.@: double spacing)
751 @item
752 Line length and indenting
753 @item
754 Macros, strings, diversions, and traps
755 @item
756 Number registers
757 @item
758 Tabs, leaders, and fields
759 @item
760 Input and output conventions and character translation
761 @item
762 Overstrike, bracket, line drawing, and zero-width functions
763 @item
764 Local horizontal and vertical motions and the width function
765 @item
766 Three-part titles
767 @item
768 Output line numbering
769 @item
770 Conditional acceptance of input
771 @item
772 Environment switching
773 @item
774 Insertions from the standard input
775 @item
776 Input/output file switching
777 @item
778 Output and error messages
779 @end itemize
782 @node Macro Package Intro, Preprocessor Intro, groff Capabilities, Introduction
783 @section Macro Packages
784 @cindex macro packages
786 Since @code{groff} provides such low level facilities, it can be quite
787 difficult to use by itself.  However, @code{groff} provides a
788 @dfn{macro} facility to specify how certain routine operations (e.g.@w{
789 }starting paragraphs, printing headers and footers, etc.)@: should be
790 done.  These macros can be collected together into a @dfn{macro
791 package}.  There are a number of macro packages available; the most
792 common (and the ones described in this manual) are @option{-man},
793 @option{-mdoc}, @option{-me}, @option{-ms}, and @option{-mm}.
796 @node Preprocessor Intro, Output device intro, Macro Package Intro, Introduction
797 @section Preprocessors
798 @cindex preprocessors
800 Although @code{groff} provides most functions needed to format a
801 document, some operations would be unwieldy (e.g.@: to draw pictures).
802 Therefore, programs called preprocessors were written which understand
803 their own language and produce the necessary @code{groff} operations.
804 These preprocessors are able to differentiate their own input from the
805 rest of the document via markers.
807 To use a preprocessor, @acronym{UNIX} pipes are used to feed the output
808 from the preprocessor into @code{groff}.  Any number of preprocessors
809 may be used on a given document; in this case, the preprocessors are
810 linked together into one pipeline.  However, in @code{groff}, the user
811 does not need to construct the pipe, but only tell @code{groff} what
812 preprocessors to use.
814 @code{groff} currently has preprocessors for producing tables
815 (@code{tbl}), typesetting equations (@code{eqn}), drawing pictures
816 (@code{pic} and @code{grn}), and for processing bibliographies
817 (@code{refer}).  An associated program which is useful when dealing with
818 preprocessors is @code{soelim}.
820 A free implementation of @code{grap}, a preprocessor for drawing graphs,
821 can be obtained as an extra package.
823 There are other preprocessors in existence, but, unfortunately, no free
824 implementations are available.  Among them are preprocessors for drawing
825 mathematical pictures (@code{ideal}) and chemical structures
826 (@code{chem}).
829 @node Output device intro, Credits, Preprocessor Intro, Introduction
830 @section Output Devices
831 @cindex postprocessors
832 @cindex output devices
833 @cindex devices for output
835 @code{groff} actually produces device independent code which may be fed
836 into a postprocessor which will produce output for a particular device.
837 Currently, @code{groff} has postprocessors for @sc{PostScript},
838 character terminals, X@w{ }Windows (for previewing), @TeX{} DVI format,
839 HP LaserJet@w{ }4 and Canon LBP printers, and @acronym{HTML}.
842 @node Credits,  , Output device intro, Introduction
843 @section Credits
844 @cindex credits
846 Large portions of this manual were taken from existing documents, most
847 notably, the manual pages for the @code{groff} package by James Clark,
848 and Eric Allman's papers on the @option{-me} macro package.
852 @node Invoking groff, Tutorial for Macro Users, Introduction, Top
853 @chapter Invoking @code{groff}
854 @cindex invoking @code{groff}
855 @cindex @code{groff} invocation
857 @pindex groff
858 @pindex gtroff
859 This section focuses on how to invoke the @code{groff} front end.  This
860 front end takes care of the details of constructing the pipeline among
861 the preprocessors, @code{gtroff} and the postprocessor.
863 It has become a tradition that GNU programs get the prefix @samp{g} to
864 distinguish it from its original counterparts provided by the host
865 (@pxref{Environment}, for more details).  Thus, for example, @code{geqn}
866 is GNU @code{eqn}.  On operating systems like Linux or the Hurd, which
867 don't contain proprietary software, this prefix is omitted since GNU
868 @code{troff} is the only used incarnation of @code{troff}.  Exception:
869 @code{groff} is never replaced by @code{roff}.
871 @menu
872 * Options::                     
873 * Environment::                 
874 * Invocation Examples::         
875 @end menu
878 @node Options, Environment, Invoking groff, Invoking groff
879 @section Options
880 @cindex options
882 @pindex groff
883 @pindex gtroff
884 @pindex gpic
885 @pindex geqn
886 @pindex ggrn
887 @pindex gtbl
888 @pindex grefer
889 @pindex gsoelim
890 @code{groff} normally runs the @code{gtroff} program and a postprocessor
891 appropriate for the selected device.  The default device is @samp{ps}.
892 It can optionally preprocess with any of @code{gpic}, @code{geqn},
893 @code{gtbl}, @code{ggrn}, @code{grefer}, or @code{gsoelim}.
895 This section only documents options to the @code{groff} front end.  Many
896 of the arguments to @code{groff} are passed on to @code{gtroff},
897 therefore those are also included.  Arguments to pre- or postprocessors
898 can be found in @ref{Invoking gpic}, @ref{Invoking geqn}, @ref{Invoking
899 gtbl}, @ref{Invoking ggrn}, @ref{Invoking grefer}, @ref{Invoking
900 gsoelim}, @ref{Invoking grotty}, @ref{Invoking grops}, @ref{Invoking
901 grohtml}, @ref{Invoking grodvi}, @ref{Invoking grolj4}, @ref{Invoking
902 grolbp}, and @ref{Invoking gxditview}.
904 The command line format for @code{groff} is:
906 @example
907 groff [ -abeghilpstvzCENRSUVXZ ] [ -F@var{dir} ] [ -m@var{name} ]
908       [ -T@var{def} ] [ -f@var{fam} ] [ -w@var{name} ] [ -W@var{name} ]
909       [ -M@var{dir} ] [ -d@var{cs} ] [ -r@var{cn} ] [ -n@var{num} ]
910       [ -o@var{list} ] [ -P@var{arg} ] [ -L@var{arg} ] [ -I@var{dir} ]
911       [ @var{files}@dots{} ]
912 @end example
914 The command line format for @code{gtroff} is as follows.  As can be
915 seen, many of the options to @code{groff} are actually passed on to
916 @code{gtroff}.
918 @example
919 gtroff [ -abivzCERU ] [ -w@var{name} ] [ -W@var{name} ] [ -d@var{cs} ]
920        [ -f@var{fam} ] [ -m@var{name} ] [ -n@var{num} ]
921        [ -o@var{list} ] [ -r@var{cn} ] [ -T@var{name} ]
922        [ -F@var{dir} ] [ -M@var{dir} ] [ @var{files}@dots{} ]
923 @end example
925 Options without an argument can be grouped behind a single @option{-}.
926 A filename of @samp{-} denotes the standard input.
928 @pindex grog
929 The @code{grog} command can be used to guess the correct @code{groff}
930 command to format a file.
932 @table @samp
933 @item -h
934 Print a help message.
935 @item -e
936 Preprocess with @code{geqn}.
937 @item -t
938 Preprocess with @code{gtbl}.
939 @item -g
940 Preprocess with @code{ggrn}.
941 @item -p
942 Preprocess with @code{gpic}.
943 @item -s
944 Preprocess with @code{gsoelim}.
945 @item -R
946 Preprocess with @code{grefer}.  No mechanism is provided for passing
947 arguments to @code{grefer} because most @code{grefer} options have
948 equivalent commands which can be included in the file.  @xref{grefer},
949 for more details.
951 @pindex troffrc
952 @pindex troffrc-end
953 Note that @code{gtroff} also accepts a @option{-R} option, which is not
954 accessible via @code{groff}.  This option prevents the loading of the
955 @file{troffrc} and @file{troffrc-end} files.
956 @item -v
957 Make programs run by @code{groff} print out their version number.
958 @item -V
959 Print the pipeline on stdout instead of executing it.
960 @item -z
961 Suppress output from @code{gtroff}.  Only error messages will be
962 printed.
963 @item -Z
964 Do not postprocess the output of @code{gtroff}.  Normally @code{groff}
965 will automatically run the appropriate postprocessor.
966 @item -P@var{arg}
967 Pass @var{arg} to the postprocessor.  Each argument should be passed
968 with a separate @option{-P} option.  Note that @code{groff} does not
969 prepend @samp{-} to @var{arg} before passing it to the postprocessor.
970 @item -l
971 Send the output to a printer.  The command used for this is specified by
972 the print command in the device description file.
973 @item -L@var{arg}
974 Pass @var{arg} to the spooler.  Each argument should be passed with a
975 separate @option{-L} option.  Note that @code{groff} does not prepend a
976 @samp{-} to @var{arg} before passing it to the postprocessor.
977 @item -T@var{dev}
978 Prepare output for device @var{dev}.  The default device is @samp{ps}.
979 The following are the output devices currently available:
980 @table @code
981 @item ps
982 For @sc{PostScript} printers and previewers.
983 @item dvi
984 For @TeX{} DVI format.
985 @item X75
986 For a 75@dmn{dpi} X11 previewer.
987 @item X100
988 For a 100@dmn{dpi} X11 previewer.
989 @item ascii
990 For typewriter-like devices.
991 @item latin1
992 For typewriter-like devices using the @w{ISO Latin-1} (@w{ISO 8859-1})
993 character set.
994 @item utf8
995 For typewriter-like devices which use the Unicode (@w{ISO 10646})
996 character set with @w{UTF-8} encoding.
997 @item lj4
998 For an HP LaserJet4-compatible (or other PCL5-compatible) printer.
999 @item lbp
1000 For Canon @acronym{CAPSL} printers (@w{LBP-4} and @w{LBP-8} series laser
1001 printers).
1002 @item html
1003 To produce @acronym{HTML} output.
1004 @end table
1006 The postprocessor to be used for a device is specified by the
1007 @code{postpro} command in the device description file.  (@xref{Font
1008 Files}, for more info.)  This can be overridden with the @option{-X}
1009 option.
1010 @item -X
1011 Preview with @code{gxditview} instead of using the usual postprocessor.
1012 This is unlikely to produce good results except with @option{-Tps}.
1014 Note that this is not the same as using @option{-TX75} or
1015 @option{-TX100} to view a document with @code{gxditview}: The former
1016 will us the metrics of the specified device, whereas the latter will use
1017 X-specific fonts and metrics.
1018 @item -N
1019 Don't allow newlines with @code{eqn} delimiters.  This is the same as
1020 the @option{-N} option in @code{geqn}.
1021 @item -S
1022 Safer mode.  Pass the @option{-S} option to @code{gpic} and use the
1023 @option{-msafer} macros with @code{gtroff} (enabled by default).
1024 @item -U
1025 Unsafe mode.  Reverts to the old unsafe behaviour.
1026 @item -a
1027 Generate an @acronym{ASCII} approximation of the typeset output.
1028 @item -b
1029 Print a backtrace with each warning or error message.  This backtrace
1030 should help track down the cause of the error.  The line numbers given
1031 in the backtrace may not always be correct: @code{gtroff} can get
1032 confused by @code{as} or @code{am} requests while counting line numbers.
1033 @item -i
1034 Read the standard input after all the named input files have been
1035 processed.
1036 @item -w@var{name}
1037 Enable warning @var{name}.  Available warnings are described in
1038 @ref{Debugging}.  Multiple @option{-w} options are allowed.
1039 @item -W@var{name}
1040 Inhibit warning @var{name}.  Multiple @option{-W} options are allowed.
1041 @item -E
1042 Inhibit all error messages.
1043 @item -C
1044 Enable compatibility mode.
1045 @item -d@var{cs}
1046 @itemx -d@var{name}=s
1047 Define @var{c} or @var{name} to be a string @var{s}; @var{c} must be a
1048 one-letter @var{name}.
1049 @item -f@var{fam}
1050 Use @var{fam} as the default font family.
1051 @item -m@var{name}
1052 Read in the file @file{tmac.@var{name}}.  Normally this will be searched
1053 for in the library directory of @code{groff}.
1054 @item -n@var{num}
1055 Number the first page @var{num}.
1056 @item -o@var{list}
1057 Output only pages in @var{list}, which is a comma-separated list of page
1058 ranges; @var{n} means print page @var{n}, @samp{@var{m}-@var{n}} means
1059 print every page between @var{m} and @var{n}, @samp{-@var{n}} means
1060 print every page up to @var{n}, @samp{@var{n}-} means print every page
1061 from @var{n}.  @code{gtroff} will exit after printing the last page in
1062 the list.
1063 @item -r@var{cn}
1064 @itemx -r@var{name}=@var{n}
1065 Set number register @var{c} or @var{name} to @var{n}; @var{c} must be a
1066 one-letter @var{name}; @var{n} can be any @code{gtroff} numeric
1067 expression.
1068 @item -F@var{dir}
1069 Search @var{dir} for subdirectories dev@var{name} (@var{name} is the
1070 name of the device) for the @file{DESC} file and font files before the
1071 normal directory.
1072 @item -M@var{dir}
1073 Search directory @var{dir} for macro files before the normal directory.
1074 @item -I@var{dir}
1075 This option is as described in @ref{gsoelim}.  It implies the
1076 @option{-s} option.
1077 @end table
1080 @node Environment, Invocation Examples, Options, Invoking groff
1081 @section Environment
1082 @cindex environment variables
1083 @cindex variables in environment
1085 There are also several environment variables (of the operating system,
1086 not within @code{gtroff}) which can modify the behavior of @code{groff}.
1088 @table @code
1089 @item GROFF_COMMAND_PREFIX
1090 @tindex GROFF_COMMAND_PREFIX
1091 If this is set to @var{X}, then @code{groff} will run
1092 @var{X}@code{troff} instead of @code{gtroff}.  This also applies to
1093 @code{tbl}, @code{pic}, @code{eqn}, @code{grn}, @code{refer}, and
1094 @code{soelim}.  It does not apply to @code{grops}, @code{grodvi},
1095 @code{grotty}, @code{grohtml}, @code{grolj4}, and @code{gxditview}.
1096 @item GROFF_TMAC_PATH
1097 @tindex GROFF_TMAC_PATH
1098 A colon separated list of directories in which to search for macro
1099 files.
1100 @item GROFF_TYPESETTER
1101 @tindex GROFF_TYPESETTER
1102 The default output device.
1103 @item GROFF_FONT_PATH
1104 @tindex GROFF_FONT_PATH
1105 A colon separated list of directories in which to search for the
1106 @code{dev}@var{name} directory.
1107 @item PATH
1108 @tindex PATH
1109 The search path for commands executed by @code{groff}.
1110 @item GROFF_TMPDIR
1111 @tindex GROFF_TMPDIR
1112 @tindex TMPDIR
1113 The directory in which temporary files will be created.  If this is not
1114 set and @env{TMPDIR} is set, temporary files will be created in that
1115 directory.  Otherwise temporary files will be created in @code{/tmp}.
1116 The @code{grops} and @code{grefer} commands can create temporary files.
1117 @end table
1120 @node Invocation Examples,  , Environment, Invoking groff
1121 @section Invocation Examples
1122 @cindex invocation examples
1123 @cindex examples of invocation
1125 This section will list several common uses of @code{groff} and the
1126 command line which will accomplish it.
1128 @example
1129 groff file
1130 @end example
1132 @noindent
1133 This command processes @var{file} without a macro package or a
1134 preprocessor.  The output device is the default, @var{ps}, and the
1135 output is sent to stdout.
1137 @example
1138 groff -t -mandoc -Tascii file | less
1139 @end example
1141 @noindent
1142 This is basically what a call to the @code{man} program does.  The
1143 manual page @var{file} is processed with the @option{-mandoc} macros
1144 (which in turn either calls the @option{-man} or the @option{-mdoc}
1145 macro package), using the @code{tbl} preprocessor and the
1146 @acronym{ASCII} output device.  Finally, the result is displayed with
1147 the @code{less} pager.
1149 @example
1150 groff -X -me file
1151 @end example
1153 @noindent
1154 Preview @var{file} with @code{gxditview}, using the @option{-me} macro
1155 package.  Since no @option{-T} option is specified, use the default
1156 device (@samp{ps}).
1158 @example
1159 groff -man -rD1 -z file
1160 @end example
1162 @noindent
1163 Check @var{file} with the @option{-man} macro package, forcing
1164 double-sided printing---don't produce any output.
1166 @subsection @code{grog}
1168 @code{grog} reads files and guesses which of the @code{groff}
1169 preprocessors and/or macro packages are are required for formatting
1170 them, and prints the @code{groff} command including those options on the
1171 standard output.  The options generated are one of @option{-e},
1172 @option{-man}, @option{-me}, @option{-mm}, @option{-ms}, @option{-p},
1173 @option{-R}, @option{-g}, @option{-s}, and @option{-t}.
1175 A filename of @samp{-} is taken to refer to the standard input.  If no
1176 files are specified the standard input will be read.  Any specified
1177 options will be included in the printed command.  No space is allowed
1178 between options and their arguments.  For example,
1180 @example
1181 grog -Tdvi paper.ms
1182 @end example
1184 @noindent
1185 will guess the appropriate command to print @file{paper.ms} and then
1186 print it to the command line after adding the @option{-Tdvi} option.
1187 For direct execution, enclose the call to @code{grog} in backquotes on
1188 the @acronym{UNIX} shell prompt:
1190 @example
1191 `grog -Tdvi paper.ms` > paper.dvi
1192 @end example
1194 @noindent
1195 As seen in the example, it is still necessary to redirect the output to
1196 something meaningful (i.e.@: either a file or a pager program like
1197 @code{less}).
1201 @node Tutorial for Macro Users, Macro Packages, Invoking groff, Top
1202 @chapter Tutorial for Macro Users
1203 @cindex tutorial for macro users
1204 @cindex macro tutorial for users
1205 @cindex user's tutorial for macros
1206 @cindex user's macro tutorial
1208 Most users tend to use a macro package to format their papers.  This
1209 means that the whole breadth of @code{groff} is not necessary for most
1210 people.  This chapter covers the material needed to efficiently use a
1211 macro package.
1213 @menu
1214 * Basics::                      
1215 * Common Features::             
1216 @end menu
1219 @node Basics, Common Features, Tutorial for Macro Users, Tutorial for Macro Users
1220 @section Basics
1221 @cindex basics
1223 This section covers some of the basic concepts necessary to understand
1224 how to use a macro package.@footnote{This section is derived from
1225 @cite{Writing Papers with nroff using -me} by Eric P.@w{ }Allman.}
1226 References are made throughout to more detailed information, if desired.
1228 @code{gtroff} reads an input file prepared by the user and outputs a
1229 formatted document suitable for publication or framing.  The input
1230 consists of text, or words to be printed, and embedded commands
1231 (@dfn{requests} and @dfn{escapes}), which tell @code{gtroff} how to
1232 format the output.  For more detail on this @pxref{Embedded Commands}.
1234 The word @dfn{argument} is used in this manual to mean a word or number
1235 which appears on the same line as a request which modifies the meaning
1236 of that request.  For example, the request
1238 @example
1240 @end example
1242 @noindent
1243 spaces one line, but
1245 @example
1246 .sp 4
1247 @end example
1249 @noindent
1250 spaces four lines.  The number@w{ }4 is an argument to the @code{sp}
1251 request which says to space four lines instead of one.  Arguments are
1252 separated from the request and from each other by spaces.  More details
1253 on this can be found in @ref{Request Arguments}.
1255 The primary function of @code{gtroff} is to collect words from input
1256 lines, fill output lines with those words, justify the right hand margin
1257 by inserting extra spaces in the line, and output the result.  For
1258 example, the input:
1260 @example
1261 Now is the time
1262 for all good men
1263 to come to the aid
1264 of their party.
1265 Four score and seven
1266 years ago,...
1267 @end example
1269 @noindent
1270 will be read, packed onto output lines, and justified to produce:
1272 @quotation
1273 Now is the time for all good men to come to the aid of their party.
1274 Four score and seven years ago,...
1275 @end quotation
1277 @cindex break
1278 @cindex line break
1279 Sometimes a new output line should be started even though the current
1280 line is not yet full; for example, at the end of a paragraph.  To do
1281 this it is possible to cause a @dfn{break}, which starts a new output
1282 line.  Some requests cause a break automatically, as do blank input
1283 lines and input lines beginning with a space.
1285 Not all input lines are text to be formatted.  Some of the input lines
1286 are requests which describe how to format the text.  Requests always
1287 have a period (@samp{.}) or an apostrophe (@samp{'}) as the first
1288 character of the input line.
1290 The text formatter also does more complex things, such as automatically
1291 numbering pages, skipping over page boundaries, putting footnotes in the
1292 correct place, and so forth.
1294 Here a few hints for preparing text for input to @code{gtroff}.  First,
1295 keep the input lines short.  Short input lines are easier to edit, and
1296 @code{gtroff} will pack words onto longer lines anyhow.  In keeping with
1297 this, it is helpful to begin a new line after every period, comma, or
1298 phrase, since common corrections are to add or delete sentences or
1299 phrases.  Secondly, do not hyphenate words at the end of
1300 lines---@code{gtroff} is smart enough to hyphenate words for the user as
1301 needed, but is not smart enough to take hyphens out and join a word back
1302 together.  Also, words such as ``mother-in-law'' should not be broken
1303 over a line, since then a space can occur where not wanted, such as
1304 ``@w{mother- in}-law''.
1306 @findex ls
1307 @cindex double spacing
1308 @cindex spacing
1309 @code{gtroff} will double space output text automatically if using the
1310 request @w{@samp{.ls 2}}.  Single spaced mode can be reactivated by
1311 typing @w{@samp{.ls 1}}.
1313 A number of requests allow to change the way the output looks, sometimes
1314 called the @dfn{layout} of the output page.  Most of these requests
1315 adjust the placing of @dfn{white space} (blank lines or spaces).
1317 @findex bp
1318 @cindex new page
1319 The @samp{.bp} request starts a new page.
1321 @findex sp
1322 @cindex blank lines
1323 @cindex empty lines
1324 @cindex lines, empty
1325 The request @w{@samp{.sp @var{N}}} leaves @var{N}@w{ }lines of blank
1326 space.  @var{N}@w{ }can be omitted (meaning skip a single line) or can
1327 be of the form @var{N}i (for @var{N}@w{ }inches) or @var{N}c (for
1328 @var{N}@w{ }centimeters).  For example, the input:
1330 @example
1331 .sp 1.5i
1332 My thoughts on the subject
1334 @end example
1336 @noindent
1337 leaves one and a half inches of space, followed by the line ``My
1338 thoughts on the subject'', followed by a single blank line.
1340 @findex ce
1341 @cindex centering lines
1342 @cindex lines, centering
1343 Text lines can be centered by using the @code{ce} request.  The line
1344 after @code{ce} is centered (horizontally) on the page.  To center more
1345 than one line, use @w{@samp{.ce @var{N}}} (where @var{N} is the number
1346 of lines to center), followed by the @var{N}@w{ }lines.  To center many
1347 lines without counting them, type:
1349 @example
1350 .ce 1000
1351 lines to center
1352 .ce 0
1353 @end example
1355 @noindent
1356 The @w{@samp{.ce 0}} request tells @code{groff} to center zero more
1357 lines, in other words, stop centering.
1359 @findex br
1360 @cindex line break
1361 @cindex break
1362 All of these requests cause a break; that is, they always start a new
1363 line.  To start a new line without performing any other action, use
1364 @code{br}.
1367 @node Common Features,  , Basics, Tutorial for Macro Users
1368 @section Common Features
1369 @cindex common features
1370 @cindex features, common
1372 @code{gtroff} provides very low level operations for formatting a
1373 document.  There are many common routine operations which are done in
1374 all documents.  These common operations are written into @dfn{macros}
1375 and collected into a @dfn{macro package}.
1377 All macro packages provide certain common capabilities which fall into
1378 the following categories.
1380 @subsection Paragraphs
1381 @cindex paragraphs
1383 One of the most common and most used capability is starting a paragraph.
1384 There are a number of different types of paragraphs, any of which can be
1385 initiated with macros supplied by the macro package.  Normally,
1386 paragraphs start with a blank line and the first line indented, like the
1387 text in this manual.  There are also block style paragraphs, which omit
1388 the indentation:
1390 @example
1391 Some   men  look   at  constitutions   with  sanctimonious
1392 reverence, and deem them like the ark of the covenant, too
1393 sacred to be touched.
1394 @end example
1396 @noindent
1397 And there are also indented paragraphs which begin with a tag or label
1398 at the margin and the remaining text indented.
1400 @example
1401 one   This is  the first paragraph.  Notice  how the first
1402       line of  the resulting  paragraph lines up  with the
1403       other lines in the paragraph.
1404 longlabel
1405       This  paragraph   had  a  long   label.   The  first
1406       character of text on the first line will not line up
1407       with  the  text  on  second  and  subsequent  lines,
1408       although they will line up with each other.
1409 @end example
1411 A variation of this is a bulleted list.
1412 @c XXX description
1414 @subsection Sections and Chapters
1416 Most macro packages supply some form of section headers.  The simplest
1417 kind is simply the heading on a line by itself in bold type.  Others
1418 supply automatically numbered section heading or different heading
1419 styles at different levels.  Some, more sophisticated, macro packages
1420 supply macros for starting chapters and appendices.
1422 @subsection Headers and Footers
1424 Every macro package gives some way to manipulate the headers and
1425 footers (or @dfn{titles}) on each page.  Some packages will allow for
1426 different ones on the even and odd pages (for material printed in a book
1427 form).
1429 The titles are called three-part titles, that is, there is a
1430 left-justified part, a centered part, and a right-justified part.  An
1431 automatically generated page number may be put in any of these fields
1432 with the @samp{%} character (@pxref{Page Layout} for more details).
1434 @subsection Page Layout
1436 Most macro packages let thte user specify top and bottom margins and
1437 other details about the appearance of the printed pages.
1439 @subsection Displays
1440 @cindex displays
1442 Displays are sections of text to be set off from the body of the paper.
1443 Major quotes, tables, and figures are types of displays, as are all the
1444 examples used in this document.
1446 @cindex quotes, major
1447 @cindex major quotes
1448 @dfn{Major quotes} are quotes which are several lines long, and hence
1449 are set in from the rest of the text without quote marks around them.
1451 @cindex list
1452 A @dfn{list} is an indented, single spaced, unfilled display.  Lists
1453 should be used when the material to be printed should not be filled and
1454 justified like normal text, such as columns of figures or the examples
1455 used in this paper.
1457 @cindex keep
1458 A @dfn{keep} is a display of lines which are kept on a single page if
1459 possible.  An example for a keep might be a diagram.  Keeps differ from
1460 lists in that lists may be broken over a page boundary whereas keeps
1461 will not.
1463 @cindex keep, floating
1464 @cindex floating keep
1465 Floating keeps move relative to the text.  Hence, they are good for
1466 things which will be referred to by name, such as ``See figure@w{ }3''.
1467 A floating keep will appear at the bottom of the current page if it will
1468 fit; otherwise, it will appear at the top of the next page.  Meanwhile,
1469 the surrounding text will `flow' around the keep, thus leaving now blank
1470 areas.
1472 @subsection Footnotes and annotations
1473 @cindex footnotes
1474 @cindex annotations
1476 There are a number of requests to save text for later printing.
1478 @dfn{Footnotes} are printed at the bottom of the current page.
1480 @cindex delayed text
1481 @dfn{Delayed text} is very similar to a footnote except that it is
1482 printed when called for explicitly.  This allows a list of references to
1483 appear (for example) at the end of each chapter, as is the convention in
1484 some disciplines.
1486 Most macro packages which supply this functionality also supply a means
1487 of automatically numbering either type of annotation.
1489 @subsection Table of Contents
1490 @cindex table of contents
1491 @cindex contents, table of
1493 @dfn{Tables of contents} are a type of delayed text having a tag
1494 (usually the page number) attached to each entry after a row of dots.
1495 The table accumulates throughout the paper until printed, usually after
1496 the paper has ended.  Many macro packages will provide the ability to
1497 have several tables of contents (i.e.@: one standard one, one for
1498 tables, etc).
1500 @subsection Indices
1501 @cindex index
1503 While some macro packages will use the term @dfn{index}, none actually
1504 provide that functionality.  The facilities they call indices are
1505 actually more appropriate for tables of contents.
1507 @subsection Paper formats
1508 @cindex paper formats
1510 Some macro packages provide stock formats for various kinds of
1511 documents.  Many of them provide a common format for the title and
1512 opening pages of a technical paper.  The @option{-mm} macros in
1513 particular provide formats for letters and memoranda.
1515 @subsection Multiple Columns
1517 Some macro packages (except @option{-man}) provide the ability to have
1518 two or more columns on a page.
1520 @subsection Font and Size changes
1522 The built-in font and size functions are not always intuitive, so all
1523 macro packages provide macros to make these operations simpler.
1525 @subsection Predefined Strings
1527 Most macro packages provide various predefined strings for a variety of
1528 uses; examples are sub- and superscripts, printable dates, quotes and
1529 various special characters.
1531 @subsection Preprocessor Support
1533 All macro packages provide support for the various preprocessors.
1535 @subsection Configuration and Customization
1537 Some macro packages provide means of customizing many of details of how
1538 the package behaves.  This ranges from setting the default type size to
1539 changing the appearance of section headers.
1543 @node Macro Packages, Programming Tutorial, Tutorial for Macro Users, Top
1544 @chapter Macro Packages
1545 @cindex macro packages
1546 @cindex packages, macros
1548 This chapter documents the main macro packages that come with
1549 @code{groff}.
1551 @menu
1552 * -man::                        
1553 * -mdoc::                       
1554 * -ms::                         
1555 * -me::                         
1556 * -mm::                         
1557 @end menu
1560 @node -man, -mdoc, Macro Packages, Macro Packages
1561 @section -man
1562 @cindex @option{-man}
1564 @c XXX documentation
1567 @node -mdoc, -ms, -man, Macro Packages
1568 @section -mdoc
1569 @cindex @option{-mdoc}
1571 @c XXX documentation
1574 @node -ms, -me, -mdoc, Macro Packages
1575 @section -ms
1576 @cindex @option{-ms}
1578 @c XXX documentation
1581 @node -me, -mm, -ms, Macro Packages
1582 @section -me
1583 @cindex @option{-me}
1585 @c XXX documentation
1588 @node -mm,  , -me, Macro Packages
1589 @section -mm
1590 @cindex @option{-mm}
1592 @c XXX documentation
1596 @node Programming Tutorial, Preprocessors, Macro Packages, Top
1597 @chapter Programming Tutorial
1598 @cindex programming tutorial
1599 @cindex tutorial for programming
1601 This chapter covers @strong{all} of the facilities of @code{gtroff}.
1602 Users of macro packages may skip it.
1605 @menu
1606 * Text::                        
1607 * Input Conventions::           
1608 * Measurements::                
1609 * Expressions::                 
1610 * Identifiers::                 
1611 * Embedded Commands::           
1612 * Registers::                   
1613 * Manipulating Filling and Adjusting::  
1614 * Manipulating Hyphenation::    
1615 * Manipulating Spacing::        
1616 * Tabs and Fields::             
1617 * Character Translations::      
1618 * Line Layout::                 
1619 * Page Layout::                 
1620 * Page Control::                
1621 * Fonts::                       
1622 * Sizes::                       
1623 * Strings::                     
1624 * Conditionals and Loops::      
1625 * Writing Macros::              
1626 * Page Motions::                
1627 * Drawing Requests::            
1628 * Traps::                       
1629 * Diversions::                  
1630 * Environments::                
1631 * I/O::                         
1632 * Postprocessor Access::        
1633 * Miscellaneous::               
1634 * Debugging::                   
1635 * Implementation Differences::  
1636 * Summary::                     
1637 @end menu
1640 @node Text, Input Conventions, Programming Tutorial, Programming Tutorial
1641 @section Text
1642 @cindex text
1644 @code{gtroff} input files contain text with control commands
1645 interspersed throughout.  But, even without control codes, @code{gtroff}
1646 will still do several things the input text: filling and adjusting,
1647 adding additional space after sentences, hyphenating and inserting
1648 implicit line breaks.
1650 @menu
1651 * Filling and Adjusting::       
1652 * Hyphenation::                 
1653 * Sentences::                   
1654 * Tab Stops::                   
1655 * Implicit Line Breaks::        
1656 @end menu
1658 @node Filling and Adjusting, Hyphenation, Text, Text
1659 @subsection Filling and Adjusting
1660 @cindex filling and adjusting
1661 @cindex adjusting and filling
1663 When @code{gtroff} reads in text it collects words from input and fits
1664 as many of them together on one output line as it can.  This is known as
1665 @dfn{filling}.
1667 Once @code{gtroff} has a @dfn{filled} line it will try to @dfn{adjust}
1668 it.  Which means it will widen the spacing between words until the text
1669 reaches the right margin (in the default adjustment mode).  Extra spaces
1670 between words are preserved, but spaces at the end of lines are ignored.
1671 Spaces at the front of a line will cause a @dfn{break} (breaks will be
1672 explained in @ref{Implicit Line Breaks})
1674 @xref{Manipulating Filling and Adjusting}.
1676 @node Hyphenation, Sentences, Filling and Adjusting, Text
1677 @subsection Hyphenation
1678 @cindex hyphenation
1680 Since the odds of finding a set of words, for every output line, which
1681 will fit nicely on a line without inserting excessive amounts of space
1682 between words is not great, @code{gtroff} will hyphenate words so that
1683 lines can be justified without there being too much space between words.
1684 It uses an internal hyphenation algorithm, to indicate which words can
1685 be hyphenated and how to do so.  When a word is hyphenated the first
1686 part of the word will be added to the current filled line being output
1687 (with an attached hyphen), and the other portion will be added to the
1688 next line to be filled.
1690 @xref{Manipulating Hyphenation}.
1692 @node Sentences, Tab Stops, Hyphenation, Text
1693 @subsection Sentences
1694 @cindex sentences
1696 Although it is often debated, some typesetting rules say there should be
1697 different amounts of space after various punctuation marks.  For example,
1698 a period at the end of a sentence should have twice as much space
1699 following it as would a comma or a period as part of an abbreviation.
1701 @cindex sentence spaces
1702 @cindex spaces between sentences
1703 @cindex french-spacing
1704 @code{gtroff} does this by flagging certain characters (normally
1705 @samp{!}, @samp{?} and @samp{.}) as @dfn{end of sentence} characters.
1706 When @code{gtroff} encounters one of these characters at the end of a
1707 line it will append two @dfn{sentence spaces} in the formatted output.
1708 (Thus, one of the conventions mentioned in @ref{Input Conventions}).
1710 @c XXX also describe how characters like ) are treated here -jjc
1711 @c gotta do some research on this -trent
1713 @node Tab Stops, Implicit Line Breaks, Sentences, Text
1714 @subsection Tab Stops
1715 @cindex tab stops
1716 @cindex stops, tabulator
1718 @code{gtroff} translates @dfn{tabulator stops}, also called @dfn{tabs},
1719 in the input into movements to the next tab stop.  These tab stops are
1720 initially located every half inch across the page.  Using this simple
1721 tables can easily be made.  However, this can often be deceptive as the
1722 appearance (and width) of the text on a terminal and the results from
1723 @code{gtroff} can vary greatly.
1725 Also, a possible sticking point is that lines beginning with tab
1726 characters will still be filled, again producing unexpected results.
1727 For example, the following input
1729 @multitable {12345678} {12345678} {12345678} {12345678}
1730 @item
1731 @tab 1 @tab 2 @tab 3
1732 @item
1733 @tab   @tab 4 @tab 5
1734 @end multitable
1736 @noindent
1737 will produce
1739 @multitable {12345678} {12345678} {12345678} {12345678} {12345678} {12345678} {12345678}
1740 @item
1741 @tab 1 @tab 2 @tab 3 @tab   @tab 4 @tab 5
1742 @end multitable
1744 @xref{Tabs and Fields}.
1746 @node Implicit Line Breaks,  , Tab Stops, Text
1747 @subsection Implicit Line Breaks
1748 @cindex implicit line breaks
1749 @cindex implicit breaks of lines
1750 @cindex line, implicit breaks
1751 @cindex break
1752 @cindex break, implicit
1753 @cindex line break
1755 An important concept in @code{gtroff} is the @dfn{break}.  When a break
1756 occurs, @code{gtroff} will output the partially filled line
1757 (unadjusted), and resume collecting and filling text on the next output
1758 line.
1760 @cindex blank line
1761 @cindex empty line
1762 @cindex line, blank
1763 There are several ways to cause a break in @code{gtroff}.  A blank line
1764 will not only cause a break, but it will also cause a one line vertical
1765 space (effectively a blank line) to be output.
1767 A line which begins with a space will cause a break and the space will
1768 be output at the beginning of the next line.  Note that this space isn't
1769 adjusted, even in fill mode.
1771 The end of file will also cause a break (otherwise the last line of the
1772 document may vanish!)
1774 Certain requests also cause breaks, implicitly or explicity.  This will
1775 be discussed later.
1777 @xref{Manipulating Filling and Adjusting}.
1780 @node Input Conventions, Measurements, Text, Programming Tutorial
1781 @section Input Conventions
1782 @cindex input conventions
1783 @cindex conventions for input
1785 Since @code{gtroff} does filling automatically, it is traditional in
1786 @code{groff} not to try and type things in as nicely formatted
1787 paragraphs.  These are some conventions commonly used when typing
1788 @code{gtroff} text:
1790 @itemize @bullet{}
1791 @item
1792 Break lines after punctuation, particularly at the end of sentences,
1793 and in other logical places.  Keep separate phrases on lines by
1794 themselves, as entire phrases are often added or deleted when editing.
1795 @item
1796 Try to keep lines less than 40-60@w{ }characters, to allow space for
1797 inserting more text.
1798 @item
1799 Do not try to do any formatting in a @acronym{WYSIWYG} manner (i.e.@:
1800 don't try and use spaces to get proper indentation).
1801 @end itemize
1804 @node Measurements, Expressions, Input Conventions, Programming Tutorial
1805 @section Measurements
1806 @cindex measurements
1808 @cindex units of measurement
1809 @cindex basic units
1810 @cindex machine units
1811 @cindex measurement units
1812 @code{gtroff} (like any other programs) requires numeric parameters to
1813 specify various measurements.  Most numeric parameters@footnote{those
1814 that specify vertical or horizontal motion or a type size} may have a
1815 @dfn{measurement unit} attached.  These units are specified as a single
1816 character which immediately follows the number or expression.  Each of
1817 these units are understood, by @code{gtroff}, to be a multiple of its
1818 @dfn{basic unit}.  So, whenever a different measurement unit is
1819 specified @code{gtroff} converts this into its @dfn{basic units}.  This
1820 basic unit, represented by a @samp{u}, is a device dependent measurement
1821 which is quite small, ranging from 1/75th to 1/72000th of an inch; all
1822 other units are converted eventually to basic units.  The values may be
1823 given as fractional numbers---nevertheless, fractional basic units are
1824 always rounded to integers.
1826 Some of the measurement units are completely independent of any of the
1827 current settings (e.g.@: type size) of @code{gtroff}.
1829 @table @code
1830 @item i
1831 @cindex inch
1832 @cindex @code{i} unit
1833 @cindex unit, @code{i}
1834 Inches.  An antiquated measurement unit still in use in certain
1835 backwards countries.  One inch is equal to 2.54@dmn{cm}.
1836 @item c
1837 @cindex centimeter
1838 @cindex @code{c} unit
1839 @cindex unit, @code{c}
1840 Centimeters.  One centimeter is equal to 0.3937@dmn{in}.
1841 @item p
1842 @cindex points
1843 @cindex @code{p} unit
1844 @cindex unit, @code{p}
1845 Points.  This is a typesetter's measurement used for measure type size.
1846 It is 72@w{ }points to an inch.
1847 @item P
1848 @cindex pica
1849 @cindex @code{P} unit
1850 @cindex unit, @code{P}
1851 Pica.  Another typesetting measurement.  6@w{ }Picas to an inch (and
1852 12@w{ }points to a pica).
1853 @item s
1854 @itemx z
1855 @cindex @code{s} unit
1856 @cindex unit, @code{s}
1857 @cindex @code{z} unit
1858 @cindex unit, @code{z}
1859 @xref{Fractional Type Sizes}, for a discussion of these units.
1860 @end table
1862 The other measurements understood by @code{gtroff} are dependent on
1863 settings currently in effect in @code{gtroff}.  These are very useful
1864 for specifying measurements which should look proper with any size of
1865 text.
1867 @table @samp
1868 @item m
1869 @cindex em unit
1870 @cindex @code{m} unit
1871 @cindex unit, @code{m}
1872 Ems.  This unit is equal to the current font size in points.  So called
1873 because it is @emph{approximately} the width of the letter@w{ }@samp{m}
1874 in the current font.
1875 @item n
1876 @cindex en unit
1877 @cindex @code{n} unit
1878 @cindex unit, @code{n}
1879 Ens.  This is half of an em.
1880 @item v
1881 @cindex vertical space
1882 @cindex space, vertical
1883 @cindex @code{v} unit
1884 @cindex unit, @code{v}
1885 Vertical space.  This is equivalent to the current line spacing.
1886 @xref{Sizes}, for more information about this.
1887 @item M
1888 @cindex @code{M} unit
1889 @cindex unit, @code{M}
1890 100ths of an em.
1891 @end table
1893 @xref{Fractional Type Sizes}.
1895 @menu
1896 * Default Units::               
1897 @end menu
1899 @node Default Units,  , Measurements, Measurements
1900 @subsection Default Units
1901 @cindex default units
1902 @cindex units, default
1904 Many requests take a default unit.  While this can be helpful at times,
1905 it can cause strange errors in some expressions.  For example, the line
1906 length request expects em's.  Here are several attempts to get a line
1907 length of 3.5@w{ }inches and the results:
1909 @example
1910 3.5i      @result{}   3.5i
1911 7/2       @result{}   0i
1912 7/2i      @result{}   0i
1913 7i/2      @result{}   .1i
1914 7i/2u     @result{}   3.5i
1915 @end example
1917 @noindent
1918 As shown in the example, the safest way to specify measurements is to
1919 always attach a scaling indicator.
1922 @node Expressions, Identifiers, Measurements, Programming Tutorial
1923 @section Expressions
1924 @cindex expressions
1926 @code{gtroff} has most of operators common to other languages:
1928 @c XXX more details; examples
1930 @itemize @bullet
1931 @item
1932 @cindex arithmetic operators
1933 @cindex operators, arithmetic
1934 @findex +
1935 @findex -
1936 @findex /
1937 @findex *
1938 @findex %
1939 Arithmetic: @samp{+} (addition), @samp{-} (subtraction), @samp{/}
1940 (division), @samp{*} (multiplication), @samp{%} (modulo).
1941 @item
1942 @cindex comparison operators
1943 @cindex operators, comparison
1944 @findex <
1945 @findex >
1946 @findex >=
1947 @findex <=
1948 @findex =
1949 @findex ==
1950 Comparison: @samp{<} (less than), @samp{>} (greater than), @samp{<=}
1951 (less than or equal), @samp{>=} (greater than or equal), @samp{=}
1952 (equal), @samp{==} (the same as @samp{=}).
1953 @item
1954 @cindex logical operators
1955 @cindex operators, logical
1956 @findex &
1957 @findex :
1958 Logical: @samp{&} (logical and), @samp{:} (logical or).
1959 @item
1960 @cindex unary operators
1961 @cindex operators, unary
1962 @findex -
1963 @findex +
1964 @findex !
1965 Unary operators: @samp{-} (negating, i.e.@: changing the sign), @samp{+}
1966 (just for completeness; does nothing in expressions), @samp{!} (logical
1967 not).  See below for the use of unary operators in motion requests.
1968 @c XXX (if/while only??)
1969 @item
1970 @cindex extremum operators
1971 @cindex operators, extremum
1972 @findex >?
1973 @findex <?
1974 Extremum: @samp{>?} (maximum), @samp{<?} (minimum).  For example,
1975 @samp{5>?3} yields@w{ }@samp{5}.
1976 @c XXX add example
1977 @item
1978 @cindex scaling operator
1979 @cindex operator, scaling
1980 Scaling: @code{(@var{c};@var{e})}.  Evaluate @var{e} using @var{c} as
1981 the default scaling indicator.  If @var{c} is missing, ignore scaling
1982 indicators in the evaluation of @var{e}.
1983 @end itemize
1985 @cindex parentheses
1986 @findex (
1987 @findex )
1988 Parentheses may be used as in any other language.  However, in
1989 @code{gtroff} they are necessary to ensure order of evaluation.
1990 @code{gtroff} has no operator precedence; expressions are evaluated left
1991 to right.  This means that @samp{3+5*4} is evaluated as if it were
1992 parenthesized like @samp{(3+5)*4}, not as @samp{3+(5*4)}, as expected.
1994 @findex +
1995 @findex -
1996 @findex |
1997 @cindex motion operators
1998 @cindex operators, motion
1999 For many requests which cause a motion on the page, the unary operators
2000 work differently.  The @samp{+} and @samp{-} operators indicate a motion
2001 relative to the current position (down or up, respectively).  The
2002 @samp{|} operator indicates an absolute position on the page or input
2003 line.
2004 @c XXX (????)
2005 @samp{+} and @samp{-} are also treated differently by the @code{nr}
2006 request.
2007 @c XXX (?), add xref
2009 @cindex space characters in expressions
2010 @cindex expressions and space characters
2011 Due to the way arguments are parsed, spaces are not allowed in
2012 expressions, unless the entire expression is surrounded by parentheses.
2014 @xref{Request Arguments}, and @ref{Conditionals and Loops}.
2017 @node Identifiers, Embedded Commands, Expressions, Programming Tutorial
2018 @section Identifiers
2019 @cindex identifiers
2021 Like any other language, @code{gtroff} has rules for properly formed
2022 @dfn{identifiers}.  In @code{gtroff}, an identifier can be made up of
2023 almost any printable character.  The exception are the following
2024 characters:
2026 @itemize @bullet
2027 @cindex whitespace characters
2028 @cindex newline character
2029 @cindex character, whitespace
2030 @item
2031 Whitespace characters (space, tabs, and newlines).
2032 @cindex character, backspace
2033 @cindex backspace character
2034 @item
2035 Backspace (@code{0x08}) and character code @code{0x01}.
2036 @cindex illegal input characters
2037 @cindex input characters, illegal
2038 @cindex characters, illegal input
2039 @cindex unicode
2040 @item
2041 The following input characters are illegal and will be ignored, causing
2042 a warning message: @code{0x00}, @code{0x0B}, @code{0x0D}-@code{0x1F},
2043 @code{0x80}-@code{0x9F}.  Currently, some of these reserved codepoints
2044 are used internally, thus making it non-trivial to extend @code{gtroff}
2045 to cover Unicode or other character sets resp.@: encodings which use
2046 characters of these ranges.
2048 Note that illegal characters will be removed before parsing; an
2049 identifier `foo', followed by an illegal character, followed by `bar'
2050 will be treated as `foobar'.
2051 @end itemize
2053 For example, any of the following is valid.
2055 @example
2059 end-list
2061 @end example
2063 @findex ]
2064 Note that identifiers longer than two characters with a closing bracket
2065 (@samp{]}) in its name can't be accessed with escape sequences which
2066 expect an identifier as a parameter.
2068 @c XXX xref
2070 @deffn Escape \A ident
2071 Whether an identifier @var{ident} is valid in @code{gtroff} can be
2072 tested with the @code{\A} escape.  It expands to the character@w{ }1
2073 or@w{ }0 according to whether its argument (given in quotes) is or is
2074 not acceptable as the name of a string, macro, diversion, number
2075 register, environment, or font.  It will return@w{ }0 if no argument is
2076 given.  This is useful for looking up user input in some sort of
2077 associative table.
2079 @example
2080 \A'end-list'
2081     @result{} 1
2082 @end example
2083 @end deffn
2085 @c XXX add xrefs above
2087 Identifiers in @code{gtroff} can be any length, but, in some contexts,
2088 @code{gtroff} needs to be told where identifiers end and text begins
2089 (and in different ways depending on their length).
2091 @findex (
2092 @findex [
2093 @findex ]
2094 @itemize @bullet{}
2095 @item
2096 Single character.
2097 @item
2098 Two characters.  Must be prefixed with @samp{(} in some situations.
2099 @item
2100 Arbitrary length (@code{gtroff} only).  Must be bracketed with @samp{[}
2101 and@w{ }@samp{]} in some situations.  Any length identifier can be put
2102 in brackets.
2103 @end itemize
2105 @cindex undefined identifiers
2106 @cindex indentifiers, undefined
2107 Unlike many other programming languages, undefined identifiers are
2108 silently ignored or expanded to nothing.
2110 @c XXX add info about -ww command line option.
2112 @xref{Interpolating Registers}, and @ref{Strings}.
2115 @node Embedded Commands, Registers, Identifiers, Programming Tutorial
2116 @section Embedded Commands
2117 @cindex embedded commands
2118 @cindex commands, embedded
2120 Most documents need more functionality beyond filling, adjusting and
2121 implicit line breaking.  In order to gain further functionality,
2122 @code{gtroff} allows commands to be embedded into the text, in two ways.
2124 The first is a @dfn{request} which takes up an entire line, and does
2125 some large scale operation (e.g.@: break lines, start new pages).
2127 The other is an @dfn{escape} which can be embedded anywhere in the text,
2128 or even as an argument to a request.
2129 @c XXX (Not always?)
2130 Escapes generally do more minor operations like sub- and superscripts,
2131 print a symbol, etc.
2133 @menu
2134 * Requests::                    
2135 * Macros::                      
2136 * Escapes::                     
2137 @end menu
2139 @node Requests, Macros, Embedded Commands, Embedded Commands
2140 @subsection Requests
2141 @cindex requests
2143 @cindex control character
2144 @cindex character, control
2145 @findex '
2146 @findex .
2147 A request line begins with a control character, which is either a single
2148 quote (@samp{'}) or a period (@samp{.}).  These can be changed;
2149 @xref{Character Translations}, for details.  After this there may be
2150 optional tabs or spaces followed by an identifier which is the name of
2151 the request.  This may be followed by any number of space-separated
2152 arguments.
2154 @cindex zero width space character
2155 @cindex character, zero width space
2156 @cindex space character, zero width
2157 @findex \&
2158 To begin a line with a control character without it being interpreted,
2159 precede it with @code{\&}.  This represents a zero width space, which
2160 means it will not affect the output.
2162 In most cases the period is used as a control character.  Several
2163 requests will cause a break; using the single quote control character
2164 will prevent this.
2166 @menu
2167 * Request Arguments::           
2168 @end menu
2170 @node Request Arguments,  , Requests, Requests
2171 @subsubsection Request Arguments
2172 @cindex request arguments
2173 @cindex arguments to requests
2175 Arguments to requests (and macros) are processed much like the shell:
2176 The line is split into arguments according to spaces.  An argument which
2177 is intended to contain spaces can either be enclosed in quotes (single
2178 or double), or have the spaces @dfn{escaped} with backslashes.
2180 @example
2181 .uh The Mouse Problem
2182 .uh "The Mouse Problem"
2183 .uh The\ Mouse\ Problem
2184 @end example
2186 @findex \~
2187 @findex \@key{SP}
2188 @noindent
2189 The first line is the @code{uh} macro being called with 3 arguments,
2190 @samp{The}, @samp{Mouse}, and @samp{Problem}.  The latter two have the
2191 same effect or calling the @code{uh} macro with one argument @samp{The
2192 Mouse Problem}.@footnote{The last solution, i.e., using escaped spaces,
2193 is `classical' in the sense that it can be found in most @code{troff}
2194 documents.  Nevertheless, it is not optimal in all situations since
2195 @samp{\ } inserts a fixed-width space character which can't stretch.
2196 @code{gtroff} provides a different command @code{\~} to insert a
2197 stretchable space.}
2199 @findex ds
2200 Note, however, that the @code{ds} request works differently.
2201 @xref{Strings}, for more details.
2203 @node Macros, Escapes, Requests, Embedded Commands
2204 @subsection Macros
2205 @cindex macros
2207 @code{gtroff} has a @dfn{macro} facility for defining a series of lines
2208 which can be invoked by name.  They are called in the same manner as
2209 requests---arguments also may be passed in the same manner.
2211 @xref{Writing Macros}, and @ref{Request Arguments}.
2213 @node Escapes,  , Macros, Embedded Commands
2214 @subsection Escapes
2215 @cindex escapes
2217 Escapes may occur anywhere in the input to @code{gtroff}.  They begin
2218 with a backslash usually and are followed by a single character which
2219 indicates the function to be performed.  The escape character can be
2220 changed; @xref{Character Translations}.
2222 @findex (
2223 @findex [
2224 @findex ]
2225 Escape sequences which require an identifier as a parameter accept three
2226 possible syntax forms.
2228 @itemize @bullet
2229 @item
2230 The next single character is the identifier.
2231 @item
2232 If this single character is an opening parenthesis, take the following
2233 two characters as the identifier.  Note that there is no closing
2234 parenthesis after the identifier.
2235 @item
2236 If this single character is an opening bracket, take all characters
2237 until a closing bracket as the identifier.
2238 @end itemize
2240 @noindent
2241 Examples:
2243 @example
2245 \n(XX
2246 \*[TeX]
2247 @end example
2249 @findex '
2250 @cindex argument delimiting characters
2251 @cindex characters, argument delimiting
2252 @cindex delimiting characters for arguments
2253 Other escapes may require several arguments and/or some special format.
2254 In such cases the argument is traditionally enclosed in single quotes
2255 (and quotes are always used in this manual for the definitions of the
2256 escape sequences).  The enclosed text is then processed according to
2257 what that escape expects.  Example:
2259 @example
2260 \l'1.5i\(bu'
2261 @end example
2263 @findex \o
2264 @findex \b
2265 @findex \X
2266 Note that the quote character can be replaced with any other character
2267 which does not occur in the argument (even a newline or a space
2268 character) in the following escapes: @code{\o}, @code{\b}, and
2269 @code{\X}.  This makes e.g.
2271 @example
2272 A caf
2277 in Paris
2278   @result{} A caf@'e in Paris
2279 @end example
2281 @noindent
2282 possible, but it is better not to use this feature to avoid confusion.
2284 @findex \%
2285 @findex \@key{SP}
2286 @findex \|
2287 @findex \^
2288 @findex \@{
2289 @findex \@}
2290 @findex \'
2291 @findex \`
2292 @findex \-
2293 @findex \_
2294 @findex \!
2295 @findex \?
2296 @findex \@@
2297 @findex \)
2298 @findex \/
2299 @findex \,
2300 @findex \&
2301 @findex \~
2302 @findex \0
2303 @findex \a
2304 @findex \c
2305 @findex \d
2306 @findex \e
2307 @findex \E
2308 @findex \p
2309 @findex \r
2310 @findex \t
2311 @findex \u
2312 The following escapes sequences (which are handled similar to characters
2313 since they don't take a parameter) are also allowed as delimiters:
2314 @code{\%}, @w{@samp{\ }}, @code{\|}, @code{\^}, @code{\@{}, @code{\@}},
2315 @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!}, @code{\?},
2316 @code{\@@}, @code{\)}, @code{\/}, @code{\,}, @code{\&}, @code{\~},
2317 @code{\0}, @code{\a}, @code{\c}, @code{\d}, @code{\e}, @code{\E},
2318 @code{\p}, @code{\r}, @code{\t}, and @code{\u}.  Again, don't use these
2319 if possible.
2321 @findex \A
2322 @findex \Z
2323 @findex \C
2324 @findex \w
2325 No newline characters as delimiters are allowed in the following
2326 escapes: @code{\A}, @code{\Z}, @code{\C}, and @code{\w}.
2328 @findex \D
2329 @findex \h
2330 @findex \H
2331 @findex \l
2332 @findex \L
2333 @findex \N
2334 @findex \R
2335 @findex \s
2336 @findex \S
2337 @findex \v
2338 @findex \x
2339 Finally, the escapes @code{\D}, @code{\h}, @code{\H}, @code{\l},
2340 @code{\L}, @code{\N}, @code{\R}, @code{\s}, @code{\S}, @code{\v}, and
2341 @code{\x} can't use the following characters as delimiters:
2343 @itemize @bullet
2344 @cindex numbers
2345 @cindex digits
2346 @item
2347 The digits @code{0}-@code{9}.
2348 @cindex operators
2349 @findex +
2350 @findex -
2351 @findex /
2352 @findex *
2353 @findex %
2354 @findex <
2355 @findex >
2356 @findex =
2357 @findex &
2358 @findex :
2359 @findex (
2360 @findex )
2361 @findex .
2362 @item
2363 The (single character) operators @samp{+-/*%<>=&:().}.
2364 @item
2365 @cindex space character
2366 @cindex character, space
2367 @cindex tab character
2368 @cindex character, tab
2369 @cindex newline character
2370 @cindex character, newline
2371 The space, tab, and newline characters.
2372 @findex \%
2373 @findex \@{
2374 @findex \@}
2375 @findex \'
2376 @findex \`
2377 @findex \-
2378 @findex \_
2379 @findex \!
2380 @findex \@@
2381 @findex \/
2382 @findex \c
2383 @findex \e
2384 @findex \p
2385 @item
2386 All escape sequences except @code{\%}, @code{\@{}, @code{\@}},
2387 @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!}, @code{\@@},
2388 @code{\/}, @code{\c}, @code{\e}, and @code{\p}.
2389 @end itemize
2391 @findex \\
2392 @findex \e
2393 @findex \E
2394 To have a backslash appear in the output several escapes are defined:
2395 @code{\\}, @code{\e} or @code{\E}.  These are very similar, and only
2396 differ with respect to being used in macros or diversions.
2397 @xref{Copy-in Mode}, and @ref{Diversions}, for more information.
2399 @xref{Identifiers}.
2401 @menu
2402 * Comments::                    
2403 @end menu
2405 @node Comments,  , Escapes, Escapes
2406 @subsubsection Comments
2407 @cindex comments
2409 Probably one of the most@footnote{Unfortunately, this is a lie.  But
2410 hopefully future @code{gtroff} hackers will believe it :-)} common forms
2411 of escapes is the comment.
2413 @deffn Escape \"
2414 Start a comment.  Everything to the end of the input line is ignored.
2416 This may sound simple, but it can be tricky to keep the comments from
2417 interfering with the appearance of the final output.
2419 @findex ds
2420 If the escape is to the right of some text or a request, that portion of
2421 the line will be ignored, but the space leading up to it will be noticed
2422 by @code{gtroff}.  This only affects the @code{.ds} request.
2423 @c XXX (any others?)
2425 One possibly irritating idiosyncracy is that tabs must not be used to
2426 line up comments.  Tabs are not treated as white space between the
2427 request and macro arguments.
2429 @cindex undefined request
2430 @cindex request, undefined
2431 A comment on a line by itself will be treated as a blank line, because
2432 after eliminating the comment, that is all that remains:
2434 @example
2435 Test
2436 \" comment
2437 Test
2438 @end example
2440 @noindent
2441 will produce
2443 @example
2444 Test
2446 Test
2447 @end example
2449 As a consequence, it is common to start the line with @code{.\"} which
2450 will cause the line to be treated as an undefined request and thus
2451 ignored completely.
2453 Another commenting scheme seen sometimes is three consecutive single
2454 quotes (@code{'''}) at the beginning of a line.  This works, but
2455 @code{gtroff} will give a warning about an undefined macro, which is
2456 harmless, but irritating.
2457 @end deffn
2459 @deffn Escape \#
2460 Now to avoid all this @code{gtroff} has a new comment mechanism using
2461 the @code{\#} escape.  This escape works the same as @code{\"} except
2462 that the newline is also ignored:
2464 @example
2465 Test
2466 \# comment
2467 Test
2468 @end example
2470 @noindent
2471 will produce
2473 @example
2474 Test Test
2475 @end example
2477 @noindent
2478 as expected.
2479 @end deffn
2481 @findex ig
2482 For large blocks of text, the @code{ig} request may be useful.
2483 @xref{Strings}.
2485 @c XXX definition of .ig
2487 @node Registers, Manipulating Filling and Adjusting, Embedded Commands, Programming Tutorial
2488 @section Registers
2489 @cindex registers
2491 Numeric variables in @code{gtroff} are called @dfn{registers}.  There
2492 are a number of built-in registers, supplying anything from the date to
2493 details of formatting parameters.
2495 @xref{Identifiers}, for details on register identifiers.
2497 @menu
2498 * Setting Registers::           
2499 * Interpolating Registers::     
2500 * Auto-increment::              
2501 * Assigning Formats::           
2502 * Built-in Registers::          
2503 @end menu
2505 @node Setting Registers, Interpolating Registers, Registers, Registers
2506 @subsection Setting Registers
2507 @cindex setting registers
2508 @cindex registers, setting
2510 Registers are defined resp.@: set via the @code{nr} request or the
2511 @code{\R} escape.
2513 @deffn Request nr ident value
2514 @deffnx Escape \R ident value
2515 Set number register @var{ident} to @var{value}.  If @var{ident} doesn't
2516 exist, it will be created.
2517 @end deffn
2519 For example, the following two lines are equivalent:
2521 @example
2522 .nr a 1
2523 \R'a 1'
2524 @end example
2526 Both @code{nr} and @code{\N} have two additional special forms to
2527 increment resp.@: decrement a register.
2529 @deffn Request nr ident +value
2530 @deffnx Request nr ident -value
2531 @deffnx Escape \N ident +value
2532 @deffnx Escape \N ident -value
2533 Increment (decrement) register @var{ident} by @var{value}.
2535 @example
2536 .nr a 1
2537 .nr a +1
2539     @result{} 2
2540 @end example
2542 To assign the negated value of a register to another register, some care
2543 must be taken to get the desired result:
2545 @example
2546 .nr a 7
2547 .nr b 3
2548 .nr a -\nb
2550     @result{} 4
2551 .nr a (-\nb)
2553     @result{} -3
2554 @end example
2556 @noindent
2557 The surrounding parentheses prevent the interpretation of the minus sign
2558 as a decrementing operator.
2559 @end deffn
2561 @deffn Request rr ident
2562 Remove number register @var{ident}.
2563 @end deffn
2565 @deffn Request rnn ident1 ident2
2566 Rename number register @var{ident1} to @var{ident2}.
2567 @end deffn
2569 @deffn Request aln ident1 ident2
2570 This request creates an alias @var{ident1} for a number register
2571 @var{ident2}.  The new name and the old name will be exactly equivalent.
2572 If @var{ident1} is undefined, a warning of type @samp{reg} will be
2573 generated, and the request will be ignored.  @xref{Debugging}, for
2574 information about warnings.
2575 @end deffn
2577 @node Interpolating Registers, Auto-increment, Setting Registers, Registers
2578 @subsection Interpolating Registers
2579 @cindex interpolating registers
2580 @cindex registers, interpolating
2582 Numeric registers can be accessed via the @code{\n} escape.
2584 @deffn Escape \n ident
2585 @c XXX is the following correct?
2586 Interpolate number register @var{ident}.  This means that the value of
2587 the register is expanded in-place while @code{gtroff} is parsing the
2588 input line.
2590 @example
2591 .nr a 5
2592 .nr as \na+\na
2593 \n(as
2594     @result{} 10
2595 @end example
2596 @end deffn
2598 @node Auto-increment, Assigning Formats, Interpolating Registers, Registers
2599 @subsection Auto-increment
2600 @cindex auto-increment
2601 @cindex increment, automatic
2603 Number registers can also be auto-incremented and auto-decremented.  The
2604 increment resp.@: decrement factor can be specified with a third
2605 argument to the @code{nr} request or @code{\N} escape.
2607 @deffn Request nr ident value incr
2608 @deffnx Escape \N ident value incr
2609 Set number register @var{ident} to @var{value}; the increment for
2610 auto-incrementing is set to @var{incr}.
2611 @end deffn
2613 To activate auto-incrementing, the escape @code{\n} has a special syntax
2614 form.
2616 @deffn Escape \n +ident
2617 @deffnx Escape \n -ident
2618 Before interpolating, increment resp.@: decrement @var{ident} by the
2619 auto-increment value as specified with the @code{nr} request (or the
2620 @code{\N} escape).  If no auto-increment value has been specified, both
2621 syntax forms are identical to @code{\n}.
2622 @end deffn
2624 For example,
2626 @example
2627 .nr a 0 1
2628 .nr xx 0 -5
2629 .nr foo 0 2
2630 \n+a, \n+a, \n+a, \n+a, \n+a
2632 \n-(xx, \n-(xx, \n-(xx, \n-(xx, \n-(xx
2634 \n+[foo], \n+[foo], \n+[foo], \n+[foo], \n+[foo]
2635 @end example
2637 @noindent
2638 produces
2640 @example
2641 1, 2, 3, 4, 5
2642 -5, -10, -15, -20, -25
2643 2, 4, 6, 8, 10
2644 @end example
2646 To change the increment value without changing the value of a register,
2647 the following can be used.
2649 @example
2650 .nr a \na 10
2651 @end example
2653 @node Assigning Formats, Built-in Registers, Auto-increment, Registers
2654 @subsection Assigning Formats
2655 @cindex assigning formats
2656 @cindex formats, assigning
2658 @findex af
2659 When a register is used in the text of an input file (as opposed to part
2660 of an expression) it is textually replaced (or interpolated) with a
2661 representation of that number.  This output format can be changed to a
2662 variety of formats (numbers, Roman numerals, etc).  This is done using
2663 the @code{af} request.  The first argument to @code{af} is the name of
2664 the number register to be changed, and the second argument is the output
2665 format.  The following output formats are available:
2667 @table @samp
2668 @item 1
2669 This is the default format, decimal numbers: 1, 2, 3,@w{ }@dots{}
2670 @item 0@dots{}01
2671 Decimal numbers with as many leading zeros as specified.  So, @samp{01}
2672 would result in 01, 02, 03,@w{ }@dots{}
2673 @item I
2674 @cindex roman numerals
2675 @cindex numerals, Roman
2676 Upper-case Roman numerals: 0, I, II, III, IV,@w{ }@dots{}
2677 @item i
2678 Lower-case Roman numerals: 0, i, ii, iii, iv,@w{ }@dots{}
2679 @item A
2680 Upper-case letters: A, B, C, @dots{},@w{ }Z, AA, AB,@w{ }@dots{}
2681 @item a
2682 Lower-case letters: a, b, c, @dots{},@w{ }z, aa, ab,@w{ }@dots{}
2683 @end table
2685 The following example will produce @samp{10, X, j, 010}:
2687 @example
2688 .nr a 10
2689 .af a 1           \" the default format
2690 \na,
2691 .af a I
2692 \na,
2693 .af a a
2694 \na,
2695 .af a 001
2697 @end example
2699 @findex \g
2700 The @code{\g} escape returns the current format of the specified
2701 register.  For example, @samp{\ga} after the previous example would
2702 produce the string @samp{001}.  If the register hasn't been defined yet,
2703 nothing is returned.
2705 @node Built-in Registers,  , Assigning Formats, Registers
2706 @subsection Built-in Registers
2707 @cindex built-in registers
2708 @cindex registers, built-in
2710 The following lists some built-in registers which are not described
2711 elsewhere in this manual.  Any register which begin with a @samp{.} is
2712 read-only.  A complete listing of all built-in registers can be found in
2713 @ref{Register Index}.
2715 @table @code
2716 @item .H
2717 @vindex .H
2718 Horizontal resolution in basic units.
2719 @item .V
2720 @vindex .V
2721 Vertical resolution in basic units.
2722 @item dw
2723 @vindex dw
2724 Day of the week (1-7).
2725 @item dy
2726 @vindex dy
2727 Day of the year (1-31).
2728 @item mo
2729 @vindex mo
2730 Current month (1-12).
2731 @item year
2732 @vindex year
2733 The year.
2734 @item yr
2735 @vindex yr
2736 The year minus@w{ }1900.  Unfortunately, the @acronym{UNIX} Version@w{
2737 }7 @code{troff} documentation had a year@w{ }2000 bug: It incorrectly
2738 claimed that @samp{\n(yr} was the last two digits of the year.  That
2739 claim has never been true of either traditional @code{troff} or GNU
2740 @code{troff}.  Old @code{troff} input that looks like this:
2742 @example
2743 '\" The following line stopped working after 1999
2744 This document was formatted in 19\n(yr.
2745 @end example
2747 @noindent
2748 can be corrected as follows:
2750 @example
2751 This document was formatted in \n[year].
2752 @end example
2754 @noindent
2755 or, to be portable to older @code{troff} versions, as follows:
2757 @example
2758 .nr y4 1900+\n(yr
2759 This document was formatted in \n(y4.
2760 @end example
2762 @item .c
2763 @vindex .c
2764 @itemx c.
2765 @vindex c.
2766 The current @emph{input} line number.
2767 @item ln
2768 @vindex ln
2769 The current @emph{output} line number.
2770 @item .x
2771 @vindex .x
2772 The major version number.  For example, if the version number is@w{
2773 }1.03 then @code{.x} will contain@w{ }@samp{1}.
2774 @item .y
2775 @vindex .y
2776 The minor version number.  For example, if the version number is@w{
2777 }1.03 then @code{.y} will contain@w{ }@samp{03}.
2778 @item .Y
2779 @vindex .Y
2780 The revision number of @code{groff}.
2781 @item .g
2782 @vindex .g
2783 Always@w{ }1.  Macros should use this to determine whether they are
2784 running under GNU @code{troff}.
2785 @item .A
2786 @vindex .A
2787 If the current output device is @acronym{ASCII}, this is set to@w{ }1,
2788 zero otherwise.
2789 @item .P
2790 @vindex .P
2791 This register indicates whether the current page is actually being
2792 printed, i.e., whether the @option{-o} option is being used to only
2793 print selected pages.  @xref{Options}, for more information.
2794 @end table
2797 @node Manipulating Filling and Adjusting, Manipulating Hyphenation, Registers, Programming Tutorial
2798 @section Manipulating Filling and Adjusting
2799 @cindex manipulating filling and adjusting
2800 @cindex filling and adjusting, manipulating
2801 @cindex adjusting and filling, manipulating
2802 @cindex justifying text
2803 @cindex text, justifying
2805 @findex br
2806 @cindex break
2807 @cindex line break
2808 Various ways of causing @dfn{breaks} were given in @ref{Implicit Line
2809 Breaks}.  The @code{br} request will likewise cause a break.  Several
2810 other requests will also cause breaks, but implicitly.  They are
2811 @code{bp}, @code{ce}, @code{fi}, @code{fl}, @code{in}, @code{nf},
2812 @code{sp}, and @code{ti}.
2814 @findex nf
2815 @findex fi
2816 @vindex .u
2817 Initially, @code{gtroff} will fill and adjust text to both margins.
2818 Filling can be disabled via the @code{nf} request and re-enabled with
2819 the @code{fi} request.  These implicitly disable and re-enable
2820 adjusting.  Both of these will cause a break in the text currently being
2821 filled.  The number register @code{.u} is equal to@w{ }1 in fill mode
2822 and@w{ }0 in no-fill mode.
2824 @findex ad
2825 @findex na
2826 Adjusting can be disabled with the @code{ad} request and re-enabled with
2827 the @code{na} request.  The @code{ad} request takes a single argument to
2828 indicate how to adjust text.
2830 @table @samp
2831 @item l
2832 @cindex ragged-right
2833 Adjust text to the left margin.  This produces what is traditionally
2834 called ragged-right text.
2835 @item r
2836 @cindex ragged-left
2837 Adjust text to the right margin, producing ragged-left text.
2838 @item c
2839 @cindex centered text
2840 Center filled text.
2841 @c XXX difference to .ce?
2842 @item b
2843 @itemx n
2844 Justify to both margins.  This is default of @code{gtroff}.
2845 @end table
2847 With no argument to @code{ad}, @code{gtroff} will adjust lines the same
2848 way it was the last time it was filling.  For example:
2850 @example
2851 text
2852 .ad r
2853 text
2854 .ad c
2855 text
2857 text
2858 .ad  \" back to centering
2859 text
2860 @end example
2862 @vindex .j
2863 The current adjustment mode is available in the number register
2864 @code{.j}.
2866 @findex \p
2867 The escape @code{\p} will cause a break and the remaining text to be
2868 adjusted.
2870 @cindex word space size
2871 @cindex size of word space
2872 @cindex space between words
2873 @cindex sentence space size
2874 @cindex size of sentence space
2875 @cindex space between sentences
2876 @findex ss
2877 The @code{ss} request changes the minimum size of a space between filled
2878 words.  It takes its units as one twelfth of the space width parameter
2879 for the current font.  Initially both the word space size and the
2880 sentence space size are@w{ }12.
2882 If two arguments are given to the @code{ss} request, the second argument
2883 gives the sentence space size.  If the second argument is not given, the
2884 sentence space size will be the same as the word space size.  The
2885 sentence space size is used in two circumstances: If the end of a
2886 sentence occurs at the end of a line in fill mode, then both an
2887 inter-word space and a sentence space will be added; if two spaces
2888 follow the end of a sentence in the middle of a line, then the second
2889 space will be a sentence space.  Note that the behaviour of
2890 @acronym{UNIX} @code{troff} will be exactly that exhibited by GNU
2891 @code{troff} if a second argument is never given to the @code{ss}
2892 request.  In GNU @code{troff}, as in @acronym{UNIX} @code{troff}, a
2893 sentence should always be followed with either a newline or two spaces.
2895 @vindex .ss
2896 @vindex .sss
2897 The number registers @code{.ss} and @code{.sss} are the values of the
2898 parameters set by the first and second arguments of the @code{ss}
2899 request.
2901 @findex ce
2902 @cindex centering lines
2903 @cindex lines, centering
2904 The @code{ce} request will center text.  While the @w{@samp{ad c}}
2905 request will also center text, it has the side effect of filling the
2906 text.  The @code{.ce} request will not fill the text it affects.  This
2907 request causes a break.
2909 With no arguments, @code{ce} will fill the next line of text.  The
2910 single argument @code{ce} takes is a number indicating the number of
2911 lines to be centered.  If the argument is zero, centering is disabled.
2913 A common idiom is to turn on centering for a large number of lines, and
2914 to turn off centering after text to be centered.  This is useful for any
2915 request which takes a number of lines as an argument.
2917 @example
2918 .ce 1000
2919 replace this
2920 with
2921 something
2922 more interesting
2923 @dots{}
2924 .ce 0
2925 @end example
2927 @vindex .ce
2928 The @code{.ce} number register contains the number of lines remaining to
2929 be centered, as set by the @code{ce} request.
2931 @cindex justifying text
2932 @cindex text, justifying
2933 @cindex right-justifying
2934 @findex rj
2935 @vindex .rj
2936 A similar request is @code{rj} request which will justify unfilled text
2937 to the right margin.  Its arguments are identical to the @code{ce}
2938 request.  The @code{.rj} number register is the number of lines to be
2939 right-justified as set by the @code{rj} request.
2942 @node Manipulating Hyphenation, Manipulating Spacing, Manipulating Filling and Adjusting, Programming Tutorial
2943 @section Manipulating Hyphenation
2944 @cindex manipulating hyphenation
2945 @cindex hyphenation, manipulating
2947 As discussed in @ref{Hyphenation}, @code{gtroff} will hyphenate words.
2948 There are a number of ways to influence how hyphenation is done.
2950 @findex nh
2951 @findex hy
2952 @vindex .hy
2953 Hyphenation can be turned off with the @code{nh} request, and turned
2954 back on with the @code{hy} request.  However, the hyphenation facilities
2955 of @code{gtroff} are far more flexible than this.  The @code{hy} request
2956 can be used to tell @code{gtroff} to restrict hyphenation to certain
2957 cases.  The request takes a single numeric argument.  The current
2958 hyphenation restrictions can be found in the number register @code{.hy}.
2960 @table @samp
2961 @item 1
2962 The default argument, which indicates to hyphenate without restrictions.
2963 @item 2
2964 Do not hyphenate the last word on a page or column.
2965 @item 4
2966 Do not hyphenate the last two characters of a word.
2967 @item 8
2968 Do not hyphenate the first two characters of a word.
2969 @end table
2971 The values in the previous table are additive.  For example, the
2972 value@w{ }12 causes @code{gtroff} to neither hyphenate the last two nor
2973 the first two characters of a word.
2975 @findex hlm
2976 @vindex .hlc
2977 @vindex .hlm
2978 @findex \%
2979 @cindex explicit hyphens
2980 @cindex hyphen, explicit
2981 The @code{hlm} request will set the maximum number of consecutive
2982 hyphenated lines to the value given as the first argument.  If this
2983 number is negative, there is no maximum.  The default value is@w{ }-1.
2984 This value is associated with the current environment.  Only lines
2985 output from an environment count towards the maximum associated with
2986 that environment.  Hyphens resulting from @code{\%} are counted;
2987 explicit hyphens are not.  The current setting of this is available in
2988 the @code{.hlm} register.  Also the number of immediately preceding
2989 consecutive hyphenated lines are available in the number register
2990 @code{.hlc}.
2992 @findex hw
2993 The @code{hw} request specifies how a specific word is to be hyphenated.
2994 It takes only one argument which is the word with hyphens at the
2995 hyphenation points.  For example:
2997 @example
2998 .hw in-sa-lub-rious
2999 @end example
3001 @noindent
3002 This request can be used more than once.
3004 @c XXX
3005 @c In old versions of troff there was a
3006 @c limited amount of space to store such information, fortunately,
3007 @c with groff, this is no longer a restriction.
3009 @findex \%
3010 @cindex hyphenation character
3011 @cindex character, hyphenation
3012 @cindex disabling hyphenation
3013 @cindex hyphenation, disabling
3014 To tell @code{gtroff} how to hyphenate words on the fly, the @code{\%}
3015 escape, also known as the @dfn{hyphenation character}, can be used.
3016 Preceding a word with this character will prevent it from being
3017 hyphenated, putting it in a word will indicate to @code{gtroff} that the
3018 word may be hyphenated at that point.  Note that this mechanism will
3019 only affect one word; to change the hyphenation of a word for the entire
3020 document, use the @code{hw} request.
3022 @findex hc
3023 The @code{hc} request changes the hyphenation character.  The character
3024 specified as an argument will then work the same as the @code{\%}
3025 escape, and, thus, no longer appear in the output.  Without an argument
3026 it will return the hyphenation character to @code{\%}.
3028 @cindex hyphenation patterns
3029 @cindex pattern for hyphenation
3030 @findex hpf
3031 To further customize hyphenation the @code{hpf} request will read in a
3032 file of hyphenation patterns.  This file will be searched for in the
3033 same way that @file{tmac.@var{name}} is searched for when the
3034 @option{-m@var{name}} option is specified.
3036 It should have the same format as the argument to the @code{\patterns}
3037 primitive in @TeX{}; the letters appearing in this file are interpreted
3038 as hyphenation codes.  A @samp{%} character in the patterns file
3039 introduces a comment that continues to the end of the line.
3041 @findex hla
3042 @findex hpf
3043 @pindex troffrc
3044 @pindex troffrc-end
3045 The set of hyphenation patterns is associated with the current language
3046 set by the @code{hla} request.  The @code{hpf} request is usually
3047 invoked by the @file{troffrc} or @file{troffrc-end} file.
3049 @findex hcode
3050 The @code{hcode} request has the following syntax:
3052 @example
3053 .hcode @var{c1 code1 c2 code2...}
3054 @end example
3056 It sets the hyphenation code of character @var{c1} to @var{code1} and
3057 that of @var{c2} to @var{code2}.  A hyphenation code must be a single
3058 input character (not a special character) other than a digit or a space.
3059 Initially each lower-case letter has a hyphenation code, which is
3060 itself, and each upper-case letter has a hyphenation code which is the
3061 lower-case version of itself.
3063 @cindex hyphenation margin
3064 @cindex margin for hyphenation
3065 @findex hym
3066 @vindex .hym
3067 The @code{hym} request will set the hyphenation margin to the value
3068 given as its argument: when the current adjustment mode is not@w{
3069 }@samp{b}, the line will not be hyphenated if the line is no more than
3070 that amount short.  The default hyphenation margin is@w{ }0.  The
3071 default scaling indicator for this request is@w{ }m.  The hyphenation
3072 margin is associated with the current environment.  The current
3073 hyphenation margin is available in the @code{.hym} register.
3075 @cindex hyphenation space
3076 @findex hys
3077 @vindex .hys
3078 The @code{hys} request sets the hyphenation space to the value given as
3079 the first argument: when the current adjustment mode is@w{ }@samp{b},
3080 don't hyphenate the line if the line can be justified by adding no more
3081 than that amount of extra space to each word space.  The default
3082 hyphenation space is@w{ }0.  The default scaling indicator for this
3083 request is@w{ }m.  The hyphenation space is associated with the current
3084 environment.  The current hyphenation space is available in the
3085 @code{.hys} register.
3087 @cindex soft hyphen character
3088 @cindex character, soft hyphen
3089 @findex shc
3090 The @code{shc} request will set the soft hyphen character to the
3091 character given as an argument.  If the argument is omitted, the soft
3092 hyphen character will be set to the default character @code{\(hy}.  The
3093 soft hyphen character is the character which will be inserted when a
3094 word is hyphenated at a line break.  If the soft hyphen character does
3095 not exist in the font of the character immediately preceding a potential
3096 break point, then the line will not be broken at that point.  Neither
3097 definitions (specified with the @code{char} request) nor translations
3098 (specified with the @code{tr} request) are considered when finding the
3099 soft hyphen character.
3101 @findex hla
3102 @findex hpf
3103 @findex hw
3104 @vindex .hla
3105 @pindex troffrc
3106 @pindex troffrc-end
3107 The @code{hla} request will set the current hyphenation language to that
3108 given by the first argument.  Hyphenation exceptions specified with the
3109 @code{hw} request and hyphenation patterns specified with the @code{hpf}
3110 request are both associated with the current hyphenation language.  The
3111 @code{hla} request is usually invoked by the @file{troffrc} or the
3112 @file{troffrc-end} files.  The current hyphenation language is available
3113 in the number register @code{.hla}.
3116 @node Manipulating Spacing, Tabs and Fields, Manipulating Hyphenation, Programming Tutorial
3117 @section Manipulating Spacing
3118 @cindex manipulating spacing
3119 @cindex spacing, manipulating
3121 @findex sp
3122 The @code{sp} request will cause @code{gtroff} to space downwards the
3123 distance specified as the first argument.  With no argument it will
3124 advance 1@w{ }line.  A negative argument will cause @code{gtroff} to
3125 move up the page the specified distance.  If the argument is preceded by
3126 a @samp{|} @code{gtroff} will move that distance from the top of the
3127 page.
3129 @cindex double-spacing
3130 @findex ls
3131 @vindex .L
3132 For double or triple spaced output use @code{ls}.  This request causes
3133 @code{troff} to output @var{n}-1 blank lines after each line of text,
3134 where @var{n} is the argument given to the @code{ls} request.  With no
3135 argument @code{gtroff} will go back to single spacing.  The number
3136 register @code{.L} contains the current line spacing setting.
3138 @findex \x
3139 @vindex .a
3140 Sometimes, extra vertical spacing is only needed occasionally, i.e.@: to
3141 allow space for a tall construct (like an equation).  The @code{\x}
3142 escape will do this.  The escape is given a numerical argument (like
3143 @samp{\x'3p'}).  If this number is positive extra vertical space will be
3144 inserted below the current line.  A negative number will add space
3145 above.  If this escape is used multiple times on the same line, the
3146 maximum of the values is used.  The @code{.a} number register contains
3147 the most recent (nonnegative) extra vertical line space.
3149 @c XXX
3150 @example
3151 ... example of inline equation ...
3152 @end example
3154 @findex ns
3155 @findex rs
3156 @cindex no-space mode
3157 @cindex mode, no-space
3158 Spacing (either via @code{sp} or via blank lines) can be disabled with
3159 the @code{ns} request.  This will enable @dfn{no-space mode}.  This mode
3160 will end when actual text is output or the @code{rs} request is
3161 encountered.  No-space mode will also prevent requests to advance to the
3162 next page unless they are accompanied by a page number (@pxref{Page
3163 Control}, for more information).
3166 @node Tabs and Fields, Character Translations, Manipulating Spacing, Programming Tutorial
3167 @section Tabs and Fields
3168 @cindex tabs and fields
3169 @cindex fields and tabs
3171 @findex \t
3172 Tab stops are much like those on a typewriter: a tab character (or the
3173 @code{\t} escape) on input will cause horizontal motion to the next tab
3174 stop.
3176 @findex ta
3177 Tab stops can be changed with the @code{ta} request.  This request takes
3178 a series of numbers as arguments which indicate where each tab stop is
3179 to be (overriding any previous settings).  These can be specified
3180 absolutely, i.e.@: as the distance from the left margin.  For example,
3181 the following will set tab stops every one inch.
3183 @example
3184 .ta 1i 2i 3i 4i 5i 6i
3185 @end example
3187 Tab stops can also be specified relatively (using a leading @samp{+})
3188 which means that the specified tab stop will be set that distance from
3189 the previous tab stop.  For example, the following is equivalent to the
3190 previous example.
3192 @example
3193 .ta 1i +1i +1i +1i +1i +1i
3194 @end example
3196 After the specified tab stops repeat values may be set for tabs beyond
3197 the last one specified.  This is most commonly used to specify tabs set
3198 at equal intervals.  The complete syntax for setting tabs is
3200 @example
3201 ta @var{n1} @var{n2} @dots{} @var{nn} T @var{r1} @var{r2} @dots{} @var{rn}
3202 @end example
3204 @noindent
3205 This will set tabs at positions @var{n1}, @var{n2}, @dots{}, @var{nn}
3206 and then set tabs at @var{nn}+@var{r1}, @var{nn}+@var{r2}, @dots{},
3207 @var{nn}+@var{rn} and then at @var{nn}+@var{rn}+@var{r1},
3208 @var{nn}+@var{rn}+@var{r2}, @dots{}, @var{nn}+@var{rn}+@var{rn}, and so
3209 on.  For example the following is, yet again, the same as the previous
3210 examples.
3212 @example
3213 .ta T 1i
3214 @end example
3216 The material in each tab column may be justified to the right or left
3217 or centered in the column.  This is specified by appending an
3218 @samp{R}, @samp{L} or @samp{C} to the number specifying that tab stop.
3219 The default justification is @samp{L}.  Example:
3221 @example
3222 .ta 1i 2iC 2iR
3223 @end example
3225 @vindex .tabs
3226 The number register @code{.tabs} contains a string representation of the
3227 current tab settings suitable for use as an argument to the @code{ta}
3228 request.
3230 @findex tc
3231 Normally @code{gtroff} will fill the space to the next tab stop with
3232 spaces.  This can be change with the @code{tc} request.  With no
3233 argument @code{gtroff} will revert to using spaces.
3235 @subsection Leaders
3236 @cindex leaders
3238 @findex lc
3239 Sometimes it may may be desirable to use the @code{tc} request to fill a
3240 particular tab stop with a given character, but also normal tab stops on
3241 the rest of the line.  For this @code{gtroff} provides an alternate tab
3242 mechanism, called @dfn{leaders} which will do just that.  They are used
3243 exclusively to produce a repeated run of characters to the next tab
3244 stop.
3246 The character that will be repeated can be declared with the @code{lc}
3247 request.  Without an argument, the leaders will act the same as tabs.
3249 @findex \a
3250 Leader are invoked by using the @code{\a} escape while specifying the
3251 @code{ta} request.
3253 @cindex table of contents
3254 @cindex contents, table of
3255 For a table of contents, to name an example, tab stops may be defined so
3256 that the section number is one tab stop, the title is the second with
3257 the remaining space being filled with a line of dots, and then the page
3258 number slightly separated from the dots.
3260 @example
3261 .lc .
3262 .ta .5iR 5i +.25i
3263 1.1\tFoo\a\t12
3264 @end example
3266 @subsection Fields
3267 @cindex fields
3269 @findex fc
3270 Fields are a more general way of laying out tabular data.
3272 @code{fc}
3274 @c XXX add explanation
3276 @node Character Translations, Line Layout, Tabs and Fields, Programming Tutorial
3277 @section Character Translations
3278 @cindex character translations
3279 @cindex translations of characters
3281 @findex cc
3282 @findex c2
3283 @findex .
3284 @findex '
3285 The control character (@samp{.}) and the no-break control character
3286 (@samp{'}) can be changed with the @code{cc} and @code{c2} requests,
3287 respectively.  The single argument is the new character to be used.
3288 With no argument the normal control character is restored.
3290 @findex ec
3291 @findex eo
3292 The @code{eo} request will completely disable the escape mechanism.  The
3293 @code{ec} request can be used to change the escape character from the
3294 default @samp{\} to what is specified as an argument.  It can be also
3295 used to re-enable the escape mechanism after an @code{eo} request.
3297 @findex tr
3298 The @code{tr} request will translate characters.
3300 @c XXX more info
3302 @findex trnt
3303 @findex \!
3304 @code{trnt} is the same as the @code{tr} request except that the
3305 translations do not apply to text that is transparently throughput into
3306 a diversion with @code{\!}.  @xref{Diversions}, for more information.
3307 For example,
3309 @example
3310 .tr ab
3311 .di x
3312 \!.tm a
3315 @end example
3317 @noindent
3318 will print @samp{b}; if @code{trnt} is used instead of @code{tr} it will
3319 print @samp{a}.
3322 @node Line Layout, Page Layout, Character Translations, Programming Tutorial
3323 @section Line Layout
3324 @cindex line layout
3325 @cindex layout, line
3327 @cindex dimensions, line
3328 @cindex line dimensions
3329 The following drawing shows the dimensions which @code{gtroff} uses for
3330 placing a line of output onto the page.  They are labeled with the
3331 request which manipulates that dimension.
3333 @example
3334 @group
3335               | -->| in |<--                   |
3336            -->| po |<-----------ll------------>|
3337               +----+----+----------------------+----+
3338               |    :    :                      :    |
3339               +----+----+----------------------+----+
3340 @end group
3341 @end example
3343 @noindent
3344 These dimensions are:
3346 @ftable @code
3347 @item po
3348 @cindex left margin
3349 @cindex margin, left
3350 @cindex page offset
3351 @cindex offset, page
3352 @vindex .o
3353 @dfn{Page offset}--This is the leftmost position of text on the final
3354 output, defining the @dfn{left margin}.  It can be adjusted with the
3355 @code{po} request, and the current setting can be found in the built-in
3356 number register @code{.o}.  Note that this request does not cause a
3357 break, so changing the page offset in the middle of text being filled
3358 may not yield the expected result.
3359 @item in
3360 @cindex indentation
3361 @cindex line indentation
3362 @vindex .i
3363 @dfn{Indentation}--This is the distance from the left margin where text
3364 will be printed.  This can be adjusted with the @code{in} request, and
3365 the current setting can be found in the built-in number register.
3366 @code{.i}.  This request causes a break.
3368 @findex ti
3369 @vindex .in
3370 There is also the request @code{ti} which will cause one output line to
3371 be indented, after which the indentation returns to@w{ }0.  This request
3372 causes a break.  The number register @code{.in} is the indent that
3373 applies to the current output line.
3374 @item ll
3375 @cindex line length
3376 @cindex length of line
3377 @vindex .l
3378 @vindex .ll
3379 @dfn{Line length}--This is the distance from the left margin to right
3380 margin.  This can be adjusted with the @code{ll} request, and the
3381 current setting can be found in the built-in number register @code{.l}
3382 Note, as the figure implies, line length is not affected by the current
3383 indentation.  The number register @code{.ll} is the line length that
3384 applies to the current output line.
3385 @end ftable
3387 @example
3388 .in +.5i
3389 .ll -.5i
3390 A bunch of really boring text which should
3391 be indented from both margins.
3392 Replace me with a better (and more) example!
3393 .in -.5i
3394 .ll +.5i
3395 @end example
3398 @node Page Layout, Page Control, Line Layout, Programming Tutorial
3399 @section Page Layout
3400 @cindex page layout
3401 @cindex layout, page
3403 @code{gtroff} provides some very primitive operations for controlling
3404 page layout.
3406 @cindex page length
3407 @cindex length of page
3408 @findex pl
3409 @vindex .p
3410 The @dfn{page length} can be specified via the @code{pl} request.  This
3411 is the length of the physical output page.  The current setting can be
3412 found in the built-in number register @code{.p}.  Note that this only
3413 specifies the size of the page, not the top and bottom margins.  Those
3414 are not done by groff directly.  @xref{Traps}, for further information
3415 on how to do this.
3417 @cindex headers
3418 @cindex footers
3419 @cindex titles
3420 @code{gtroff} provides several operations which help in setting up top
3421 and bottom titles (or headers and footers)
3423 @cindex title line
3424 @cindex three-part title
3425 @findex tl
3426 @findex %
3427 The @code{tl} request will print a @dfn{title line}, which consists of
3428 three parts: a left justified portion, a centered portion and a right
3429 justified portion.  The argument to @code{tl} is specified as
3430 @code{'@var{left}'@var{center}'@var{right}'}.  The @samp{%} character is
3431 replaced with the current page number.  This character can be changed
3432 with the @code{pc} request (see below).
3434 @cindex length of title line
3435 @cindex title line, length
3436 @findex lt
3437 @vindex .lt
3438 The title line is printed using its own line length, which is specified
3439 with the @code{lt} request.  The current setting of this is available in
3440 the @code{.lt} number register.
3442 @cindex page number
3443 @cindex number, page
3444 @findex pn
3445 The @code{pn} request will change the page number of the @emph{next}
3446 page.  The only argument is the page number.
3448 @vindex %
3449 @vindex .pn
3450 The current page number is stored in the number register @code{%}.  The
3451 number register @code{.pn} contains the number of the next page: either
3452 the value set by a @code{pn} request, or the number of the current page
3453 plus@w{ }1.
3455 @cindex changing the page number character
3456 @cindex page number character, changing
3457 @findex pc
3458 The @code{pc} request will change the page number character (used by the
3459 @code{tl} request) to a different character.  With no argument, this
3460 mechanism is disabled.
3462 @xref{Traps}.
3465 @node Page Control, Fonts, Page Layout, Programming Tutorial
3466 @section Page Control
3467 @cindex page control
3468 @cindex control, page
3470 @findex bp
3471 @findex pn
3472 To stop processing the current page, and move to the next page, invoke
3473 the @code{bp} request.  This request will also cause a break.  It can
3474 also take an argument of what the next page should be numbered.  The
3475 only difference between @code{bp} and @code{pn} is that @code{pn} does
3476 not cause a break or actually eject a page.
3478 @example
3479 .de newpage
3481 'sp .5i
3482 .tl 'left top'center top'right top'
3483 'sp .3i
3485 @end example
3487 @cindex orphan
3488 @findex ne
3489 It is often necessary to force a certain amount of space before a new
3490 page occurs.  This is most useful to make sure that there is not a
3491 single @dfn{orphan} line left at the bottom of a page.  The @code{ne}
3492 request will ensure that there is a certain distance, specified by the
3493 first argument, before the next page is triggered (@pxref{Traps}, for
3494 further information).  The default unit for @code{ne} is @code{v} and
3495 the default argument is@w{ }1@dmn{v}.
3497 For example, to make sure that no fewer than 2@w{ }lines get orphaned,
3498 do the following before each paragraph:
3500 @example
3501 .ne 2
3502 .ti +5n
3503 text
3504 @end example
3506 @findex sv
3507 @findex os
3508 @findex ne
3509 @code{sv} is similar to the @code{ne} request; it reserves the specified
3510 amount of vertical space.  If the desired amount of space exists before
3511 the next trap (bottom page boundary), the space will be output
3512 immediately.  If there is not enough space, it is stored for later
3513 output via the @code{os} request.  The default argument is@w{ }1@dmn{v}
3514 and the default unit is @code{v}.
3517 @node Fonts, Sizes, Page Control, Programming Tutorial
3518 @section Fonts
3519 @cindex fonts
3521 @findex ft
3522 @findex \f
3523 @code{gtroff} has the ability to switch fonts at any point in the text.
3524 There are two ways to do this, via the @code{ft} request and the
3525 @code{\f} escape.
3527 Fonts are generally specified as upper-case strings, which are usually
3528 1@w{ }to 4 characters representing an abbreviation or acronym of the font
3529 name.
3531 The basic set of fonts are @samp{R}, @samp{I}, @samp{B}, and @samp{BI}.
3532 These are Times Roman, Italic, Bold, and Bold Italic.  There is also at
3533 least one symbol font which contains various special symbols (Greek,
3534 mathematics).  Such symbols fonts cannot be used directly, but should be
3535 used via an escape.
3537 @menu
3538 * Changing Fonts::              
3539 * Font Families::               
3540 * Font Positions::              
3541 * Using Symbols::               
3542 * Artificial Fonts::            
3543 * Ligatures and Kerning::       
3544 @end menu
3546 @node Changing Fonts, Font Families, Fonts, Fonts
3547 @subsection Changing Fonts
3548 @cindex changing fonts
3549 @cindex fonts, changing
3551 @findex ft
3552 @cindex previous font
3553 @cindex font, previous
3554 Font changes can be done either with the @code{ft} request or the
3555 @code{\f} request.  With no arguments it will switch to the previous
3556 font (also known as @samp{P}).
3558 @example
3559 eggs, bacon,
3560 .ft B
3561 spam
3563 and sausage.
3564 @end example
3566 @findex \f
3567 The @code{\f} escape is useful for changing fonts in the middle of
3568 words:
3570 @example
3571 eggs, bacon, \fBspam\fP and sausage.
3572 @end example
3574 @noindent
3575 Both of the above examples will produce the same output.  Note the usage
3576 of @samp{P} to indicate the previous font---using @code{\f} it is not
3577 possible to omit this parameter.
3579 Sometimes when putting letters of different fonts, more or less space at
3580 such boundaries are needed.  There are two escapes to help with this.
3582 @findex \/
3583 @cindex italic correction
3584 @cindex correction, italic
3585 The @code{\/} escape increases the width of the preceding character so
3586 that the spacing between that character and the following character will
3587 be correct if the following character is a Roman character.  For
3588 example, if an italic@w{ }f is immediately followed by a Roman right
3589 parenthesis, then in many fonts the top right portion of the f will
3590 overlap the top left of the right parenthesis.  It is a good idea to use
3591 this escape sequence whenever an italic character is immediately
3592 followed by a Roman character without any intervening space.  This small
3593 amount of space is also called @dfn{italic correction}.
3595 @c XXX example
3596 @c producing @i{f}), which is ugly.  Inserting \/ produces f) and avoids
3597 @c this problem.
3599 @findex \,
3600 @cindex left italic correction
3601 @cindex correction, left italic
3602 The @code{\,} escape modifies the spacing of the following character so
3603 that the spacing between that character and the preceding character will
3604 be correct if the preceding character is a Roman character.  It is a
3605 good idea to use this escape sequence whenever a Roman character is
3606 immediately followed by an italic character without any intervening
3607 space.  In analogy to above, this space could be called @dfn{left italic
3608 correction}, but this term isn't used widely.
3610 @c XXX example
3611 @c For example, inserting \, between the parenthesis and the f changes
3612 @c (f to (f.
3614 @findex ftr
3615 @findex ft
3616 @findex ul
3617 @findex bd
3618 @findex \f
3619 @findex cs
3620 @findex tkf
3621 @findex special
3622 @findex fspecial
3623 @findex fp
3624 @findex code
3625 The @code{ftr} request will translate fonts; its syntax is
3627 @example
3628 .ftr @var{F} @var{G}
3629 @end example
3631 @noindent
3632 which translates font@w{ }@var{F} to font@w{ }@var{G}.  Whenever a font
3633 named @var{F} is referred to in a @code{\f} escape sequence, or in the
3634 @code{ft}, @code{ul}, @code{bd}, @code{cs}, @code{tkf}, @code{special},
3635 @code{fspecial}, @code{fp}, or @code{code} requests, font@w{ }@var{G} will
3636 be used.  If @var{G} is missing, or equal to @var{F} then font@w{
3637 }@var{F} will not be translated.
3639 @node Font Families, Font Positions, Changing Fonts, Fonts
3640 @subsection Font Families
3641 @cindex font families
3642 @cindex families, font
3644 Due to the variety of fonts available, @code{gtroff} has added the
3645 concept of font families.  Each of these families has four styles
3646 (@samp{R}, @samp{I}, @samp{B} and @samp{BI}).
3648 The fonts are specified as the concatenation of the font family and
3649 style.  Specifying a font without the family part will cause
3650 @code{gtroff} to use that style of the current family.  By default,
3651 @code{gtroff} uses the Times family.
3653 This way, it is possible to use the basic four fonts and to select a
3654 different font family on the command line.
3656 @findex fam
3657 @vindex .fam
3658 Font families can be switched with the @code{fam} request.  The current
3659 font family is available in the number register @code{.fam}.  This is a
3660 string-valued register.
3662 @example
3663 spam,
3664 .fam H
3665 spam,
3666 .ft B
3667 spam,
3668 .fam T
3669 spam,
3670 .ft AR
3671 baked beans,
3672 .ft R
3673 and spam.
3674 @end example
3676 @node Font Positions, Using Symbols, Font Families, Fonts
3677 @subsection Font Positions
3678 @cindex font positions
3679 @cindex positions, font
3681 For the sake of old phototypesetters and compatability with old versions
3682 of @code{troff}, @code{gtroff} has the concept of font @dfn{positions},
3683 on which various fonts are mounted.  The last one or two are reserved
3684 for the symbol font(s).
3686 @findex fp
3687 New fonts can be mounted with the @code{fp} request.  These numeric
3688 positions can then be referred to with font changing commands.  When
3689 @code{gtroff} starts it is using font number one.
3691 @example
3692 .fp 1 H
3693 .fp 2 HI
3694 .fp 3 HB
3695 wink, wink,
3696 .ft 2
3697 nudge, nudge,
3699 .ft 3
3700 say no more!
3702 @end example
3704 @noindent
3705 Note that after these font changes have taken place the original font
3706 is restored.
3708 @vindex .f
3709 The current font in use, as a font position, is available in number
3710 register @code{.f}.  This can be useful to remember the current font,
3711 for later recall.
3713 @example
3714 .nr save-font \n(.f
3715 ... lots 'o text ...
3716 .ft \n[save-font]
3717 @end example
3719 @vindex .fp
3720 The number of the next free font position is available in the number
3721 register @code{.fp}.  This is useful when mounting a new font, like so:
3723 @example
3724 .fp \n[.fp] NEATOFONT
3725 @end example
3727 @pindex DESC
3728 Fonts not listed in the @file{DESC} file are automatically mounted on
3729 the next available font position when they are referenced.  If a font is
3730 to be mounted explicitly with the @code{fp} request on an unused font
3731 position, it should be mounted on the first unused font position, which
3732 can be found in the @code{.fp} register.  Although @code{gtroff} does
3733 not enforce this strictly, it will not allow a font to be mounted at a
3734 position whose number is much greater than that of any currently used
3735 position.
3737 @findex fp
3738 The @code{fp} request has an optional third argument.  This argument
3739 gives the external name of the font, which is used for finding the font
3740 description file.  The second argument gives the internal name of the
3741 font which is used to refer to the font in @code{gtroff} after it has
3742 been mounted.  If there is no third argument then the internal name will
3743 be used as the external name.  This feature make it possible to use
3744 fonts with long names in compatibility mode.
3746 @node Using Symbols, Artificial Fonts, Font Positions, Fonts
3747 @subsection Using Symbols
3748 @cindex using symbols
3749 @cindex symbols, using
3751 @findex \(
3752 @findex \[
3753 Symbols can be inserted by using a special escape sequence.  This escape
3754 is simply the escape character (usually a backslash) followed by an
3755 identifier.  The symbol identifiers have to be two or more characters,
3756 since single characters conflict with all the other escapes.  The
3757 identifier can be either preceded by a parenthesis if it is two
3758 characters long, or surrounded by square brackets.  So, the symbol for
3759 the mathematical Greek letter `pi' can be produced either by @code{\(*p}
3760 or @code{\[*p]}.
3762 @example
3763 area = \(*p\fIr\fP\u2\d
3764 @end example
3766 @findex \C
3767 The escape @code{\C'@var{xxx}'} will typeset the character named
3768 @var{xxx}.  Normally it is more convenient to use @code{\[@var{xxx}]}.
3769 But @code{\C} has the advantage that it is compatible with recent
3770 versions of @code{ditroff} and is available in compatibility mode.
3772 @findex \N
3773 @findex char
3774 The escape @code{\N'@var{n}'} will typeset the character with code@w{
3775 }@var{n} in the current font.  @var{n} can be any integer.  Most devices
3776 only have characters with codes between 0 and@w{ }255.  If the current
3777 font does not contain a character with that code, special fonts will
3778 @emph{not} be searched.  The @code{\N} escape sequence can be
3779 conveniently used on conjunction with the @code{char} request:
3781 @example
3782 .char \[phone] \f(ZD\N'37'
3783 @end example
3785 @noindent
3786 @pindex DESC
3787 @cindex unnamed characters
3788 @cindex characters, unnamed
3789 The code of each character is given in the fourth column in the font
3790 description file after the charset command.  It is possible to include
3791 unnamed characters in the font description file by using a name of
3792 @samp{---}; the @code{\N} escape sequence is the only way to use these.
3794 @c XXX should be `glyph', not `character'
3796 @findex cflags
3797 @cindex character properties
3798 @cindex properties of characters
3799 Each character has certain properties associated with it.  These
3800 properties can be modified with the @code{cflags} request.  The first
3801 argument is the the sum of the desired flags and the remaining arguments
3802 are the characters to have those properties.
3804 @table @code
3805 @item 1
3806 @cindex end of sentence characters
3807 @cindex characters, end of sentence
3808 the character ends sentences (initially characters @samp{.?!} have this
3809 property)
3810 @item 2
3811 @cindex hyphenating characters
3812 @cindex characters, hyphenation
3813 lines can be broken before the character (initially no characters have
3814 this property)
3815 @item 4
3816 lines can be broken after the character (initially the characters
3817 @samp{-\(hy\(em} have this property)
3818 @item 8
3819 @cindex overlapping characters
3820 @cindex characters, overlapping
3821 the character overlaps horizontally (initially the characters
3822 @samp{\(ul\(rn\(ru} have this property)
3823 @item 16
3824 the character overlaps vertically (initially character @samp{\(br} has
3825 this property)
3826 @item 32
3827 @cindex transparent characters
3828 @cindex characters, transparent
3829 an end of sentence character followed by any number of characters with
3830 this property will be treated as the end of a sentence if followed by a
3831 newline or two spaces; in other words the character is @dfn{transparent}
3832 for the purposes of end of sentence recognition---this is the same as
3833 having a zero space factor in @TeX{} (initially characters
3834 @samp{"')]*\(dg\(rq} have this property).
3835 @end table
3837 @findex char
3838 @cindex defining characters
3839 @cindex characters, defining
3840 New characters can be created with the @code{char} request.  It is
3841 called as
3843 @example
3844 .char @var{c} @var{string}
3845 @end example
3847 @findex tr
3848 @findex lc
3849 @findex \l
3850 @findex \L
3851 @findex hcode
3852 @noindent
3853 This defines character@w{ }@var{c} to be @var{string}.  Every time
3854 character@w{ }@var{c} needs to be printed, @var{string} will be
3855 processed in a temporary environment and the result will be wrapped up
3856 into a single object.  Compatibility mode will be turned off and the
3857 escape character will be set to @samp{\} while @var{string} is being
3858 processed.  Any emboldening, constant spacing or track kerning will be
3859 applied to this object rather than to individual characters in
3860 @var{string}.  A character defined by this request can be used just like
3861 a normal character provided by the output device.  In particular other
3862 characters can be translated to it with the @code{tr} request; it can be
3863 made the leader character by the @code{lc} request; repeated patterns
3864 can be drawn with the character using the @code{\l} and @code{\L} escape
3865 sequences; words containing the character can be hyphenated correctly,
3866 if the @code{hcode} request is used to give the character a hyphenation
3867 code.  There is a special anti-recursion feature: use of character
3868 within the character's definition will be handled like normal characters
3869 not defined with @code{char}.
3871 @findex rchar
3872 @cindex removing character definition
3873 @cindex character, removing definition
3874 A character definition can be removed with the @code{rchar} request.
3875 Its arguments are the characters to be removed.  This undoes the effect
3876 of a @code{char} request.
3878 @xref{Special Characters}.
3880 @node Artificial Fonts, Ligatures and Kerning, Using Symbols, Fonts
3881 @subsection Artificial Fonts
3882 @cindex artificial fonts
3883 @cindex fonts, artificial
3885 There are a number of requests for artificially creating fonts.  These
3886 are largely vestigial remains from the days when output devices did not
3887 have a wide variety of fonts, and when @code{nroff} and @code{troff}
3888 were separate programs.  These are no longer necessary in GNU
3889 @code{troff}.
3891 @findex ul
3892 @cindex underlining
3893 The @code{ul} request will print subsequent lines in italics on a device
3894 capable of it, or underline the text on an character output device.  The
3895 single argument is the number of lines to be ``underlined,'' with no
3896 argument, the next line will be underlined.
3898 @findex cu
3899 @cindex continuous underlining
3900 @cindex underlining, continuous
3901 The @code{cu} request is similar to @code{ul} ...
3903 @c XXX more info
3905 @findex uf
3906 @cindex underline font
3907 @cindex font for underlining
3908 The @code{uf} request will set the underline font used by @code{ul} and
3909 @code{cu}.
3911 @findex bd
3912 @cindex imitating bold face
3913 @cindex bold face, imitating
3914 The @code{bd} request artificially creates a bold font by printing each
3915 character twice, slightly offset.  The first argument specifies the font
3916 to embolden, and the second is the number of basic units, minus one, by
3917 which the two characters will be offset.  If the second argument is
3918 missing, emboldening will be turned off.
3920 @node Ligatures and Kerning,  , Artificial Fonts, Fonts
3921 @subsection Ligatures and Kerning
3922 @cindex ligatures and kerning
3923 @cindex kerning and ligatures
3925 What are ligatures?
3927 @c XXX more info
3929 @findex lg
3930 @vindex .lg
3931 The ligature mechanism can be switched on or off with the @code{lg}
3932 request; if the parameter is non-zero or missing, ligatures are enabled,
3933 otherwise disabled.  Default is on.  The current ligature mode can be
3934 found in the number register @code{.lg} (set to@w{ }1 if ligatures are
3935 enabled, 0@w{ }otherwise).
3937 What is kerning?
3939 @c XXX more info
3941 @cindex zero width space character
3942 @cindex character, zero width space
3943 @cindex space character, zero width
3944 If the font description file contains pairwise kerning information,
3945 characters from that font will be kerned.  Kerning between two
3946 characters can be inhibited by placing @code{\&} between them.
3948 @findex kern
3949 @vindex .kern
3950 Kerning can be activated with the @code{kern} request.  If the parameter
3951 is non-zero or missing, enable pairwise kerning, otherwise disable it.
3952 The number register @code{.kern} is set to@w{ }1 if pairwise kerning is
3953 enabled, 0@w{ }otherwise.
3955 @findex tkf
3956 @cindex track kerning
3957 @cindex kerning, track
3958 What is track kerning?
3960 @c XXX more info
3962 Track kerning must be used with great care since it is usually
3963 considered bad typography if the reader notices the effect.  The syntax
3964 of the @code{tkf} request is
3966 @example
3967 .tkf @var{f} @var{s1} @var{n1} @var{s2} @var{n2}
3968 @end example
3970 @noindent
3971 Enable track kerning for font@w{ }@var{f}.  If the current font is@w{
3972 }@var{f} the width of every character will be increased by an amount
3973 between @var{n1} and @var{n2}; if the current point size is less than or
3974 equal to @var{s1} the width will be increased by @var{n1}; if it is
3975 greater than or equal to @var{s2} the width will be increased by
3976 @var{n2}; if the point size is greater than or equal to @var{s1} and
3977 less than or equal to @var{s2} the increase in width is a linear
3978 function of the point size.
3981 @node Sizes, Strings, Fonts, Programming Tutorial
3982 @section Sizes
3983 @cindex sizes
3985 @cindex baseline
3986 @cindex type size
3987 @cindex size of type
3988 @cindex vertical spacing
3989 @cindex spacing, vertical
3990 @code{gtroff} uses two dimensions with each line of text, type size and
3991 vertical spacing.  The @dfn{type size} is the height from the text
3992 @dfn{baseline} to the top of the tallest character (descenders may drop
3993 below this baseline).  @dfn{Vertical spacing} is the amount of space
3994 @code{gtroff} allows for a line of text; normally, this is about 20%@w{
3995 }larger than the current type size.  Ratios smaller than this can result
3996 in hard-to-read text; larger that this, it will spread the text out more
3997 vertically (useful for term papers).  By default, @code{gtroff} uses
3998 10@w{ }point type on 12@w{ }point spacing.
4000 @cindex leading
4001 The difference between type size and vertical spacing is known, by
4002 typesetters, as @dfn{leading}.
4004 @menu
4005 * Changing Type Sizes::         
4006 * Fractional Type Sizes::       
4007 @end menu
4009 @node Changing Type Sizes, Fractional Type Sizes, Sizes, Sizes
4010 @subsection Changing Type Sizes
4011 @cindex changing type sizes
4012 @cindex type sizes, changing
4014 @findex ps
4015 @findex vs
4016 @findex \s
4017 @vindex .s
4018 @vindex .v
4019 Using the @code{ps} request and the @code{\s} escape the type size can
4020 be changed.  The @code{vs} request will change the vertical spacing.
4021 The default unit for the @code{ps} and @code{vs} requests are points.
4022 The number registers @code{.s} and @code{.v} contain the current type
4023 size and vertical spacing.
4025 These requests take parameters in units of points.  It is possible to
4026 specify sizes as an absolute size, or as a relative change from the
4027 current size.  The size@w{ }0 means go back to the previous size.  With
4028 no argument it will also revert to the previous size.
4030 @example
4031 snap, snap,
4032 .ps +2
4033 grin, grin,
4034 .ps +2
4035 wink, wink, \s+2nudge, nudge,\s+8 say no more!
4036 .ps 10
4037 @end example
4039 The @code{\s} escape may be called in a variety of ways.  Much like
4040 other escapes there must be a way to determine where the argument ends
4041 and the text begins.  Any of the following forms are valid:
4043 @table @code
4044 @item \s@var{n}
4045 Set the point size to @var{n}@w{ }points.  @var{n}@w{ }must be either 0
4046 or in the range 4 to@w{ }39.
4047 @itemx \s+@var{n}
4048 @itemx \s-@var{n}
4049 Increase resp.@: decrease the point size by @var{n}@w{ }points.
4050 @var{n}@w{ }must be exactly one digit.
4051 @item \s(@var{nn}
4052 Set the point size to @var{nn}@w{ }points.  @var{nn} must be exactly two
4053 digits.
4054 @item \s+(@var{nn}
4055 @itemx \s-(@var{nn}
4056 @itemx \s(+@var{nn}
4057 @itemx \s(-@var{nn}
4058 Increase resp.@: decrease the point size by @var{nn}@w{ }points.
4059 @var{nn} must be exactly two digits.
4060 @end table
4062 @xref{Fractional Type Sizes}, for yet another syntactical form of using
4063 the @code{\s} escape.
4065 Some devices may only have certain permissible sizes, in which case
4066 @code{gtroff} will round to the nearest permissible size.
4068 @c XXX example
4070 @example
4071 ... .sz macro example?? ...
4072 @end example
4074 @node Fractional Type Sizes,  , Changing Type Sizes, Sizes
4075 @subsection Fractional Type Sizes
4076 @cindex fractional type sizes
4077 @cindex type sizes, fractional
4079 @cindex @code{s} unit
4080 @cindex unit, @code{s}
4081 @cindex @code{z} unit
4082 @cindex unit, @code{z}
4083 @findex ps
4084 @findex cs
4085 @findex tkf
4086 @findex \H
4087 @findex \s
4088 A @dfn{scaled point} is equal to 1/@var{sizescale} points, where
4089 @var{sizescale} is specified in the @file{DESC} file (1@w{ }by default.)
4090 There is a new scale indicator @samp{z} which has the effect of
4091 multiplying by @var{sizescale}.  Requests and escape sequences in
4092 @code{gtroff} interpret arguments that represent a point size as being in
4093 units of scaled points, but they evaluate each such argument using a
4094 default scale indicator of @samp{z}.  Arguments treated in this way are
4095 the argument to the @code{ps} request, the third argument to the
4096 @code{cs} request, the second and fourth arguments to the @code{tkf}
4097 request, the argument to the @code{\H} escape sequence, and those
4098 variants of the @code{\s} escape sequence that take a numeric expression
4099 as their argument (see below).
4101 For example, suppose @var{sizescale} is@w{ }1000; then a scaled point
4102 will be equivalent to a millipoint; the request @w{@samp{.ps 10.25}} is
4103 equivalent to @w{@samp{.ps 10.25z}} and thus sets the point size to 10250
4104 scaled points, which is equal to 10.25@w{ }points.
4106 It would make no sense to use the @samp{z} scale indicator in a numeric
4107 expression whose default scale indicator was neither @samp{u} nor
4108 @samp{z}, and so @code{gtroff} disallows this.  Similarly it would make
4109 no sense to use a scaling indicator other than @samp{z} or @samp{u} in a
4110 numeric expression whose default scale indicator was @samp{z}, and so
4111 @code{gtroff} disallows this as well.
4113 There is also new scale indicator @samp{s} which multiplies by the
4114 number of units in a scaled point.  So, for example, @samp{\n[.ps]s} is
4115 equal to @samp{1m}.  Be sure not to confuse the @samp{s} and @samp{z}
4116 scale indicators.
4118 @vindex .s
4119 @vindex .ps
4120 The number register @code{.s} returns the point size in points as decimal
4121 fraction.  There is also a new number register @code{.ps} that returns
4122 the point size in scaled points.
4124 @vindex .psr
4125 @vindex .sr
4126 The last-requested point size in scaled points is contained in the
4127 @code{.psr} number register.  The last requested point size in points as
4128 a decimal fraction can be found in @code{.psr}.  This is a string-valued
4129 register.
4131 @table @code
4132 @item \s[@var{n}]
4133 @itemx \s'@var{n}'
4134 Set the point size to @var{n} scaled points; @var{n}@w{ }is a numeric
4135 expression with a default scale indicator of @samp{z}.
4136 @item \s[+@var{n}]
4137 @itemx \s[-@var{n}]
4138 @itemx \s+[@var{n}]
4139 @itemx \s-[@var{n}]
4140 @itemx \s'+@var{n}'
4141 @itemx \s'-@var{n}'
4142 @itemx \s+'@var{n}'
4143 @itemx \s-'@var{n}'
4144 Increases resp.@: decreases the point size by @var{n} scaled points;
4145 @var{n} is a numeric expression with a default scale indicator of
4146 @samp{z}.
4147 @end table
4149 @xref{Font Files}.
4152 @node Strings, Conditionals and Loops, Sizes, Programming Tutorial
4153 @section Strings
4154 @cindex strings
4156 @findex ds
4157 @code{gtroff} has string variables, which are entirely for user
4158 convenience (i.e.@: there are no built-in strings).  They are defined
4159 via the @code{ds} request.
4161 @example
4162 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d
4163 @end example
4165 @findex \*
4166 @cindex string interpolation
4167 @cindex string expansion
4168 @cindex interpolation of strings
4169 @cindex expansion of strings
4170 They are interpolated, or expanded in-place, via the @code{\*} escape:
4172 @example
4173 The \*(UX Operating System
4174 @end example
4176 If the string named by the @code{\*} does not exist, the escape will be
4177 replaced by nothing.
4179 @cindex comments, with @code{ds}
4180 @strong{Caution:} Unlike other requests, the second argument to the
4181 @code{ds} request takes up the entire line including trailing spaces.
4182 This means that comments on a line with such a request can introduce
4183 unwanted space into a string.
4185 @example
4186 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d \" UNIX trademark
4187 @end example
4189 @noindent
4190 Instead the comment should be put on another line or have the comment
4191 escape adjacent with the end of the string.
4193 @example
4194 .ds UX \s-1UNIX\s0\u\s-3tm\s0\d\"  UNIX trademark
4195 @end example
4197 @cindex trailing quotes
4198 @cindex quotes, trailing
4199 @cindex leading spaces with @code{ds}
4200 @cindex spaces with @code{ds}
4201 To produce leading space the string can be started with a double quote.
4202 No trailing quote is needed; in fact, any trailing quote is included in
4203 your string.
4205 @example
4206 .ds sign "           Yours in a white wine sauce,
4207 @end example
4209 @findex as
4210 @cindex appending to strings
4211 @cindex strings, appending
4212 The @code{as} request will append a string to another string.  It works
4213 similar to the @code{ds} request except that it appends the second
4214 argument onto the string named by the first argument.
4216 @example
4217 .as sign " with shallots, onions and garlic,
4218 @end example
4220 @findex \@key{RET}
4221 @cindex multi-line strings
4222 @cindex strings, multi-line
4223 @cindex newline character, escaping
4224 @cindex escaping newline characters
4225 Strings are not limited to a single line of text.  A string can span
4226 several lines by escaping the newlines with a backslash.  The resulting
4227 string will be stored @emph{without} the newlines.
4229 @example
4230 .ds foo lots and lots \
4231 of text are on these \
4232 next several lines
4233 @end example
4235 @findex substring
4236 @cindex substrings
4237 Rudimentary string manipulation routines are given with the
4238 @code{substring} and @code{length} requests.  The former has the
4239 following syntax:
4241 @example
4242 .substring @var{xx} @var{n1} [@var{n2}]
4243 @end example
4245 @noindent
4246 It replaces the string in register@w{ }@var{xx} with the substring
4247 defined by the indices @var{n1} and@w{ }@var{n2}.  The first character
4248 in the string has index one.  If @var{n2} is omitted, it is taken to be
4249 equal to the string's length.  If the index value @var{n1} or @var{n2}
4250 is negative or zero, it will be counted from the end of the string,
4251 going backwards: The last character has index@w{ }0, the character
4252 before the last character has index@w{ }-1, etc.
4254 @findex length
4255 @cindex length of a string
4256 @cindex string, length of
4257 Here the syntax of the @code{length} request:
4259 @example
4260 .length @var{xx} @var{string}
4261 @end example
4263 @noindent
4264 It computes the length of @var{string} and returns it in the number
4265 register@w{ }@var{xx} (which is not necessarily defined before).
4267 @findex rn
4268 @code{rn}
4270 @c XXX
4272 @findex rm
4273 @code{rm}
4275 @c XXX
4277 @findex als
4278 @code{als}
4280 @c XXX
4282 @findex chop
4283 @code{chop}
4285 @c XXX
4287 @xref{Identifiers}, and @ref{Comments}.
4290 @node Conditionals and Loops, Writing Macros, Strings, Programming Tutorial
4291 @section Conditionals and Loops
4292 @cindex conditionals and loops
4293 @cindex loops and conditionals
4295 @findex if
4296 @findex while
4297 In @code{if} and @code{while} requests, there are several more operators
4298 available:
4300 @table @code
4301 @item e
4302 @itemx o
4303 True if the current page is even or odd numbered (respectively).
4304 @item n
4305 @itemx t
4306 True if the document is being processed by @code{nroff} (or a character
4307 device) resp.@: @code{troff}.
4308 @item '@var{xxx}'@var{yyy}'
4309 True if the string @var{xxx} is equal to the string @var{yyy}.  Other
4310 characters can be used in place of the single quotes.
4311 @c XXX (Which?)
4312 The strings are `formatted' before being compared.
4313 @c XXX (?)
4314 @item r@var{xxx}
4315 True if there is a number register named @var{xxx}.
4316 @item d@var{xxx}
4317 True if there is a string, macro, diversion, or request named @var{xxx}.
4318 @item c@var{ch}
4319 @findex char
4320 True if there is a character @var{ch} available; @var{ch} is either an
4321 @acronym{ASCII} character or a special character (@code{\(@var{ch}} or
4322 @code{\[@var{ch}]}); the condition will also be true if @var{ch} has
4323 been defined by the @code{char} request.
4324 @end table
4326 @menu
4327 * if-else::                     
4328 * while::                       
4329 @end menu
4331 @node if-else, while, Conditionals and Loops, Conditionals and Loops
4332 @subsection if-else
4333 @cindex if-else
4335 @code{gtroff} has if-then-else constructs like other languages, although
4336 the formatting can be painful.
4338 @findex if
4339 The @code{if} request has the following syntax:
4341 @example
4342 .if @var{expr} @var{anything}
4343 @end example
4345 @noindent
4346 where @var{expr} is the expression to be evaluated; @var{anything} (the
4347 remainder of the line) will be executed if @var{expr} evaluates to
4348 non-zero (true).  @var{anything} will be interpreted as though it was on
4349 a line by itself.  @xref{Expressions}, for more info.
4351 Here are some examples:
4353 @example
4354 .if t .ls 2                             \" double spacing in troff
4355 .if 0 .ab how'd this happen?
4356 @end example
4358 @findex ie
4359 @findex el
4360 An if-then-else is written using two requests @code{ie} and @code{el}.
4361 The first request is the `if' part and the latter is the `else' part.
4363 @c XXX example
4365 @example
4368 @end example
4370 @findex \@{
4371 @findex \@}
4372 In many cases more than one request is to be executed as a result of any
4373 of these requests.  This can be done using the @code{\@{} and @code{\@}}
4374 escapes.  The following example shows the possible ways to use these
4375 escapes (note the position of the opening and closing braces).
4377 @example
4378 .ie t \@{\
4379 .    ds lq ``
4380 .    ds rq ''
4381 .\@}
4382 .el \
4383 .\@{\
4384 .    ds lq "
4385 .    ds rq "\@}
4386 .ds qq "
4387 @end example
4389 @xref{Expressions}.
4391 @node while,  , if-else, Conditionals and Loops
4392 @subsection while
4393 @cindex while
4395 @findex while
4396 @code{gtroff} provides a looping construct using the @code{while}
4397 request, which is used much like the @code{if} (and related) requests.
4398 The first argument is an expression which will be evaluated.  The
4399 @code{while} request will interpret the remainder of the line until the
4400 expression evaluates to 0 or false.
4402 @example
4403 .nr a 0 1
4404 .while (\na<9) \&\n+a,
4405 \&\n+a
4406 @end example
4408 @noindent
4409 The preceding example produces:
4411 @example
4412 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
4413 @end example
4415 @cindex zero width space character
4416 @cindex character, zero width space
4417 @cindex space character, zero width
4418 @findex \&
4419 @noindent
4420 Note the usage of the @code{\&} escape to avoid a control character at
4421 the beginning of a line.
4423 @findex break
4424 @findex continue
4425 The @code{break} request will @dfn{break} out of a while loop.  Be sure
4426 not to confuse this with the @code{br} request (causing a line break).
4427 The @code{continue} request will finish the current iteration of a while
4428 loop, immediately restarting the next iteration.
4430 @xref{Expressions}.
4433 @node Writing Macros, Page Motions, Conditionals and Loops, Programming Tutorial
4434 @section Writing Macros
4435 @cindex writing macros
4436 @cindex macros, writing
4438 @findex de
4439 A @dfn{macro} is a collection of text and embedded commands which can be
4440 invoked multiple times.  Macros are used for defining common operations.
4441 Macros are defined using the @code{de} request.  This request takes a
4442 name for the macro as the first argument.  Subsequent lines are copied
4443 into an internal buffer until the line @code{..} is encountered.  The
4444 optional second argument to @code{de} can change this ending token.
4446 Here a small example macro called @samp{P} which will cause a break and
4447 the insertion of some vertical space.  It could be used to separate
4448 paragraphs.
4450 @example
4451 .de P
4453 .sp .8v
4455 @end example
4457 @findex am
4458 The @code{am} request works similarly to @code{de} except it appends
4459 onto the macro named by the first argument.  So, to make the previously
4460 defined @samp{P} macro actually do indented instead of block paragraphs,
4461 is is possible to add the necessary code to the existing macro like
4462 this:
4464 @example
4465 .am P
4466 .ti +5n
4468 @end example
4470 @findex als
4471 @cindex aliases, macro
4472 @cindex macro aliases
4473 Macros can be aliased with the @code{als} request.
4475 @c XXX example
4477 @menu
4478 * Copy-in Mode::                
4479 * Parameters::                  
4480 @end menu
4482 @node Copy-in Mode, Parameters, Writing Macros, Writing Macros
4483 @subsection Copy-in Mode
4484 @cindex copy-in mode
4485 @cindex mode, copy-in
4487 @findex \n
4488 @findex \$
4489 @findex \*
4490 @findex \\
4491 @findex \@key{RET}
4492 When @code{gtroff} reads in the text for a macro or diversion it copies
4493 the text (including request lines, but excluding escapes) into an
4494 internal buffer.  Escapes will be converted into an internal form,
4495 except for @code{\n}, @code{\$}, @code{\*}, @code{\\} and
4496 @code{\@key{RET}} which are evaluated and inserted into the text where
4497 the escape was located.  This is known as @dfn{copy-in} mode.
4499 What this means is that you can specify when these escapes are to be
4500 evaluated (either at copy-in time or at the time of use) by insulating
4501 the escapes with an extra backslash.  Compare this to the @code{\def}
4502 and @code{\edef} commands in @TeX{}.
4504 For example, the following will result in the numbers 20 and@c{ }10
4505 being printed:
4507 @example
4508 .nr x 20
4509 .de y
4510 .nr x 10
4511 \&\nx
4512 \&\\nx
4515 @end example
4517 @node Parameters,  , Copy-in Mode, Writing Macros
4518 @subsection Parameters
4519 @cindex parameters
4521 @findex \$
4522 @vindex .$
4523 The arguments to a macro can be examined using a variety of escapes.
4524 The number of arguments is available in the @code{.$} number register.
4525 Any individual argument can be retrieved with one of the following
4526 escapes:
4528 @cindex copy-in mode
4529 The escapes @code{\$@var{n}}, @code{\$(@var{nn}} and
4530 @code{\$[@var{nnn}]} will result in the @var{n}th, @var{nn}th or
4531 @var{nnn}th argument.  As usual, the first form only accepts a single
4532 number (larger than zero), the second only a two-digit number (larger or
4533 equal to@w{ }10), and the third any positive integer value (larger than
4534 zero).  Macros can have an unlimited number of arguments.  Note that due
4535 to copy-in mode, two backslashes should be used on these in actual use
4536 to prevent interpolation until the macro is actually invoked.
4538 @findex shift
4539 The request @code{shift} will shift the arguments 1@w{ }position, or as
4540 many positions as specified by its argument.  After executing this
4541 request, argument@w{ }@var{i} will become argument @var{i}-@var{n};
4542 arguments 1 to@w{ }@var{n} will no longer be available.  Shifting by
4543 negative amounts is currently undefined.
4545 @findex \$*
4546 @findex \$@@
4547 In some cases it is convenient to use all of the arguments at once (for
4548 example, to pass the arguments along to another macro).  The @code{\$*}
4549 escape is the concatenation of all the arguments separated by spaces.  A
4550 similar escape is @code{\$@@}, which is the concatenation of all the
4551 arguments with each surrounded by double quotes, and separated by
4552 spaces.
4554 @findex \$0
4555 @findex als
4556 The @code{\$0} escape is the name by which the current macro was
4557 invoked.  The @code{als} request can make a macro have more than one
4558 name.
4560 @example
4561 .de vl
4562 .ie \\n(.$=1 .ds Vl Pre-Release Version
4563 .el          .ds Vl Version \\$3, \\$4.
4565 @end example
4567 This would be called as
4569 @example
4570 .vl $Id$
4571 @end example
4573 @xref{Request Arguments}.
4576 @node Page Motions, Drawing Requests, Writing Macros, Programming Tutorial
4577 @section Page Motions
4578 @cindex page motions
4579 @cindex motions, page
4581 @findex sp
4582 Motions up and down the page can be done with the @code{sp} request.
4583 However, this causes a break so that the actual effect is to move to the
4584 left margin and then to the specified location.
4586 @findex mk
4587 @findex rt
4588 The request @code{mk} can be used to mark a location on a page, for
4589 movement to later.  This request takes a register name as an argument in
4590 which to store the current page location.  With no argument it will
4591 store the location in an internal register.  The results of this can be
4592 used later by the @code{rt} or the @code{sp} request.  The @code{rt}
4593 request will return @emph{upwards} to the location given in the register
4594 name given as an argument, with no argument it will return to the
4595 location marked with the @code{mk} request
4597 @c XXX example
4599 @example
4600 ... dual column example ...
4601 @end example
4603 The following escapes give fine control of movements about the page.
4605 @findex \v
4606 @cindex vertical motion
4607 @cindex motion, vertical
4608 The @code{\v'@var{e}'} enables arbitrary vertical motion from the
4609 current location on the page.  The argument@w{ }@var{e} specifies the
4610 distance to move; positive is downwards and negative upwards.  The
4611 default unit for this escape is vertical spaces, @code{v}'s.  Beware,
4612 however, that @code{gtroff} will leave text processing to continue
4613 wherever the motion ends, so to avoid interference with text processing,
4614 motions should be balanced.
4616 There are some special case escapes for vertical motion.
4618 @ftable @code
4619 @item \r
4620 move upwards@w{ }1@dmn{v}.
4621 @item \u
4622 move upwards@w{ }.5@dmn{v}.
4623 @item \d
4624 move down@w{ }.5@dmn{v}.
4625 @end ftable
4627 @findex \h
4628 Horizontal motions can be done via the @code{\h'@var{e}'} escape.  The
4629 expression@w{ }@var{e} indicates how far to move: positive is rightwards
4630 and negative leftwards.
4632 There are a number of special case escapes for horizontal motion:
4634 @ftable @code
4635 @item \@key{SP}
4636 an unbreakable and unpaddable (i.e.@: not expanded during filling)
4637 space.  (Note: It is a backslash followed by a space.)
4638 @item \~
4639 an unbreakable space that stretches like a normal inter-word space when a
4640 line is adjusted.
4641 @item \|
4642 a 1/6th em space.
4643 @item \^
4644 a 1/12th em space.
4645 @item \0
4646 a space the size of a digit.
4647 @cindex zero width space character
4648 @cindex character, zero width space
4649 @cindex space character, zero width
4650 @item \&
4651 A zero width space.
4652 @item \)
4653 Like @code{\&} except that it behaves like a character declared with the
4654 @code{cflags} request to be transparent for the purposes of end of
4655 sentence recognition.
4656 @end ftable
4658 @c XXX example
4660 @example
4661 ... tex logo example ...
4662 @end example
4664 @findex \w
4665 @cindex width escape
4666 @cindex escape, width
4667 A frequent need is to do horizontal movement based on the width of some
4668 arbitrary text (e.g.@: given as an argument to a macro).  For that,
4669 there is the escape @code{\w'@var{text}'} which will interpolate to the
4670 width of the given @var{text} in basic units.
4672 @c XXX example
4674 @example
4675 ... strlen example ...
4676 @end example
4678 Font changes may occur in @var{text} which don't affect current
4679 settings.
4681 After use, @code{\w} sets several registers:
4683 @table @code
4684 @vindex st
4685 @vindex sb
4686 @item st
4687 @itemx sb
4688 The highest and lowest point, respectively, in @var{text}.
4689 @vindex rst
4690 @vindex rsb
4691 @item rst
4692 @itemx rsb
4693 Like the @code{st} and @code{sb} registers, but takes account of the
4694 heights and depths of characters.
4695 @vindex ct
4696 @item ct
4697 is set according to what kinds of characters occur in @var{text}:
4698 @table @asis
4699 @item 0
4700 only short characters, no descenders or tall characters.
4701 @item 1
4702 descender
4703 @item 2
4704 tall character
4705 @item 3
4706 both a descender and a tall character
4707 @end table
4708 @vindex ssc
4709 @item ssc
4710 The amount of horizontal space (possibly negative) that should be added
4711 to the last character before a subscript.
4712 @vindex skw
4713 @item skw
4714 How far to right of the center of the last character in the @code{\w}
4715 argument, the center of an accent from a Roman font should be placed
4716 over that character.
4717 @end table
4719 @findex \k
4720 @vindex .k
4721 @code{\k}
4723 @code{.k}
4725 @c XXX documentation
4728 @node Drawing Requests, Traps, Page Motions, Programming Tutorial
4729 @section Drawing Requests
4730 @cindex drawing requests
4731 @cindex requests for drawing
4733 @code{gtroff} provides a number of ways to draw lines and other figures
4734 on the page.  Used in combination with the page motion commands
4735 (@pxref{Page Motions}, for more info), a wide variety of figures can be
4736 drawn.  However, for complex drawings these operations can be quite
4737 cumbersome, and it may be wise to use graphic preprocessors like
4738 @code{gpic} or @code{ggrn}.  @xref{gpic}, and @ref{ggrn}, for more
4739 information.
4741 All drawing is done via escapes.
4743 @findex \l
4744 @cindex horizontal line
4745 @cindex line, horizontal
4746 The @code{\l} escape will draw a line rightwards from the current
4747 location.  The full syntax for this escape is
4749 @example
4750 \l'@var{l}@var{c}'
4751 @end example
4753 @noindent
4754 where @var{l} is the length of the line to be drawn, starting at the
4755 current location; positive numbers will draw to the right, and negative
4756 will draw towards the left.  This can also be specified absolutely
4757 (i.e.@: with a leading @samp{|}) which will draw back to the beginning
4758 of the line.
4760 @cindex underscore character
4761 @cindex character, underscore
4762 @cindex line drawing character
4763 @cindex character for line drawing
4764 The optional second parameter @var{c} is a character to draw the line
4765 with.  If this second argument is not specified, @code{gtroff} will use
4766 the underscore character.
4768 @cindex zero width space character
4769 @cindex character, zero width space
4770 @cindex space character, zero width
4771 @findex \&
4772 To separate the two arguments (to prevent @code{gtroff} from
4773 interpreting a drawing character as a scaling indicator) use @code{\&}.
4775 Here a small useful example:
4777 @example
4778 .de box
4779 \(br\\$*\(br\l'|0\(rn'\l'|0\(ul'
4781 @end example
4783 @noindent
4784 @findex |
4785 Note that this works by outputting a box rule (a vertical line), then
4786 the text given as an argument and then another box rule.  Then the line
4787 drawing escapes both draw from the current location to the beginning of
4788 the @emph{input} line.
4790 @findex \L
4791 @cindex vertical line
4792 @cindex line, vertical
4793 @cindex line drawing character
4794 @cindex character for line drawing
4795 @cindex box rule character
4796 @cindex character, box rule
4797 Vertical lines are drawn using the @code{\L} escape.  Its parameters are
4798 specified similar to the @code{\l} escape.  If the length is positive,
4799 the movement will be downwards, and upwards for negative values.  The
4800 default character is the box rule character.  As with the vertical
4801 motion escapes, text processing will blindly continue where the line
4802 ends.
4804 @c XXX example
4806 @example
4807 ...box macro...
4808 @end example
4810 @findex \D
4811 More flexible drawing functions are available via the @code{\D} escape.
4812 While the previous escapes will work on a character device, these
4813 escapes will not.
4815 @table @code
4816 @item \D'l @var{dx} @var{dy}'
4817 Draw a line from the current location to the relative point specified by
4818 (@var{dx},@var{dy}).
4820 @c XXX example
4822 @example
4823 ...revised box macro...
4824 @end example
4826 @item \D'c @var{d}'
4827 @cindex circles
4828 Draw a circle with a diameter of @var{d} with the leftmost point at the
4829 current position.
4830 @item \D'C @var{d}'
4831 Draw a solid circle with the same parameters as an outlined circle.
4832 @item \D'e @var{dx} @var{dy}'
4833 @cindex ellipses
4834 Draw an ellipse with a horizontal diameter of @var{dx} and a vertical
4835 diameter of @var{dy} with the leftmost point at the current position.
4836 @item \D'E @var{dx} @var{dy}'
4837 Draw a solid ellipse with the same parameters as an outlined ellipse.
4838 @item \D'a @var{dx1} @var{dy1} @var{dx2} @var{dy2}'
4839 @cindex arcs
4840 Draw an arc clockwise from the current location through the two
4841 specified locations (@var{dx1},@var{dy1}) and (@var{dx2},@var{dy2}).
4842 @item \D'~ @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
4843 @cindex splines
4844 Draw a spline from the current location to (@var{dx1},@var{dy1}) and
4845 then to (@var{dx2},@var{dy2}), and so on.
4846 @item \D'f @var{n}'
4847 @cindex gray shading
4848 @cindex shading
4849 Set the shade of gray to be used for filling solid objects to@w{
4850 }@var{n}; @var{n}@w{ }must be an integer between 0 and@w{ }1000, where 0
4851 corresponds solid white and 1000 to solid black, and values in between
4852 correspond to intermediate shades of gray.  This applies only to solid
4853 circles, solid ellipses and solid polygons.  By default, a level of@w{
4854 }1000 will be used.
4855 @item \D'p @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
4856 @cindex polygons
4857 Draw a polygon from the current location to (@var{dx1},@var{dy1}) and
4858 then to (@var{dx2},@var{dy2}) and so on.  When the specified data points
4859 are exhausted, a line is drawn back to the starting point.
4861 @c XXX example
4863 @example
4864 ... box example (yes, again)...
4865 @end example
4867 @itemx \D'P @var{dx1} @var{dy1} @var{dx2} @var{dy2} ...'
4868 Draw a solid polygon with the same parameters as an outlined polygon.
4870 @c XXX example
4872 @example
4873 ... shaded box example ...
4874 @end example
4876 @item \D't @var{n}'
4877 @cindex line thickness
4878 @cindex thickness of lines
4879 Set the current line thickness to @var{n} machine units.  A value of
4880 zero selects the smallest available line thickness.  A negative value
4881 makes the line thickness proportional to the current point size (this is
4882 the default behaviour of @code{ditroff}).
4883 @end table
4885 @findex \b
4886 @cindex pile, character
4887 @cindex character pile
4888 The @code{\b} escape will @dfn{pile} a sequence of characters
4889 vertically, and center it vertically on the current line.  This can be
4890 used to build large brackets and braces.
4892 @example
4893 \b'\(lt\(bv\(lk\(bv\(lb'
4894 @end example
4896 @xref{Drawing Functions}.
4898 @node Traps, Diversions, Drawing Requests, Programming Tutorial
4899 @section Traps
4900 @cindex traps
4902 @dfn{Traps} are locations, which, when reached, will call a specified
4903 macro.  These traps can occur at a given location on the page, at a
4904 given location in the current diversion, after a certain number of input
4905 lines or at the end of input.
4907 @menu
4908 * Page Location Traps::         
4909 * Diversion Traps::             
4910 * Input Line Traps::            
4911 * End-of-input Traps::          
4912 @end menu
4914 @node Page Location Traps, Diversion Traps, Traps, Traps
4915 @subsection Page Location Traps
4916 @cindex page location traps
4917 @cindex traps, page location
4919 @c XXX definition of wh request
4921 @cindex page headers
4922 @cindex page footers
4923 @cindex headers
4924 @cindex footers
4925 Page location traps are frequently used for page headers and footers.
4926 The following is a simple example of this.
4928 @example
4929 .de hd                \" Page header
4930 'sp .5i
4931 .tl 'Title''date'
4932 'sp .3i
4934 .de fo                \" Page footer
4935 'sp 1v
4936 .tl ''%''
4939 .wh 0   hd            \" trap at top of the page
4940 .wh -1i fo            \" trap one inch from bottom
4941 @end example
4943 @vindex .t
4944 @cindex distance to next trap
4945 @cindex trap, distance
4946 The number register @code{.t} is the distance to the next trap.
4948 @findex ch
4949 @cindex changing trap location
4950 @cindex trap, changing location
4951 The location of a trap can be changed later on with the @code{ch}
4952 request.  The first argument is the name of the macro to be invoked at
4953 the trap, and the second argument is the new location for the trap.
4954 This is useful for building up footnotes in a diversion to allow more
4955 space at the bottom of the page for them.
4957 @c XXX
4959 @example
4960 ... (simplified) footnote example ...
4961 @end example
4963 @findex vpt
4964 @findex wh
4965 @findex dt
4966 @vindex .vpt
4967 The @code{vpt} request will enable vertical position traps if the
4968 argument is non-zero, disable them otherwise.  Vertical position traps
4969 are traps set by the @code{wh} or @code{dt} requests.  Traps set by the
4970 @code{it} request are not vertical position traps.  The parameter that
4971 controls whether vertical position traps are enabled is global.
4972 Initially vertical position traps are enabled.  The current setting of
4973 this is available in the number register @code{.vpt}.
4975 @vindex .trunc
4976 @findex ne
4977 The number register @code{.trunc} contains the amount of vertical space
4978 truncated by the most recently sprung vertical position trap, or, if the
4979 trap was sprung by a @code{ne} request, minus the amount of vertical
4980 motion produced by the @code{ne} request.  In other words, at the point
4981 a trap is sprung, it represents the difference of what the vertical
4982 position would have been but for the trap, and what the vertical
4983 position actually is.
4985 @vindex .ne
4986 The number register @code{.ne} contains the amount of space that was
4987 needed in the last @code{ne} request that caused a trap to be sprung.
4988 Useful in conjunction with the @code{.trunc} register.  @xref{Page
4989 Control}, for more information.
4991 @node Diversion Traps, Input Line Traps, Page Location Traps, Traps
4992 @subsection Diversion Traps
4993 @cindex diversion traps
4994 @cindex traps, diversion
4996 @findex dt
4997 @vindex .t
4998 Traps can also be set @emph{within} a diversion using the @code{dt}
4999 request.  Like @code{wh} the first argument is the location of the trap
5000 and the second argument is the name of the macro to be invoked.  The
5001 number register @code{.t} will still work within diversions.
5002 @xref{Diversions}, for more information.
5004 @node Input Line Traps, End-of-input Traps, Diversion Traps, Traps
5005 @subsection Input Line Traps
5006 @cindex input line traps
5007 @cindex traps, input line
5009 @findex it
5010 The @code{it} request will set an input line trap.  The format for
5011 calling this is
5013 @example
5014 .it @var{n} @var{name}
5015 @end example
5017 @noindent
5018 where @var{n} is the number of lines of input which may be read before
5019 @dfn{springing} the trap, @var{name} is the macro to be invoked.
5020 Request lines are not counted as input lines.
5022 For example, one possible use is to have a macro which will print the
5023 next @var{n}@w{ }lines in a bold font.
5025 @example
5026 .de B
5027 .it B-end \\$1
5028 .ft B
5030 .de B-end
5031 .ft R
5033 @end example
5035 @node End-of-input Traps,  , Input Line Traps, Traps
5036 @subsection End-of-input Traps
5037 @cindex end-of-input traps
5038 @cindex traps, end-of-input
5040 @findex em
5041 The @code{em} request will set a trap at the end of input.  The macro
5042 specified as an argument will be executed after the last line of the
5043 input file has been processed.
5045 For example, if the document had to have a section at the bottom of the
5046 last page for someone to approve it, the @code{em} request could be
5047 used.
5049 @example
5050 .de approval
5051 .ne 5v
5052 .sp |(\\n(.t-6v)
5053 .in +4i
5054 .lc _
5056 Approved:\t\a
5058 Date:\t\t\a
5060 .em approval
5061 @end example
5064 @node Diversions, Environments, Traps, Programming Tutorial
5065 @section Diversions
5066 @cindex diversions
5068 In @code{gtroff} it is possible to @dfn{divert} text into a named
5069 storage area.  Due to the similarity to defining macros it is sometimes
5070 said to be stored in a macro.  This is used for saving text for output
5071 at a later time, which is useful for keeping blocks of text on the same
5072 page, footnotes, tables of contents and indices.
5074 @findex di
5075 @findex da
5076 A diversion is initiated by the @code{di} request.  Like the @code{de}
5077 request, it takes an argument of a macro name to divert subsequent text
5078 into.  The @code{da} macro will append to an existing diversion.
5080 @code{di} (resp.@: @code{da}) without an argument ends the diversion.
5082 @c XXX example
5084 @example
5085 ... end-note example ...
5086 @end example
5088 @vindex .z
5089 @vindex .d
5090 @vindex nl
5091 @vindex .h
5092 @cindex nested diversions
5093 @cindex diversion, nested
5094 Diversions may be nested.  The number register @code{.z} contains the
5095 name of the current diversion.  The number register @code{.d} contains
5096 the current vertical place in the diversion.  If not in a diversion it
5097 is the same as the register @code{nl}.
5099 @c XXX more info
5101 @code{.h}
5103 @vindex dn
5104 @vindex dl
5105 After completing a diversion, the built-in number registers @code{dn}
5106 and @code{dl} contain the vertical and horizontal size of the diversion.
5108 @example
5109 .\" Center text both horizontally & vertically
5110 .de (c
5113 .di @@c
5115 .de )c
5118 .nr @@s (((\\n(.tu-\\n(dnu)/2u)-1v)
5119 .sp \\n(@@su
5120 .ce 1000
5124 .ce 0
5125 .sp \\n(@@su
5128 .rr @@s
5130 @end example
5132 @findex \!
5133 @cindex transparent output
5134 @cindex output, transparent
5135 Requests, macros and escapes are interpreted when read into a diversion.
5136 There are two ways to prevent this; either way will take the given text
5137 and @dfn{transparently} embed it into the diversion.  The first method
5138 is to prefix the line with @code{\!}.  This will cause the entire line
5139 to be transparently inserted into the diversion.  This is useful for
5140 macros which shouldn't be invoked until the diverted text is actually
5141 output.
5143 @c XXX anything is read in copy mode. (what about \! ??)
5145 @findex \?
5146 The other way is to surround the text by the @code{\?} escape, i.e.
5148 @example
5149 \?@var{anything}\?
5150 @end example
5152 @noindent
5153 @var{anything} may not contain newlines; use @code{\!}  to embed
5154 newlines in a diversion.  The escape sequence @code{\?} is also
5155 recognized in copy mode and turned into a single internal code; it is
5156 this code that terminates anything.  Thus the following example will
5157 print@w{ }4.
5159 @example
5160 .nr x 1
5162 .di d
5163 \?\\?\\\\?\\\\\\\\nx\\\\?\\?\?
5165 .nr x 2
5166 .di e
5169 .nr x 3
5170 .di f
5173 .nr x 4
5175 @end example
5177 @findex asciify
5178 @cindex unformatting diversions
5179 @cindex diversion, unformatting
5180 The @code{asciify} request only exists in order to make certain gross
5181 hacks work with GNU @code{troff}.  It @dfn{unformats} the diversion
5182 specified as an argument in such a way that @acronym{ASCII} characters
5183 that were formatted and diverted will be treated like ordinary input
5184 characters when the diversion is reread.  For example, the following
5185 will set register @code{n} to@w{ }1.
5187 @example
5188 .tr @@.
5189 .di x
5190 @@nr\ n\ 1
5193 .tr @@@@
5194 .asciify x
5196 @end example
5198 @xref{Copy-in Mode}.
5201 @node Environments, I/O, Diversions, Programming Tutorial
5202 @section Environments
5203 @cindex environments
5205 It happens frequently that some text should be printed in a certain
5206 format regardless of what may be in effect at the time, for example, in
5207 a trap invoked macro to print headers and footers.  To solve this
5208 @code{gtroff} has @dfn{environments} in which text is processed.  An
5209 environment contains most of the parameters that control text
5210 processing.  It is possible to switch amongst these environments; by
5211 default @code{gtroff} processes text in environment@w{ }0.  The
5212 following is the information kept in an environment.
5214 @itemize @bullet{}
5215 @item
5216 type size
5217 @item
5218 font (family and style)
5219 @item
5220 page parameters
5221 @item
5222 fill/adjust mode
5223 @item
5224 tab stops
5225 @item
5226 partially collected lines
5227 @end itemize
5229 These environments may be given arbitrary names (@pxref{Identifiers},
5230 for more info).  Old versions of @code{troff} only had environments
5231 named @samp{0}, @samp{1} and@w{ }@samp{2}.
5233 @findex ev
5234 @vindex .ev
5235 The @code{ev} request will switch among environments.  The single
5236 argument is the name of the environment to switch to.  With no argument
5237 @code{gtroff} will switch back to the previous environment.  There is no
5238 limit on the number of named environments; they will be created the
5239 first time that they are referenced.  The @code{.ev} register contains
5240 the name or number of the current environment.  This is a string-valued
5241 register.
5243 Note that a call to @code{ev} (with argument) will push the previously
5244 active environment onto a stack.  If, say, environments @samp{foo},
5245 @samp{bar}, and @samp{zap} are called (in that order), the first
5246 @code{ev} request without parameter will switch back to environment
5247 @samp{bar} (which will be popped off the stack), and a second call will
5248 switch back to environment @samp{foo}.
5250 @c XXX example
5252 @example
5253 ... page break macro, revised ...
5254 @end example
5256 Here another example:
5258 @example
5259 .ev footnote-env
5260 .fam N
5261 .ps 6
5262 .vs 8
5263 .ll -.5i
5266 .ev footnote-env
5267 \(dg Note the large, friendly letters.
5269 @end example
5271 @findex evc
5272 To copy an environment into the current one, use the @code{evc} request,
5273 which takes the name of the environment to copy from as an argument.
5276 @node I/O, Postprocessor Access, Environments, Programming Tutorial
5277 @section I/O
5278 @cindex i/o
5279 @cindex input and output requests
5280 @cindex requests for input and output
5281 @cindex output and input requests
5283 @findex so
5284 The @code{so} request will read in the file given as an argument and
5285 include it in place of the @code{so} request.  This is quite useful for
5286 large documents, i.e.@: keeping each chapter in a separate file.
5287 @xref{gsoelim}, for more information.
5289 @findex mso
5290 The @code{mso} request is the same as the @code{so} request except that
5291 the file is searched for in the same way that @file{tmac.@var{name}} is
5292 searched for when the @option{-m@var{name}} option is specified.
5294 @findex cf
5295 @cindex transparent output
5296 @cindex output, transparent
5297 The @code{cf} and @code{trf} requests are to include a file.  It will
5298 transparently output the contents of file filename.  Each line is output
5299 as it were preceded by @code{\!}; however, the lines are not subject to
5300 copy-mode interpretation.  If the file does not end with a newline, then
5301 a newline will be added.  For example, to define a macro@w{ }@code{x}
5302 containing the contents of file@w{ }@file{f}, use
5304 @example
5305 .di x
5306 .trf f
5308 @end example
5310 The request @w{@code{.cf @var{filename}}}, when used in a diversion,
5311 will embed in the diversion an object which, when reread, will cause the
5312 contents of @var{filename} to be transparently copied through to the
5313 output.  In @acronym{UNIX} @code{troff}, the contents of @var{filename}
5314 is immediately copied through to the output regardless of whether there
5315 is a current diversion; this behaviour is so anomalous that it must be
5316 considered a bug.
5318 @findex trf
5319 With @code{trf}, unlike @code{cf}, the file cannot contain characters
5320 such as NUL that are not legal @code{gtroff} input characters.
5322 @c XXX xref to illegal input characters
5324 @findex nx
5325 The @code{nx} request will force @code{gtroff} to continue processing of
5326 the file specified as an argument.
5328 @findex rd
5329 The @code{rd} request will read from standard input, and include what is
5330 read as though it were part of the input file.  Text is read until a
5331 blank line is encountered.
5333 @cindex form letters
5334 @cindex letters, form
5335 Using these two requests it is easy to set up form letters.  The form
5336 letter template is constructed like this:
5338 @example
5340 \*(td
5341 .sp 2
5347 Body of letter.
5349 .nx repeat.let
5350 @end example
5352 @findex ex
5353 @noindent
5354 When this is run, the following file should be redirected in.  Note that
5355 requests included in this file are executed as though they were part of
5356 the form letter.  The last block of input is the @code{ex} requests
5357 which tells groff to stop processing.  If this was not there, groff
5358 would not know when to stop.
5360 @example
5361 Trent A. Fisher
5362 708 NW 19th Av., #202
5363 Portland, OR  97209
5365 Dear Trent,
5367 Len Adollar
5368 4315 Sierra Vista
5369 San Diego, CA  92103
5371 Dear Mr. Adollar,
5374 @end example
5376 @findex pi
5377 @code{pi}
5379 @c XXX documentation
5381 @findex sy
5382 The @code{sy} request will allow arbitrary system commands to be
5383 executed from within a @code{gtroff} document.  The output is not saved
5384 anyplace, so it is up to the user to do so.
5386 @c XXX add info about safer and unsafe mode
5388 For example, the following example will introduce the current time
5389 into a document:
5391 @cindex time, current
5392 @cindex current time
5393 @pindex perl
5394 @example
5395 .sy perl -e 'printf ".nr H %d\\n.nr M %d\\n.nr S %d\\n",\
5396              (localtime(time))[2,1,0]' > /tmp/x\n[$$]
5397 .so /tmp/x\n[$$]
5398 .sy rm /tmp/x\n[$$]
5399 \nH:\nM:\nS
5400 @end example
5402 @noindent
5403 Note that this works by having the @code{perl} script (run by @code{sy})
5404 print out the @code{nr} requests which will set the number registers
5405 @samp{H}, @samp{M} and @samp{S}, and then reads those commands in with
5406 the @code{so} request.
5408 @vindex systat
5409 The @code{systat} number register contains the return value of the
5410 @code{system()} function executed by the last @code{sy} request.
5412 @findex open
5413 The @code{open} request will open a file (specified as the second
5414 argument) for writing and associate the stream (specified as the first
5415 argument) with it.
5417 @findex opena
5418 The @code{opena} is like @code{open}, but if the file exists, append to
5419 it instead of truncating it.
5421 @findex write
5422 @findex ds
5423 @cindex copy-in mode
5424 @cindex mode, copy-in
5425 The @code{write} request will write to the file associated with the
5426 stream specified by the first argument.  The stream must previously have
5427 been the subject of an open request.  The remainder of the line is
5428 interpreted as the @code{ds} request reads its second argument: A
5429 leading @samp{"} will be stripped, and it will be read in copy-in mode.
5431 @findex close
5432 The @code{close} request will close the stream specified by the first
5433 argument; stream will no longer be an acceptable argument to the
5434 @code{write} request.
5436 @c XXX example
5438 @example
5439 ... example of open write &c...
5440 @end example
5442 @findex \V
5443 The @code{\V} escape will interpolate the contents of the specified
5444 environment variable, as returned by @code{getenv()}.  The argument to
5445 @code{\V} is specified as an identifier, i.e.@: @samp{\V@var{x}},
5446 @samp{\V(@var{xx}} or @samp{\V[@var{xxx}]}.  @code{\V} is interpreted in
5447 copy-in mode.
5450 @node Postprocessor Access, Miscellaneous, I/O, Programming Tutorial
5451 @section Postprocessor Access
5452 @cindex postprocessor access
5453 @cindex access of postprocessor
5455 There are two escapes which will allow information to be directly given
5456 to the postprocessor.  This is particularly useful for embedding
5457 @sc{PostScript} into the final document.
5459 @findex \X
5460 The @code{\X} escape will embed its argument into the @code{gtroff}
5461 output preceded with @w{@samp{x X}}.
5463 @findex \Y
5464 The @code{\Y} escape is called with an identifier (i.e.@:
5465 @code{\Y@var{x}}, @code{\Y(@var{xx}} or @code{\Y[@var{xxx}]}).  This is
5466 approximately equivalent to @samp{\X'\*[@var{xxx}]'}.  However, the
5467 contents of the string or macro @var{xxx} are not interpreted; also it
5468 is permitted for @var{xxx} to have been defined as a macro and thus
5469 contain newlines (it is not permitted for the argument to @code{\X} to
5470 contain newlines).  The inclusion of newlines requires an extension to
5471 the @acronym{UNIX} @code{troff} output format, and will confuse drivers
5472 that do not know about this extension.
5474 @xref{Output Devices}.
5477 @node Miscellaneous, Debugging, Postprocessor Access, Programming Tutorial
5478 @section Miscellaneous
5479 @cindex miscellaneous
5481 This section contains parts of @code{gtroff} which cannot (yet) be
5482 categorized elsewhere in this manual.
5484 @findex nm
5485 @cindex line numbers
5486 @cindex numbers, line
5487 Line numbers can be printed in the left margin using the @code{nm}
5488 request.  The first argument is the line number of the @emph{next}
5489 output line; this defaults to@w{ }1.  The second argument indicates on
5490 which lines numbers will be printed, i.e.@: 5 means put line numbers on
5491 every 5@w{ }lines; this defaults to@w{ }1.  The third argument is the
5492 space to be left between the number and the text; this defaults to@w{
5493 }1.  The fourth argument is the indentation of the line numbers.
5494 Without arguments, line numbers are turned off.
5496 @findex nn
5497 The @code{nn} request will temporarily turn off line numbering.  The
5498 first argument is the number of lines not to be numbered; this defaults
5499 to@w{ }1.
5501 @c XXX (does this disable incrementing or display?)
5503 @c XXX example
5505 @example
5506 ... line numbering example ...
5507 @end example
5509 @findex mc
5510 @cindex margin characters
5511 @cindex characters for margins
5512 Margin characters can be automatically printed to the right of the text
5513 with the @code{mc} request.  The first argument is the character to be
5514 printed, and the second argument is the distance away from the main body
5515 text.  With no arguments the margin characters are turned off.  If this
5516 occurs before a break, no margin character will be printed.
5518 @pindex nrchbar
5519 @pindex changebar
5520 This is quite useful for indicating text that has changed, and, in fact,
5521 there are programs available for doing this (they are called
5522 @code{nrchbar} and @code{changebar} and can be found in any
5523 @samp{comp.sources.unix} archive.
5525 @c XXX example
5527 @example
5528 ... margin char example ...
5529 @end example
5531 @findex lf
5532 @pindex soelim
5533 @cindex multi-file documents
5534 @cindex documents, multi-file
5535 The primary reason for the existence of @code{lf} is to make debugging
5536 documents which are split into many files, which are then put together
5537 with @code{soelim} and other preprocessors.  The first argument is the
5538 name of the file and the second argument is the input line number in
5539 that file.  This way @code{gtroff} can produce error messages which are
5540 intelligible to the user.
5542 @c XXX example
5544 @example
5545 ... example of soelim'ed doc ...
5546 @end example
5549 @node Debugging, Implementation Differences, Miscellaneous, Programming Tutorial
5550 @section Debugging
5551 @cindex debugging
5553 @code{gtroff} is not easy to debug, but there are some useful features
5554 and strategies for debugging.
5556 @itemize @bullet{}
5557 @item
5558 @findex tm
5559 The @code{tm} request will send output to stderr; this is very useful
5560 for printing debugging output.
5561 @item
5562 When doing something involved it is useful to leave the debugging
5563 statements in the code and have them turned on by a command line flag.
5565 @example
5566 .if \n(DB .tm debugging output
5567 @end example
5569 @noindent
5570 To activate these statements say
5572 @example
5573 groff -rDB=1 file
5574 @end example
5576 @item
5577 @findex ab
5578 @cindex aborting
5579 The @code{ab} request is similar to the @code{tm} request, except that
5580 it will cause @code{gtroff} to stop processing.  With no argument it
5581 will print @samp{User Abort}.
5582 @item
5583 @findex ex
5584 @cindex exiting
5585 The @code{ex} request will also cause @code{gtroff} to stop processing
5586 (if encountered at the topmost level; see also @ref{I/O}.
5587 @item
5588 If it is known in advance that there will be many errors and no useful
5589 output, @code{gtroff} can be forced to suppress formatted output with
5590 the @option{-z} flag.
5591 @item
5592 @findex pm
5593 @cindex dumping symbol table
5594 @cindex symbol table, dumping
5595 The @code{pm} request will dump out the entire symbol table.
5596 @item
5597 @findex pnr
5598 @cindex dumping number registers
5599 @cindex number registers, dumping
5600 The @code{pnr} request will print the names and contents of all
5601 currently defined number registers on stderr.
5602 @item
5603 @findex ptr
5604 @cindex dumping traps
5605 @cindex traps, dumping
5606 The @code{ptr} request will print the names and positions of all traps
5607 (not including input line traps and diversion traps) on stderr.  Empty
5608 slots in the page trap list are printed as well, because they can affect
5609 the priority of subsequently planted traps.
5610 @item
5611 @findex fl
5612 @cindex flush output
5613 @cindex output, flush
5614 @cindex interactive use of @code{gtroff}
5615 @cindex @code{gtroff}, interactive use
5616 The @code{fl} request instructs @code{gtroff} to flush its output
5617 immediately.  The intention is that this be used when using
5618 @code{gtroff} interactively.  There is little other use for it.
5619 @item
5620 @findex backtrace
5621 @cindex backtrace of input stack
5622 @cindex input stack, backtrace
5623 The @code{backtrace} request will print a backtrace of the input stack
5624 on stderr.
5625 @item
5626 @cindex warnings
5627 @code{gtroff} has command line options for printing out more warnings
5628 (@option{-w}) and for printing backtraces (@option{-b}) when a warning
5629 or an error occurs.  The most verbose level of warnings is @option{-ww}.
5630 @item
5631 @findex warn
5632 @vindex .warn
5633 @cindex level of warnings
5634 @cindex warnings, level
5635 The @code{warn} request controls the level of warnings checked for.  The
5636 only argument is the sum of the numbers associated with each warning
5637 that is to be enabled; all other warnings will be disabled.  The number
5638 associated with each warning is listed below.  For example,
5639 @w{@code{.warn 0}} will disable all warnings, and @w{@code{.warn 1}}
5640 will disable all warnings except that about missing characters.  If an
5641 argument is not given, all warnings will be enabled.  The number
5642 register @code{.warn} contains the current warning level.
5643 @end itemize
5645 @subsection Warnings
5646 @cindex warnings
5648 The warnings that can be given to @code{gtroff} are divided into the
5649 following categories.  The name associated with each warning is used by
5650 the @option{-w} and @option{-W} options; the number is used by the
5651 @code{warn} request and by the @code{.warn} register.
5653 @table @samp
5654 @item char
5655 @itemx 1
5656 Non-existent characters.  This is enabled by default.
5657 @item number
5658 @itemx 2
5659 Invalid numeric expressions.  This is enabled by default.
5660 @xref{Expressions}.
5661 @item break
5662 @itemx 4
5663 In fill mode, lines which could not be broken so that their length was
5664 less than the line length.  This is enabled by default.
5665 @item delim
5666 @itemx 8
5667 Missing or mismatched closing delimiters.
5668 @item el
5669 @itemx 16
5670 @findex ie
5671 @findex el
5672 Use of the @code{el} request with no matching @code{ie} request.
5673 @xref{if-else}.
5674 @item scale
5675 @itemx 32
5676 Meaningless scaling indicators.
5677 @item range
5678 @itemx 64
5679 Out of range arguments.
5680 @item syntax
5681 @itemx 128
5682 Dubious syntax in numeric expressions.
5683 @item di
5684 @itemx 256
5685 @findex di
5686 @findex da
5687 Use of @code{di} or @code{da} without an argument when there is no
5688 current diversion.
5689 @item mac
5690 @itemx 512
5691 @findex de
5692 @c XXX more findex entries
5693 Use of undefined strings, macros and diversions.  When an undefined
5694 string, macro or diversion is used, that string is automatically defined
5695 as empty.  So, in most cases, at most one warning will be given for each
5696 name.
5697 @item  reg
5698 @itemx 1024
5699 @findex nr
5700 @c XXX more findex entries
5701 Use of undefined number registers.  When an undefined number register is
5702 used, that register is automatically defined to have a value of@w{ }0.
5703 A definition is automatically made with a value of@w{ }0.  So, in most
5704 cases, at most one warning will be given for use of a particular name.
5705 @item  tab
5706 @itemx 2048
5707 Use of a tab character where a number was expected.
5708 @item  right-brace
5709 @itemx 4096
5710 @findex \@}
5711 Use of @code{\@}} where a number was expected.
5712 @item  missing
5713 @itemx 8192
5714 Requests that are missing non-optional arguments.
5715 @item  input
5716 @itemx 16384
5717 Illegal input characters.
5718 @item  escape
5719 @itemx 32768
5720 Unrecognized escape sequences.  When an unrecognized escape sequence is
5721 encountered, the escape character is ignored.
5722 @item  space
5723 @itemx 65536
5724 @cindex compatibility mode
5725 Missing space between a request or macro and its argument.  This warning
5726 will be given when an undefined name longer than two characters is
5727 encountered, and the first two characters of the name make a defined
5728 name.  The request or macro will not be invoked.  When this warning is
5729 given, no macro is automatically defined.  This is enabled by default.
5730 This warning will never occur in compatibility mode.
5731 @item  font
5732 @itemx 131072
5733 Non-existent fonts.  This is enabled by default.
5734 @item all
5735 All warnings except @samp{di}, @samp{mac} and @samp{reg}.  It is
5736 intended that this covers all warnings that are useful with traditional
5737 macro packages.
5738 @item w
5739 All warnings.
5740 @end table
5743 @node Implementation Differences, Summary, Debugging, Programming Tutorial
5744 @section Implementation Differences
5745 @cindex implementation differences
5746 @cindex differences in implementation
5747 @cindex compatibility mode
5748 @cindex mode, compatibility
5750 GNU @code{troff} has a number of features which cause incompatibilities
5751 with documents written with old versions of @code{troff}.
5753 @cindex long names
5754 @cindex names, long
5755 Long names cause some incompatibilities.  @acronym{UNIX} @code{troff}
5756 will interpret
5758 @example
5759 .dsabcd
5760 @end example
5762 @findex \*
5763 @findex \n
5764 @findex cp
5765 @vindex .C
5766 @noindent
5767 as defining a string @samp{ab} with contents @samp{cd}.  Normally, GNU
5768 @code{troff} will interpret this as a call of a macro named
5769 @code{dsabcd}.  Also @acronym{UNIX} @code{troff} will interpret
5770 @code{\*[} or @code{\n[} as references to a string or number register
5771 called @samp{[}.  In GNU @code{troff}, however, this will normally be
5772 interpreted as the start of a long name.  In compatibility mode GNU
5773 @code{troff} will interpret these things in the traditional way.  In
5774 compatibility mode, however, long names are not recognized.
5775 Compatibility mode can be turned on with the @option{-C} command line
5776 option, and turned on or off with the @code{cp} request.  The number
5777 register @code{.C} is@w{ }1 if compatibility mode is on, 0@w{
5778 }otherwise.
5780 @findex \A
5781 @findex \|
5782 @findex \^
5783 @findex \&
5784 @findex \@}
5785 @findex \@{
5786 @findex \@key{SP}
5787 @findex \'
5788 @findex \`
5789 @findex \-
5790 @findex \_
5791 @findex \!
5792 @findex \%
5793 @findex \c
5794 GNU @code{troff} does not allow the use of the escape sequences
5795 @code{\|}, @code{\^}, @code{\&}, @code{\@}}, @code{\@{},
5796 @code{\@key{SP}}, @code{\'}, @code{\`}, @code{\-}, @code{\_}, @code{\!},
5797 @code{\%}, and @code{\c} in names of strings, macros, diversions, number
5798 registers, fonts or environments; @acronym{UNIX} @code{troff} does.  The
5799 @code{\A} escape sequence (@pxref{Identifiers}) may be helpful in
5800 avoiding use of these escape sequences in names.
5802 @cindex fractional point sizes
5803 @cindex point sizes, fractional
5804 @findex ps
5805 Fractional point sizes cause one noteworthy incompatibility.  In
5806 @acronym{UNIX} @code{troff} the @code{ps} request ignores scale
5807 indicators and thus
5809 @example
5810 .ps 10u
5811 @end example
5813 @noindent
5814 will set the point size to 10@w{ }points, whereas in GNU @code{troff} it
5815 will set the point size to 10@w{ }scaled points.  @xref{Fractional Type
5816 Sizes}, for more information.
5818 @findex bd
5819 @findex cs
5820 @findex tkf
5821 @findex tr
5822 @findex fp
5823 @cindex input and output characters
5824 @cindex output characters
5825 @cindex characters, input and output
5826 In GNU @code{troff} there is a fundamental difference between
5827 unformatted, input characters, and formatted, output characters.
5828 Everything that affects how an output character will be output is stored
5829 with the character; once an output character has been constructed it is
5830 unaffected by any subsequent requests that are executed, including
5831 @code{bd}, @code{cs}, @code{tkf}, @code{tr}, or @code{fp} requests.
5832 Normally output characters are constructed from input characters at the
5833 moment immediately before the character is added to the current output
5834 line.  Macros, diversions and strings are all, in fact, the same type of
5835 object; they contain lists of input characters and output characters in
5836 any combination.  An output character does not behave like an input
5837 character for the purposes of macro processing; it does not inherit any
5838 of the special properties that the input character from which it was
5839 constructed might have had.  For example,
5841 @example
5842 .di x
5843 \\\\
5847 @end example
5849 @findex \e
5850 @findex \!
5851 @findex \?
5852 @cindex transparent output
5853 @cindex output, transparent
5854 @noindent
5855 will print @samp{\\} in GNU @code{troff}; each pair of input backslashes
5856 is turned into one output backslash and the resulting output backslashes
5857 are not interpreted as escape characters when they are reread.
5858 @acronym{UNIX} @code{troff} would interpret them as escape characters
5859 when they were reread and would end up printing one @samp{\}.  The
5860 correct way to obtain a printable backslash is to use the @code{\e}
5861 escape sequence: This will always print a single instance of the current
5862 escape character, regardless of whether or not it is used in a
5863 diversion; it will also work in both GNU @code{troff} and @acronym{UNIX}
5864 @code{troff}.  To store, for some reason, an escape sequence in a
5865 diversion that will be interpreted when the diversion is reread, either
5866 use the traditional @code{\!} transparent output facility, or, if this
5867 is unsuitable, the new @code{\?} escape sequence.
5869 @xref{Diversions}, for more information.
5872 @node Summary,  , Implementation Differences, Programming Tutorial
5873 @section Summary
5874 @cindex summary
5876 @c XXX documentation
5880 @node Preprocessors, Output Devices, Programming Tutorial, Top
5881 @chapter Preprocessors
5882 @cindex preprocessors
5884 This chapter describes all preprocessors that come with @code{groff} or
5885 which are freely available.
5887 @menu
5888 * geqn::                        
5889 * gtbl::                        
5890 * gpic::                        
5891 * ggrn::                        
5892 * grap::                        
5893 * grefer::                      
5894 * gsoelim::                     
5895 @end menu
5898 @node geqn, gtbl, Preprocessors, Preprocessors
5899 @section @code{geqn}
5900 @cindex @code{eqn}
5901 @cindex @code{geqn}
5903 @c XXX
5905 @menu
5906 * Invoking geqn::               
5907 @end menu
5909 @node Invoking geqn,  , geqn, geqn
5910 @subsection Invoking @code{geqn}
5911 @cindex invoking @code{geqn}
5912 @cindex @code{geqn}, invoking
5914 @c XXX
5917 @node gtbl, gpic, geqn, Preprocessors
5918 @section @code{gtbl}
5919 @cindex @code{tbl}
5920 @cindex @code{gtbl}
5922 @c XXX
5924 @menu
5925 * Invoking gtbl::               
5926 @end menu
5928 @node Invoking gtbl,  , gtbl, gtbl
5929 @subsection Invoking @code{gtbl}
5930 @cindex invoking @code{gtbl}
5931 @cindex @code{gtbl}, invoking
5933 @c XXX
5936 @node gpic, ggrn, gtbl, Preprocessors
5937 @section @code{gpic}
5938 @cindex @code{pic}
5939 @cindex @code{gpic}
5941 @c XXX
5943 @menu
5944 * Invoking gpic::               
5945 @end menu
5947 @node Invoking gpic,  , gpic, gpic
5948 @subsection Invoking @code{gpic}
5949 @cindex invoking @code{gpic}
5950 @cindex @code{gpic}, invoking
5952 @c XXX
5955 @node ggrn, grap, gpic, Preprocessors
5956 @section @code{ggrn}
5957 @cindex @code{grn}
5958 @cindex @code{ggrn}
5960 @c XXX
5962 @menu
5963 * Invoking ggrn::               
5964 @end menu
5966 @node Invoking ggrn,  , ggrn, ggrn
5967 @subsection Invoking @code{ggrn}
5968 @cindex invoking @code{ggrn}
5969 @cindex @code{ggrn}, invoking
5971 @c XXX
5974 @node grap, grefer, ggrn, Preprocessors
5975 @section @code{grap}
5976 @cindex @code{grap}
5978 A freely available implementation of @code{grap}, written by Ted Faber,
5979 is available as an extra package from the following address:
5981 @display
5982 @url{http://www.lunabase.org/~faber/Vault/software/grap/}
5983 @end display
5986 @node grefer, gsoelim, grap, Preprocessors
5987 @section @code{grefer}
5988 @cindex @code{refer}
5989 @cindex @code{grefer}
5991 @c XXX
5993 @menu
5994 * Invoking grefer::             
5995 @end menu
5997 @node Invoking grefer,  , grefer, grefer
5998 @subsection Invoking @code{grefer}
5999 @cindex invoking @code{grefer}
6000 @cindex @code{grefer}, invoking
6002 @c XXX
6005 @node gsoelim,  , grefer, Preprocessors
6006 @section @code{gsoelim}
6007 @cindex @code{soelim}
6008 @cindex @code{gsoelim}
6010 @c XXX
6012 @menu
6013 * Invoking gsoelim::            
6014 @end menu
6016 @node Invoking gsoelim,  , gsoelim, gsoelim
6017 @subsection Invoking @code{gsoelim}
6018 @cindex invoking @code{gsoelim}
6019 @cindex @code{gsoelim}, invoking
6021 @c XXX
6025 @node Output Devices, File formats, Preprocessors, Top
6026 @chapter Output Devices
6027 @cindex output devices
6028 @cindex devices for output
6030 @c XXX
6032 @menu
6033 * Special Characters::          
6034 * grotty::                      
6035 * grops::                       
6036 * grodvi::                      
6037 * grolj4::                      
6038 * grolbp::                      
6039 * grohtml::                     
6040 * gxditview::                   
6041 @end menu
6044 @node Special Characters, grotty, Output Devices, Output Devices
6045 @section Special Characters
6046 @cindex special characters
6047 @cindex characters, special
6049 @c XXX
6051 @xref{Font Files}.
6054 @node grotty, grops, Special Characters, Output Devices
6055 @section @code{grotty}
6056 @cindex @code{grotty}
6058 @c XXX
6060 @menu
6061 * Invoking grotty::             
6062 @end menu
6064 @node Invoking grotty,  , grotty, grotty
6065 @subsection Invoking @code{grotty}
6066 @cindex invoking @code{grotty}
6067 @cindex @code{grotty}, invoking
6069 @c XXX
6072 @node grops, grodvi, grotty, Output Devices
6073 @section @code{grops}
6074 @cindex @code{grops}
6076 @c XXX
6078 @menu
6079 * Invoking grops::              
6080 * Embedding PostScript::        
6081 @end menu
6083 @node Invoking grops, Embedding PostScript, grops, grops
6084 @subsection Invoking @code{grops}
6085 @cindex invoking @code{grops}
6086 @cindex @code{grops}, invoking
6088 @c XXX
6090 @node Embedding PostScript,  , Invoking grops, grops
6091 @subsection Embedding @sc{PostScript}
6092 @cindex embedding postscript
6093 @cindex postscript, embedding
6095 @c XXX
6098 @node grodvi, grolj4, grops, Output Devices
6099 @section @code{grodvi}
6100 @cindex @code{grodvi}
6102 @c XXX
6104 @menu
6105 * Invoking grodvi::             
6106 @end menu
6108 @node Invoking grodvi,  , grodvi, grodvi
6109 @subsection Invoking @code{grodvi}
6110 @cindex invoking @code{grodvi}
6111 @cindex @code{grodvi}, invoking
6113 @c XXX
6116 @node grolj4, grolbp, grodvi, Output Devices
6117 @section @code{grolj4}
6118 @cindex @code{grolj4}
6120 @c XXX
6122 @menu
6123 * Invoking grolj4::             
6124 @end menu
6126 @node Invoking grolj4,  , grolj4, grolj4
6127 @subsection Invoking @code{grolj4}
6128 @cindex invoking @code{grolj4}
6129 @cindex @code{grolj4}, invoking
6131 @c XXX
6134 @node grolbp, grohtml, grolj4, Output Devices
6135 @section @code{grolbp}
6136 @cindex @code{grolbp}
6138 @c XXX
6140 @menu
6141 * Invoking grolbp::             
6142 @end menu
6144 @node Invoking grolbp,  , grolbp, grolbp
6145 @subsection Invoking @code{grolbp}
6146 @cindex invoking @code{grolbp}
6147 @cindex @code{grolbp}, invoking
6149 @c XXX
6152 @node grohtml, gxditview, grolbp, Output Devices
6153 @section @code{grohtml}
6154 @cindex @code{grohtml}
6156 @c XXX
6158 @menu
6159 * Invoking grohtml::            
6160 @end menu
6162 @node Invoking grohtml,  , grohtml, grohtml
6163 @subsection Invoking @code{grohtml}
6164 @cindex invoking @code{grohtml}
6165 @cindex @code{grohtml}, invoking
6167 @c XXX
6170 @node gxditview,  , grohtml, Output Devices
6171 @section @code{gxditview}
6172 @cindex @code{gxditview}
6174 @c XXX
6176 @menu
6177 * Invoking gxditview::          
6178 @end menu
6180 @node Invoking gxditview,  , gxditview, gxditview
6181 @subsection Invoking @code{gxditview}
6182 @cindex invoking @code{gxditview}
6183 @cindex @code{gxditview}, invoking
6185 @c XXX
6186 @c X11's xditview
6190 @node File formats, Installation, Output Devices, Top
6191 @chapter File formats
6192 @cindex file formats
6193 @cindex formats, file
6195 @c XXX
6197 @menu
6198 * gtroff Output::               
6199 * Font Files::                  
6200 @end menu
6203 @node gtroff Output, Font Files, File formats, File formats
6204 @section @code{gtroff} Output
6205 @cindex @code{gtroff} output
6206 @cindex output, @code{gtroff}
6208 This section describes the format output of GNU @code{troff}.  The
6209 output format used by GNU @code{troff} is very similar to that used by
6210 @acronym{UNIX} device-independent @code{troff} (@code{ditroff}).
6212 @menu
6213 * Output Format::               
6214 * Device Control::              
6215 * Drawing Functions::           
6216 * Line Continuation::           
6217 @end menu
6219 @node Output Format, Device Control, gtroff Output, gtroff Output
6220 @subsection Output Format
6221 @cindex output format
6222 @cindex format of output
6224 @cindex 8-bit input
6225 @cindex input, 8-bit
6226 The output format is text based, as opposed to a binary format (like
6227 @TeX{} DVI).  The output format is @w{8-bit} clean, thus single
6228 characters can have the eighth bit set, as can the names of fonts and
6229 special characters.
6231 The output format consists of single command characters with attached
6232 parameters which are separated from subsequent text by whitespace or a
6233 newline.
6235 The names of characters and fonts can be of arbitrary length; drivers
6236 should not assume that they will be only two characters long (as
6237 @code{ditroff} does).
6239 When a character is to be printed, that character will always be in the
6240 current font.  Unlike @code{ditroff}, it is not necessary for drivers to
6241 search special fonts to find a character.
6243 @table @code
6244 @item H@var{n}
6245 @c XXX
6246 @item V@var{n}
6247 @c XXX
6248 @item h@var{n}
6249 @c XXX
6250 @item v@var{n}
6251 @c XXX
6252 @item c@var{n}
6253 @c XXX
6254 @item C@var{n}
6255 @c XXX
6256 @item @var{nn}@var{c}
6257 @c XXX
6258 @item t@var{xxx}
6259 @var{xxx} is any sequence of characters terminated by a space or a
6260 newline; the first character should be printed at the current position,
6261 the the current horizontal position should be increased by the width of
6262 the first character, and so on for each character.  The width of the
6263 character is that given in the font file, appropriately scaled for the
6264 current point size, and rounded so that it is a multiple of the
6265 horizontal resolution.  Special characters cannot be printed using this
6266 command.
6268 @kindex tcommand
6269 @pindex DESC
6270 This command is only allowed if the @samp{tcommand} line is present in
6271 the @file{DESC} file.
6272 @item u@var{n} @var{xxx}
6273 This is same as the @samp{t} command except that after printing each
6274 character, the current horizontal position is increased by the sum of
6275 the width of that character and@w{ }@var{n}.
6277 This command is only allowed if the @samp{tcommand} line is present in
6278 the @file{DESC} file.
6279 @item n@var{a}@var{b}
6280 @c XXX
6281 @item p@var{n}
6282 @c XXX
6283 @item s@var{n}
6284 @kindex sizescale
6285 @pindex DESC
6286 The argument to the @samp{s} command is in scaled points (units of
6287 points/@var{n}, where @var{n} is the argument to the @samp{sizescale}
6288 command in the @file{DESC} file).
6289 @item f@var{n}
6290 @item x @dots{} \n
6291 Device control.
6292 @c XXX more info
6293 @item D@var{c} @var{x}@dots{}\n
6294 @c XXX
6295 @end table
6297 @node Device Control, Drawing Functions, Output Format, gtroff Output
6298 @subsection Device Control
6299 @cindex device control
6300 @cindex control of devices
6302 The @samp{x} command is normally followed by a letter or word indicating
6303 the function to perform, followed by white space separated arguments.
6305 The first argument can be abbreviated to the first letter.
6307 @table @code
6308 @item x init
6309 @c XXX
6310 @item x T
6311 @c XXX
6312 @item x res @var{n} @var{h} @var{v}
6313 @c XXX
6314 @item x H
6315 @c XXX more info
6316 The argument to the @w{@samp{x Height}} command is also in scaled
6317 points.
6318 @end table
6320 The first three output commands are guaranteed to be:
6322 @example
6323 x T device
6324 x res n h v
6325 x init
6326 @end example
6328 @noindent
6329 For example, the input
6331 @example
6332 crunchy \fH\s+2frog\s0\fP!?
6333 @end example
6335 @noindent
6336 will produce
6338 @c XXX example
6340 @example
6341 ... sample output here ...
6342 @end example
6344 @node Drawing Functions, Line Continuation, Device Control, gtroff Output
6345 @subsection Drawing Functions
6346 @cindex drawing functions
6347 @cindex functions for drawing
6349 @pindex gpic
6350 The @samp{D} drawing command has been extended.  These extensions will
6351 only be used by GNU @code{pic} if the @option{-x} option is given.
6353 @xref{Drawing Requests}.
6355 @table @code
6356 @c XXX ...
6357 @item Df @var{n}
6358 Set the shade of gray to be used for filling solid objects to@w{
6359 }@var{n}; @var{n}@w{ }must be an integer between 0 and@w{ }1000, where 0
6360 corresponds solid white and 1000 to solid black, and values in between
6361 correspond to intermediate shades of gray.  This applies only to solid
6362 circles, solid ellipses and solid polygons.  By default, a level of@w{
6363 }1000 will be used.  Whatever color a solid object has, it should
6364 completely obscure everything beneath it.  A value greater than@w{ }1000
6365 or less than@w{ }0 can also be used: this means fill with the shade of
6366 gray that is currently being used for lines and text.  Normally this
6367 will be black, but some drivers may provide a way of changing this.
6368 @item DC @var{d}
6369 Draw a solid circle with a diameter of@w{ }@var{d} with the leftmost
6370 point at the current position.
6371 @item DE @var{dx} @var{dy}
6372 Draw a solid ellipse with a horizontal diameter of@w{ }@var{dx} and a
6373 vertical diameter of@w{ }@var{dy} with the leftmost point at the current
6374 position.
6375 @item Dp @var{dx1} @var{dy1} @var{dx2} @var{dy2} @dots{} @var{dxn} @var{dyn}
6376 Draw a polygon with.  The first vertex is at the current position, the
6377 second vertex at an offset (@var{dx1},@var{dy1}) from the current
6378 position, the second vertex at an offset (@var{dx2},@var{dy2}) from the
6379 first vertex, and so on up to the @var{n}-th vertex.  At the moment, GNU
6380 @code{pic} only uses this command to generate triangles and rectangles.
6381 @item DP @var{dx1} @var{dy1} @var{dx2} @var{dy2} @dots{} @var{dxn} @var{dyn}
6382 Like @code{Dp} but draw a solid rather than outlined polygon.
6383 @item Dt @var{n}
6384 @cindex line thickness
6385 @cindex thickness of lines
6386 Set the current line thickness to @var{n}@w{ }machine units.
6387 Traditionally, @acronym{UNIX} @code{troff} drivers use a line thickness
6388 proportional to the current point size; drivers should continue to do
6389 this if no @code{Dt} command has been given, or if a @code{Dt} command
6390 has been given with a negative value of@w{ }@var{n}.  A zero value of@w{
6391 }@var{n} selects the smallest available line thickness.
6392 @end table
6394 @findex \D
6395 A difficulty arises in how the current position should be changed after
6396 the execution of these commands.  This is not of great importance since
6397 the code generated by GNU @code{pic} does not depend on this.  Given a
6398 drawing command of the form
6400 @example
6401 \D'@var{c} @var{x1} @var{y1} @var{x2} @var{y2} @dots{} @var{xn} @var{yn}'
6402 @end example
6404 @findex \w
6405 @vindex st
6406 @findex sb
6407 @noindent
6408 where @var{c} is not one of @samp{c}, @samp{e}, @samp{l}, @samp{a} or
6409 @samp{~}, @acronym{UNIX} @code{troff} will treat each of the x@w{ }value
6410 as a horizontal quantity, and each of the y@w{ }values as a vertical
6411 quantity and will assume that the width of the drawn object is sum if
6412 all x@w{ }values, and that the height is the sum of all y@w{ }values.
6413 (The assumption about the height can be seen by examining the @code{st}
6414 and @code{sb} registers after using such a @code{D}@w{ }command in a
6415 @code{\w} escape sequence.)  This rule also holds for all the original
6416 drawing commands with the exception of @code{De}.  For the sake of
6417 compatibility GNU @code{troff} also follows this rule, even though it
6418 produces an ugly result in the case of the @code{Df}, @code{Dt}, and, to
6419 a lesser extent, @code{DE}@w{ }commands.  Thus after executing a
6420 @code{D}@w{ }command of the form
6422 @example
6423 D@var{c} @var{x1} @var{y1} @var{x2} @var{y2} @dots{} @var{xn} @var{yn}
6424 @end example
6426 @noindent
6427 the current position should be increased horizontally by the sum of all
6428 x@w{ }values and vertically by the sum of all y@w{ }values.
6430 @node Line Continuation,  , Drawing Functions, gtroff Output
6431 @subsection Line Continuation
6432 @cindex line continuation in output commands
6433 @cindex output commands, line continuation
6435 There is a continuation convention which permits the argument to the
6436 @w{@samp{x X}} command to contain newlines: When outputting the argument
6437 to the @w{@samp{x X}} command, GNU @code{troff} will follow each newline
6438 in the argument with a @samp{+} character (as usual, it will terminate
6439 the entire argument with a newline); thus if the line after the line
6440 containing the @w{@samp{x X}} command starts with @samp{+}, then the
6441 newline ending the line containing the @w{@samp{x X}} command should be
6442 treated as part of the argument to the @w{@samp{x X}} command, the
6443 @samp{+} should be ignored, and the part of the line following the
6444 @samp{+} should be treated like the part of the line following the
6445 @w{@samp{x X}} command.
6448 @node Font Files,  , gtroff Output, File formats
6449 @section Font Files
6450 @cindex font files
6451 @cindex files, font
6453 The @code{gtroff} font format is roughly a superset of the
6454 @code{ditroff} font format.  Unlike the @code{ditroff} font format,
6455 there is no associated binary format; all files are text files.  The
6456 font files for device @var{name} are stored in a directory
6457 @file{dev@var{name}}.  There are two types of file: a device description
6458 file called @file{DESC} and for each font@w{ }@samp{F} a font file
6459 called@w{ }@file{F}.
6461 @menu
6462 * DESC file format::            
6463 * Font file format::            
6464 @end menu
6466 @node DESC file format, Font file format, Font Files, Font Files
6467 @subsection @file{DESC} file format
6468 @cindex @file{DESC} file format
6469 @cindex font description file format
6470 @cindex format of font description file
6471 @pindex DESC
6473 The @file{DESC} file can contain the following types of line:
6475 @table @code
6476 @kindex res
6477 @item res @var{n}
6478 There are @var{n} machine units per inch.
6479 @kindex hor
6480 @item hor @var{n}
6481 The horizontal resolution is @var{n} machine units.
6482 @kindex vert
6483 @item vert @var{n}
6484 The vertical resolution is @var{n} machine units.
6485 @kindex sizescale
6486 @item sizescale @var{n}
6487 The scale factor for point sizes.  By default this has a value of@w{ }1.
6488 One scaled point is equal to one point/@var{n}.  The arguments to the
6489 @code{unitwidth} and @code{sizes} commands are given in scaled points.
6490 @xref{Fractional Type Sizes}, for more information.
6491 @kindex unitwidth
6492 @item unitwidth @var{n}
6493 Quantities in the font files are given in machine units for fonts whose
6494 point size is @var{n}@w{ }scaled points.
6495 @kindex tcommand
6496 @item tcommand
6497 This means that the postprocessor can handle the @samp{t} and @samp{u}
6498 output commands.
6499 @kindex sizes
6500 @item sizes @var{s1} @var{s2} @dots{} @var{sn} 0
6501 This means that the device has fonts at @var{s1}, @var{s2}, @dots{}
6502 @var{sn} scaled points.  The list of sizes must be terminated by a@w{
6503 }0.  Each @var{si} can also be a range of sizes @var{m}-@var{n}.  The
6504 list can extend over more than one line.
6505 @kindex styles
6506 @item styles @var{S1} @var{S2} @dots{} @var{Sm}
6507 The first @var{m}@w{ }font positions will be associated with styles
6508 @var{S1} @dots{} @var{Sm}.
6509 @kindex fonts
6510 @item fonts @var{n} @var{F1} @var{F2} @var{F3} @dots{} @var{Fn}
6511 Fonts @var{F1} @dots{} @var{Fn} will be mounted in the font positions
6512 @var{m}+1, @dots{}, @var{m}+@var{n} where @var{m} is the number of
6513 styles.  This command may extend over more than one line.  A font name
6514 of@var{ }0 will cause no font to be mounted on the corresponding font
6515 position.
6516 @kindex family
6517 @item family @var{fam}
6518 The default font family is @var{fam}.
6519 @kindex charset
6520 @item charset
6521 This line and everything following in the file are ignored.  It is
6522 allowed for the sake of backwards compatibility.
6523 @end table
6525 The @code{res}, @code{unitwidth}, @code{fonts} and @code{sizes} lines
6526 are compulsory.  Other commands are ignored by @code{gtroff} but may be
6527 used by postprocessors to store arbitrary information about the device
6528 in the @file{DESC} file.
6530 @c XXX add other commands resp. xrefs to output devices
6531 @c XXX add obsolete commands
6533 @node Font file format,  , DESC file format, Font Files
6534 @subsection Font file format
6535 @cindex font file format
6536 @cindex format of font files
6538 A font file has two sections.  The first section is a sequence of lines
6539 each containing a sequence of blank delimited words; the first word in
6540 the line is a key, and subsequent words give a value for that key.
6542 @table @code
6543 @kindex name
6544 @item name @var{F}
6545 The name of the font is@w{ }@var{F}.
6546 @kindex spacewidth
6547 @item spacewidth @var{n}
6548 The normal width of a space is@w{ }@var{n}.
6549 @kindex slant
6550 @item slant @var{n}
6551 The characters of the font have a slant of @var{n}@w{ }degrees.
6552 (Positive means forward.)
6553 @kindex ligatures
6554 @item ligatures @var{lig1} @var{lig2} @dots{} @var{lign} [0]
6555 Characters @var{lig1}, @var{lig2}, @dots{}, @var{lign} are ligatures;
6556 possible ligatures are @samp{ff}, @samp{fi}, @samp{fl}, @samp{ffi} and
6557 @samp{ffl}.  For backwards compatibility, the list of ligatures may be
6558 terminated with a@w{ }0.  The list of ligatures may not extend over more
6559 than one line.
6560 @kindex special
6561 @item special
6562 The font is special; this means that when a character is requested that
6563 is not present in the current font, it will be searched for in any
6564 special fonts that are mounted.
6565 @end table
6567 Other commands are ignored by @code{gtroff} but may be used by
6568 postprocessors to store arbitrary information about the font in the font
6569 file.
6571 @cindex comments in font files
6572 @cindex font files, comments
6573 @kindex #
6574 The first section can contain comments which start with the @samp{#}
6575 character and extend to the end of a line.
6577 The second section contains one or two subsections.  It must contain a
6578 @code{charset} subsection and it may also contain a @code{kernpairs}
6579 subsection.  These subsections can appear in any order.  Each
6580 subsection starts with a word on a line by itself.
6582 @kindex charset
6583 The word @code{charset} starts the character set subsection.  The
6584 @code{charset} line is followed by a sequence of lines.  Each line gives
6585 information for one character.  A line comprises a number of fields
6586 separated by blanks or tabs.  The format is
6588 @c XXX fix it for new HTML additions
6590 @example
6591 @var{name} @var{metrics} @var{type} @var{code} @var{comment}
6592 @end example
6594 @cindex 8-bit input
6595 @cindex input, 8-bit
6596 @findex \N
6597 @kindex ---
6598 @noindent
6599 @var{name} identifies the character: If @var{name} is a single
6600 character@w{ }@var{c} then it corresponds to the @code{gtroff} input
6601 character @var{c}; if it is of the form @samp{\@var{c}} where @var{c} is
6602 a single character, then it corresponds to the @code{gtroff} input
6603 character@w{ }\@var{c}; otherwise it corresponds to the groff input
6604 character @samp{\[@var{name}]}.  (If it is exactly two characters
6605 @var{xx} it can be entered as @samp{\(@var{xx}}.)  @code{gtroff}
6606 supports 8-bit characters; however some utilities have difficulties with
6607 eight-bit characters.  For this reason, there is a convention that the
6608 name @samp{char@var{n}} is equivalent to the single character whose code
6609 is@w{ }@var{n}.  For example, @samp{char163} would be equivalent to the
6610 character with code@w{ }163 which is the pounds sterling sign in @w{ISO
6611 Latin-1} character set.  The name @samp{---} is special and indicates
6612 that the character is unnamed; such characters can only be used by means
6613 of the @code{\N} escape sequence in @code{gtroff}.
6615 @c XXX input encodings vs. output encodings
6617 The @var{type} field gives the character type:
6619 @table @code
6620 @item 1
6621 the character has an descender, for example, `p';
6622 @item 2
6623 the character has an ascender, for example, `b';
6624 @item 3
6625 the character has both an ascender and a descender, for example, `('.
6626 @end table
6628 The @var{code} field gives the code which the postprocessor uses to
6629 print the character.  The character can also be input to @code{gtroff}
6630 using this code by means of the @code{\N} escape sequence.  The code can
6631 be any integer.  If it starts with @samp{0} it will be interpreted as
6632 octal; if it starts with @samp{0x} or @samp{0X} it will be interpreted as
6633 hexadecimal.
6635 Anything on the line after the @var{code} field will be ignored.
6637 The @var{metrics} field has the form:
6639 @example
6640 @var{width}[,@var{height}[,@var{depth}[,@var{italic_correction}
6641   [,@var{left_italic_correction}[,@var{subscript_correction}]]]]]
6642 @end example
6644 @noindent
6645 There must not be any spaces between these subfields (it has been split
6646 here into two lines for better legibility only).  Missing subfields are
6647 assumed to be@w{ }0.  The subfields are all decimal integers.  Since
6648 there is no associated binary format, these values are not required to
6649 fit into a variable of type @samp{char} as they are in @code{ditroff}.
6650 The @var{width} subfield gives the width of the character.  The
6651 @var{height} subfield gives the height of the character (upwards is
6652 positive); if a character does not extend above the baseline, it should
6653 be given a zero height, rather than a negative height.  The @var{depth}
6654 subfield gives the depth of the character, that is, the distance below
6655 the lowest point below the baseline to which the character extends
6656 (downwards is positive); if a character does not extend below above the
6657 baseline, it should be given a zero depth, rather than a negative depth.
6658 The @var{italic_correction} subfield gives the amount of space that
6659 should be added after the character when it is immediately to be
6660 followed by a character from a Roman font.  The
6661 @var{left_italic_correction} subfield gives the amount of space that
6662 should be added before the character when it is immediately to be
6663 preceded by a character from a Roman font.  The
6664 @var{subscript_correction} gives the amount of space that should be
6665 added after a character before adding a subscript.  This should be less
6666 than the italic correction.
6668 A line in the @code{charset} section can also have the format
6670 @example
6671 @var{name} "
6672 @end example
6674 @noindent
6675 This indicates that @var{name} is just another name for the character
6676 mentioned in the preceding line.
6678 @kindex kernpairs
6679 The word @code{kernpairs} starts the kernpairs section.  This contains a
6680 sequence of lines of the form:
6682 @example
6683 @var{c1} @var{c2} @var{n}
6684 @end example
6686 This means that when character @var{c1} appears next to character
6687 @var{c2} the space between them should be increased by@w{ }@var{n}.
6688 Most entries in kernpairs section will have a negative value for@w{
6689 }@var{n}.
6693 @node Installation, Request and Operator Index, File formats, Top
6694 @chapter Installation
6695 @cindex installation
6697 @c XXX
6701 @node Request and Operator Index, Register Index, Installation, Top
6702 @chapter Request and Operator Index
6704 @printindex fn
6708 @node Register Index, Font File Keyword Index, Request and Operator Index, Top
6709 @chapter Register Index
6711 @printindex vr
6715 @node Font File Keyword Index, Program and File Index, Register Index, Top
6716 @chapter Font File Keyword Index
6718 @printindex ky
6722 @node Program and File Index, Concept Index, Font File Keyword Index, Top
6723 @chapter Program  and File Index
6725 @printindex pg
6729 @node Concept Index,  , Program and File Index, Top
6730 @chapter Concept Index
6732 @printindex cp
6736 @summarycontents
6737 @contents
6738 @bye