quarto-dev / quarto-cli

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

Conditional content error #1108

Open bbartholdy opened 2 years ago

bbartholdy commented 2 years ago

OS: Pop!_OS 22.04 LTS x86_64 Quarto version: 0.9.550

Minimal example to reproduce error:

quarto create-project mybook --type book

Add conditional content to bottom of intro.qmd:

# Introduction

This is a book created from markdown and executable code.

See @knuth84 for additional discussion of literate programming.

::: {.content-visible when-format="html"}

Will only appear in HTML.

:::

Render book:

quarto render --to all

Encountered error:

Error running filter /opt/quarto/share/filters/quarto-pre/quarto-pre.lua:
/opt/quarto/share/filters/quarto-pre/quarto-pre.lua:217: attempt to call a nil value (field 'formatMatches')
stack traceback:
    /opt/quarto/share/filters/quarto-pre/quarto-pre.lua:233: in function 'handleVisible'
    (...tail calls...)

Output of quarto check

[✓] Checking Quarto installation......OK
      Version: 0.9.550
      Path: /opt/quarto/bin

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

[✓] Checking Python 3 installation....OK
      Version: 3.9.7 (Conda)
      Path: /home/bjorn/miniconda3/bin/python
      Jupyter: 4.9.2
      Kernels: python3

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

[✓] Checking R installation...........OK
      Version: 4.2.0
      Path: /usr/lib/R
      LibPaths:
        - /home/bjorn/R/x86_64-pc-linux-gnu-library/4.2
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      rmarkdown: 2.14

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

The last version (that I know of) that did not produce an error was 0.9.426

dragonstyle commented 2 years ago

Thanks for reporting this! Fixed here 57d6f2f5eb1958a0d04b8eb7a3d768f24ad516e3 and a fresh release is on the way.

bbartholdy commented 2 years ago

Error has been resolved!

I just wanted to check if the following is expected behaviour:

pdf-conditional

The left side is the pdf output based on the following conditional content:

::: {.content-visible when-format="html"}

# A Chapter only for HTML

Will only appear in HTML.

## Introduction

This is a book created from markdown and executable code.

See @knuth84 for additional discussion of literate programming.

:::

The text is left out of the pdf format but the level 1 heading is still there.

jjallaire commented 2 years ago

@dragonstyle I think this is b/c we are taking the first header in partitiionMarkdown -- I wonder if need to be slightly more choosey and only take the header if its the first thing in the file?

dragonstyle commented 2 years ago

I think there are some challenges to creating conditional chapters in this way (for example, if you were to try to create a PDF only chapter you'd end up with empty untitled pages in web or epub output). This sort of 'happens' to work for PDF chapters because of how we generate the book LaTeX, but it seems risky to rely upon.

Without proprocessing the _quarto.yml I don't know how to add a chapter to only one format, but pehaps @jjallaire has ideas here...

cderv commented 2 years ago

Regarding adding different set of chapters from different output format, bookdown configuration rmd_files, which is used to select the files to includes in the book, supports specifying a different set by format.

Reminder: the default in bookdown is to include all (R)md file found not prefixed by underscore. The rmd_files key is used to change this default behavior.

Search rmd_files in here for context: https://bookdown.org/yihui/bookdown/usage.html

Not sure how complex it would be to support this type of configuration in our YAML. (unless it already exists ? I missed the doc in this case)

jjallaire commented 2 years ago

Non we don't support that currently in YAML but we certainly could. I'm going to target this for post v1.0.

fitzchivalrik commented 2 years ago

Just stumbled upon this very issue when trying to 'exclude' the index.md in non-HTML output. An index file is mandatory for books currently, but I do not need that output in the PDF.

::: {.content-visible when-format="html"}

# Preface {.unnumbered}

This is a webpage version of the PDF documentation for your convenience.

:::

Same issue arises for references, I use biblatex for PDF output and a custom bibliography.md (alongside an empty biblio.tex partial to remove the default behaviour)

:::: {.content-visible when-format="html"}

# Bibliography

::: {#refs}
:::

::::
\printbibliography
\clearpage
\pagenumbering{Roman}

This results in an additional empty 'Bibliography' chapter in PDF output, followed by the actual bibliography.

Just to give a few more examples where a complete 'content-removed when not condition' would be appreciated.

jjallaire commented 2 years ago

@dragonstyle Let's take a look at this later on today to see if there isn't something simple we can do (I think we need a local repro that illustrates the problem so we can reason about it better). It seems like excluding content from PDFs should be much easier than excluding pages from the HTML website.

mpadge commented 2 years ago

I've got an example repo reproducing another manifestation of this issue (with latest "99.9.9" dev version). The .content-hidden is ignored when rendering pdf, dumps raw HTML straight into index.tex, and fails compilation. A solution would be really appreciated!

cderv commented 2 years ago

@mpadge I can't reproduce your example repo. Maybe we can discuss in an issue in your example repo ? I opened https://github.com/mpadge/quarto-test/issues/1 to discuss.

salim-b commented 1 year ago

I think this is b/c we are taking the first header in partitiionMarkdown -- I wonder if need to be slightly more choosey and only take the header if its the first thing in the file?

@jjallaire Is #3681 also caused by this?