Next: , Previous: Suppressing output, Up: gtroff Reference


5.28 Colors

— Request: .color [n]
— Register: \n[.color]

If n is missing or non-zero, activate colors (this is the default); otherwise, turn it off.

The read-only number register .color is 1 if colors are active, 0 otherwise.

Internally, color sets a global flag; it does not produce a token. Similar to the cp request, you should use it at the beginning of your document to control color output.

Colors can be also turned off with the -c command line option.

— Request: .defcolor ident scheme color_components

Define color with name ident. scheme can be one of the following values: rgb (three components), cmy (three components), cmyk (four components), and gray or grey (one component).

Color components can be given either as a hexadecimal string or as positive decimal integers in the range 0–65535. A hexadecimal string contains all color components concatenated. It must start with either # or ##; the former specifies hex values in the range 0–255 (which are internally multiplied by 257), the latter in the range 0–65535. Examples: #FFC0CB (pink), ##ffff0000ffff (magenta). The default color name value is device-specific (usually black). It is possible that the default color for \m and \M is not identical.

A new scaling indicator f has been introduced which multiplies its value by 65536; this makes it convenient to specify color components as fractions in the range 0 to 1 (1f equals 65536u). Example:

          
          .defcolor darkgreen rgb 0.1f 0.5f 0.2f

Note that f is the default scaling indicator for the defcolor request, thus the above statement is equivalent to

          
          .defcolor darkgreen rgb 0.1 0.5 0.2
— Request: .gcolor [color]
— Escape: \mc
— Escape: \m(co
— Escape: \m[color]
— Register: \n[.m]

Set (glyph) drawing color. The following examples show how to turn the next four words red.

          
          .gcolor red
          these are in red
          .gcolor
          and these words are in black.
          
          \m[red]these are in red\m[] and these words are in black.

The escape \m[] returns to the previous color, as does a call to gcolor without an argument.

The name of the current drawing color is available in the read-only, string-valued number register ‘.m’.

The drawing color is associated with the current environment (see Environments).

Note that \m doesn't produce an input token in gtroff. As a consequence, it can be used in requests like mc (which expects a single character as an argument) to change the color on the fly:

          
          .mc \m[red]x\m[]
— Request: .fcolor [color]
— Escape: \Mc
— Escape: \M(co
— Escape: \M[color]
— Register: \n[.M]

Set fill (background) color for filled objects drawn with the \D'...' commands.

A red ellipse can be created with the following code:

          
          \M[red]\h'0.5i'\D'E 2i 1i'\M[]

The escape \M[] returns to the previous fill color, as does a call to fcolor without an argument.

The name of the current fill (background) color is available in the read-only, string-valued number register ‘.M’.

The fill color is associated with the current environment (see Environments).

Note that \M doesn't produce an input token in gtroff.