quarto-dev / quarto-cli

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

Contents Shortcode not working for pdf output (relates to Feature 10552) #10671

Open natecostello opened 2 months ago

natecostello commented 2 months ago

Bug description

This relates to Feature 10552.

When I try and output, to pdf, the minimal example in the documentation. I get this a malformed document and an incorrect output:

quarto preview /workspaces/quarto-playpen-2/.devcontainer/content_test_qmd.qmd --to pdf --no-brow
ser --no-watch-inputs

Output:

Starting python3 kernel...Done

Executing 'content_test_qmd.quarto_ipynb'
  Cell 1/1: 'a-cell'...Done

pandoc 
  to: latex
  output-file: content_test_qmd.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

WARNING (/opt/quarto/share/filters/main.lua:15386) [Malformed document] Found `contents` shortcode without a corresponding div with id: a-cell.
This might happen because the shortcode is used in div context, while the id corresponds to a span.
Removing from document.

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

running xelatex - 2
  This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/Debian) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

Output created: content_test_qmd.pdf

Steps to reproduce

## A section

Here we define a plot.

```{python}
#| echo: false
#| label: a-cell
import matplotlib.pyplot as plt
plt.plot([1,2,3])

Another section

Here we use the plot, inside a callout:

::: callout-note

Note the following plot

{{< contents a-cell >}}

:::


### Expected behavior

A pdf that is consistent with the documentation.

### Actual behavior

I get the error above, and a document that looks like this:

<img width="485" alt="image" src="https://github.com/user-attachments/assets/70f0ac8a-3352-4f45-8475-abb115157066">

### Your environment

- IDE: VS Code  1.92.2
- OS: 13.6.7 Ventura 

### Quarto check output

```bash
Quarto 1.6.9
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.6.9
      Path: /opt/quarto/bin

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

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

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.1
      Path: /usr/local/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.
      Install R from https://cloud.r-project.org/
mcanouil commented 2 months ago

FYI, the feature seems to be working only for HTML-based formats. @cscheid Is it a known limitation currently not stated? https://prerelease.quarto.org/docs/authoring/contents.html

cscheid commented 2 months ago

This is a consequence of https://github.com/quarto-dev/quarto-cli/issues/7062 and related bugs. The problem, specifically, is that the label is being assigned to the image rather than the cell in this case:

## A section

Here we define a plot.

::: {.cell execution_count=1}

::: {.cell-output .cell-output-display}
![](10671_files/figure-pdf/a-cell-output-1.pdf){#a-cell}
:::
:::
cscheid commented 2 months ago

In HTML, we produce this:

## A section

Here we define a plot.

::: {#cell-a-cell .cell execution_count=1}

::: {.cell-output .cell-output-display}
![](10671_files/figure-html/a-cell-output-1.png){#a-cell width=579 height=411}
:::
:::

Note that now there's a cell-a-cell id on the resulting div.