Mom -- Graphical Objects

Back to Table of Contents | Next: Document processing

# Graphical objects

- Introduction to graphical objects
- Graphical objects behaviour
- Order of arguments
- Index of graphical objects macros

## Introduction to graphical objects

Groff has a number of inline escapes for drawing rules, polygons, ellipses and splines. All begin with `\D` (presumably for “Draw”) and are documented in the groff info manual:
info groff => Escape index => \D The escapes allow you to draw just about any simple graphical object you can think of, but owing to their syntax, they’re not always easy to read, which can make tweaking them difficult. Additionally, while they perform in a consistent manner, they don’t always perform in an expected manner.

Experience shows that the most common graphical elements typesetters need are rules (horizontal and vertical), boxes, and circles (or ellipses). For this reason, mom provides macros to draw these objects in an easy-to-understand way; the results are predictable, and mom’s syntax makes fixes or tweaks painless.

For example, if you want to draw a 2-inch square outline box at the left margin using groff’s `\D` escapes, it looks like this:
back up by weight +-------+ | | \D't 500'\h'-500u'\D'p 2i 0 0 2i -2i 0 0 -2i' | | | | +-------+ +------------------------+ set rule draw box, 1 line at a time weight Obviously, this isn’t very efficient for something as simple as a box.

Here’s the same box, drawn with mom’s box drawing macro, `DBX`:
left margin indent--+ +--box width | | .DBX .5 0 2i 2i | | rule weight--+ +--box depth (in points)

Mom’s graphical object macros allow—in fact, require—giving the rule weight (“thickness”) for the object (or saying that you want it filled), an indent from the left margin where the object begins, the dimensions of the object, and optionally a colour for the object.

There are no defaults for the arguments to mom'a graphical object macros, which means you must supply the arguments every time you invoke them.

Note: As stated above, mom only provides macros for commonly-used graphical objects (rules, boxes, circles). More complex objects (polygons, non-straight lines, splines) must be drawn using groff’s `\D` escapes.

### Graphical object behaviour

Mom’s graphical object macros all behave in the following, carved-in-stone ways:

1. Objects are drawn from the baseline down, including horizontal rules.
2. Objects begin precisely at the left indent supplied as an argument to the macro.
3. Objects are drawn from left to right.
4. Enclosed objects (boxes, circles) are drawn from the perimeter inward.
5. Objects return to their horizontal/vertical point of origin.

The consistency means that once you've mastered the very simple order of arguments that applies to invoking graphical object macros, you can draw objects with full confidence that you know exactly where they’re placed and how much room they occupy. Furthermore, because all return to their point of origin, you’ll know exactly where you are on the page.

### Order of arguments

The order of arguments to the graphical object macros is the same for every macro:

- the `W`eight of the rule
  - if the object is enclosed (i.e. is a box or circle), the weight of the rule if you want the object outlined
  - the single word, `SOLID`, may be used in place of the weight argument if you want the object filled
- the `I`ndent from the current left margin at which to begin the object
- the `L`ength of the object, if applicable
- the `D`epth of the object, if applicable
- the `C`olour of the object (optional)

A simple mnemonic for the order of arguments is “WILD Card”. If you fix the mnemonic in your brain and apply a little judicious reasoning, you’ll always remember how to draw graphical objects. The “judicious reasoning” means that, for example, horizontal rules don’t require a depth and vertical rules don’t require a length. Thus, in the case of drawing a horizontal rule, you supply the macro, `DRH`, with only the arguments (from the mnemonic) that apply: W-I-L (and possibly C).

### Graphical objects macros

- DRH – horizontal rules
- DRV – vertical rules
- DBX – box
- DCL – circles or ellipses

### Drawing horizontal rules

Macro: DRH `<none> | <weight> <indent> <length> [<colour>]`

• the argument to `<weight>` is in points, but do NOT append the unit of measure, `p`
• `<indent>` and `<length>` require a unit of measure
• arithmetic expressions to `<indent>` and `<length>` must be surrounded by parentheses

If all you want is to draw a rule from your current left margin to your current right margin (in other words, a "full measure" rule), you may invoke `.DRH` without any arguments.

Note: DRH is the only graphical object macro that may be invoked without arguments. The weight (“thickness”) of the rule is determined by the argument you last gave the macro, RULE_WEIGHT. DRH, used this way, is exactly equivalent to entering the inline escape, `\*[RULE]`.

To draw horizontal rules of a specified length, you must, at a minimum, supply DRH with the arguments `weight,` `indent` (measured from the current left margin) and `length`.

Optionally, you may give a `colour` argument. The colour may be either one defined with NEWCOLOR, or a named X-colour inititialized with XCOLOR, or an X-colour alias (again, initialized with XCOLOR).

Say, for example, you want to draw a 1-1/4 point horizontal rule that starts 2 picas from the current left margin and runs for 3 inches. To do so, you'd invoke `.DRH` like this:
weight length | | .DRH 1.25 2P 3i | indent (Note that the rule weight argument, which is expressed in points, must NOT have the unit of measure `p` appended to it.)

If, in addition, you want the rule blue:
.DRH 1.25 2P 3i blue

### How mom handles the positioning of horizontal rules

Horizontal rules are drawn from left to right, and from the baseline down. “From the baseline down” means that if you request a rule with a weight of four points, the four points of rule fall entirely below the baseline.

