groff
[Top][All Lists]
Advanced

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

Re: [Groff] tbl is not flexible to adjust itself according to page layou


From: Mike Bianchi
Subject: Re: [Groff] tbl is not flexible to adjust itself according to page layout
Date: Sun, 14 Sep 2008 10:50:29 -0400
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

On Sat, Sep 13, 2008 at 12:01:53AM +0800, address@hidden wrote:
> 
> Hello. One issue with tbl is it does not warp the line of text within
> table cells unless explicitly warped around using T{ and T}. If the page
> is too narrow to hold the table, the table simply expands to outside of
> the page. This is probably less flexible than HTML where the table is
> always trying to linewrap its content to fit in page narrow-ness.
> 
> Is there no other way than wrapping content with T{ and T}? Having these
> wrappers makes the source code difficult to read for my super-large
> table, and I have to wrap every cell because I don't know which one
> might cause the table to expand outside of page right margin. My
> document is a 10 page table, difficult to manage. A try-and-error
> approach (print it out, check which cell is too wide, wrap only that
> cell with T{ T}) is too time consuming and is not following the basic
> principle of using a computer (to let computer does repetitive work
> instead of human).
> 
> Searched tbl manual without luck yet.
> 
> Thanks in advance for suggestions & comments.


To the best of my knowledge  newline T{ ... T} newline  is the only
mechanism that does what you want.


BUT I've written a quick preprocessor that you could use in front of
tbl(1)  in your pipeline (or in front of  groff -p ... ) to get the effect
you asked for.

I called the script  tbl_pp  (tbl preprocessor) and it reads:

-------------------------------------------------------------

#!/bin/sh

tab='_'

#       NOTE:  the  \1/g  and the  T}/g  lines must not be indented!

exec sed '
        /^\.TS/,/^\.TE/ {
                /^TT{/ {
                        s/^TT{//
                        s/.*/T{&T}/
                        s/'"${tab}"'/T}'"${tab}"'T{/g
                }
                s/T{\(.\)/T{\
\1/g
                s/\(.\)T}/\1\
T}/g
        }
        '

-------------------------------------------------------------



My test script reads ...

-------------------------------------------------------------

#!/bin/sh

trap 'rm /tmp/$$' 1 2 3 15

tbl_pp  <<\!  |  groff -t -mm - >/tmp/$$
.
.P
start
.
.na
.
.TS
tab(_) ;
l l l l .
.
asdlkfj_asdlfjk_dasjflldaskfj_ads
asdlkfjdasf_asdlfjk_dasjflldaskfj_ads
.
TT{aaaaaaaaaaaa aaaa aaaaaaa aa aaaaaaaaaaaa_bbbbb bbbb bbbbbb bbbb bbbbb 
bbb_ccc ccccccc ccccccccc ccccccccc ccccccc_dddddd ddddd ddddddddddd
.
T{111111111111 1111 1111111 11 111111111111T}_T{22222 2222 222222 2222 22222 
222T}_T{333 3333333 333333333 333333333 3333333T}_T{444444 44444 44444444444T}
.
.TE
.
done
!

gv /tmp/$$

-------------------------------------------------------------


I've defined a tbl tab to be  _  in both the  .TS ... .TE  table
and the tbl_pp script.  Clearly they need to match.

There lines in the groff test that are just a  .  to make reading the
script easier.  They have no effect.


There are two ways to trigger the mechanism that turns tab-separated
columns into  tab T{ newline ... newline T} tab  delineated columns:

        IF at line begins with  TT{  that line is wrapped in T{ ... T}
        and each tab (i.e.  _ ) is turned into  newline T} tab T{ newline .


        IF any other tbl line contains any number copies of  T{ ... T} ,
        it is changed into  T{ newline ... newline T} .

One of each trigger are illustrated in the test script.


I think one could reasonably make the case that any occurrences of
 T{ ... T}  should (optionally?) be processed as if the newlines were present,
as an enhancement to  tbl .

But, the originators of UNIX and troff back in the day would argue that
this sort of preprocessor shows the value of small, simple algorithms
encapsulated in small, simple scripts and this is the right way to do this.
You don't have to wait for a change to the big tool, you can accomplish the
same thing on your own right now (if you know enough shell script tricks).

But I, too, find the  newline T} tab T{ newline  mechanism cumbersome and
would welcome an alternative.

Let's all go get a beer and discuss this somewhere ;)
                                                                Mike

-- 
 Mike Bianchi
 Foveal Systems

 973 822-2085   call to arrange Fax

 address@hidden
 http://www.AutoAuditorium.com
 http://www.FovealMounts.com




reply via email to

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