GNU Info

Info Node: (groff)Writing Macros

(groff)Writing Macros


Next: Page Motions Prev: Conditionals and Loops Up: gtroff Reference
Enter node , (file) or (file)node

Writing Macros
==============

   A "macro" is a collection of text and embedded commands which can be
invoked multiple times.  Use macros to define common operations.

 - Request: .de name [end]
     Define a new macro named NAME.  `gtroff' copies subsequent lines
     (starting with the next one) into an internal buffer until it
     encounters the line `..' (two dots).  The optional second argument
     to `de' changes this to a macro to `.END'.

     Note that no leading whitespace is allowed in the line containing
     the ending token (either `..' or the macro `.END').

     Here a small example macro called `P' which causes a break and
     inserts some vertical space.  It could be used to separate
     paragraphs.


          .de P
          .  br
          .  sp .8v
          ..


 - Request: .am xx
     Works similarly to `de' except it appends onto the macro named XX.
     So, to make the previously defined `P' macro actually do indented
     instead of block paragraphs, add the necessary code to the
     existing macro like this:


          .am P
          .ti +5n
          ..


 - Request: .als new old
     Create an alias named NEW for the request, string, macro, or
     diversion object named OLD.  The new name and the old name are
     exactly equivalent (it is similar to a hard rather than a soft
     link). If OLD is undefined, `gtroff' generates a warning of type
     `mac' and ignores the request.

     The `de', `am', `di', `da', `ds', and `as' requests only create a
     new object if the name of the macro, diversion or string diversion
     is currently undefined or if it is defined to be a request;
     normally they modify the value of an existing object.

Copy-in Mode
Parameters

automatically generated by info2www version 1.2.2.9