quarto-dev / quarto-cli

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

Generated figures from an included `.qmd` are not found #951

Closed mcanouil closed 2 years ago

mcanouil commented 2 years ago

Figures are generated in the directory in which the .qmd lives. But in the context of a self-contained HTML, when including .qmd files from a subdirectory, images are not retrieved by the main document: [WARNING] Could not fetch resource content/index_files/figure-html/fig2-1.png

I tried setting execute-dir: project, but same result, i.e., the figure from the included .qmd is not found.

I found nothing in https://quarto.org/docs/authoring/includes.html, but I might have missed something.

quarto-cli#951
├── content
│   └── fig2.qmd
└── index.qmd
---
title: 'quarto-dev/quarto-cli#951'
author: Mickaël Canouil, *Ph.D.*
format:
  html:
    self-contained: true
---

## Figure

```{r}
#| label: fig1
plot(2)

{{< include content/fig2.qmd >}}



Example: <https://github.com/mcanouil/quarto-issues/tree/main/quarto-cli%23951>
Version: `0.9.433`
mcanouil commented 2 years ago

I tried using knitr option to put the figures in the same place (which worked).

knitr:
  opts_chunk:
    fig.path: 'figures/'
quarto-cli#951
├── content
│   └── fig2.qmd
├── figures
│   ├── fig1-1.png
│   └── fig2-1.png
├── index.html
└── index.qmd

But still producing the warning (and fig2-1.png is still not displayed): [WARNING] Could not fetch resource content/figures/fig2-1.png

jjallaire commented 2 years ago

@cscheid I can repro this and I'm afraid this might imply that we need to not resolve images relatively within included files. What's happening is that we are "fixing up" the figures created by knitr to point to the "content/" directory. You can see this in the included keep-md below.

One possible solution is that we could exclude computationally generated paths but I'm afraid this would be too confusing/inconsistent. I recall we had some debate about how to handle (and a "fixup" option to trigger the other behavior) and we thought it would be nice to resolve the images relatively. Here not so nice though :-) I'd propose we get rid of the special resolution for included files. What do you think?

keep-md intermediate output:

---
title: 'quarto-dev/quarto-cli#951'
author: Mickaël Canouil, *Ph.D.*
format:
  html:
    self-contained: true
    keep-md: true
---

## Figure

::: {.cell}

```{.r .cell-code}
plot(2)

::: {.cell-output-display} {width=672} ::: :::

<!-- quarto-file-metadata: eyJpbmNsdWRlX2RpcmVjdG9yeSI6ImNvbnRlbnQifQ== -->{=html}

<!-- quarto-file-metadata: eyJpbmNsdWRlX2RpcmVjdG9yeSI6ImNvbnRlbnQifQ== -->

::: {.cell}

plot(2)

::: {.cell-output-display} {width=672} ::: :::

<!-- quarto-file-metadata: eyJjbGVhcl9pbmNsdWRlX2RpcmVjdG9yeSI6dHJ1ZX0= -->{=html}

<!-- quarto-file-metadata: eyJjbGVhcl9pbmNsdWRlX2RpcmVjdG9yeSI6dHJ1ZX0= -->
mcanouil commented 2 years ago

I do not know if it is exactly the same issue, but I believe it is.

The following setup in the yaml, will result in slides without background.
While, it's working fine when the generated html is at the same level as the qmd file it comes from.

format:
  revealjs:
    self-contained: true
    background-image: background.jpeg
    output-file: docs/index.html

See index2.qmd in https://github.com/mcanouil/quarto-issues/tree/main/quarto-cli%23951

Version: 0.9.440

Edit: After further tests, it appears that the background-image is never embedded in the html file for some reason. If the background image is set with {background-image="assets/background.jpg"}, it is embedded.

cscheid commented 2 years ago

We've disabled the "smart" fixing up of directories which was clearly broken in this case. Now, include tags behave completely "textually", that is, they're entirely equivalent to copying and pasting the content of the included file (potentially recursively) in the original .qmd.

This behavior is simple to describe, but produces unintuitive results whe include files in different directories have relative links. Because of that, we recommend that you either keep includes in the same directory as the original files, or use root-relative ("absolute") links in includes.

cscheid commented 2 years ago

I'm going to go ahead and close this. If the issue persists for you, let me know and we'll reopen.

mcanouil commented 2 years ago

The main issue is solved.

Should I open a separate one (it seems unrelated after all) for https://github.com/quarto-dev/quarto-cli/issues/951#issuecomment-1134779581 I opened a separate issue.