-
Notifications
You must be signed in to change notification settings - Fork 331
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
Citations in tables do not render correctly outside of raw markdown and kable #3340
Comments
Ooh, @debruine's issue/solution in #1710 also works here! This can be fixed by removing the class with
|
i was looking for this too. however if i use result = "asis", the rendered html files unable to recognise it as table for cross reference.
is there any way to caption the table and crossref it? |
I think you need |
Using
|
This is now fixed, although For a preview of how this is going to work in the future, consider this snippet using an in-development branch of
If you tell gt that you're providing it with markdown input (through If you don't call |
@cscheid about this, Aren't we enclosing ourself the result in Raw Block ? I believe we do it here What more would be needed ? I think we need to make sure what is planned for gt will work for other framework. Also, some comment on why in R Markdown ecosystem the raw block is not used. This is because that way it can benefit with Pandoc from the This means that with rmarkdown, Rmd file---
title: "Citations in tables"
output:
bookdown::html_document2:
keep_md: true
references:
- type: article-journal
id: Lovelace1842
author:
- family: Lovelace
given: Augusta Ada
issued:
date-parts:
- - 1842
title: >-
Sketch of the analytical engine invented by Charles Babbage, by LF Menabrea,
officer of the military engineers, with notes upon the memoir by the translator
title-short: Molecular structure of nucleic acids
container-title: Taylor’s Scientific Memoirs
volume: 3
page: 666-731
language: en-GB
---
## Raw Markdown
This works.
| Thing | Citation |
|-------|---------------|
| 1234 | @Lovelace1842 |
## `knitr::kable()`
This works.
```{r}
library(knitr)
tibble::tribble(
~Thing, ~Citation,
1234, "@Lovelace1842"
) |>
kable()
```
## `kableExtra::kbl()`
This doesn't work.
```{r}
library(kableExtra)
tibble::tribble(
~Thing, ~Citation,
1234, "@Lovelace1842"
) |>
kbl() |>
kable_styling()
```
## `gt::gt()`
This doesn't work.
```{r}
library(gt)
tibble::tribble(
~Thing, ~Citation,
1234, "@Lovelace1842"
) |>
gt()
```
Putting that here in case R Markdown user are wondering why the difference. |
@cscheid Do you know which branch of gt has support for the preview version here (#3340 (comment))? Using the |
Anyone know if this should be working now? I don't think it is for me.
Produces this output: I'm expecting a Linked "Section 1" to appear inside the table? This also doesn't work with Current versions: |
Actually, now that I say that, I wonder. @rich-iannone, shouldn't that fmt_markdown be wrapping the markdown content in a
|
We do have a second issue, though, which is that gt emits if table.attributes[constants.kDisableProcessing] ~= nil then This one is a @jameshowison : you'll need to install the latest 1.4 prerelease (and wait for the confirmation and fix of the |
Okay, there was a change required in I tested with this .qmd:
and got this document, where hovering on the formatted citation yields the full reference. Really sorry it took so long to discover the underlying |
I can confirm this works on |
I believe this could be in knitr directly that this should be done. So we could try sync an update with 1.4 release for this. I opened an issue there. |
That might be related to yihui/knitr#2289, though that issue is specifically about HTML output |
Somehow, gt is not formatting this with markdown, but is emitting LaTeX, cf
@rich-iannone, do you know what's going on here? |
The document is using I don't think we have yet an equivalent of If you want HTML tables, even in ```{r}
library(gt)
tibble::tribble(
~Thing, ~Citation,
1234, "@Lovelace1842"
) |>
gt() |> fmt_markdown() |> as_raw_html()
``` This will correctly process the citation in the table, even for PDF outputs. So at the end, this is a gt choice: when inside quarto document rendering, if output format is LaTeX, should it generate a HTML table anyway ? At least when Otherwise, it will be to the user to explicitly ask for HTML version of the table. |
And, more specifically, I thought that |
Ok cool, yeah, I also thought that {gt} had changed for non-HTML formats and emitted HTML. Adding Normal HTML output:
With But that's definitely a {gt} issue, not a Quarto issue |
yeah I know that. We all agree here ! The code I shared was about specifically outputting HTML in the PDF format for it to work.
I don't think it has. @rich-iannone is this a plan to output HTML table for LaTeX document when rendered in Quarto ? Only drawback of this approach is possibly loosing all the custom LaTeX styling for gt table if any, that can't be set through Quarto/Pandoc writing the raw LaTeX instead of gt directly. The example share by @andrewheiss is a hint about this I believe. Possibly some quarto improvement on this not gt as this is Quarto/Pandoc that is generating the raw LaTeX inserted, and no more gt. @rich-iannone I let you open a ticket on your repo to track potential improvement and more testing. |
@andrewheiss me and Carlos discussed this and we have a good plan in place that will preserve the LaTeX table code that gt generates while also allowing Quarto to properly handle citations as well as performing the Markdown conversion. More to come. |
@rich-iannone the PR on the quarto side is here #7451 |
Following up on this (and related to #9342), @rich-iannone is there a way to use For example, this qmd has an equation and a citation: ---
title: "Citations in tables"
format:
html: default
pdf:
keep-tex: true
references:
- type: article-journal
id: Lovelace1842
author:
- family: Lovelace
given: Augusta Ada
issued:
date-parts:
- - 1842
title: >-
Sketch of the analytical engine invented by Charles Babbage, by LF Menabrea,
officer of the military engineers, with notes upon the memoir by the translator
title-short: Molecular structure of nucleic acids
container-title: Taylor’s Scientific Memoirs
volume: 3
page: 666-731
language: en-GB
---
$$
a^2 + b^2 = c^2
$${#eq-math}
```{r}
library(gt)
tibble::tribble(
~Thing, ~Citation,
1234, "@Lovelace1842",
5678, "@eq-math"
) |>
gt() |>
fmt_markdown(Citation)
``` When rendering to PDF, those ```{=latex}
% QExvdmVsYWNlMTg0Mg==} is "@Lovelace1842" in base-64 encoding
% QGVxLW1hdGg= is "@eq-math" in base-64 encoding
\begin{tabular}{cc}
Thing & Citation \\
1234 & \QuartoMarkdownBase64{QExvdmVsYWNlMTg0Mg==} \\
5678 & \QuartoMarkdownBase64{QGVxLW1hdGg=} \\
\end{tabular}
``` I tried adding the base64 content myself in
…but {gt} automatically converts \begin{longtable*}{rl}
\toprule
Thing & Citation \\
\midrule\addlinespace[2.5pt]
1234 & \textbackslash{}QuartoMarkdownBase64\{QExvdmVsYWNlMTg0Mg==\} \\
5678 & \textbackslash{}QuartoMarkdownBase64\{QGVxLW1hdGg=\} \\
\bottomrule
\end{longtable*} and this PDF: Is there a way to get {gt} to emit |
@andrewheiss I believe this is somewhat related to this issue I opened in GT for the case for HTML But same workaround applies library(gt)
tibble::tribble(
~Thing, ~Citation,
1234, "\\QuartoMarkdownBase64{QGVxLW1hdGg=}",
5678, "\\QuartoMarkdownBase64{QExvdmVsYWNlMTg0Mg==}"
) |>
gt() |>
fmt_passthrough(
columns = Citation,
escape = FALSE
) Using It should write this table \begin{longtable}{rl}
\toprule
Thing & Citation \\
\midrule\addlinespace[2.5pt]
1234 & \QuartoMarkdownBase64{QGVxLW1hdGg=} \\
5678 & \QuartoMarkdownBase64{QExvdmVsYWNlMTg0Mg==} \\
\bottomrule
\end{longtable} Hope it helps |
Bug description
There is inconsistent behavior when including citation keys inside tables, but it's a really tricky issue and I'm not sure if it's a Quarto issue or an issue with other table-making packages.
When making a table with regular Markdown or with
knitr::kable()
, citation keys that are included in table rows are rendered correctly by pandoc.However, when making a table with
kableExtra::kbl()
orgt::gt()
, pandoc doesn't see the citation keys.Here's a reproducible example:
Raw Markdown and
knitr::kable()
work correctly:kableExtra::kbl()
andgt::gt()
do not render the citation:This is a known issue in both kableExtra (haozhu233/kableExtra#214 (comment)) and gt (rstudio/gt#112 (comment)), and the existing solution for both packages is to use bookdown's text reference feature to render the citation outside of the table and then automatically include the rendered citation inside the table when knitting, like this:
This doesn't work in Quarto, though. #1959 and #1785 are about adding bookdown-esque text references to Quarto, which would potentially solve this issue.
This is with RStudio 2022.07.2+576 on macOS Monterey 12.6, but it happens across platforms
Checklist
The text was updated successfully, but these errors were encountered: