Skip to content

Conditional content error #1108

Closed
Closed

Description

@bbartholdy

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

Activity

  1. self-assigned this
    on Jun 8, 2022
  2. added this to the 1.0 milestone on Jun 8, 2022
  3. dragonstyle commented on Jun 8, 2022

    @dragonstyle
    Collaborator

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

  4. added
    verify-fixed
    on Jun 8, 2022
  5. bbartholdy commented on Jun 9, 2022

    @bbartholdy
    Author

    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.

  6. jjallaire commented on Jun 9, 2022

    @jjallaire
    Collaborator

    @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?

  7. dragonstyle commented on Jun 9, 2022

    @dragonstyle
    Collaborator

    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...

  8. cderv commented on Jun 9, 2022

    @cderv
    Member

    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)

  9. jjallaire commented on Jun 11, 2022

    @jjallaire
    Collaborator

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

  10. modified the milestones: 1.0, Future on Jun 11, 2022
  11. removed
    verify-fixed
    on Jun 11, 2022
  12. fitzchivalrik commented on Jun 13, 2022

    @fitzchivalrik

    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.

  13. modified the milestones: Future, 1.0 on Jun 13, 2022
  14. jjallaire commented on Jun 13, 2022

    @jjallaire
    Collaborator

    @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.

  15. modified the milestones: 1.0, Future on Jun 16, 2022
  16. mpadge commented on Jul 13, 2022

    @mpadge
  17. cderv commented on Jul 13, 2022

    @cderv
  18. salim-b commented on Dec 15, 2022

    @salim-b
    Contributor

    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?

  19. added
    bug
    on Apr 28, 2024
  20. mcanouil commented on Mar 29, 2025

    @mcanouil
    Collaborator

    Cannot reproduce on latest Quarto.

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    booksbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions