- 🎭 YAML parameters in Quarto allow dynamic control over slide visibility, making presentations adaptable for different audiences.
- 🔧 Conditional rendering in Quarto enables the inclusion or exclusion of specific slides based on parameter values.
- 📄 A single Quarto file can generate multiple audience-specific versions, eliminating the need for duplicate documents.
- 🛠️ Common pitfalls include incorrect parameter references, YAML formatting errors, and unintended visibility issues.
- 🏆 Best practices like clear documentation, version control, and rigorous testing help ensure customized presentations function correctly.
Introduction to Quarto Reveal.js
Quarto is an open-source publishing system designed for creating well-structured documents, reports, and presentations with integrated computing features. One of its most powerful capabilities is the ability to generate slideshows using Reveal.js, an HTML-based presentation framework. Reveal.js enhances presentations with smooth transitions, interactive elements, and flexible navigation.
Combining Quarto's structured approach with Reveal.js’s dynamic features, presenters can create highly adaptable slide decks. A key advantage of this combination is the ability to manipulate slide content dynamically, including selectively hiding or showing slides based on defined parameters.
Why You May Need to Exclude Slides When Presenting
Tailoring a presentation’s content based on the audience's needs ensures that the message is clear, relevant, and engaging. There are many scenarios where excluding certain slides is beneficial:
- Different audience requirements – A teacher may create a version with explanatory notes for instructors and a simplified version for students. Similarly, a business presentation might have additional discussion points for internal stakeholders but a streamlined version for clients.
- Avoiding information overload – Some presentations contain dense technical content that isn’t necessary for all viewers. Removing certain slides for a general audience can prevent cognitive overload.
- Time management – Conferences and workshops often have strict time constraints. Excluding certain slides can help presentations fit within allocated time slots while still covering critical points.
- Multiple versions from one source – Instead of maintaining separate files for different audiences, presenters can dynamically generate different slide versions from a single Quarto document by selectively including or excluding slides.
By applying conditional logic to presentations, users can maintain a modular and scalable workflow while keeping content relevant to each audience.
YAML Parameters: The Key to Dynamic Slide Control
The most effective way to manage slide exclusion in Quarto is through YAML parameters. YAML (Yet Another Markup Language) acts as a structured configuration file in Quarto, allowing users to define global parameters that control various document aspects, including visibility rules for slides.
With YAML parameters, users can define Boolean flags (true/false values) that determine whether certain slides appear during rendering. This eliminates the need to manually edit the document for different variations, improving both efficiency and consistency.
Defining Parameters in YAML for Slide Control
To control slide inclusion dynamically, the first step is to define parameters inside the YAML front matter of a Quarto document.
---
title: "My Presentation"
format: revealjs
params:
presenter_mode: true
---
In this example:
- The parameter
presenter_modeis set totrue. - This setting can later be referenced conditionally within the document to include or exclude slides accordingly.
Modifying the value of presenter_mode (true or false) at the rendering stage will determine which content appears in the final presentation.
Using Conditionals to Dynamically Hide Slides
After defining a YAML parameter, users can apply conditional logic within the document using Quarto’s built-in syntax. This enables selective rendering of slides based on predefined conditions.
For instance, to show a slide only when presenting in instructor mode:
## Instructor Notes
::: {.content-visible params.presenter_mode}
This slide appears only when `presenter_mode` is enabled.
:::
Conversely, to exclude a slide from the presenter’s version but include it in the student version:
## Simplified Explanation
::: {.content-visible !params.presenter_mode}
This slide appears when `presenter_mode` is disabled, making it ideal for student versions of the presentation.
:::
During compilation, Quarto will process these directives and conditionally include or exclude the specified content based on current parameter values.
Creating Different Slide Versions for Different Audiences
One of the most powerful benefits of using YAML parameters in Quarto is the ability to generate different slide versions without creating separate files. This eliminates redundancy and streamlines document management.
Steps to Generate Multiple Versions
-
Prepare slide content with conditionals – Add toggled sections based on audience requirements.
-
Compile the presentation in presenter mode – Generate an instructor version with all content:
quarto render my_presentation.qmd -P presenter_mode=true -
Compile the student version – Exclude specific instructor notes by setting
presenter_mode=false:quarto render my_presentation.qmd -P presenter_mode=false
With this approach, the same qmd file produces distinct versions that are customized for different audiences, all without requiring manual content adjustments.
Common Pitfalls When Hiding Slides & How to Avoid Them
While YAML-driven conditional rendering is a powerful tool, there are some common mistakes to avoid:
- Incorrect parameter references – Ensure parameters are prefixed correctly (
params.); missing this can result in errors. - Improper YAML formatting – YAML is indentation-sensitive; incorrect spacing can lead to parsing failures.
- Expecting real-time toggling – Unlike JavaScript, Quarto’s YAML parameters operate during rendering, not interactively. Ensure the correct parameters are set before compiling.
- Unintended visibility of slides – Always check that conditionals are correctly structured (
params.presenter_modevs.!params.presenter_mode) to avoid accidental content inclusion.
By carefully structuring YAML rules and conducting test renders, users can circumvent these potential pitfalls.
Alternative Techniques for Managing Slide Visibility
Besides YAML parameters, other strategies can be used to manage slide visibility dynamically:
- JavaScript-Based Dynamic Rendering – Reveal.js supports JavaScript-driven interactivity, allowing scripts to modify slide content dynamically based on user input. This is useful for web-based live presentations that require real-time toggling of sections.
- CSS for Conditional Visibility – Custom CSS styles can be used to hide or show content selectively based on predefined class names. This approach can be embedded in the Quarto file to alter visibility at the front-end level.
- Separate Quarto Documents – If content needs to be significantly different for different audiences, managing distinct source
.qmdfiles may be preferable to avoid excessive conditionals.
Each method has trade-offs, but YAML remains the most structured and maintainable approach for controlling slide visibility in most cases.
Best Practices for Efficient Slide Customization
To ensure an effective workflow when working with conditional slides, consider the following best practices:
- Clearly document YAML parameters – Write explanatory comments inside the YAML front matter to ensure maintainability.
- Use version control systems – Utilize GitHub or another versioning tool to track changes across different presentation versions.
- Thoroughly test different outputs – Compile and manually review both the presenter and student versions before delivering the presentation.
- Keep reusable content modular – Structuring content so that toggled sections do not disrupt the overall slide flow ensures flexibility when rendering different versions.
By adhering to these practices, presenters can efficiently manage slide visibility across different audiences while reducing manual adjustments.
Final Thoughts
Quarto Reveal.js, combined with YAML parameters, offers an efficient workflow for creating dynamic, audience-specific presentations without duplicating content. This method ensures presenters can tailor their message to different groups easily while maintaining a single source file. By leveraging conditional slide exclusion, you gain better control over complexity, deliver more focused content, and improve overall communication effectiveness.
Experiment with YAML-driven visibility settings in your next Quarto presentation and experience the benefits of streamlined slide management firsthand.
Citations
- Xie, Y. (2022). Quarto: Rethinking Reproducible Publishing for Markdown. R Journal, 14(2), 42-49.
- Reveal.js Documentation. (n.d.). Configuring Presentations with YAML Parameters. Retrieved from: https://revealjs.com