While Markdown parsers like pandoc know what LaTeX is, commonmark does not, and that means LaTeX equations will end up with extra markup due to commonmark's desire to escape characters.

However, if you have LaTeX equations that use either $ or $$ to delimit them, you can protect them from formatting changes with the $protect_math() method (for users of the yarn object) or the protect_math() function (for those using the output of to_xml()). Below is a demonstration using the yarn object:

path <- system.file("extdata", "math-example.md", package = "tinkr")
math <- tinkr::yarn$new(path)
math$tail() # malformed
math$protect_math()$tail() # success!

Note, however, that there are a few caveats for this:

  1. The dollar notation for inline math must be adjacent to the text. E.G. $\alpha$ is valid, but $ \alpha$ and $\alpha $ are not valid.
  2. We do not currently have support for bracket notation
  3. If you use a postfix dollar sign in your prose (e.g. BASIC commands or a Burroughs-Wheeler Transformation demonstration), you must be sure to either use punctuation after the trailing dollar sign OR format the text as code. (i.e. `INKEY$` is good, but INKEY$ by itself is not good and will be interpreted as LaTeX code, throwing an error: r path <- system.file("extdata", "basic-math.md", package = "tinkr") math <- tinkr::yarn$new(path) math$head(15) # malformed math$protect_math() #error


ropensci/tinkr documentation built on May 18, 2024, 8:34 a.m.