-
Notifications
You must be signed in to change notification settings - Fork 328
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
Math formatting does not work in styled KableExtra tables #555
Comments
Thanks for the report. I believe this happens because in Quarto the HTML table is inserted as a raw HTML block using
whereas with R Markdown, it is inserted directly in the markdown document without raw block. This allows the Pandoc's extensions output:
html_document:
md_extensions: -markdown_in_html_blocks This extensions won't apply in HTML code inserted in Raw content block. This explain why Quarto does not give the same results. For now, you would need to try other table framework, or use markdown tables and not HTML ones. We need to see where the fenced part are added and if we could make an exception somehow... 🤔 Nevermind - found it. We are specifically inserting kable() results in raw block. quarto-cli/src/resources/rmd/patch.R Lines 209 to 217 in b3b4a40
This definitely prevent using markdown content inside the table cell. |
The reason we are doing this is so that all of our This code does work (but is not full width): ``{r}
data <- data.frame(X1 = c(1,2,3,4),
X2 = c(5,6,7,8),
X3 = c(9,10,11,12),
Y = c('R', 'R','G', 'R'),
stringsAsFactors = F)
colnames(data) <- c('$X_{1}$', '$X_{2}$', '$X_{3}$', '$Y$')
library(knitr)
kable(data, row.names = TRUE)
``` We have an intermediate term work item to provide additional ability to customize bootstrap table output (which could encompass the full width option). I'm more inclined to enhance our ability to customize table output than to provide back doors that circumvent other features (even at the cost of losing some compatibility). |
Thanks for the precision. There is also the option of having HTML tables tools deal with such markdown content in the first place. I agree that this is better to not circumvent any existing feature. |
Hi, I'd just share my case for future reference. I happened to find a case where math formatting works in kableExtra tables on quarto, using Quarto 1.3.353 with Pandoc 3.1.1. Trick is to add three lines of options, which makes meghanto's reprex work:
The point is that fig-cap line is mandatory, and must not be empty ("") nor space (" ", " ", etc.). Below is the reprex.
Contrary to the stackoverflow answer for revealjs case by Julian on Jan 13, 2023, addition of Here's output of quarto check.
|
Note that the issue is not really about The following will produce the exact same behaviour: ---
format: html
---
```{=html}
<table>
<thead>
<tr>
<th> $X_{1}$ </th>
<th> $X_{2}$ </th>
<th> $X_{3}$ </th>
<th> $Y$ </th>
</tr>
</thead>
<tbody>
<tr>
<td> 1 </td>
<td> 5 </td>
<td> 9 </td>
<td> R </td>
</tr>
</tbody>
</table>
``` Note that maths are rendered if the table is not in a raw block. @cscheid I think having math being rendering by MathJax (and others) for HTML table would be a nice thing to have here. (side effect it will solve issues for multiple third party table generator) |
This is a kableExtra side effect (or even problem in quarto context) and it may not be reliable. kableExtra will produce HTML here, but
Quarto will parse HTML only when HTML I don't know why kableExtra would do that here, or if this is an oversight, but definitely not reliable IMO.
Regarding how Quarto works, currently we parse raw HTML directly with Pandoc. This means when pandoc parses the HTML table, it won't identified any Math written as Markdown syntax. This is like Citation or other Markdown content. It needs to follow the explanation at https://quarto.org/docs/authoring/tables.html#html-tables with the If table packages like kableExtra allows to insert content as such, then it will work. @mcanouil your example showing this change would be ---
title: "Test"
format: html
---
```{=html}
<table>
<thead>
<tr>
<th> <span data-qmd="$X_{1}$"></span> </th>
<th> <span data-qmd="$X_{2}$"></span> </th>
<th> <span data-qmd="$X_{3}$"></span> </th>
<th> <span data-qmd="$Y$"></span> </th>
</tr>
</thead>
<tbody>
<tr>
<td> 1 </td>
<td> 5 </td>
<td> 9 </td>
<td> R </td>
</tr>
</tbody>
</table>
``` So third party package needs to leverage that in Quarto context, like gt has started doing it. Though, for equation, gt has chosen another solution, by now rendering math inside table using katex at rendering time (in R) to insert rendered math in the HTML table. This is available in dev version following merging of So your example @mickeykawai would be ---
title: "Test"
format: html
keep-md: true
---
```{r}
library(gt)
data <- data.frame(X1 = c(1,2,3,4),
X2 = c(5,6,7,8),
X3 = c(9,10,11,12),
Y = c('R', 'R','G', 'R'))
gt(data) |>
cols_label(
X1 = '$X_{1}$',
X2 = '$X_{2}$',
X3 = '$X_{3}$',
Y = '$Y$',
.fn = md
)
```
Hope it helps understand the context Honestly, I don't think we need to do more in Quarto right now, especially for kableExtra support. It should be updated to use the different features that Quarto support for Markdown processing in HTML table IMO. |
oh, I forgot about the Right now, there is only one sentence "hidden" in the middle of the HTML table section (https://quarto.org/docs/authoring/tables.html#html-tables) |
Yes we don't have yet some developer docs for contributors to Quarto ecosystem. First step could be a blog post about this |
Should we also reach out to developers of the main libraries (R, Python, and Julia) about this (not necessarily right now)? |
I am using Quarto 0.9.180 with Pandoc 2.5
Here is a sample qmd file
And here is the corresponding rmd file.
The two html outputs are here.
The quarto output does not render the math.
The text was updated successfully, but these errors were encountered: