[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Groff] UTP and "WYSIWYG" groff
[Groff] UTP and "WYSIWYG" groff
Fri, 14 Mar 2003 21:15:52 -0000 (GMT)
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
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.
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
.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
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".
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
.nr PO 1.195i
.nr LL 9.5i
.nr LT \\n[LL]u
which serves this purpose).
NOW FOR THE SCRIPT:
if [ "`basename $0`" = "ge_L" ] ; then
export GROFFge="groff -P-l -rPL=8.267 -rLL=9.693"
echo "Landscape Mode"
echo "Portrait Mode"
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
if [ ! -s $trname.ps ] ; then
echo '%!PS-Adobe-3.0' > $trname.ps
xterm -name "GE_aux" -title "GE_x_$trname" \
-geometry 80x36+0-0 &
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 &
ps -ax | grep gv | grep -v grep
while [ -n "`ps -ax | grep -v grep | grep $gvpid`" ] ; do
if [ $trname.tr -nt $trname.watch ] ; then
$GROFFge -Tps -dgrDATE="$grDATE" -tpe -ms $trname.tr > $trname.ps
kill -1 $gv_PID
kill -15 $AUX_ID
Best wishes to all,
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 167 1972
Date: 14-Mar-03 Time: 21:15:52
------------------------------ XFMail ------------------------------
|[Prev in Thread]
||[Next in Thread]|
- [Groff] UTP and "WYSIWYG" groff,
Ted Harding <=