Furthermore, after the rule is drawn, mom returns you to the current left margin, at the same vertical position on the page as when DRH was invoked. In other words, DRH causes no movement on the page, either horizontal or vertical.

### Drawing vertical rules

Macro: DRV `<weight> <indent> <depth> [<colour>]`

• the argument to `<weight>` is in points, but do NOT append the unit of measure, `p`
• `<indent>` and `<depth>` require a unit of measure
• arithmetic expressions to `<indent>` and `<depth>` must be surrounded by parentheses

To draw vertical rules of a specified length, you must, at a minimum, supply DRV with the arguments `weight,` `indent` (measured from the current left margin) and `depth`.

Optionally, you may give a `colour` argument. The colour may be either one defined with NEWCOLOR, or a named X-colour inititialized with XCOLOR, or an X-colour alias (again, initialized with XCOLOR).

Say, for example, you want to draw a 3/4-point vertical rule that starts 19-1/2 picas from the current left margin and has a depth of 6 centimeters. To do so, you'd invoke `.DRV` like this:
weight depth | | .DRV .75 19P+6p 6c | indent (Note that the rule weight argument, which is expressed in points, must NOT have the unit of measure `p` appended to it.)

If, in addition, you want the rule red:
.DRV .75 19P+6p 6c red

### How mom handles the positioning of vertical rules

Vertical rules are drawn from the baseline down, and from left to right. "Left to right" means that if you request a rule with a weight of four points, the four points of rule fall entirely to the left of the indent given to DRV.

Furthermore, after the rule is drawn, mom returns you to the current left margin, at the same vertical position on the page as when DRV was invoked. In other words, DRV causes no movement on the page, either horizontal or vertical.

### Drawing boxes

Macro: DBX `< <weight> | SOLID > <indent> <length> <depth> [<colour>]`

• the argument to `<weight>` is in points, but do NOT append the unit of measure `p`
• `<indent>`, `<length>`, and `<depth>` require a unit of measure
• arithmetic expressions to `<indent>`, `<length>`, and `<depth>` must be surrounded by parentheses

To draw boxes of specified dimensions, you must, at a minimum, supply DBX with the arguments `weight` or `SOLID`, `indent` (measured from the current left margin), `length` and `depth`.

Optionally, you may give a `colour` argument. The colour may be either one defined with NEWCOLOR, or a named X-colour inititialized with XCOLOR, or an X-colour alias (again, initialized with XCOLOR).

Say, for example, you want to draw a 1/2 point outline box that starts one inch from the current left margin and has the dimensions 12 picas x 6 picas. To do so, you'd invoke `.DBX` like this:
indent depth | | .DBX .5 1i 12P 6P | | weight length (Note that the box weight argument, which is expressed in points, must NOT have the unit of measure `p` appended to it.)

If you want the same box, but solid (“filled”) rather than drawn as an outline:
.DBX SOLID 1i 12P 6P Additionally, if you want the box green:
.DBX .5 1i 12P 6P green or .DBX SOLID 1i 12P 6P green

### How mom handles the positioning of boxes

Boxes are drawn from the baseline down, from left to right, and from the perimeter inward. “From the perimeter inward” means that if you request a box weight of six points, the 6-point rules used to draw the outline of the box fall entirely within the dimensions of the box.

Furthermore, after the box is drawn, mom returns you to the current left margin, at the same vertical position on the page as when DBX was invoked. In other words, DBX causes no movement on the page, either horizontal or vertical.

### Drawing circles (ellipses)

Macro: DCL `< <weight> | SOLID > <indent> <length> <depth> [<colour>]`

• the argument to `<weight>` is in points, but do NOT append the unit of measure, `p`
• the arguments `<indent>`, `<length>` and `<depth>` require a unit of measure
• arithmetic expressions to `<indent>`, `<length>` and `<depth>` must be surrounded by parentheses

To draw circles of specified dimensions, you must, at a minimum, supply DCL with the arguments `weight` or `SOLID`, `indent` (measured from the current left margin), `length` and `depth`.

Optionally, you may give a `colour` argument. The colour may be either one defined with NEWCOLOR, or a named X-colour inititialized with XCOLOR, or an X-colour alias (again, initialized with XCOLOR).

Say, for example, you want to draw a 1/2 point outline circle (ellipse, actually, in this case) that starts one inch from the current left margin and has the dimensions 6 centimeters x 3 centimeters. To do so, you'd invoke `.DCL` like this:
indent depth | | .DCL .5 1i 6c 3c | | weight length (Note that the box weight argument, which is expressed in points, must NOT have the unit of measure `p` appended to it.)

If you want the same box, but solid (“filled”) rather than drawn as an outline:
.DCL SOLID 1i 6c 3c Additionally, if you want the circle yellow:
.DCL .5 1i 6c 3c yellow or .DCL SOLID 1i 6c 3c yellow

### How mom handles the positioning of circles (ellipses)

Circles (ellipses) are drawn from the baseline down, from left to right, and from the perimeter inward. “From the perimeter inward” means that if you request a circle weight of six points, the 6-point rule used to draw the outline of the circle or ellipse falls entirely within the dimensions of the circle or ellipse.

Furthermore, after the circle is drawn, mom returns you to the current left margin, at the same vertical position on the page as when DCL was invoked. In other words, DCL causes no movement on the page, either horizontal or vertical.

Back to Table of Contents | Top | Next: Document processing