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

Figure numbering for multiple figures not as subfigures #12167

Open
kandolfp opened this issue Feb 27, 2025 · 6 comments
Open

Figure numbering for multiple figures not as subfigures #12167

kandolfp opened this issue Feb 27, 2025 · 6 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@kandolfp
Copy link

kandolfp commented Feb 27, 2025

Bug description

The referencing for figures that are not subfigures but multiple figures defined via a single computation is not working as expected. The label always points to the last figure and extending the label with -1, -2 as for subfigures is not working.

Steps to reproduce

--- 
title: "foo"
---

Example form the [docs](https://quarto.org/docs/authoring/figures.html#layout):

```{python}
#| label: fig-test
#| layout-ncol: 2
#| fig-cap: 
#|   - "Line Plot 1"
#|   - "Line Plot 2"

import matplotlib.pyplot as plt
plt.plot([1,23,2,4])
plt.show()

plt.plot([8,65,23,90])
plt.show()
```

Referencing the different Figures is not working correctly

- `@fig-test`: @fig-test
- `@fig-test-1`: @fig-test-1
- `@fig-test-1`: @fig-test-2
              

Actual behavior

I run:

quarto render file.qmd --to pdf

Starting python3 kernel...Done

Executing 'file.quarto_ipynb'
  Cell 1/1: 'fig-test'...Done

pandoc 
  to: latex
  output-file: file.tex
  standalone: true
  pdf-engine: xelatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf
  
metadata
  documentclass: scrartcl
  classoption:
    - DIV=11
    - numbers=noendperiod
  papersize: letter
  header-includes:
    - \KOMAoption{captions}{tableheading}
  block-headings: true
  title: foo
  
WARNING (/tmp/quartobug/.venv/lib/python3.12/site-packages/quarto_cli/share/filters/main.lua:13878) Unable to resolve crossref @fig-test-1
WARNING (/tmp/quartobug/.venv/lib/python3.12/site-packages/quarto_cli/share/filters/main.lua:13878) Unable to resolve crossref @fig-test-2

Rendering PDF
running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023/Debian) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode
  
running xelatex - 2
  This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023/Debian) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode
  

Output created: file.pdf

The label with no extension references the second figure, the two other labels do not exist.

Expected behavior

I expected a table with different labels. The first is ambiguous and (in my opinion) should not provide a result. The second and third line should reference the two figures.

If I do the same with html as output both figures have <div id="fig-test"

Your environment

  • Ubuntu 24.04
  • Quarto > 1.6.40 (tested also with latest build on github)

Quarto check output

quarto check
Quarto 1.7.3
[✓] Checking environment information...
      Quarto cache location: ~/.cache/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.7.3
      Path: /tmp/quartodebug/.venv/lib/python3.12/site-packages/quarto_cli/quarto-1.7.3/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /usr/bin
      Version: 2023

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.3
      Path: /tmp/quartodebug/.venv/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

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

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/
@kandolfp kandolfp added the bug Something isn't working label Feb 27, 2025
@mcanouil
Copy link
Collaborator

@kandolfp as you are using an old pre-release, could you upgrade to use the latest pre-release?

@kandolfp
Copy link
Author

@kandolfp as you are using an old pre-release, could you upgrade to use the latest pre-release?

Result stays the same, just a change in the version for the warning message.

New output of quarto check

Quarto 1.7.13
[✓] Checking environment information...
      Quarto cache location: ~/.cache/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.7.13
      Path: /tmp/quartobug/.venv/lib/python3.12/site-packages/quarto_cli/quarto-1.7.13/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /usr/bin
      Version: 2023

[✓] Checking Chrome Headless....................OK
      Chrome:  (not detected)

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.3
      Path: /tmp/quartobug/.venv/bin/python
      Jupyter: 5.7.2
      Kernels: python3

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

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.

I also tried with main but did not get different results. I also checked the tex and the label is the same in both captions.

@cscheid cscheid self-assigned this Feb 27, 2025
@cscheid
Copy link
Collaborator

cscheid commented Feb 27, 2025

Thanks for the report. There's definitely something not working as well as it should be.

Just so that we're all clear, I'll note that the way you're trying to create figures doesn't quite match our documentation on the page. We document creating referenceable subfigures, and not referenceable top-level figures.

The code in the docs is:

```{python}
#| label: fig-charts
#| fig-cap: "Charts"
#| fig-subcap: 
#|   - "First"
#|   - "Second"
#| layout-ncol: 2

import matplotlib.pyplot as plt
plt.plot([1,23,2,4])
plt.show()

plt.plot([8,65,23,90])
plt.show()
```

Importantly, it has fig-cap and fig-subcap.

With all that said, I agree that the way Quarto is handling your code today is not ideal. The code needs to distinguish between all of the different possible permutations of crossref, figures, subfigures, multiple figures, and layouts. It's unfortunately very finicky and prone to regressions, so I can't give you a good estimate of when we'll fix it.

In the meantime, you could try a workaround with the fenced div syntax.

--- 
title: "foo"
keep-md: true
---

Example form the [docs](https://quarto.org/docs/authoring/figures.html#layout):

```{python}
import matplotlib.pyplot as plt
```

::: {layout-ncol=2}

::: {#fig-test-1}

```{python}
#| echo: false
plt.plot([1,23,2,4])
plt.show()
```

Line Plot 1

:::

::: {#fig-test-2}

```{python}
#| echo: false
plt.plot([8,65,23,90])
plt.show()
```

Line Plot 2

:::

:::


Referencing the different Figures:

- `@fig-test-1`: @fig-test-1
- `@fig-test-2`: @fig-test-2      

I've verified that the above example works in main.

@kandolfp
Copy link
Author

kandolfp commented Feb 27, 2025

Thanks for having a look and the workaround. I highly appreciate it and also the very quick response time of all of you!

Just so that we're all clear, I'll note that the way you're trying to create figures doesn't quite match our documentation on the page. We document creating referenceable subfigures, and not referenceable top-level figures.

Fair enough, I somewhat merged the two examples from the docs and I did not interpret the statement about the labels as if and only if :).

Maybe I should also explain why I cam up with this and why I tried without using fig-subcap:

I am working on several lecture notes in the book class. When I create a pdf for something like the above figures, I get several floating objects in tex and therefore in some situations much nicer placement within the document as if I use subfigures.

@mcanouil
Copy link
Collaborator

mcanouil commented Feb 27, 2025

FYI, this use of layout with one single label and multiple "top-level" figures never worked in Quarto (at least from 1.0.38).
So, there is no regression and it is not really a bug.

@cscheid
Copy link
Collaborator

cscheid commented Feb 27, 2025

So, there is no regression and it is not really a bug.

I think it's a bug. It might be a hard one to fix because of the reasons I described, but at the very least we should be emitting warnings or error messages.

@cscheid cscheid added this to the Future milestone Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants