13.  Environments

      As we mentioned, there is a potential problem when going across a page boundary: parameters like size and font for a page title may well be different from those in effect in the text when the page boundary occurs. troff provides a very general way to deal with this and similar situations. There are three `environments', each of which has independently settable versions of many of the parameters associated with processing, including size, font, line and title lengths, fill/nofill mode, tab stops, and even partially collected lines. Thus the titling problem may be readily solved by processing the main text in one environment and titles in a separate one with its own suitable parameters.

      The command .ev nshifts to environment nnmust be 0, 1 or 2. The command .evwith no argument returns to the previous environment. Environment names are maintained in a stack, so calls for different environments may be nested and unwound consistently.

      Suppose we say that the main text is processed in environment 0, which is where troff begins by default. Then we can modify the new page macro .NPto process titles in environment 1 like this: ^de NP
^ev 1 \" shift to new environment
^lt 6i \" set parameters here
^ft R
^ps 10
... any other processing ...
^ev \" return to previous environment
^^
It is also possible to initialize the parameters for an environment
outside the
.NPmacro,
but the version shown keeps all the processing in one place
and is thus easier to understand and change.