manubot / rootstock

Clone me to create your Manubot manuscript
https://manubot.github.io/rootstock/
Other
453 stars 178 forks source link

Table layout: configuring word wrap and column widths #323

Open olgabot opened 4 years ago

olgabot commented 4 years ago

Related: https://github.com/manubot/rootstock/issues/294 https://github.com/manubot/rootstock/issues/254

Hello, I'm working on a PR that includes tables that have inline citations, and this seems to be confusing the PDF and HTML formatters. For example, this table:

| Citation                                                              | Alphabet   | Amino acid groups                                                               |
|:----------------------------------------------------------------------|:-----------|:--------------------------------------------------------------------------------|
| Phillips, R., *et al*. (2012). [@raw:phillips2012physical]            | hp2        | `AFGILMPVWY` `CDEHKNQRST`                                                       |
| Peterson, E. L., *et al*. (2009) [@doi:10.1093/bioinformatics/btp164] | gbmr4      | `G` `ADKERNTSQ` `YFLIVMCWH` `P`                                                 |
| Dayhoff, M. O., & Eck, R. V. (1968). [@raw:dayhoff1969atlas]          | dayhoff6   | `AGPST` `HRK` `DENQ` `FWY` `ILMV` `C`                                           |
| This paper                                                            | botvinnik8 | `AG` `DE` `RK` `NQ` `ST` `FY` `LIV` `CMWHP`                                     |
| Hu, X., & Friedberg, I. (2019). [@doi:10.1093/gigascience/giz118]     | aa9        | `G` `AST` `KR` `EQ` `DN` `CFILMVY` `W` `H` `P`                                  |
| Peterson, E. L., *et al*. (2009) [@doi:10.1093/bioinformatics/btp164] | sdm12      | `G` `A` `D` `KER` `N` `TSQ` `YF` `LIVM` `C` `W` `H` `P`                         |
| Peterson, E. L., *et al*. (2009) [@doi:10.1093/bioinformatics/btp164] | hsdm17     | `G` `A` `D` `KE` `R` `N` `T` `S` `Q` `Y` `F` `LIV` `M` `C` `W` `H` `P`          |
| Dayhoff, M. O., & Eck, R. V. (1968). [@raw:dayhoff1969atlas]          | protein20  | `G` `A` `D` `E` `K` `R` `N` `T` `S` `Q` `Y` `F` `L` `I` `V` `M` `C` `W` `H` `P` |

Gets rendered in the HTML as:

Screen Shot 2020-03-11 at 9 40 51 AM

And in the PDF as:

Screen Shot 2020-03-11 at 9 41 05 AM

It seems that there's extra spacing in the first column, which includes a bunch of citations that then get processed to be much narrower. Is there a way to enable word wrap in a particular column (in this case, e.g. the first column)? StackOverflow says that <br> can force a line break in the cell, but is there a way to enable word wrap?

Here is a google doc that has the kind of spacing I would like:

Screen Shot 2020-03-11 at 9 50 08 AM

The second and third columns should not allow word wrapping, but the first column can. Is this possible to specify?

Thank you!

dhimmel commented 4 years ago

I think you can adjust the widths of the --- in the second row below:

| Citation                                                              | Alphabet   | Amino acid groups                                                               |
|:----------------------------------------------------------------------|:-----------|:--------------------------------------------------------------------------------|

I believe Pandoc uses these to determine column width. From https://pandoc.org/MANUAL.html#extension-pipe_tables

If a pipe table contains a row whose printable content is wider than the column width (see --columns), then the table will take up the full text width and the cell contents will wrap, with the relative cell widths determined by the number of dashes in the line separating the table header from the table body. (For example ---|- would make the first column 3/4 and the second column 1/4 of the full text width.) On the other hand, if no lines are wider than column width, then cell contents will not be wrapped, and the cells will be sized to their contents.

So it looks like Pandoc is perhaps writing the HTML that enables wrapping. @vincerubinetti are there HTML classes that can be used to disable wrapping on a certain column?

olgabot commented 4 years ago

Ah, interesting. i'm using Atom's markdown-table-formatter package which autoformats based on the contents of the table, and that's probably affecting the output! I'll try turning it off and manually adjusting the table widths

vincerubinetti commented 4 years ago

I don't believe we have generic utility wrap or nowrap classes in the default theme. Perhaps we should consider it for cases like this.

As Daniel said, adjusting your dash widths will affect how Pandoc sets the % widths of the columns in a table. I'm not sure it's a good idea that Pandoc does that. Maybe we can disable that somehow?

vincerubinetti commented 3 years ago

@dhimmel Can we make this issue specifically about table column wrapping, and deferring column width discussions to #254? Maybe rename the issue to suit?

Looking at this again, it's a bit harder than I thought.

We could create some wrap/nowrap util classes, but you'd have to apply them to each cell. And worse, I don't think you'd be able to use the convenient {.class} markdown/pandoc syntax; you'd have to use our attributes plugin, eg <!-- $class="nowrap" -->.

I believe there would have to be a special plugin to do this. I don't see a convenient workaround. The best solution I can think of is to add something to the attributes plugin that detects if the attribute is being applied to a table header cell, and then also applies that attribute to all body cells in the same column. But then what if you actually do only want to apply the attribute to the header cell?

dhimmel commented 3 years ago

Can we make this issue specifically about table column wrapping

Yes I will rename. Reading through this issue, it seems that the issue is primarily with the table layout, and that the layout issues are probably not caused by the presence of citations (besides how their raw forms affected the atom-generated markdown table). I agree it makes sense to consolidate future column width discussion in https://github.com/manubot/rootstock/issues/254.

We can use this issue for column wrapping discussion. For these table issues, it's best if we can track down an upstream pandoc issue where we might be able to nudge along progress or find existing workarounds. I'm not actually sure there is an issue here besides column width, based on Pandoc pipe_tables docs:

If a pipe table contains a row whose Markdown content is wider than the column width (see --columns), then the table will take up the full text width and the cell contents will wrap, with the relative cell widths determined by the number of dashes in the line separating the table header from the table body.

So I think the first thing we need to know is whether the desired behavior can be achieved by setting columns widths. Or whether we can find anything to improve Pandoc's column width settings.