groff
[Top][All Lists]
Advanced

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

[Groff] UTP and "WYSIWYG" groff


From: Ted Harding
Subject: [Groff] UTP and "WYSIWYG" groff
Date: Fri, 14 Mar 2003 21:15:52 -0000 (GMT)

Hi Folks,

First, many congratulations to Larry Kollar and The UTP Team
for producing an almost complete version of "Unix Text Processing".
A very fine effort, beautifully done.

For those who want to find it, see

  http://www.alltel.net/~kollar/utp/

Browsing though this reminded me that a "turn-off" for many
is the non-WYSISYG nature of troff/groff. Of course, those
who got used to it in the old days also got accustomed to
mentally visualising what the results would look like, but
that's still an effort.

For some years, I've been using a script which in effect
offers slightly delayed WYSIWIG visualisation to the groff
user. In effect, editing the groff source (in 'vim' in my case)
you also have 'gv' rendering the PostScript output. Every so
often, you save your file (using ":w") which triggers an
automatic formatting by groff into PS output, which is then
immediately re-read by gv. On a reasonably fast system, even
a large document gets re-displayed within a second or two, and
in any case immediately groff has finished re-formatting it.

Below is a version of the script; it's filename is 'ge'
("groff edit") and of course it has permission 755. There is also
a command 'ge_L' for working in Landscape orientation; this is a
symbolic link to 'ge', and 'ge' starts by finding out how it was
called. I have tried to strip out "localisms", though some parameters
(such as "geometry" for the various X windows, or the use of "ms"
macros; and some people may prefer another editor such as emacs or
nedit rather than vim) will need to be changed by other users to suit
their own needs).

Clearly, it is highly dependent on the way Unix/Linux works,
and also requires an X-Windows environment. I don't know how
DOS/Windows users of groff would achieve anything comparable,
though it might be possible.

USAGE:

   ge filename

opens:

a) an xterm holding a 'vim' editing session on file "filename.tr".
   If this is a new file, two lines are planted at the start of the
   file:
     .ds DATE <system date at file creation time>
     .\".ds DATE \*[grDATE]"
   The first defines string DATE as the document creation date,
   the second takes the string grDATE as defined in the groff
   command line when 'ge' is invoked, and it is the date on
   which the editing session began. By choosing which one is
   "commented out" you can have either date substituted in
   your formatted document (and "grDATE" remains available,
   e.g. as a verion date or date of printing).

b) a PostScript file "filename.ps" which will contain formatted
   groff output. If this is a new file, it has the line
   %%PS-Adobe 3.0
   planted at its start, so that it is a valid (if otherwise
   empty) PostScript file, and will be read without fault by 'gv'.

c) An instance of 'gv', reading "filename.ps". Whenever this file
   is changed, a signal is sent to 'gv' which then re-reads the file.

d) An auxiliary xterm window, open in the working directory which was
   current when 'ge' was invoked, which allows the user to "work on
   the side" (e.g. editing other relevant files) while working in 'ge'.

Working: The user edits "filename.tr" in (a). At any time, if the
user executes the 'vim' command ":w", thereby saving the work at
that point, an instance of 'groff' is automatically invoked which
emits formatted PS into "filename.ps". This is done by having a
loop which compares the time stamp on "filename.tr" with the timestamp
on a file "filename.watch" which was 'touch'ed last time "filename.tr"
was changed; if the former is newer than the latter, 'groff' is invoked.
When 'groff has finished its job, a "kill -1" signal is sent to 'gv',
which forces it to re-read "filename.ps".

When the editing session is finished, closing the 'gv' window (e.g.
by typing "q" when it is raised) will also kill the auxiliary window,
leaving only the 'vim' window. At this point, quit altogether by
entering the vim command ":wq".


USAGE:

    ge_L

does exactly the same, except that everything is done in Landscape
orientation (though it is up to the user to insert Landscape page
metrics into the "filename.tr" document: for instance I have a macro

    .de landscape_metrics
    .pl 8.142i
    .nr PO 1.195i
    .nr LL 9.5i
    .lt \\n[LL]u
    .nr LT \\n[LL]u
    ..

which serves this purpose).

NOW FOR THE SCRIPT:
===================

#! /bin/bash
    export gv_PID=$!
   export SCALEBASE="1"

## Normal
export GROFFge="groff"
export MODEge="Portrait"
export GEOMgv="978x820-0+0"
export GEOMge="80x36+127+0"

## Landscape
if [ "`basename $0`" = "ge_L" ] ; then
  export GROFFge="groff -P-l -rPL=8.267 -rLL=9.693"
  echo "Landscape Mode"
  export MODEge="Landscape"
  export GEOMgv="1100x750-0+0"
  export GEOMge="80x47+255+0"
else
  echo "Portrait Mode"
fi

touch $trname.tr
touch $trname.watch
touch $trname.ps
export grDATE="`date +'%-d %B %Y'`"

if [ ! -s $trname.tr ] ; then
  echo -n ".ds DATE " > $trname.tr
  date +'%-d %B %Y' >> $trname.tr
  echo -n ".\\\".ds DATE \\*[grDATE]" >> $trname.tr
fi

if [ ! -s $trname.ps ] ; then
  echo '%!PS-Adobe-3.0' > $trname.ps
fi

xterm -name "GE_aux" -title "GE_x_$trname" \
   -geometry 80x36+0-0 &
export AUX_ID=$!
xterm -name "GE $trname.tr" -title "GE $trname.tr" \
      -geometry $GEOMge -fn 10x20 \
      -e vim $trname.tr &
gv -scale 2 -scalebase $SCALEBASE -antialias -spartan \
   -geometry $GEOMgv $trname.ps &
export gv_PID=$!

export gvpid=$!
echo $gvpid
ps -ax | grep gv | grep -v grep

while [ -n "`ps -ax |  grep -v grep | grep $gvpid`" ] ; do
  if [ $trname.tr -nt $trname.watch ] ; then
    touch $trname.watch
    $GROFFge -Tps -dgrDATE="$grDATE" -tpe -ms $trname.tr > $trname.ps
    kill -1 $gv_PID
  fi
done
rm $trname.watch
kill -15 $AUX_ID

================================================================

Best wishes to all,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 167 1972
Date: 14-Mar-03                                       Time: 21:15:52
------------------------------ XFMail ------------------------------

reply via email to

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