groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] Re: Disabling SGR in grotty(1): gory details


From: Werner LEMBERG
Subject: [Groff] Re: Disabling SGR in grotty(1): gory details
Date: Wed, 23 Oct 2002 23:49:37 +0200 (CEST)

> This seemed to work at a glance, but later I discovered the
> new .output command, and modified this as follows (the new
> version produced less noise for ``troff -Tascii /dev/null''):
>
> .if n .do output "x X tty: sgr 0

See below.

> This seemed to work too, but after a further inspection it
> turned out it did not -- it broke horribly with everything
> formatted with the -ms package -- try it with this small
> chunk of -ms formatted text:
>
> .TL
> Title
> .AU
> Author
> .PP
>
> $ groff -b -Tascii -mtty-char -ms <this_chunk>
> /usr/share/tmac/s.tmac:1095: backtrace: macro address@hidden'
> /usr/share/tmac/s.tmac:172: backtrace: macro `TL'
> x:1: warning: number register `0:LL' not defined
> /usr/share/tmac/s.tmac:1095: backtrace: macro address@hidden'
> /usr/share/tmac/s.tmac:172: backtrace: macro `TL'
> x:1: warning: number register `0:ri' not defined
> /usr/share/tmac/s.tmac:1095: backtrace: macro address@hidden'
> /usr/share/tmac/s.tmac:172: backtrace: macro `TL'
> x:1: warning: number register `0:pri' not defined
> ...

Reason for the failure is that the ms package plants a trap at
position zero to call cov*first-page-init; after executing the .output
request *before* loading the ms macros this trap isn't called at the
right time.

> Then I remembered seeing this in the Groff info document:
>
> : This request can't be used before the first page has started - if
> : you get an error, simply insert `.br' before the `output' request.
>
> I wondered why I do not get any meaningful error as was promised.

Because the error is based on a not-called macro, and not of an
internal failure of groff; since .output is called in the top
diversion, a new page is started automatically.

> So I have a bunch of questions here, in the order of importancy:
>
> 1.  How do I disable the SGR output from troffrc or troffrc-end?

You must undo the top of page transition by setting the `nl' register
to a negative value:

  .if n \{\
  .  do output "x X tty: sgr 0
  .  nr nl 0-1
  .\}

A very obscure feature but documented in groff.texinfo...  BUT see
below.

> 2.  Why don't I get the same error from using .output in troffrc
>     as if I put it in troffrc-end?

Because the first time the trap isn't invoked, and the second time it
is.

> 3.  Why am I getting these spurious ``character above first line
>     discarded'' warnings from all -ms formatted texts when SGR
>     encoded output is enabled?

If you look at the troff output (with the above change to troffrc),
you see something similar to this:

  x T ascii
  x res 240 24 40
  x init
  p1
  x X tty: sgr 0
  DFd
  x font 1 R
  f1
  s10
  V160
  H696
  md
  t-2-
  ...

The `x X' line is emitted with the vertical position at zero.
`Vertical position' is the position of the *baseline*; since there are
no default offsets for tty, line 0 can't be displayed and is thus
discarded.  As soon as there is real output, the line number is
increased by one.

Thus our next job is to ensure that the vertical position is not zero
while emitting the `x X' line:

  .if n \{\
  .  do nop \X'tty: sgr 0'
  .  sp -1
  .  nr nl 0-1
  .\}

Result:

  x T ascii
  x res 240 24 40
  x init
  p1
  V40
  H0
  x font 1 R
  f1
  s10
  md
  DFd
  x X tty: sgr 0
  n40 0
  V160
  H696
  t-2-
  ...

This is still not correct: Note the `t-2-' line.  As the last
correction, we have to decrease the current page number by 1.

  .if n \{\
  .  do nop \X'tty: sgr 0'
  .  sp -1
  .  nr % -1 
  .  nr nl 0-1
  .\}

Please test.


     Werner

reply via email to

[Prev in Thread] Current Thread [Next in Thread]