Open AlloriMD opened 5 months ago
Unfortunately, your example is not small, reproducible or self-contained.
For instance, if I create a book:
quarto create project book demo Demo
Then add the following snippet to intro.qmd
or index.qmd
:
:::{#fig-figureone}
```{python}
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
plt.plot(x, y)
plt.show()
Some caption :::
{#fig-figuretwo}
@fig-figureone
@fig-figuretwo
I get the expected results.
---
You can share a **self-contained "working" (reproducible)** Quarto document using the following syntax, _i.e._, using more backticks than you have in your document (usually four ` ```` `).
See <https://quarto.org/bug-reports.html#small-is-beautiful-aim-for-a-single-document-with-10-lines>.
If you have multiple files (and if it is **absolutely required** to have multiple files), please share as a Git repository.
<table>
<tr><th>R</th><th>Python</th></tr>
<tr><td>
`````md
````qmd
---
title: "Reproducible Quarto Document"
format: html
engine: knitr
---
This is a reproducible Quarto document.
```{r}
x <- c(1, 2, 3, 4, 5)
y <- c(1, 4, 9, 16, 25)
plot(x, y)
The end.
````qmd
---
title: "Reproducible Quarto Document"
format: html
engine: jupyter
---
This is a reproducible Quarto document.
```{python}
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
plt.plot(x, y)
plt.show()
The end.
Additionally and if not already given, please share the output of quarto check
within a code blocks (i.e., using three backticks ```txt
), see https://quarto.org/bug-reports.html#check.
We're aware of this bug but have had a hard time reproducing it.
I'd prefer a big example as opposed to not having one at all. Would you mind sending a link to a github repository? Thank you.
Let's not close this issue just yet, but I think it is a duplicate of https://github.com/quarto-dev/quarto-cli/issues/9294
Thanks for pointing me in the right direction. When I create a new Book Project that has a flat layout, everything worked as expected.
I tracked down the problem to how chapters are listed in _quarto.yml
-- If the path to the chapter file is prefixed with a ./
, then the figure crossref problem happens:
chapters:
- index.qmd
- part: "PART ONE"
chapters:
- ./_chapters/ch01.qmd
- ./_chapters/ch02.qmd
Note that the book otherwise appears completely normal. All pages render, and the web site is navigable. It's just that the figure crossref doesn't work right.
However, when I removed the ./
prefix in the YAML chapter listing, then the crossrefs appear correctly.
chapters:
- index.qmd
- part: "PART ONE"
chapters:
- _chapters/ch01.qmd
- _chapters/ch02.qmd
(I guess I'm so used to using ./
and ../
when specifying paths that I must've changed it to "clean it up" at some point, not realizing that Quarto YAML would not like that.)
Anyway, thanks so much for the help. It wasn't as much a bug with crossref as understanding how Quarto expects the chapter filenames need to appear within the YAML definition of the book structure.
It may be worth giving an example of a book that organizes the structure into folders/subfolders, since all the examples on the Quarto web site represent a "flat" organizational scheme for all the files. To see an example where the path is specified without any ./
prefix might help someone else out. Or maybe a callout box to highlight this tidbit.
I see some of what you're reporting, but I still can't fully reproduce it. with ./ch1.qmd
instead of ch1.qmd
, I do get a loud warning about failing to resolve cross-references:
book:
title: "Issue-9304"
author: "Norah Jones"
date: "4/8/2024"
chapters:
- index.qmd
- intro.qmd
- part: "Part I"
chapters:
- ./ch1.qmd
- ./ch2.qmd
- summary.qmd
- references.qmd
$ quarto render
...
WARN: index.html: Unable to resolve crossref @fig-1
WARN: index.html: Unable to resolve crossref @fig-2
...
This is already a bug on our side, but even in this case, I don't get the result you do. Instead, I simply get the (standard, otherwise intended) failed crossref id:
I really would prefer to have a full example from you that we can run. Could you provide that if at all possible?
Sorry it took a while, but I was able to create an example Quarto Book that reproducibly demonstrates the bug: cf. https://github.com/AlloriMD/quarto_bug_9304
Briefly, this Quarto Book specifies chapters in the subdirectory _chapters
. The _quarto.yml
file lists these chapter filenames using a relative path, eg ./_chapters/ch01.qmd
. If you preview the Quarto Book and then look at the second chapter with all the figures, you will see that the figure cross-references all appear as "fig-id" instead of as "Figure 1".
By simply removing the ./
in _quarto.yml
and saving the file, the Quarto Book preview will update and will resolve the figure cross-references correctly, eg "Figure 1".
This sample GitHub repository also includes a .gif screen recording that demonstrates the problem.
Side question: Why are you using the _
prefix for directories? In Quarto, it means that those are hidden and should not be discovered by Quarto.
In Quarto, it means that those are hidden and should not be discovered by Quarto.
Just to clarify: they're hidden by default if no render list is specified, but if they show in the configuration, we do respect it. (I've also tested and confirmed that the bug is unrelated to _chapters
vs chapters
, it really is only about ./path
vs path
)
Side question: Why are you using the
_
prefix for directories?
@cscheid, I decided to prefix all the "Quarto bits" with the _
(I even named the refs file "_references.bib") so that they must be explicitly listed in the _quarto.yml
file in order to be processed. Thus, the directory structure of the project has "_chapters", "_figures", "_data", etc.
Perhaps it is "belts and suspenders," but that makes sure that quarto render
only assembles the pieces as defined by the project, and I don't risk having the chapters being rendered separately. (I think I had that issue when I was trying to keep parts of a Manuscript Project in separate files, and I carried over the practice to Book Projects.)
Bug description
What I did... In a Quarto Book project edited by plaintext editor and compiled to HTML (web page) at the command line, I created a document with several figures and subsequently crossref'd them using the
@fig-id
notation.What happened...
fig-id
is not being resolved to the number.@fig-fake-name-that-doesnt-exist
) displays in the same way, as "Figure fig-fake-name-that-doesnt-exist") -- without the?
that usually precedes an unknown crossref.What I expected to happen...
fig-id
should display a question mark in front of the figure, as happens with bibliographic citations; e.g., "Figure ?fig-fake-name-that-doesnt-exist".Steps to reproduce
::: {#fig-python-code-chunk-within-div width=150}
Figure generated from running a code chunk within a DIV. :::
Now we will try to crossref each of them:
Fin.