I often find that I want to include the code required to produce output in quarto documents. However, sometimes the code can make the quarto document messier to read through, especially for people who are not interested in the code. The code-fold option in quarto provides a way to make more space for content, while still making the code easily accessible. However, even the code fold buttons can take up unnecessary space. I have found an easy solution that uses OJS code chunks to create a toggle for the code folds. The trick is to modify the CSS conditioning on an input. In this article I use a checkbox.
Additionally, I hide the checkbox and code fold buttons from the printed version of the webpage. To test this functionality press . Code that is expanded is still included in the printed version. I find that this approach provides the best balance between functionality and aesthetics.
Example
In a recent blog post I shared Table 1 which is based on the “Anscombe’s quartet” dataset. To see how you can reproduce these results check the “Show code folds” option and then expand the code fold.