tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* Inconsistent table width
@ 2019-12-30 19:34 Anthony J. Bentley
  2019-12-31 23:21 ` Ingo Schwarze
  0 siblings, 1 reply; 2+ messages in thread
From: Anthony J. Bentley @ 2019-12-30 19:34 UTC (permalink / raw)
  To: tech

Hi,

This table from xkeyboard-config(7) renders incorrectly.

.TS
left,box;
lB lB
___
lB l.
Model   Description
pc101   Generic 101-key PC
.TE


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

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

-- 
Anthony J. Bentley
--
 To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv

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

* Re: Inconsistent table width
  2019-12-30 19:34 Inconsistent table width Anthony J. Bentley
@ 2019-12-31 23:21 ` Ingo Schwarze
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Schwarze @ 2019-12-31 23:21 UTC (permalink / raw)
  To: Anthony J. Bentley; +Cc: tech

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

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

end of thread, other threads:[~2019-12-31 23:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-30 19:34 Inconsistent table width Anthony J. Bentley
2019-12-31 23:21 ` 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).