Bookdown contest submission: Modern Statistics for Modern Biology & msmbstyle

Modern Statistics for Modern Biology is a text book by Susan Holmes and Wolfgang Huber that is due to be published in the near future. The print version has been written in a literate programming style using LaTeX/Sweave and uses many of the design principles found in Tufte Handouts. Although not currently publicly available, but the general layout of the print edition can be seen in this screen shot:

To accompany the book we have used R Markdown & bookdown to create a freely available HTML version of the book hosted at https://www-huber.embl.de/msmb/

Our intention was to maintain a similar style to the print version, with heavy use of the margin for additional information, along with consistent styling for headings etc. To achieve this we have created the package msmbstyle, which can be found at GitHub - grimbough/msmbstyle: Tufte inspired bookdown template

You can view an example website at https://www-huber.embl.de/users/msmith/msmbstyle/ ; the R Markdown documents used to create it are available in the /inst/extdata/ directory of the package

Technical Details

Given the influence of the Tufte Handout styling on the printed copy of the book, msmbstyle relys heavily on the tufte package to provide notes and figures in the margin. Where possible it reuses tufte code (including via tufte::: if the required function is not exported). This means that all formatting options provided by tufte can also be used within an R Markdown document styled using msmbstyle.

We include the functions msmb_html and msmb_html_book (adapted from corresponding functions in tufte) that can be set in the output field of the YAML header. These apply additional modifications to the HTML to provide the header bar and drop-down navigation menu.

msmbstyle also provides additional functions for including 'Questions' and 'Solutions' within the document. These can be used inline within the Rmd document to demarcate the region that should be included in the question. The resulting HTML output includes appropriate <div> tags to indicate these regions, and javascript is used to allow the reader to toggle their visibility.

Questions can optionally be labelled, numbered, and referenced within the main text. This is done within the internal function msmb_build_chapter (based on bookdown::html_build_chapter). This functionality is similar to using one of the 'Theorem' environments, but with the option to mark the start and end within the document, rather than putting content within a single code-chunk.

These additions are styled, along with some more minor tweaks from to the tufte formatting, using an additional CSS file distributed with the msmbstyle. This also attempts to provide a coherent experience when using mobile devices, modifying the layout and navigation options appropriately e.g.

or

To further experiment the layout across different devices, there is a developmental version using Bootstrap for the layout that can be seen at https://www-huber.embl.de/users/msmith/msmbstyle/bootstrap/

9 Likes

Jaw dropped! This is exactly the type of bookdown extension that I was looking forward to. I didn't really spend much time on the Tufte style in bookdown, and I was hoping someone else could pick it up and polish it. Thanks for the wonderful package! In the future, I'll recommend everyone who wants to use the Tufte style with bookdown to use the msmbstyle package.

4 Likes

Great, I'm glad it was the sort of thing you were looking for, it's been a fun project to work on.

Surprisingly hard work getting from the original LaTeX/Sweave to R Markdown, but from there bookdown and tufte got me a good chunk of the way to a HTML version the authors liked. The current version of the book definitely still has some 'hacks' to place things where I want them to be, and I'm still learning a lot about the internals of knitr, so I'm continually refining msmbstyle to try and simplify things.

It'll be cool if others want to use it too.

This is really nice. I hope to use it one day. Thanks for sharing :+1:t4:

1 Like

This is absolutely fantastic! I am very happy, that I just found this and thank you very much for sharing.

Is there any chance that the LaTeX/Sweave style might be published as well as the strength of r-markdown is cross-media-publishing?

Apropos cross-media-publishing: When I tried to compile the example files from the package to PDF via render_book('index.Rmd','tufte::tufte_book') I got an error message because of the question-chunks. Of course I realize that the package was designed for HTML output and nothing else at the moment, but is there a workaround for rendering these chunks to PDF?

1 Like