quarto-dev / quarto-cli

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

Quarto manuscript reference does not resolve within table if caption and label specified #8002

Closed leonardblaschek closed 8 months ago

leonardblaschek commented 8 months ago

Bug description

References in a quarto manuscript don't resolve within in a knitr::kable() in the rendered PDF when there is a #| tbl-cap specified. HTML output and latex output without the caption works.

Screenshot_20231221_100332

I've found a bunch of seemingly related issues with tbl-cap, but most seemed to be resolved. I did not manage to get around this issue with any of the solutions/hacks I could find. Apologies if i missed something obvious.

Steps to reproduce

_quarto.yaml (except for changing agu-pdf to pdf, but different templates did not seem to make a difference) and references.bib are from the example repo (https://github.com/quarto-ext/manuscript-template-rstudio)

---
title: |
  A reprex
author:
  - name: Leonard Blaschek
bibliography: references.bib
---

This works:

Testcitation [@marrero2019]

This works:

```{r}
library(tidyverse)
library(knitr)

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]"
)

kable(test)

This does not work:

#| label: tbl-test
#| tbl-cap: Test

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]"
)

kable(test)

References {.unnumbered}

:::{#refs}

:::


### Expected behavior

The reference should resolve to "(Marrero et al. 2019)".

### Actual behavior

The reference remains unresolved as `[@marrero2019]`

### Your environment

OS: Fedora 39
quarto: 1.4.515/1.4.528/1.4.533
IDE: RStudio 2023.09.1+494 "Desert Sunflower" Release (cd7011dce393115d3a7c3db799dda4b1c7e88711, 2023-10-31) for Fedora release 39 (Thirty Nine)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.15.12 Chrome/87.0.4280.144 Safari/537.36 *(Rstudio on Fedora lacks quarto, so all quarto compilations are done directly via the CLI)*

### Quarto check output

Quarto 1.4.528 [✓] Checking versions of quarto binary dependencies... Pandoc version 3.1.9: OK Dart Sass version 1.69.5: OK Deno version 1.37.2: OK [✓] Checking versions of quarto dependencies......OK [✓] Checking Quarto installation......OK Version: 1.4.528 Path: /home/leonard/Applications/quarto/quarto-1.4.528/bin

[✓] Checking tools....................OK TinyTeX: v2023.12 Chromium: (not installed)

[✓] Checking LaTeX....................OK Using: TinyTex Path: /home/leonard/.TinyTeX/bin/x86_64-linux Version: 2023

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK Version: 3.11.5 (Conda) Path: /home/leonard/Applications/miniconda3/bin/python Jupyter: (None)

  Jupyter is not available in this Python installation.
  Install with conda install jupyter

  There is an unactivated Python environment in .dropbox-dist. Did you forget to activate it?

[✓] Checking R installation...........OK Version: 4.3.2 Path: /usr/lib64/R LibPaths:

[✓] Checking Knitr engine render......OK

dragonstyle commented 8 months ago

Note: I don't think that this is likely to be manuscript specific.

leonardblaschek commented 8 months ago

Note: I don't think that this is likely to be manuscript specific.

I hadn't tried that before, but you're right. Removing the _quarto.yaml file and specifying format: pdf in the header yields a rendered pdf with the same bug.

cscheid commented 8 months ago

Thanks, I can repro this. I'm unfortunately not quite sure how to solve it.

Immediately, the issue is that inside LaTeX table floats, we need to render the table to LaTeX during the Lua processing in order to be able to control the rendering (such as, for example, adapting the caption location). However, if we do render the table to LaTeX, we don't process citations properly.

In the "This works:" example, the citation is being processed correctly by Pandoc because Quarto doesn't need to render the table in its filter processing (since it's not a float, there's no requirement for caption processing).

leonardblaschek commented 8 months ago

Yeah, that sounds unfortunate. I unfortunately don't think I have much to contribute, beyond some more details. I hadn't realised that it was the combination of caption and label that messed things up. Some more examples:

---
title: |
  A reprex
author:
  - name: Leonard Blaschek
bibliography: references.bib
---

### This works:

Testcitation [@marrero2019]

### This works:

```{r}
library(tidyverse)
library(knitr)

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]"
)

kable(test)

No label to reference

This does not work:

#| label: tbl-test
#| tbl-cap: Test

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]"
)

kable(test)

Referencing @tbl-test.

This works (but not the label):

#| label: tbl-test-nocap

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]"
)

kable(test)

Referencing @tbl-test-nocap.

This works:

#| tbl-cap: Test

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]"
)

kable(test)

No label to reference

This does work only in latex:

#| tbl-cap: Test\\label{tab:test-kable}

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]"
)

kable(test)

Referencing Table \ref{tab:test-kable}.

References {.unnumbered}

:::{#refs}

:::



![Screenshot_20240109_221551](https://github.com/quarto-dev/quarto-cli/assets/42772760/ea5c0211-e72c-4e37-b619-8d61d300c188)

I'll let you know if I come up with anything else. Thanks for your reply, and I you find a way to fix this. I'd think this was quite a crucial issue for those of us hoping to write their papers in quarto going forward.
cscheid commented 8 months ago

I'd think this was quite a crucial issue for those of us hoping to write their papers in quarto going forward.

To be clear, we 100% will fix this at some point. It's just that there isn't an immediate fix.

cscheid commented 8 months ago

Update: there is an immediate fix, it turns out. PR is up. Thanks for the report!

cscheid commented 8 months ago

This is fixed on main. We're building new installers right now.

leonardblaschek commented 7 months ago

Thanks for the quick fix! It works, but unfortunately only for tables with one row. At least for me. As far as I can tell, it's only the addition of more rows that causes this, but I might've missed something. I hope this reproduces for you.

---
title: |
  A reprex
author:
  - name: Leonard Blaschek
bibliography: references.bib
---

```{r}
library(tidyverse)
library(knitr)
#| label: tbl-locations
#| tbl-cap: Functional lignins in plants.

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]"
)

kable(test)

References {.unnumbered}

:::{#refs}

:::


![one_row](https://github.com/quarto-dev/quarto-cli/assets/42772760/ed4bd3f3-39f6-4cc4-a6ff-801539803b45)

````qmd
---
title: |
  A reprex
author:
  - name: Leonard Blaschek
bibliography: references.bib
---

```{r}
library(tidyverse)
library(knitr)
#| label: tbl-locations
#| tbl-cap: Functional lignins in plants.

test <- tribble(
  ~Text, ~Reference,
  "Text", "[@marrero2019]",
  "Text", "[@marrero2019]"
)

kable(test)

References {.unnumbered}

:::{#refs}

:::



![two_rows](https://github.com/quarto-dev/quarto-cli/assets/42772760/d6d0c55c-7dd3-4f87-a5b8-b5b0d7f30b46)
mcanouil commented 7 months ago

@leonardblaschek Which version of Quarto are you using exactly?

Because this seems heavily related to:

leonardblaschek commented 7 months ago

Ha, great!

I was using 1.5.8, and indeed both my reprex and my real world use-case are fixed in 1.5.9. I had missed that release. Thank you!