quarto-dev / quarto-dev/quarto-cli
Book: chapters specified with with `./` in their path fail crossref resolution
Open
@cscheid is already working on this.
Since Apr 8, 2024.
bug
crossref
- Dominant language
- JavaScript
- Stars
- 6k
- Forks
- 458
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
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...
- Instead of showing up as an auto-numbered "Figure 1", "Figure 2", etc., the crossrefs are listed as "Figure fig-id". The label "Figure" was added by Quarto, but the
fig-idis not being resolved to the number. - A crossref to a fake figure (e.g.,
@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...
- Correct crossrefs should display with the figure label followed by the auto-number, e.g. "Figure 1", "Figure 2", etc.
- A crossref to a non-existent
fig-idshould 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
# Bugs
## Figure crossref not working
Consider these figures:
{#fig-simple-image width=250}
::: {#fig-image-within-div}
{width=250}
An image within a DIV
:::
```{python}
#| label: fig-python-code-chunk
#| fig-cap: "Figure generated by running a code chunk."
#| echo: true
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```
::: {#fig-python-code-chunk-within-div width=150}
```{python}
#| echo: true
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```
Figure generated from running a code chunk within a DIV.
:::
Now we will try to crossref each of them:
- @fig-simple-image -- should be "Figure 1"
- @fig-image-within-div -- should be "Figure 2"
- @fig-python-code-chunk -- should be "Figure 3"
- @fig-python-code-chunk-within-div -- should be "Figure 4"
- @fig-fake-figure-id -- should not resolve because there is no such figure id.
Fin.
Expected behavior
- Correct crossrefs should display with the figure label followed by the auto-number, e.g. "Figure 1", "Figure 2", etc. If
chapters: trueis set in thecrossref:section of_quarto.yml, then the figure numbers should be prefixed by the chapter, e.g. "Figure 1.1" for Chapter 1 or "Figure H.1" for Appendix H. - A crossref to a non-existent
fig-idshould display a question mark in front of the figure, as happens with bibliographic citations; e.g., "Figure ?fig-fake-name-that-doesnt-exist".
Actual behavior
- All figures did display correctly.
- All figure captions did display correctly immediately below the figures -- They do appear as "Figure 1: A simple image", "Figure 2: An image within a DIV", "Figure 3: Figure generated by running a code chunk.", and "Figure 4: Figure generated from running a code chunk within a DIV."
- The crossref displays incorrectly -- Instead of showing up as an auto-numbered "Figure 1", "Figure 2", etc., the crossrefs are listed as "Figure fig-id". The label "Figure" was added by Quarto, but the
fig-idis not being resolved to the number. - No '?' appears prefixing a crossref to an invalid
fig-id-- With a crossref to a fake figure (e.g.,@fig-fake-name-that-doesnt-exist) displays in the same way, as "Figure fig-fake-name-that-doesnt-exist" rather than "Figure ?fig-fake-name-that-doesnt-exist". - The error occurs no matter what kind of figure embedding I use: simple image, an image within a div, programmatic plotting from a code chunk, programmatic plotting from a code chunk contained within a div, etc.
Specific to this sample document, this is what I see as the crossref output:
- Figure fig-simple-image – should be “Figure 1”
- Figure fig-image-within-div – should be “Figure 2”
- Figure fig-python-code-chunk – should be “Figure 3”
- Figure fig-python-code-chunk-within-div – should be “Figure 4”
- Figure fig-fake-figure-id – should not resolve because there is no such figure id.
I will paste a screencap below.
It is noteworthy that this problem only occurs in HTML (web page output). The PDF rendering generates correct figure crossrefs.
Your environment
- macOS Sonoma 14.3
- Quarto 1.4.553 and pre-release 1.5.28 -- both produce the same result
- Plaintext workflow with
quarto previeworquarto renderat command line
Quarto check output
quarto check
Quarto 1.5.28
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.1.11: OK
Dart Sass version 1.70.0: OK
Deno version 1.41.0: OK
Typst version 0.10.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.5.28
Path: /Applications/quarto/bin
[✓] Checking tools....................OK
TinyTeX: (not installed)
Chromium: (not installed)
[✓] Checking LaTeX....................OK
Using: Installation From Path
Path: /Library/TeX/texbin
Version: 2024
[✓] Checking basic markdown render....OK
[✓] Checking Python 3 installation....OK
Version: 3.11.8 (Conda)
Path: /Applications/miniconda3/envs/quarto/bin/python
Jupyter: 5.7.1
Kernels: python3
[✓] Checking Jupyter engine render....OK
[✓] Checking R installation...........OK
Version: 4.2.3
Path: /Library/Frameworks/R.framework/Resources
LibPaths:
- /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
knitr: 1.42
rmarkdown: 2.21
[✓] Checking Knitr engine render......OK
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.