quarto-dev / quarto-cli

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

Quarto revealjs ignores global fig-align and fig-asp settings when rendering plots. #9800

Open eipi10 opened 5 months ago

eipi10 commented 5 months ago

Bug description

I'm trying to set global values for fig-align and fig-asp in a revealjs presentation, but quarto is ignoring them. I've tried setting them in the top level yaml (as in the example below), within execute: and within format: revealjs:, but the behavior is the same in each case. Unlike fig-asp and fig-align, quarto does respect a global setting of fig-dpi.

Steps to reproduce

---
title: "Presentation Title"
format: 
  revealjs:
    width: 1500
    height: 900
    margin: 0.1
fig-align: center
fig-asp: 1
fig-dpi: 600
editor: source
---

```{r include=FALSE}
library(tidyverse)
p = iris %>% 
  ggplot(aes(Petal.Length, Petal.Width, colour=Species)) + 
  geom_line() +
  geom_point()

Title

Ignores fig-asp and fig-align, regardless of whether these are in top-level yaml, within execute: or within revealjs:.

p

Title

With a label added to chunk options: Respects fig-align, but ignores fig-asp. But now there's an unwanted Figure 1 added as a caption.

#| label: fig-1
p

Title

Respects local fig-asp and fig-align.

#| fig-asp: !expr 9/10
#| fig-align: center
p

Output:

![Screenshot 2024-05-29 at 3 04 15 PM](https://github.com/quarto-dev/quarto-cli/assets/436817/8bb8ecad-271b-443f-a5f3-4deae323de01)

### Expected behavior

All plots should be rendered using the global `fig-align` and `fig-asp` values set in the `yaml`, unless overridden by local settings in a given chunk.

### Actual behavior

- In a chunk without a `label`, quarto ignores global `fig-align` and `fig-asp`. 
- In a chunk with a `label`, quarto respects global `fig-align` and ignores global `fig-asp`, but adds an undesired `Figure 1` caption below figure. 
- quarto respects `fig-align` and `fig-asp` when set locally within a chunk.

### Your environment

- IDE: RStudio 2024.04.1+748  
- R: 4.4.0
- OS: Windows Server 2016

### Quarto check output

```bash
Quarto 1.4.554
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.554
      Path: C:\Program Files\Quarto\bin
      CodePage: 1252

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

[>] Checking LaTeX....................OK
      Tex:  (not detected)

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

[>] Checking Python 3 installation....(None)

      Unable to locate an installed version of Python 3.
      Install Python 3 from https://www.python.org/downloads/

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

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/
eipi10 commented 5 months ago

I just reran the reproducible example above and now the global fig-asp works in all slides, but the global fig-align is still ignored in the first slide. I have no explanation for why the result is different (I haven't made any changes to my system), but I thought I should report it here.

cderv commented 5 months ago

I don't think all of this is revealjs specific

Regarding fig-asp

How do you check this is not taken into account everywhere ? Just so that we look at the same thing. It seems it is working now, and from plot size I see I think this is respected too

Not that in HTML output, Image are dynamically resize if you do not set auto-stretch: false. This is part of default behavior to have image stretched.

Regarding fig-align

When no label with fig- prefix, Quarto does not consider it a figure, and we have a regression for applying fig-align - related to this

and maybe others

So the first slide won't be centered because of this currently

but adds an undesired Figure 1 caption below figure.

I don't think we still add this if no caption. You should check

eipi10 commented 5 months ago

@cderv, thanks for your reply.

Yes, global fig-asp seems to be working as expected (even though it didn't work when I first ran my reproducible example--not sure what was going on there).

Global fig-align doesn't work unless a code chunk includes a label option. However, when the label option is included, the plot is rendered with the caption Figure ... below the plot (even when no fig-cap is included), which I don't want (see example below). Ideally, global fig-align would work without having to add a label option to each individual chunk. Indeed, the whole point of using global fig-align (and other global figure options) is to avoid having to add special options to each individual chunk.

Here's an example showing that quarto revealjs adds a Figure 1 caption to a plot when the chunk includes a label, even if there's no fig-cap option included:

---
title: "Presentation Title"
format: 
  revealjs: default
fig-align: center
fig-asp: 1
fig-dpi: 600
---

```{r include=FALSE}
library(tidyverse)
p = iris %>% 
  ggplot(aes(Petal.Length, Petal.Width, colour=Species)) + 
  geom_line() +
  geom_point() +
  theme_bw(base_size=20)

Title

#| label: fig-1
p


Output:
![Screenshot 2024-05-31 at 9 16 17 AM](https://github.com/quarto-dev/quarto-cli/assets/436817/573a2b60-ff80-47a9-9562-f6bbe402abb0)
cderv commented 5 months ago

However, when the label option is included, the plot is rendered with the caption Figure ... below the plot (even when no fig-cap is included), which I don't want (see example below)

Can you try with 1.5 pre-release ?

Ideally, global fig-align would work without having to add a label option to each individual chunk. Indeed, the whole point of using global fig-align (and other global figure options) is to avoid having to add special options to each individual chunk.

Yes this is a about

When it will be handled, it should fix also for this case.

mcanouil commented 5 months ago

If you don't want "Figure X" then don't make it a cross-referenceable figure using a label with fig- as prefix. (In 1.5, I believe there is nothing unless you set a caption).

eipi10 commented 5 months ago

I just installed Quarto 1.5.39 and setting the label option no longer adds the Figure 1 caption.

---
title: "Presentation Title"
format: 
  revealjs: default
fig-align: center
fig-asp: 1
fig-dpi: 600
---

```{r include=FALSE}
library(tidyverse)
p = iris %>% 
  ggplot(aes(Petal.Length, Petal.Width, colour=Species)) + 
  geom_line() +
  geom_point() +
  theme_bw(base_size=20)

With label

#| label: fig-1
p

Without label

p

![Screenshot 2024-05-31 at 9 32 02 AM](https://github.com/quarto-dev/quarto-cli/assets/436817/803cf713-7835-467b-83f0-ced2fa259c5b)
![Screenshot 2024-05-31 at 9 32 19 AM](https://github.com/quarto-dev/quarto-cli/assets/436817/35ecc9f5-7d58-44ae-afd8-d66412e4c746)
cderv commented 5 months ago

So that leaves us with the fig-align issue, which is directly related to the other one IMO.