Skip to content

Commit 87ef3dc

Browse files
committed
Add html_vignette template
1 parent 07df917 commit 87ef3dc

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

R/html_vignette.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@
1616
#' @inheritParams html_document
1717
#' @return R Markdown output format to pass to \code{\link{render}}
1818
#' @export
19-
html_vignette <- function(fig_width = 3.9,
20-
fig_height = 3.5,
19+
html_vignette <- function(fig_width = 3,
20+
fig_height = 3,
2121
css = NULL,
2222
mathjax = NULL,
2323
...) {
2424

2525
if (is.null(css)) {
26-
css <- system.file("vignette.css", package = "rmarkdown")
26+
css <- system.file("rmarkdown", "templates", "html_vignette" ,"resources",
27+
"vignette.css", package = "rmarkdown")
2728
}
2829

2930
html_document(fig_width = fig_width,
3031
fig_height = fig_height,
3132
fig_retina = FALSE,
33+
mathjax = mathjax,
3234
css = css,
3335
theme = NULL,
3436
highlight = "pygments",

inst/vignette.css renamed to inst/rmarkdown/templates/html_vignette/resources/vignette.css

File renamed without changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: "Vignette title"
3+
output: rmarkdown::html_vignette
4+
metadata: >
5+
\VignetteEngine{knitr::knitr}
6+
\VignetteIndexEntry{Vignette title}
7+
\usepackage[utf8]{inputenc}
8+
---
9+
10+
# Introduction
11+
12+
Vignettes are long form documentation commonly included in packages. Because they are part of the distribution of the package, they need to be as compact as possible. The `html_vignette` output type provides a custom style sheet (and tweaks some options) to ensure that the resulting html is as small as possible.
13+
14+
## Metadata
15+
16+
Note that all Rmarkdown vignettes need to include the following code somewhere in the document:
17+
18+
\VignetteEngine{knitr::knitr}
19+
\VignetteIndexEntry{Vignette title}
20+
\usepackage[utf8]{inputenc}
21+
22+
(Yes, they look like latex commands, even though this is an Rmarkdown document.) I recommend putting keeping them in the yaml metadata, as in this template.
23+
24+
## Figures
25+
26+
The figure sizes have been customised so that you can easily put two images side-by-side.
27+
28+
```{r, echo = FALSE}
29+
plot(1:10)
30+
plot(10:1)
31+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: HTML Vignette
2+
description: >
3+
Template for package vignettes. This customises the basic HTML output
4+
to take up as little space as possible.
5+
create_dir: false

0 commit comments

Comments
 (0)