tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: "Anthony J. Bentley" <anthony@anjbe.name>
Cc: tech@mandoc.bsd.lv
Subject: Re: Inconsistent table width
Date: Wed, 1 Jan 2020 00:21:04 +0100	[thread overview]
Message-ID: <20191231232104.GI79009@athene.usta.de> (raw)
In-Reply-To: <75672-1577734462.834261@FCbr.D2mH.5Uc3>

Hi Anthony,

Anthony J. Bentley wrote on Mon, Dec 30, 2019 at 12:34:22PM -0700:

> This table from xkeyboard-config(7) renders incorrectly.
> 
> .TS
> left,box;
> lB lB
> ___
> lB l.
> Model   Description
> pc101   Generic 101-key PC
> .TE

Yikes, what a mess.  The "___" layout line forces the number of
columns in the table to three because it contains three layout cell
specifiers, even though all other lines in the layout and data
sections only contain two cells.  Having three columns is certainly
not the author's intention.

> groff:
>        +-------------------------------+
>        |Model   Description            |
>        +-------------------------------+
>        |pc101   Generic 101-key PC     |
>        +-------------------------------+

You can actually see the last column in groff's output.
Usually, there is one blank after the longest cell content in the
rightmost column, i.e. between the "101-key PC" and the following "|".
But here, the are five:

   3 inter-column spacing
   1 for column three
   1 for spacing between the last column and the border

You can also see the additional column if you change the "box"
option to "allbox".

> mandoc:
>        +-----------------------------+
>        |Model   Description           |
>        +-----------------------------+
>        |pc101   Generic 101-key PC    |
>        +-----------------------------+

Mandoc mishandled columns consisting of nothing but zero-width cells.

The following commit fixes the bug.

Thank you for the report!
  Ingo


Log Message:
-----------
When all cells in a tbl(1) column are empty, set the column width
to 1n rather than to 0n, in the same way as groff does.
This fixes misformatting reported by bentley@ in xkeyboard-config(7).

Modified Files:
--------------
    mandoc:
        out.c
    mandoc/regress/tbl/layout:
        Makefile

Added Files:
-----------
    mandoc/regress/tbl/layout:
        emptycol.in
        emptycol.out_ascii

Revision Data
-------------
Index: out.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/out.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -Lout.c -Lout.c -u -p -r1.78 -r1.79
--- out.c
+++ out.c
@@ -209,13 +209,25 @@ tblcalc(struct rofftbl *tbl, const struc
 	}
 
 	/*
-	 * Column spacings are needed for span width calculations,
-	 * so set the default values now.
+	 * The minimum width of columns explicitly specified
+	 * in the layout is 1n.
 	 */
 
-	for (icol = 0; icol <= maxcol; icol++)
-		if (tbl->cols[icol].spacing == SIZE_MAX || icol == maxcol)
-			tbl->cols[icol].spacing = 3;
+	if (maxcol < sp_first->opts->cols - 1)
+		maxcol = sp_first->opts->cols - 1;
+	for (icol = 0; icol <= maxcol; icol++) {
+		col = tbl->cols + icol;
+		if (col->width < 1)
+			col->width = 1;
+
+		/*
+		 * Column spacings are needed for span width
+		 * calculations, so set the default values now.
+		 */
+
+		if (col->spacing == SIZE_MAX || icol == maxcol)
+			col->spacing = 3;
+	}
 
 	/*
 	 * Replace the minimum widths with the missing widths,
Index: Makefile
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/tbl/layout/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/tbl/layout/Makefile -Lregress/tbl/layout/Makefile -u -p -r1.3 -r1.4
--- regress/tbl/layout/Makefile
+++ regress/tbl/layout/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.4 2019/06/11 15:40:41 schwarze Exp $
+# $OpenBSD: Makefile,v 1.5 2019/12/31 22:49:17 schwarze Exp $
 
-REGRESS_TARGETS	 = center complex empty emptyline
+REGRESS_TARGETS	 = center complex empty emptycol emptyline
 REGRESS_TARGETS	+= lines lines-nogroff numbers shortlines span
 LINT_TARGETS	 = complex empty
 
--- /dev/null
+++ regress/tbl/layout/emptycol.in
@@ -0,0 +1,49 @@
+.\" $OpenBSD: emptycol.in,v 1.1 2019/12/31 22:49:17 schwarze Exp $
+.TH TBL-LAYOUT-EMPTYCOL 1 "December 31, 2019"
+.SH NAME
+tbl-layout-emptycol \- empty columns in tables
+.SH DESCRIPTION
+missing final column:
+.TS
+allbox tab(:);
+L L L
+L L.
+1:2
+a:b
+.TE
+.sp
+empty final column:
+.TS
+allbox tab(:);
+L L L
+L L.
+1:2:
+a:b
+.TE
+.sp
+final column with zero-width content:
+.TS
+allbox tab(:);
+L L L
+L L.
+1:2:\&
+a:b
+.TE
+.sp
+empty middle column:
+.TS
+allbox tab(:);
+L L L
+L.
+1::3
+a
+.TE
+.sp
+span crossing empty middle column:
+.TS
+allbox tab(:);
+L L L
+L S S.
+1::3
+span
+.TE
--- /dev/null
+++ regress/tbl/layout/emptycol.out_ascii
@@ -0,0 +1,46 @@
+TBL-LAYOUT-EMPTYCOL(1)      General Commands Manual     TBL-LAYOUT-EMPTYCOL(1)
+
+
+
+N\bNA\bAM\bME\bE
+       tbl-layout-emptycol - empty columns in tables
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       missing final column:
+
+       +--+---+---+
+       |1 | 2 |   |
+       +--+---+---+
+       |a | b |   |
+       +--+---+---+
+       empty final column:
+
+       +--+---+---+
+       |1 | 2 |   |
+       +--+---+---+
+       |a | b |   |
+       +--+---+---+
+       final column with zero-width content:
+
+       +--+---+---+
+       |1 | 2 |   |
+       +--+---+---+
+       |a | b |   |
+       +--+---+---+
+       empty middle column:
+
+       +--+---+---+
+       |1 |   | 3 |
+       +--+---+---+
+       |a |   |   |
+       +--+---+---+
+       span crossing empty middle column:
+
+       +--+---+---+
+       |1 |   | 3 |
+       +--+---+---+
+       |span      |
+       +----------+
+
+
+OpenBSD                        December 31, 2019        TBL-LAYOUT-EMPTYCOL(1)
--
 To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv

      reply	other threads:[~2019-12-31 23:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-30 19:34 Anthony J. Bentley
2019-12-31 23:21 ` Ingo Schwarze [this message]

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=20191231232104.GI79009@athene.usta.de \
    --to=schwarze@usta.de \
    --cc=anthony@anjbe.name \
    --cc=tech@mandoc.bsd.lv \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).