quarto-dev / quarto-dev/quarto-cli
Table caption is not parsed the same when using Markdown table or LaTeX table.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 6k
- Forks
- 458
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
Bug description
From https://github.com/quarto-dev/quarto-cli/discussions/1182
---
format: pdf
keep-md: true
keep-tex: true
---
```{r}
#| label: tbl-md
#| tbl-cap: "$\\beta$~1~"
knitr::kable(data.frame(x = rnorm(5)))
```
```{r}
#| label: tbl-latex
#| tbl-cap: "$\\beta$~1~"
knitr::kable(data.frame(x = rnorm(5)), format = "latex")
```

In the first case kable() will produce Markdown table, and we will process the code in there, setting the table caption as a Caption element in the AST which will preserve the $ $ math syntax.
https://github.com/quarto-dev/quarto-cli/blob/0501d0708794a5030fc3b3f64dfca23e93200c0a/src/resources/filters/quarto-pre/table-captions.lua#L136-L140
In the second case, the table produced will be LaTeX, and in this case, we'll process there:
https://github.com/quarto-dev/quarto-cli/blob/0501d0708794a5030fc3b3f64dfca23e93200c0a/src/resources/filters/quarto-pre/table-captions.lua#L201-L205
We are loosing the $ $ math syntax when calling stringify I believe, so when calling stringEscape() the \beta will not be correctly parsed as Math.
If we want to support Markdown syntax for table caption, we should probably align the two treatment.
Using Dev version of Quarto, on Windows 11.
Checklist
- formatted your issue so it is easier for us to read?
- included a minimal, self-contained, and reproducible example?
- documented the quarto version you're running, by providing the output produced by
quarto checkin a terminal in your issue? - documented the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- documented which operating system you're running? If on Linux, please provide the specific distribution as well.
- upgraded to the latest version, including your versions of R, the RStudio IDE, and relevant R packages?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/resources/filters/quarto-pre/table-captions.lua, comparing the Markdown path around lines 136-140 with the LaTeX path around lines 201-205. Reproduce the issue with the two knitr::kable examples, then verify that both paths preserve the $\beta$~1~ caption math consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- latex, lua, markdown, r
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100