quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.95k stars 326 forks source link

Table caption is not parsed the same when using Markdown table or LaTeX table. #1185

Open cderv opened 2 years ago

cderv commented 2 years ago

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)))
#| label: tbl-latex
#| tbl-cap: "$\\beta$~1~"
knitr::kable(data.frame(x = rnorm(5)), format = "latex")


![image](https://user-images.githubusercontent.com/6791940/174641745-ddc6ff1a-56d4-48d1-8e76-a91ddc62462d.png)

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

- [X] [formatted your issue](https://yihui.org/issue/#please-format-your-issue-correctly) so it is easier for us to read?
- [X] included a minimal, self-contained, and reproducible example?
- [X] documented the quarto version you're running, by providing the output produced by `quarto check` in 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?
- [X] documented which operating system you're running? If on Linux, please provide the specific distribution as well.
- [X] upgraded to the latest version, including your versions of R, the RStudio IDE, and relevant R packages?
arnaudgallou commented 1 year ago

Any chance to have this issue fixed for the v1.3 release? Having this parsing problem breaks everything that comes after (figures, tables and bibliography) and forces you to render figures/tables in individual documents, which is not convenient at all.

cscheid commented 1 year ago

The infrastructure to fix it will be there. But libraries will have to change the way they emit output, so it'll take a while for this to propagate.