mccarthy-m-g / musicians-compendium

The Musician's Compendium: a book
https://musicianscompendium.netlify.com
Other
2 stars 0 forks source link

Display method for in-text accidentals #3

Closed mccarthy-m-g closed 4 years ago

mccarthy-m-g commented 4 years ago

Displaying sharps, flats, and other music symbols in-text is an important feature for this book. Although I could write sharps with # and flats with b, this is less accurate and attractive than using the ♯ and ♭ music symbols. So far I have found two options for rendering these music symbols in bookdown:

  1. Mathjax.
  2. Unicode, as I'm doing in this post.

Both methods support some of the symbols I need, however, I've encountered problems implementing them (see below). Any help or alternate suggestions would be appreciated.

Mathjax problems

Unicode problems

Using different renderers for different outputs

I could use different renderers for HTML and PDF if the best solutions are HTML or PDF specific. If I have to go this route there is the musicography package for LaTex I could use (assuming it can be installed in my GitHub actions build; I'd have to figure that out).

mccarthy-m-g commented 4 years ago

This commit solves this issue. For anyone curious: I chose to use different renderers for HTML and PDF outputs, and will be using inline R code to reference symbols. For example: `r f` will display a flat symbol using unicode in the HTML version and the musicography package in the LaTeX version.

The only downside to this approach is that:

  1. I have to create a new R object whenever I want to include a new symbol.
  2. I have to source() the _musicSymbols.R file containing the music symbol R objects at the start of any chapter I wish to use them in. This appears to be a limitation of the knitr::is_html_output() and knitr::is_latex_output() functions, as their documentation says they only work in .Rmd files. Calling _musicSymbols.R in _bookdown.yml with before_chapter_script: does not work.
  3. The Bravura Text font doesn't seem to work in the epub version of this book.
  4. The current implantation leaves symbols invisible while the font loads (I can change the css to uncomment font-display: swap; to change this behaviour though).