The output formats of unilur are able to render chunks in coloured boxes.

Solution chunks

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...
```
This is the solution…

Put the chunk output in customized boxes

You can render your own boxes using the following chunk options defined in unilur:

  • box.title: The title of the box
  • box.body: A list containing 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()).
  • box.header: A list containing fill and/or colour to define the colours of the header.
  • box.collapse: The collapsible status of the box (only applicable to tutorial_html* formats): +NULL: the box is not collapsible +TRUE: the box is collapsed +FALSE`: the box is not collapsed but collapsible
  • box.icon: optional Font Awesome or Ionicon name. The character sequence should start with either fa- 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
```

You can add a title

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...
```

Title and icon

This box contains an icon in the header…

Define shortcuts

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:

Now set the opts.label chunk option to the alias you just created:

```{block, opts.label = "alert"}
This is an important message...
```
This is an important message…

Change the solution box theme

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
```
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:

```{block, solution = TRUE}
This is how the solution box looks like
```
This is how the solution box looks like