> Nevertheless, I think it would be better then to store both
> a tmac.<foo>-raw file and a preprocessed tmac.<foo>.

>From what I've read, the old Bell Labs [nt]roff had an option
to read macro files in a sort of "compiled" version (to reduce
startup time), so if one used this feature it would have been
useful to install the compiled version of the *preprocessed*
macro file.  But this is probably irrelevant for groff.


> Maybe a convention similar to that used for man pages --
> list required preprocessors on the first line of the source
> in a comment -- would  be better?

Interesting that you mention this, because that's exactly
what I usually do (inspired by man, of course).  That is,
I have a shell script "myroff" [*] which reads the first
line of the input file, interprets it as options, and calls
groff accordingly (and also opens/refreshes the gv window
with the output).  You could also use this shell script as
a replacement for the "driver" program groff and build your
own pipeline with it instead.

(It goes without saying that such a script is of course
permanently under construction.)


[*] which, by the way, is bound to <F1> in Vim via

  au BufNewFile,BufRead *.ro map <buffer> <F1> :up<CR>:!myroff "%"<CR><CR>

in my .vimrc (my *roff files are recognized by a ".ro"
(for "runoff") extension).


#!/bin/bash

# set -x
  trap "" 1

  roff="$1"
  post=`dirname "$1"`/`basename "$1" .ro`.ps
  view="gv --nowatch"
# groff="$HOME/comp/src/groff-cvs/groff/test-groff -P -F$HOME/lib/roff/font"
  groff=groff
# GROFF_FONT_PATH=$HOME/lib/fonts/DIT-edited:$HOME/lib/fonts/DIT-generated
  GROFF_FONT_PATH=$HOME/lib/roff/font
  export GROFF_FONT_PATH

  refresh(){
    test -z "$1" && { $view "$post" & } || kill -HUP $1
  }

  opt=""
  sort="no"
  manual="false"
  duplex="true"
  read comment options <"$roff"

  for option in $options
  do
    case $option in
      soelim)  opt="$opt -s";;
      tbl)     opt="$opt -t";;
      eqn)     opt="$opt -e";;
      pic)     opt="$opt -p";;
      refer)   opt="$opt -R";;
      man)     opt="$opt -man";;
      mdoc)    opt="$opt -mdoc";;
      ms)      opt="$opt -ms";;
      me)      opt="$opt -me";;
      mm)      opt="$opt -mm";;
      mom)     opt="$opt -mom";;
      unsafe)  opt="$opt -U";;
      land)    opt="$opt -P -l";;
      a5)      opt="$opt -P -pa5";;
      b5)      opt="$opt -P -pb5";;
      c6)      opt="$opt -P -pc6";;
      -p*)     opt="$opt -P $option";;
#     manual)  opt="$opt -P -m";;
      manual)  manual="true";;
      simplex) duplex="false";;
      resort)  sort="yes";;
      *)       echo "unknown option \"$option\"";;
    esac
  done

  if test "$sort" = "yes"
  then
    "$groff" -ww -b -Tps $opt -Z "$roff" |
      sed -f $HOME/lib/roff/resort.sed |
      grops |
      sed -e "/%%BeginFeature: \*PageSize Default/,/%%EndFeature/d
        /^%%EndSetup$/i\
        << /Duplex $duplex /ManualFeed $manual >> setpagedevice" \
      >"$post"
    rm troff.sort
  else
    "$groff" -ww -b -Tps $opt "$roff" |
      sed -e "
#        1s/$/ EPSF\\
# %%BoundingBox: 0 0 596 794/
#       /%%BeginFeature: \*PageSize Default/,/%%EndFeature/d
        /^%%EndSetup$/i\
        << /Duplex $duplex /ManualFeed $manual >> setpagedevice" \
      >"$post"
  fi

# -- ps output is like "1308677 pts/19  S  0:00.38 gv test.ps" --
# -- first item is PID, used in refresh function as $1 --
# -- [0-9] matches time and is used to exclude the grep process --

  pid=`ps x | grep "[0-9] $view $post"`
  refresh $pid

Reply via email to