The output formats of unilur
are able to render chunks in coloured boxes.
Solution chunks (using the option solution = TRUE
) are only visible when using a solution output (tutorial_html_solution
or tutorial_pdf_solution
) and are rendered by default as green boxes. In the HTML output format these boxes are in addition collapsible.
```{block, solution = TRUE}
This is the solution...
```
You can render your own boxes using the following chunk options defined in unilur
:
fill
(background) and/or colour
(text if applicable e.g. block chunk) to define the colours of the body. Use the R colour specifications (see grDevices::col2rgb()
).fill
and/or colour
to define the colours of the header.tutorial_html*
formats): +
NULL: the box is not collapsible +
TRUE: the box is collapsed +
FALSE`: the box is not collapsed but collapsiblefa-
for Font Awesome icons or ion-
for Ionicons. Alternatively you can use a function defined in a package such as icon
.Example of a coloured box:
```{block, box.title = "You can add a title", box.body = list(fill = "lightblue"), box.header = list(fill = "red", colour = "white")}
A custom box
```
Example of a coloured box using an icon:
```{block, box.title = "Title and icon", box.body = list(fill = "lightblue"), box.icon = "fa-star"}
This box contains an icon in the header...
```
knitr
allows to create option templates to set multiple chunk options that are frequently used (using the knitr::opts_template()
function and opts.label
chunk option). To demonstrate how to use this feature to create box themes, let’s define an alias named alert to set multiple box.*
chunk options:
knitr::opts_template$set(alert = list(box.title = "Watch out!",
box.body = list(fill = "#fa5b42", colour = "#fdf6d4"),
box.collapse = TRUE,
box.icon = "fa-exclamation-triangle"))
Now set the opts.label
chunk option to the alias you just created:
```{block, opts.label = "alert"}
This is an important message...
```
When you use the solution
chunk option to define solution chunks, unilur
uses the “solution” option template to render the box:
```{block, opts.label = "solution"}
This is how the solution box looks like
```
You can check the default values used for the “solution” option template:
#> List of 4
#> $ box.title : chr "solution"
#> $ box.body :List of 2
#> ..$ fill : chr "#ACFFAF4C"
#> ..$ colour: chr "black"
#> $ box.header :List of 2
#> ..$ fill : chr "#ACFFAFFF"
#> ..$ colour: chr "#456646FF"
#> $ box.collapse: logi FALSE
Thus you can override the settings:
knitr::opts_template$set(solution = list(box.title = "Look at the result",
box.body = list(fill = "pink"),
box.collapse = TRUE))
```{block, solution = TRUE}
This is how the solution box looks like
```