discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Simon Branch <simonmbranch@gmail.com>
To: discuss@mandoc.bsd.lv
Subject: tbl: incorrect width calculation in cs[s..]
Date: Sun, 3 Apr 2022 13:14:27 -0700	[thread overview]
Message-ID: <20220403201427.bugtqtlzdcygb45l@pine.sigxcpu.com> (raw)

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


             reply	other threads:[~2022-04-03 20:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-03 20:14 Simon Branch [this message]
2022-04-08 17:02 ` Ingo Schwarze
2022-04-09 17:35   ` Simon Branch
2022-04-09 17:58     ` Ingo Schwarze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220403201427.bugtqtlzdcygb45l@pine.sigxcpu.com \
    --to=simonmbranch@gmail.com \
    --cc=discuss@mandoc.bsd.lv \
    --subject='Re: tbl: incorrect width calculation in cs[s..]' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).