Configuring a Quarto website

quarto

Setting up a Quarto website is not trivial. In this post, I discuss how to setup the _quarto.yml configuration file optimally.

Published

March 31, 2024

1 Quarto website configuration

Quarto offers a lot of configuration options for html and also for websites! In this post, I focus on the configuration options I believe to be the most important. These are, of course, a reflection of my personnal priorities, but I hope it can serve as a stepping stone towards your own mastery of Quarto.

Remember that all of these options can be modified on a document-by-document basis by modifying the yaml header of the .qmd file.

2 My choices

Here is my current global settings file with comments. Check out the latest version here.

_quarto.yml
project:
1    type: website
    output-dir: docs
    resources:
        - CNAME

website:
    title: "Guillaume Dehaene"
    site-url: www.guillaumedehaene.com
2    page-footer: "This website was created with [Quarto](https://quarto.org/)."
3    page-navigation: true
    back-to-top-navigation: true
    navbar:
        left:
            - blog.qmd
        right:
            - publications.qmd
            -   href: about.html
                # file: about.qmd
                text: About me

format:
    html:
4        theme:
            - cosmo
            - style.scss
        mainfont: "EB Garamond, Georgia, serif"
        monofont: Fira Code, consolas, courier, monospace
        highlight-style: github

        html-math-method:
            method: mathjax
            url: "https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.4/tex-mml-chtml.js"
        include-in-header:
            text: |
                <style>
                @import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400..800;1,400..800&display=swap')
                @import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&display=swap')
                </style>
                <script>
5                MathJax = {
                    tex: {
                        tags: 'ams'  // should be 'ams', 'none', or 'all'
                    },
6                    output: {
                        font: 'mathjax-fira'
                    }
                };
                </script>
        
7        toc: true
        toc-location: right-body
        
8        number-sections: true
        number-depth: 3

9        shift-heading-level-by: 1
        anchor-sections: true

10        code-copy: true

11        code-tools: true

12        freeze: auto

13        link-external-icon: true
        link-external-newwindow: true

14        lang: en

15        strip-comments: true
1
Publishing to github pages using this method.
2
A simple footer which I’ll need to improve latter.
3
Add page navigation information.
4
Styling options. See my blog post on how I built the styling.
5
Number (almost all)1 all math equations.
6
Styling options. See my blog post on how I built the styling.
7
Including a toc menu:
8
Numbering sections, more or less like a Latex document. Headers from # to ### get numbered.
9
Adding an anchor symbol to headers. This is purely about communicating to the user that they can link to headers. shift-heading-level-by: 1 is necessary here. It converts # titles to <h2> instead of <h1>. <h1> elements do not receive the anchor treatment.
10
Add a “copy code” anchor to code blocks. Another nice user-facing feature.
11
Add a button to view the Quarto markdown source of each document. This is not a super useful feature but it has no downside.
12
Avoid repeating Python calculations to decrease document rendering time.
13
Add additional styling to make obvious to the user which links are external and open these in new windows / tabs.
14
Use english language for automated language construction.
15
Remove html comments from the source. Any comment I write are about the Quarto content, and are not relevant for the HTML document.

3 Page-specific options

These settings get applied globally accross the website, but they are not appropriate for special pages. Thankfully, we can override the global parameters on a given by giving them another value in the yaml header.

I’ve used this feature to customize the settings on the about.html page.

anchor-sections: false
number-sections: false
code-tools: false

This page has a very different type of content. Numbering sections, anchoring all sections, and providing the page source are all features which distract from that content. Interestingly, some features are automatically removed just by using the about page format.

4 Other interesting options

These options are presented in the order in which they appear in the Quarto docs:

  • smooth-scroll: instead of jumping to the target anchor, scroll the page smoothly. I feel that this improves the wow factor of the website, but it can also be annoying. It’s definitely a matter of personnal preference.
  • html-math-method: choose the math renderer. mathjax is the best as far as I’m concerned (especially with version 4.0 on the way) but you can try out the other options.
  • linestretch: more space between lines. Can be the right choice if you want to produce a document that a reviewer would print. That’s not really a website option though.
  • lightbox: Give a gallery scroller to the figures. I feel that this setting depends on the type of documents you write. For an article, I feel this should be on. I believe that Nature and several other journals use a similar type of styling for their figures.
  • crossref: if you want to customize the behavior of cross-references.
  • include-in-header, include-before-body, include-after-body: these commands inject html code or files in specific sections of the final document. If you need to do some advanced features, you probably need this.
  • copyright, license: the information gets added to the appendix of the document.
Back to top

Footnotes

  1. Equations can either be delimited by $$ $$ signs or an ams-delimiter (for example: \begin{equation} \end{equation}). This numbers all ams equations. I’ll have more to say about math in future posts.↩︎