Unilur Example

Usage once extension is installed

  • Activate the extension by adding the following lines to your YAML header:
format:
  unilur-html: default
  unilur-html+solution:
    # You have to specify a different output file otherwise they will 
    # overwrite themselves
    output-file: example-solution.html 

When you call quarto render, two HTML files will be produced. The one named example-solution.html will have the solution blocks included.

  • Solution code blocks are highlighted or discarded according to the chunk option unilur-solution Boolean and the global option show-solution in the YAML header.

Of note, if show-solution is absent, it is considered false.

Example with unilur-solution: true

  • Code chunk with echo: fenced
```{r}
#| unilur-solution: true

1 + 1
```
[1] 2
  • Code block without solution, so stays in whatever happens
```{r}
1 + 1
```
[1] 2
  • Solution with unilur-collapse: false
Solution
1 + 2
[1] 3

Any machinery supported by Quarto can be used:

  • Python Code chunk with unilur-solution: true
#| unilur-solution: true
for i in [3, 5, 6]:
  print(i)

Caution callouts are classic:

Danger

Red expected

But tip ones are using a yellow color to better discriminate with the new solution blocks:

Tip

Are yellow instead of green-ish (in HTML)

  • Solution with markdown text ({block}):
Solution

For text with bold or warning people about CO2 atmospheric concentration

R code can be displayed but not executed.

```{r}

1 + 1
```

You can also include div labels with unilur-solution. Note the solution will only show up in the solution file (collapsed box).

Here is a solution that is inside a div. The contents of this will only be shown in the solution document. Source code highlighting is preserved inside the div and executable.

sample(CO2,  size = 5) |> 
  head(5)
   Treatment uptake Plant conc   Type
1 nonchilled   16.0   Qn1   95 Quebec
2 nonchilled   30.4   Qn1  175 Quebec
3 nonchilled   34.8   Qn1  250 Quebec
4 nonchilled   37.2   Qn1  350 Quebec
5 nonchilled   35.3   Qn1  500 Quebec

The advantage of working inside the div labels is that standard code formatting and highlighting will apply, and code can be executed alongside standard text.