Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typst Writer: Proper captions for tables #9194

Closed
iandol opened this issue Nov 16, 2023 · 3 comments
Closed

Typst Writer: Proper captions for tables #9194

iandol opened this issue Nov 16, 2023 · 3 comments
Labels

Comments

@iandol
Copy link
Contributor

iandol commented Nov 16, 2023

At present, the Typst writer exports a markdown table like this:

|       |  A   |    B   |    C    |    D    |
|-------|-----:|-------:|--------:|--------:|
| Ratio | 0.89 |   0.93 |    1.11 |     0.9 |
: Some Ratios
#align(center)[#table(
  columns: 5,
  align: (col, row) => (auto,right,right,right,right,).at(col),
  inset: 6pt,
  [], [A], [B], [C], [D],
  [Ratio],
  [0.89],
  [0.93],
  [1.11],
  [0.9],
)
#align(center, [Some Ratios])
]

The caption is treated as text and just placed below the table. However, the "official" method is to wrap the table in a figure:

#figure(
  table(
    columns: 4,
    [t], [1], [2], [3],
    [y], [0.3s], [0.4s], [0.8s],
  ),
  caption: [Timing results],
)

https://typst.app/docs/reference/meta/figure/

This allows labels with counters and can then also be cross-referenced elsewhere...

Looking at https://github.com/jgm/pandoc/blob/main/src/Text/Pandoc/Writers/Typst.hs#L158 I could make a pull request though I know no haskell, so would just guesstimate which bits to change…

Pandoc version?
3.1.9 macOS

@iandol iandol added the bug label Nov 16, 2023
@iandol
Copy link
Contributor Author

iandol commented Nov 16, 2023

Note that Quarto also rewrites Pandoc's output to emit tables wrapped in figures, perhaps @cscheid from the Quarto team has more details to share:

#figure([
#align(center)[#table(
  columns: 5,
  align: (col, row) => (auto,right,right,right,right,).at(col),
  inset: 6pt,
  [], [Lion], [Rabbit], [Tiger], [Horse],
  [Ratio],
  [0.89],
  [0.93],
  [1.11],
  [0.9],
)
]

], caption: figure.caption(
position: top, 
[
Caption.
]), 
kind: "quarto-float-tbl", 
supplement: "Table", 
numbering: "1", 
)

@jgm jgm closed this as completed in 3591733 Nov 16, 2023
@cscheid
Copy link
Contributor

cscheid commented Nov 16, 2023

perhaps @cscheid from the Quarto team has more details to share:

Pandoc probably doesn't want to do anything special for Quarto here, since our crossref system is significantly more opinionated.

I'll just note here that #figure, in Typst parlance, is closer to a "float" in LaTeX. (Notice the kind field that controls which counter to use, etc). A pure Typst cross-referenceable element will also need a label associated with it, but I see that src/Text/Pandoc/Writers/Typst.hs will add the label based on the table identifier, so this should work well.

Typst will also automatically use a Table counter for "floats" with Table elements, so the fix from jgm in 3591733 is precisely what I'd do in Pandoc.

@iandol
Copy link
Contributor Author

iandol commented Nov 17, 2023

I can confirm I get captioned tables with numbering in Typst outputs with the latest Pandoc nightly, thank you @jgm! And thank you @cscheid for your input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants