Skip to content

Commit 62c0eb7

Browse files
authored
Add a vignette to explain using quarto::format engine (#255)
* Add a vignette to explain using quarto::format engine closes #166 - Custom Quarto Extension/Template for Vignette * Use quarto::html vignette
1 parent 94bea78 commit 62c0eb7

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

vignettes/advanced-vignettes.qmd

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: Custom Quarto Formats For Vignettes
3+
format: html
4+
vignette: >
5+
%\VignetteIndexEntry{Custom Quarto Formats For Vignettes}
6+
%\VignetteEngine{quarto::html}
7+
%\VignetteEncoding{UTF-8}
8+
---
9+
10+
## About vignettes creation with Quarto
11+
12+
Creating a vignette for a CRAN package is a way to provide documentation inside the package. Vignettes are typically longer, more detailed documents that explain how to use the package, provide examples, and demonstrate its functionality. However, vignettes are also meant to be a lightweight documentation format, so they can be included in a package without being too heavy, and hosted on CRAN package pages.
13+
14+
To follow this best practice, Quarto R package vignette engines default to a format that is more minimal than the default Quarto HTML format. See `vignette("hello", package = "quarto")`. This is also useful for most users to have a default format that correctly configures Quarto HTML format for vignettes, so users do not have to configure it themselves.
15+
16+
However, advanced users may want to customize the format used for their vignettes, for example when working with an internal package with no CRAN release where vignette size does not matter. This vignette shows how to do that.
17+
18+
## Using 'quarto::format' engine for any Quarto format
19+
20+
What if a vignette needs to be produced with a custom format? For example, if your organization has a custom Quarto format that you want to use for your vignettes, you can do so by using the `quarto::format` vignette engine.
21+
22+
```yaml
23+
format: custom-html
24+
vignette: >
25+
%\VignetteIndexEntry{Custom HTML Vignette}
26+
%\VignetteEngine{quarto::format}
27+
%\VignetteEncoding{UTF-8}
28+
```
29+
30+
When using `quarto::format`, the vignette engine will not set any default configuration and will use the one defined in the YAML header as with Quarto itself.
31+
32+
To understand this clearly, let's illustrate with these examples:
33+
34+
* This will produce a vignette with the default Quarto format (i.e., `format: html`):
35+
36+
```yaml
37+
vignette: >
38+
%\VignetteIndexEntry{Custom HTML Vignette}
39+
%\VignetteEngine{quarto::format}
40+
%\VignetteEncoding{UTF-8}
41+
```
42+
43+
* This will produce a vignette with custom configuration for Quarto HTML format:
44+
45+
```yaml
46+
format:
47+
html:
48+
theme: cosmo
49+
vignette: >
50+
%\VignetteIndexEntry{Custom HTML Vignette}
51+
%\VignetteEngine{quarto::format}
52+
%\VignetteEncoding{UTF-8}
53+
```
54+
55+
This will produce a vignette with the `cosmo` theme, which is a Bootstrap theme. Bootstrap can be heavy, so this is not recommended for CRAN vignettes.
56+
57+
* This is equivalent to using `quarto::html` vignette engine directly:
58+
59+
```yaml
60+
format:
61+
html:
62+
theme: none
63+
minimal: true
64+
embed-resources: true
65+
css: custom.css
66+
vignette: >
67+
%\VignetteIndexEntry{Custom HTML Vignette}
68+
%\VignetteEngine{quarto::format}
69+
%\VignetteEncoding{UTF-8}
70+
```
71+
72+
This will produce a vignette not using Bootstrap and with minimal feature set, as detailed in `vignette("hello", package = "quarto")`.
73+
However, you can provide your own CSS file this way. Remember that `quarto::html` uses [`vignette.css`](https://github.com/quarto-dev/quarto-r/blob/main/inst/rmarkdown/template/quarto_vignette/resources/vignette.css) by default, which is a minimal CSS file that provides basic styling for vignettes. If you want to use your own CSS file, you can specify it in the YAML header as shown above.
74+
75+
The `quarto::format` is not limited to HTML format, and any Quarto format can be used with it. For example, you can use it to create a PDF vignette using LaTeX (which is equivalent to using `quarto::pdf` vignette engine directly - see `vignette("hello-pdf", package = "quarto")`) or a PDF vignette using Typst for example:
76+
77+
```yaml
78+
format:
79+
typst:
80+
toc: true
81+
vignette: >
82+
%\VignetteIndexEntry{Typst Vignette}
83+
%\VignetteEngine{quarto::format}
84+
%\VignetteEncoding{UTF-8}
85+
```
86+
87+
This should not be used for CRAN vignettes as CRAN will try to rebuild vignette, and Typst may not be available on all systems. However, this is useful for internal packages or for packages that are not submitted to CRAN, if a Typst PDF looks more appealing to you than a LaTeX PDF.
88+
89+
## Recommendations
90+
91+
Here are the vignette engines available in the `quarto` package:
92+
93+
```{r}
94+
library(quarto)
95+
names(tools::vignetteEngine(package = "quarto"))
96+
```
97+
98+
Here is our advice on which to use:
99+
100+
- `quarto::html`: Use this for CRAN vignettes, as it provides a minimal HTML format suitable for package documentation.
101+
- `quarto::pdf`: Use this for CRAN vignettes if you prefer PDF format
102+
- `quarto::format`: Use this for custom formats, such as internal packages or when you want to use a specific Quarto format for your vignettes.
103+
This could also be useful to modify the hardcoded defaults for `quarto::html` that makes the format minimal.
104+

0 commit comments

Comments
 (0)