Skip to content

communicate format output to all engines  #2216

Closed

Description

@cscheid

Via Max Kuhn:

Does quarto have built-in environmental variables (or similar) during qmd compilation that reflects the output type? Similar to knitr::is_html_output() but cross-language and more specific about the output type?
I’m trying to write single qmd files for books that get compiled in different formats. Any tools (e.g. chunk options etc) that make that easier would be fantastic.

Activity

  1. added
    enhancement
    on Aug 30, 2022
  2. added this to the v1.2 milestone on Aug 30, 2022
  3. self-assigned this
    on Aug 30, 2022
  4. dragonstyle commented on Sep 23, 2022

    @dragonstyle
    Collaborator

    You can use conditional content at the markdown level: https://quarto.org/docs/authoring/conditional.html

    The knitr functions like is_html_output should also still work.

  5. cscheid commented on Oct 5, 2022

    @cscheid
    MemberAuthor

    Right, but I still think we should have something that signals uniformly to Jupyter and knitr and future extensions; I think the question was posed in the context of running Python code.

  6. added
    needs-discussion
    on Oct 5, 2022
  7. ghost removed
    needs-discussion
    on Oct 12, 2022
  8. ghost removed this from the v1.2 milestone on Oct 12, 2022
  9. ghost added this to the v1.3 milestone on Oct 12, 2022
  10. cscheid commented on Oct 12, 2022

    @cscheid
    MemberAuthor

    Reference: notebook.py:88 is the place to do this in Jupyter, execute.R:221 in R

  11. modified the milestones: v1.3, v1.4 on Feb 28, 2023
  12. modified the milestones: v1.4, v1.5 on Dec 4, 2023
  13. cderv commented on Jan 26, 2024

    @cderv
    Member
  14. 5 remaining items

  15. cderv commented on Sep 5, 2024

    @cderv
    Member

    We just need to choose the name of the environment, and which part of the format are we passing.

    I mean

    • targeted pandoc format only (pdf, revealjs, html, typst, ...)
      • It seems necessary to produce raw content from code
    • with variants if any ?
    • What about internally replaced format (like gfm being pandoc's commonmark + variants) ?
    • a separate env for Quarto own format (dashboard ? email ? docusaurus ?)

    Maybe we need to mimic how we split in Typescript ? (in breakFormatString() ? or maybe FormatIdenfier

    export interface FormatIdentifier {
    [kBaseFormat]?: string;
    [kTargetFormat]?: string;
    [kDisplayName]?: string;
    [kExtensionName]?: string;
    }

    Once we decide, it is easy to implement. I would do this for 1.6.

  16. cscheid commented on Sep 5, 2024

    @cscheid
    MemberAuthor

    I think we should send place exactly the contents of FormatIdentifier in an env variable. The easiest thing to do is to JSON-encode it.

  17. cderv commented on Sep 5, 2024

    @cderv
    Member

    Oh I see. No specific formatting, just passing the object. I forgot about JSON as message format. interesting ! I can submit something with all this information. Cool !

  18. modified the milestones: Future, v1.6 on Sep 5, 2024
  19. self-assigned this
    on Sep 5, 2024
  20. modified the milestones: v1.6, v1.7 on Oct 29, 2024
  21. modified the milestones: v1.7, v1.8 on Apr 1, 2025
  22. cderv commented on Jul 29, 2025

    @cderv
    Member

    First step toward this is the base format:

  23. cscheid commented on Aug 20, 2025

    @cscheid
    MemberAuthor

    Quarto 1.8 exports QUARTO_EXECUTE_INFO, an env var that points to a JSON file with ample execution information, including format (it's in fact the data in the ExecuteOptions object mentioned above)

  24. mcanouil commented on Aug 21, 2025

    @mcanouil
    Collaborator

    This works great!

    ```{r}
    jsonlite::read_json(Sys.getenv("QUARTO_EXECUTE_INFO"))[["format"]][["identifier"]][["base-format"]]
    ```
    

    Also, all the other information such as the fig- and languages will be very useful.

    Edit: here is what I had in mind with this (and it works!!!🤯)

    ---
    format: html
    lang: fr
    language:
      en:
        custom-title: Alpha
      fr:
        custom-title: Beta
    ---
    
    ```{r}
    jsonlite::read_json(
      Sys.getenv("QUARTO_EXECUTE_INFO")
    )[["format"]][["language"]][["custom-title"]]
    ```
  25. cderv commented on Aug 25, 2025

    @cderv
    Member

    I believe this issue was about make something like knitr::is_html_output() available to all engines, and closer to Quarto's format.

    Exposing all information in QUARTO_EXECUTE_INFO is really cool because it offers a lot of information to users and developers of tools; however, this means two things to me

    • QUARTO_EXECUTE_INFO content should be documented properly if we expect users to use it correctly. Just on format specifiers, some fields are Quarto-specific (e.g., base-format vs. target-format). Probably part of our more advanced doc.

    • Both the quarto R package and the quarto Python module should have helpers functions so users can access relevant information without knowing which fields to retrieve. This is especially useful to really provide an is_html_output() equivalent, or a more generic quarto_to(). quarto-dev/quarto-r#285 tracks this idea.

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

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions