comprehensive-rust icon indicating copy to clipboard operation
comprehensive-rust copied to clipboard

Lines not wrapping in PDF tables

Open mgeisler opened this issue 1 year ago • 6 comments

The Android Build Rules chapter has a table with text which should wrap. The PDFs currently don't wrap the lines:

image

I like the LaTeX environment used for the table a lot, we just need to extend it a bit to support wrapped text.

Cc @max-heller.

mgeisler avatar Jan 16 '24 10:01 mgeisler

This is a known issue. LaTeX will wrap the contents of cells if given relative widths to constrain each column. Pandoc sets these widths if its standard markdown parser is used but not if its Commonmark parser is used (see https://github.com/jgm/commonmark-hs/issues/128).

As a workaround, it should work to write a Pandoc filter that sets the width for each column to 1/n (n being the number of columns), though this will force tables that could be represented more compactly to take up the full width of the page

max-heller avatar Jan 16 '24 11:01 max-heller

This is a known issue.

Ah, thanks, I hadn't looked there!

LaTeX will wrap the contents of cells if given relative widths to constrain each column.

Yes, I remember being able to control the column widths back in the day when writing LaTeX directly. It's been several years, but I still have the good old LaTex Companion somewhere :smile:

As a workaround, it should work to write a Pandoc filter that sets the width for each column to 1/n (n being the number of columns), though this will force tables that could be represented more compactly to take up the full width of the page

Nice idea! Would it also be possible to embed a small "language" for this in a HTML comment in the Markdown? If a Pandoc filter has access to this, then that could be a nice way to do it:

<!-- Pandoc columns: default 0.8 -->

| Module Type    | Description                                                             |
|----------------|-------------------------------------------------------------------------|
| `rust_binary`  | Produces a Rust binary.                                                 |
| `rust_library` | Produces a Rust library, and provides both `rlib` and `dylib` variants. |

could perhaps be parsed and used to attach a ColWidthDefault and ColWidth 0.8 value to each column?

mgeisler avatar Jan 16 '24 12:01 mgeisler

Nice idea! Would it also be possible to embed a small "language" for this in a HTML comment in the Markdown? If a Pandoc filter has access to this, then that could be a nice way to do it:

<!-- Pandoc columns: default 0.8 -->

| Module Type    | Description                                                             |
|----------------|-------------------------------------------------------------------------|
| `rust_binary`  | Produces a Rust binary.                                                 |
| `rust_library` | Produces a Rust library, and provides both `rlib` and `dylib` variants. |

could perhaps be parsed and used to attach a ColWidthDefault and ColWidth 0.8 value to each column?

That sounds like it'd work, the HTML comment should be included in the Pandoc AST as a RawBlock

max-heller avatar Jan 16 '24 13:01 max-heller

Okay, cool! I don't know if there is precedent for "smuggling" information through like that in Pandoc?

We've done something very similar for the text extraction in mdbook-xgettext: there you can add <!-- mdbook-xgettext:skip --> to skip the next block.

mgeisler avatar Jan 16 '24 14:01 mgeisler

I don't know if there is precedent for "smuggling" information through like that in Pandoc?

There are a lot of examples out there, I'm sure someone's implemented something similar

max-heller avatar Jan 16 '24 14:01 max-heller

Nice!

I won't be putting a lot of work into this myself, so the issue is here in case someone else finds the time to work on this. I can ask internally if someone wants to contribute their 20% time to it.

mgeisler avatar Jan 17 '24 09:01 mgeisler