protect_math | R Documentation |
Protect math elements from commonmark's character escape
protect_math(body, ns = md_ns())
body |
an XML object |
ns |
an XML namespace object (defaults: |
Commonmark does not know what LaTeX is and will LaTeX equations as
normal text. This means that content surrounded by underscores are
interpreted as <emph>
elements and all backslashes are escaped by default.
This function protects inline and block math elements that use $
and $$
for delimiters, respectively.
a copy of the modified XML object
this function is also a method in the yarn object.
m <- tinkr::to_xml(system.file("extdata", "math-example.md", package = "tinkr"))
txt <- textConnection(tinkr::to_md(m))
cat(tail(readLines(txt)), sep = "\n") # broken math
close(txt)
m$body <- protect_math(m$body)
txt <- textConnection(tinkr::to_md(m))
cat(tail(readLines(txt)), sep = "\n") # fixed math
close(txt)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.