quarto-dev / quarto-cli

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

Embedding two plots in manuscripts causes issues #10344

Open Huttsa opened 1 month ago

Huttsa commented 1 month ago

Bug description

I am not sure if this a bug or if manuscripts have been planned to work certain way, but here is report anyway. Hopefully it is helpful!

Steps to reproduce

I have two .qmds, the index and penguins.qmd. The index.qmd is;

---
title: Article
authors:
  - name: Norah Jones
    affiliation: The University
    roles: writing
    corresponding: true
bibliography: references.bib
---

## Section

This is a simple placeholder for the manuscript's main document [@knuth84].

```{r}
#| label: example
1 + 1

Embedding single plot cell

{{< embed notebooks/penguins.qmd#fig-onefig >}}

Some other text here

{{< embed notebooks/penguins.qmd#fig-twofig >}}


and penguins.qmd 
````qmd
---
title: "Subfig"
---

```{r}
#| label: fig-onefig
#| fig-cap: "A plot with a single cap"
# Calculate bill ratio
plot(1)
#| label: fig-twofig
#| fig-cap: |
#|  First caption
#| fig-subcap: 
#|   - "A"
#|   - "B"
plot(2)
plot(3)
_quarto.yml is 
````qmd
project:
  type: manuscript

execute:
  freeze: false

format:
  html:
    toc: true
    comments:
      hypothesis: true

Trying to embed the cell labeled fig-charts with two ggplots causes issue.

Expected behavior

The two plots are embedded into the index.qmd and rendered.

Actual behavior

Rendering qmd embeds [notebooks\penguins.qmd]
Error running filter C:/PROGRA~1/Quarto/share/filters/main.lua:
Block, list of Blocks, or compatible element expected, got Blocks
    while retrieving function argument content
    while retrieving arguments for function Div
stack traceback:
    C:/PROGRA~1/Quarto/share/filters/main.lua:23206: in field 'render'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1233: in local 'filter_fn'
    C:/PROGRA~1/Quarto/share/filters/main.lua:635: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:625>
    (...tail calls...)
    [C]: in ?
    [C]: in method 'walk'
    C:/PROGRA~1/Quarto/share/filters/main.lua:557: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:546>
    (...tail calls...)
    C:/PROGRA~1/Quarto/share/filters/main.lua:1334: in local 'callback'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1388: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:1385>
stack traceback:
    C:/PROGRA~1/Quarto/share/filters/main.lua:557: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:546>
    (...tail calls...)
    C:/PROGRA~1/Quarto/share/filters/main.lua:1334: in local 'callback'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1388: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:1385>

removing the layout-ncol: 2 sometimes gives

Block, list of Blocks, or compatible element expected, got table
    while retrieving function argument content
    while retrieving arguments for function Div
stack traceback:
    C:/PROGRA~1/Quarto/share/filters/main.lua:22445: in field 'render'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1233: in local 'filter_fn'
    C:/PROGRA~1/Quarto/share/filters/main.lua:635: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:625>
    (...tail calls...)
    [C]: in ?
    [C]: in method 'walk'
    C:/PROGRA~1/Quarto/share/filters/main.lua:557: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:546>
    (...tail calls...)
    C:/PROGRA~1/Quarto/share/filters/main.lua:1334: in local 'callback'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1388: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:1385>
stack traceback:
    C:/PROGRA~1/Quarto/share/filters/main.lua:557: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:546>
    (...tail calls...)
    C:/PROGRA~1/Quarto/share/filters/main.lua:1334: in local 'callback'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
    C:/PROGRA~1/Quarto/share/filters/main.lua:1388: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:1385>

Your environment

RStudio "Chocolate Cosmos" Release (e4392fc9, 2024-06-05) for windows Quarto Quarto 1.6.3, also tested with 1.5 and could repo the issue

Quarto check output

Quarto 1.6.3
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.6.3
      Path: C:\Program Files\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: v2024.07.03
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Using: TinyTex
      Path: C:\Users\X\AppData\Roaming\TinyTeX\bin\windows\
      Version: 2024

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

[>] Checking Python 3 installation....OK
      Version: 3.11.2
      Path: C:/Users/X/AppData/Local/Programs/Python/Python311/python.exe
      Jupyter: 5.7.2
      Kernels: python3

