quarto-dev / quarto-cli

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

Emit better error message in the presence of incorrect `-labels` specs #4938

Open daniel1noble opened 1 year ago

daniel1noble commented 1 year ago

Bug description

Hi,

I've just started getting what appears to be an error with table crossref.lua. This appeared all of a sudden (within the last two weeks). I'm on Mac OS 13.2.1 (22D68), with Quarto v1.78.0 through VSCode 1.76.2. I think everything is updated (R ver 4.2.3) and it worked just a couple of weeks ago and now the render to .docx fails with:

Error running filter /Applications/quarto/share/filters/crossref/crossref.lua: table expected, got Inline

I'm using the gt() (very. ‘0.6.0’) package for the table I am rendering. Any help would be appreciated. Quarto check below

Thanks

quarto check

[✓] Checking Quarto installation......OK Version: 1.2.313 Path: /Applications/quarto/bin

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

[✓] Checking Python 3 installation....OK Version: 3.9.6 Path: /Applications/Xcode.app/Contents/Developer/usr/bin/python3 Jupyter: (None)

  Jupyter is not available in this Python installation.
  Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK Version: 4.2.3 Path: /Library/Frameworks/R.framework/Resources LibPaths:

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

Reproducible Example. .qmd file:

---
title: "test"
crossref:
  fig-title: 'Figure'
  fig-labels: arabic
  title-delim: "-"
  fig-prefix: "Figure"
  tbl-labels: "Table"
---
@tbl-tabs1

```{r}
#| label: tbl-tabs1
#| tbl-cap: Test

install.packages("tidyverse"); library(tidyverse)
install.packages("gt"); library(gt)

tabs1 <- data.frame(matrix(rnorm(5*11, 0, 2), ncol = 5, nrow = 11))

gt(tabs1) %>%  
    fmt_number(columns = 2:5, decimals = 2) %>% 
    tab_row_group(label = "Fixed Effects", rows = 1:7) %>% 
    tab_row_group(label = "Random Effects", rows = 8:11) %>%  
    tab_style(style = list(cell_text(weight = "bold")),
          locations = list(cells_column_labels(), cells_row_groups())) %>% 
    opt_table_lines(extent = "none")  %>% 
    tab_style(style = cell_borders(sides = c("top", "bottom")),
          locations = list(cells_column_labels()))  %>% 
    tab_style(style = cell_borders(sides = "bottom", weight = px(2)),
          locations =  cells_body(rows = 7))

 Which results in a VSCode error:

Error running filter /Applications/quarto/share/filters/crossref/crossref.lua: table expected, got Inline

as well as an Error in RStudio (2023.03.0+386 (2023.03.0+386)).

Error running filter /Applications/quarto/share/filters/crossref/crossref.lua: PandocLuaError "all choices failed\n\twhile retrieving stringifyable element" stack traceback: /Applications/quarto/share/filters/crossref/crossref.lua:2660: in function 'processRawTable' /Applications/quarto/share/filters/crossref/crossref.lua:2484: in local 'fn' /Applications/quarto/share/filters/crossref/crossref.lua:1239: in function </Applications/quarto/share/filters/crossref/crossref.lua:1233>



### Checklist

- [X] Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] Please [format your issue](https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us) so it is easier for us to read the bug report.
- [X] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] Please document the operating system you're running. If on Linux, please provide the specific distribution.
- [X] Please provide the output of `quarto check` so we know which version of quarto and its dependencies you're running.
cscheid commented 1 year ago

I can repro this, and it's a real bug. Thanks for the report! I'm investigating right now.

cscheid commented 1 year ago

Here's a minimal repro:

---
title: "test"
crossref:
  tbl-labels: "Table"
---

@tbl-tabs1

| c1 | c2 |
|----|----|
| 1  |  2 |
: Test {#tbl-tabs1}
cscheid commented 1 year ago

@jjallaire I think the bug is here: https://github.com/quarto-dev/quarto-cli/blame/main/src/resources/filters/crossref/format.lua#L194

The other code paths in that conditional chain all go through resolve, https://github.com/quarto-dev/quarto-cli/blame/main/src/resources/filters/crossref/format.lua#L144 and resolve returns { pandoc.Str() }. The fallthrough condition returns pandoc.Str().

With the new AST, this eventually causes us to crash, while pandoc itself ignores the incorrect call. I suspect we're not checking the fallthrough condition in our test suite.

In addition, our code implies that the fallthrough case should be a list of strings that we cycle through, but our v1.3 yaml schemas only support a single string.

In the end, I think this is a combination of incorrect input (we don't support "Table" as an option for tbl-labels) together with an unsupported feature since our YAML schema validation.

It's unfortunate, but I think we should ship 1.3 with this (rare) bug since I'm redoing all of crossrefs for 1.4 anyway.

cscheid commented 1 year ago

@daniel1noble I've changed the title of your issue to better reflect what's going on.

Just FYI, you have a bug in your yaml specification:

  fig-prefix: "Figure"
  tbl-labels: "Table"

you probably meant tbl-prefix there. tbl-labels is supposed to control the way in which the numbering works (I agree that the key is confusing). I'm keeping this open to track the 1.4 problem, but we won't be making any 1.3 changes.

daniel1noble commented 1 year ago

@cscheid Thanks so much for your quick response! I appreciate your efforts in fixing this. Thanks for catching the yaml issue too.

daniel1noble commented 1 year ago

I'll note that the bug in yaml header fixes the issue on my end. Thanks! However, table formatting seems to be ignored. See below:

Screenshot 2023-03-27 at 10 03 31 am

Seems like another issue, but I thought I would flag it. Same reproducible example:

---
title: "test"
crossref:
  fig-title: 'Figure'
  fig-labels: arabic
  title-delim: "-"
  fig-prefix: "Figure"
  tbl-prefix: "Table"
---
@tbl-tabs1

```{r}
#| label: tbl-tabs1
#| tbl-cap: Test

