discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
* tbl: incorrect width calculation in cs[s..]
@ 2022-04-03 20:14 Simon Branch
  2022-04-08 17:02 ` Ingo Schwarze
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Branch @ 2022-04-03 20:14 UTC (permalink / raw)
  To: discuss

Hello!  mandoc has some slightly odd behavior when formatting a table like this,
where the author wants a centered title:

   .TS
   tab(#);
   csss
   l1 l3 l1 l.
   heading
   00#NUL#01#SOH
   .TE

Groff outputs this:

       heading
   00 NUL   01 SOH

mandoc outputs this:

         heading
   00 NUL   01 SOH

There are three problems here:

   - The space after the first column isn't counted.
   - The imaginary spaces after the last column are counted, even though
     they aren't output.
   - Mandoc assumes that each column has three trailing spaces.

In other words, the control flow works like this:

   - Start with the first column's width.
   - If there are any continuation columns, add their widths and trailing
     spaces.

But I think it should work like this:

   - Start with the first column's width.
   - If there are any continuation columns, add the widths of the rest of
     the columns, and all the trailing spaces *except* for the ones after
     the last column.

This might still be incorrect (?) if there are more columns after
"cs...", but I think a partial fix is better than no fix at all.

Index: tbl_term.c
===================================================================
RCS file: /cvs/mandoc/tbl_term.c,v
retrieving revision 1.75
diff -u -r1.75 tbl_term.c
--- tbl_term.c  10 Aug 2021 12:55:04 -0000      1.75
+++ tbl_term.c  3 Apr 2022 04:39:18 -0000
@@ -820,8 +820,11 @@
        width = col->width;
        ic = dp->layout->col;
        hspans = dp->hspans;
-       while (hspans--)
-               width += tp->tbl.cols[++ic].width + 3;
+       while (hspans--) {
+               width += tp->tbl.cols[ic].spacing;
+               ic++;
+               width += tp->tbl.cols[ic].width;
+       }

        padr = width > len ? width - len : 0;
        padl = 0;
--
 To unsubscribe send an email to discuss+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-09 17:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 20:14 tbl: incorrect width calculation in cs[s..] Simon Branch
2022-04-08 17:02 ` Ingo Schwarze
2022-04-09 17:35   ` Simon Branch
2022-04-09 17:58     ` Ingo Schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).