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:
$\alpha$
is valid, but $ \alpha$
and $\alpha $
are not valid.`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
$
as currency will still work, but there is a caveat that mixing
this inline math broken across lines will cause problems:
```r
# this will be mal-formed
bad <- "It's 5:45 and I've got $5.45 in my pocket.\nThe area of a circle is $A =\n \pi r^2$, where\n$\pi$ is irrational when it hasn't had its coffee."
fails <- tinkr::yarn$new(textConnection(bad))
fails$show()
fails$
protect_math()$
show()
# This works
good <- "It's 5:45 and I've got $5.45 in my pocket.\nThe area of a circle is $A = \pi r^2$, where\n$\pi$ is irrational when it hasn't had its coffee."
works <- tinkr::yarn$new(textConnection(good))
works$show()
works$
protect_math()$
show()```
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.