pacman::p_load(tidyverse, gt)

tabs1 <- data.frame(matrix(rnorm(5*11, 0, 2), ncol = 5, nrow = 11))

gt(tabs1) %>%  
    fmt_number(columns = 2:5, decimals = 2) %>% 
    tab_row_group(label = "Fixed Effects", rows = 1:7) %>% 
    tab_row_group(label = "Random Effects", rows = 8:11) %>%  
    tab_style(style = list(cell_text(weight = "bold")),
          locations = list(cells_column_labels(), cells_row_groups())) %>% 
    opt_table_lines(extent = "none")  %>% 
    tab_style(style = cell_borders(sides = c("top", "bottom")),
          locations = list(cells_column_labels()))  %>% 
    tab_style(style = cell_borders(sides = "bottom", weight = px(2)),
          locations =  cells_body(rows = 7))
cscheid commented 1 year ago

@daniel1noble What command line did you use here?

daniel1noble commented 1 year ago

@cscheid I just used the render 'button' in VSCode .qmd document. Is that what you mean? Sorry to be dense.

cscheid commented 1 year ago

No, what I meant is that it looks like you're generating a Word document somehow by the font you're using.

I just clicked render in VS code from your document and got this instead:

image
daniel1noble commented 1 year ago

@cscheid Of course. Sorry. I understand what you mean now. Yes, this was using the word docx command. I've also tried html and pdf (see below). It works with html, but also doesn't seem to have complete formatting in pdf. For word, it seems to ignore the formatting commands completely (as above).

Sorry, this seems like another issue from this one so I can open up a new one of that's easier?

HTML:

Screenshot 2023-03-28 at 7 45 36 am

PDF:

Screenshot 2023-03-28 at 7 45 10 am
cscheid commented 1 year ago

@rich-iannone Are the gt styling commands expected to work in docx and pdf?

cscheid commented 1 year ago

@daniel1noble You might consider installing a newer version of quarto, as well as the development version of gt (there's been improvements on both in the way table styling happens)

rich-iannone commented 1 year ago

@daniel1noble styling is not yet possible for some table output formats in gt. HTML has the widest support, there has been some recent work to enable styling in docx, while LaTeX and RTF have no support yet for styling.

daniel1noble commented 1 year ago

Thanks @cscheid and @rich-iannone. Sorry I am just getting to this. I've taken @cscheid's advice and updated to more recent versions of quarto (v1.80.0), gt (v0.9.0) and I also had a crack with flextable (v 0.9.1) using VSCode (version. 1.77.2).

Styling still doesn't work on gt, but seems to be ok with flextable. However, I'm still getting cross ref issues with tables in .docx. The crossref issues also seem to depend on gt / flextable, with slightly different things happening. See below (reproducible example at the end)

Screenshot 2023-04-12 at 3 06 33 pm

This all seems to work fine with html and pdf though:

HTML: Screenshot 2023-04-12 at 3 07 28 pm

PDF: example.pdf

Here's the reproducible code for this:

---
title: "test"
crossref:
  fig-title: 'Figure'
  fig-labels: arabic
  title-delim: "-"
  fig-prefix: "Figure"
  tbl-prefix: "Table"
---
@tbl-tabs1 and @tbl-tabs2

```{r}
#| label: tbl-tabs1
#| tbl-cap: Test

pacman::p_load(tidyverse, gt, flextable)

tabs1 <- data.frame(matrix(rnorm(5*11, 0, 2), ncol = 5, nrow = 11))

gt(tabs1) 
#| label: tbl-tabs2
#| tbl-cap: Test

flextable(tabs1)


I'm not sure if there is still some bugs in word, but I thought I would let you both know in case there are some solutions

Thanks again!