Skip to content
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

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

Closed
mcanouil opened this issue May 22, 2022 · 6 comments
Closed

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

mcanouil opened this issue May 22, 2022 · 6 comments
Assignees

Comments

@mcanouil
Copy link
Collaborator

mcanouil commented May 22, 2022

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
Copy link
Collaborator Author

mcanouil commented May 22, 2022

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
Copy link
Collaborator

@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}
![](index_files/figure-html/fig1-1.png){width=672}
:::
:::


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


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


::: {.cell}

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

::: {.cell-output-display}
![](index_files/figure-html/fig2-1.png){width=672}
:::
:::



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


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

@mcanouil
Copy link
Collaborator Author

mcanouil commented May 23, 2022

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
Copy link
Collaborator

cscheid commented May 23, 2022

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
Copy link
Collaborator

cscheid commented May 24, 2022

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

@cscheid cscheid closed this as completed May 24, 2022
@mcanouil
Copy link
Collaborator Author

mcanouil commented May 25, 2022

The main issue is solved.

Should I open a separate one (it seems unrelated after all) for #951 (comment)
I opened a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants