groff
[Top][All Lists]
Advanced

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

Re: [Groff] A trap with 'tbl'!


From: Deri James
Subject: Re: [Groff] A trap with 'tbl'!
Date: Sat, 30 Jul 2011 01:14:00 +0100
User-agent: KMail/1.13.7 (Linux/2.6.38.8-desktop-4.mga; KDE/4.6.3; x86_64; ; )

On Friday 29 Jul 2011 22:25:59 Ted Harding wrote:
> Greetings All!
> I'm writing to flag up a little trap that one might
> fall into when using 'tbl'.
> 
> Background: I'm setting up a table and I want each
> row to have a row number to the left of the table.
> 
> So I have defined a "left margin number" string \*[lmn]
> to do that for each row. My first setup was to define
> \*[lmn] so as to compute the row-number incrementally,
> then move to the left, print it, and then move back:
> 
> .nr lmno -0 1
> .ds lmn \Z'\v'-1.5m'\h'-\w'\\n+[lmno]\0\0\0\0\0'u'\\n[lmno]'
> .TS H
> expand tab(#);
> ce cw(2.0i) ce.
> Name (in Capitals)#Address#Signature
> _
> .TH
> .T&
> 
> |l |l |l|.
> 
> \*[lmn]
> _
> \*[lmn]
> _
> \*[lmn]
> _
> \*[lmn]
> _
> \*[lmn]
> _
> \*[lmn]
> _
> .TE
> 
> (i.e. with 6 rows). I expected that on being encountered
> in the first row, the string \*[lmn] namely
> 
>   \Z'\v'-1.5m'\h'-\w'\n+[lmno]\0\0\0\0\0'u'\n[lmno]'
> 
> (after interpretation of the definition) would increment
> \n[lmno] from 0 to 1, move to the left, print \n[lmno] = 1,
> and then move back to the first field of that row. Then,
> in the next row, \n[lmno] would be incremented from 1 to 2,
> printed on the left, and so on.
> 
> What actually happened (I'll illustrate here using the
> above 6-row table), was that the first number was 6, not 1.
> 
> If you have more rows, say 10, then the number of the
> first row will be 10. And so on.
> 
> This happens because somehow \n+[lmno] gets interpreted
> for each row in the table before it is printed for the
> first row. Hence (in this example) it has been incremented
> from 0 to 6 at the time it is printed for the first row.
> Thereafter it is incremented by 1 for each successive
> row, so prints as 6, 7, 8, 9, 10, 11 for this example.
> 
> The work-round is to change the initial definition of
> \n[lmno] to (in this example):
> 
>   .nr lmno -6 1
> 
> or (in general)
> 
>   .nr lmno -N 1
> 
> where N is the number of rows in the table. Then \n[lmno]
> is at 1 when the first row is about to be printed.
> 
> I have yet to work out how this comes about. When I look at
> the output of 'pic' for the above input, I first see:
> 
> .nr lmno 0 1
> .ds lmn \Z'\v'-1.5m'\h'-\w'\n+[lmno]\0\0\0\0\0'u'\n[lmno]'
> .TS H
> [nasty pic-made troff code]
> .lf 11
> .nr 3w0 \n[3w0]>?\w\[tbl]\*[lmn]\[tbl]
> .lf 13
> .nr 3w0 \n[3w0]>?\w\[tbl]\*[lmn]\[tbl]
> .lf 15
> .nr 3w0 \n[3w0]>?\w\[tbl]\*[lmn]\[tbl]
> .lf 17
> .nr 3w0 \n[3w0]>?\w\[tbl]\*[lmn]\[tbl]
> .lf 19
> .nr 3w0 \n[3w0]>?\w\[tbl]\*[lmn]\[tbl]
> .lf 21
> .nr 3w0 \n[3w0]>?\w\[tbl]\*[lmn]\[tbl]
> .lf 23
> .nr 3w0 \n[3w0]>?\w\[tbl]\*[lmn]\[tbl]
> [more pic-made troff code]
> .TE
> 
> 
> So the definition of \*[lmn] has been sent to troff as
> expected, and then there are 6 lines (for the 6 lines
> of the table), and that is it as far as occurrences
> of \*[lmn] are concerned. So it would seem that troff
> has only seen \*[lmn] 6 times!
> 
> Anyway, that's it, up for discussion if anyone is so
> inclined, and in any case as a warning of unexpected
> behaviour!
> 
> Notes: The intended output of this is a table of rows of
> blank boxes, for people to write their names, addresses
> and signatures in, with a row-number to the left of each row.
> 
> Also: I know I could have done this by making a table
> with an extra numeric column of un-ruled boxes on the left,
> and put the entry \n+[lmno] into that column in each row.
> But I thougt I'd try to be clever ...
> 
> Best wishes to all,
> Ted.

Hi Ted,

I think this could be because tbl needs to know the max width of each column 
before starting to output, so when considering the first column it will have to 
examine the width of \*[lmn] foreach row that you use it on. So these six 
accesses to get the width trigger the increment before it starts to output the 
first row.

Even if you used \n+[lmno] directly (as you suggested), you would still find a 
similar problem.

Just as \Z restore page movement, maybe we need something to turn off auto 
increment within \w''.

Cheers 

Deri




reply via email to

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