2.3 Advanced features

2.3.1 Conditional text based on outputs

By using the conditional-content.lua file within the folder, the code below will allow you to have certain text only show in certain outputs.

This can useful if you have code that only works in one format, e.g. The word appears red in pdf and appears black in other formats, while the word blue appears blue in html and black in all other format - but with the following code we can ensure pdf and html have the same colours.

This should only show in the html version

I can use this to write pure html code such as making this red.

Note: There are different (and simpler) workarounds to changing colours using R-code or different lua filters (see https://bookdown.org/yihui/rmarkdown-cookbook/font-color.html), however the above allows for a wider set of flexibility.

2.3.2 Conditional text based on parameters

You can create some parameters in the preamble by:

params:

soln: False

You can then use R-code to get somethings to show or not depending on those parameters, e.g. turning solutions on or off in a problem sheet.

This text is visible (in all formats) whenever the soln parameter is set to false. The R-code evaluates the state of soln and comments this text out if soln is set to true.