[>] Checking Jupyter engine render....OK

[>] Checking R installation...........OK
      Version: 4.4.1
      Path: C:/PROGRA~1/R/R-44~1.1
      LibPaths:
        - C:/Users/X/AppData/Local/R/win-library/4.4
        - C:/Program Files/R/R-4.4.1/library
      knitr: 1.48
      rmarkdown: 2.27

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

also gives the warning WARN: Error removing file and more spefically (os error 32) about removing a file because it used by another process, the message is in system language so didnt include it here

mcanouil commented 1 month ago

@Huttsa thanks for the report. please make sure your example is usable by formatting it properly, i.e., we can't use your example if you remove the backticks for the code blocks.

Also keep it simple. Do we really need the whole tidyverse and ggolot2 figures? I believe a simple plot(1) is enough.

If your code contains code blocks, you need to enclose it using more backticks, i.e., usually four ````. See https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us.

Huttsa commented 1 month ago

@Huttsa thanks for the report. please make sure your example is usable by formatting it properly, i.e., we can't use your example if you remove the backticks for the code blocks.

Also keep it simple. Do we really need the whole tidyverse and ggolot2 figures? I believe a simple plot(1) is enough.

If your code contains code blocks, you need to enclose it using more backticks, i.e., usually four ````. See https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us.

Oh yes, sorry about that, tried to edit it to be more simple and have the correct amount of backticks.

mcanouil commented 1 month ago

Thanks I can reproduce the error. But to me the issue is not really or not only about the embed of a code cell with two plots. When I remove the code cell from index.qmd all works as expected. Note that the error does not occur outside of Manuscript.

https://github.com/user-attachments/assets/dd4e2ac2-2ad3-4f59-b1bf-2aedae8caff8

cderv commented 1 month ago

For future us, this is the intermediate .md we get from internal .qmd to .ipynb conversion for the embed feature

---
title: "Subfig"
keep-md: true
---

::: {#cell-fig-onefig .cell}

```{.r .cell-code .hidden}
#| label: fig-onefig
#| fig-cap: "A plot with a single cap"
# Calculate bill ratio
plot(1)

::: {.cell-output-display} A plot with a single cap{#fig-onefig} ::: :::

::: {#fig-twofig .cell}

#| label: fig-twofig
#| fig-cap: First caption
#| fig-subcap:
#|   - "A"
#|   - "B"
plot(2)
plot(3)

::: {.cell-output-display} A{#fig-twofig-1} :::

::: {.cell-output-display} B{#fig-twofig-2} :::

First caption :::



We are in the case of subfloats handling in this part of the Lua code
https://github.com/quarto-dev/quarto-cli/blob/0d87b08a5c1b25ec6c6573e0bed793cd67eb6687/src/resources/filters/customnodes/floatreftarget.lua#L932-L946

Probably need to add support to it. 
mcanouil commented 1 month ago

Probably need to add support to it.

I am not sure to follow or understand what is "it". Sub float is supported.

InputOutput
- `_quarto.yml` ```yml project: type: manuscript ``` - `child` ````qmd --- title: "child" --- ```{r} #| label: fig-twofig #| fig-cap: "First caption" #| fig-subcap: #| - "A" #| - "B" plot(2) plot(3) ``` ```` - `main` ````qmd --- title: main --- {{< embed child.qmd#fig-twofig >}} ```` image

But it is not supported when there is a code cell in the main document (in default type project, that's not an issue).

InputOutput
- `_quarto.yml` ```yml project: type: manuscript ``` - `child` ````qmd --- title: "child" --- ```{r} #| label: fig-twofig #| fig-cap: "First caption" #| fig-subcap: #| - "A" #| - "B" plot(2) plot(3) ``` ```` - `main` ````qmd --- title: main --- ```{r} 1 + 1 ``` {{< embed child.qmd#fig-twofig >}} ```` image
cderv commented 1 month ago

Nice finding ! Removing the codeblock in main doc solves it ! I'll hide my previous post as your examples are better. thank you !

mcanouil commented 1 month ago

Look at the screen recording ;) https://github.com/quarto-dev/quarto-cli/issues/10344#issuecomment-2241723984

cscheid commented 1 month ago

Thanks for the added examples, @mcanouil. That makes the bug sufficiently loud to me that I'll try to fix in 1.6.