protect_math {tinkr} | R Documentation |
Protect math elements from commonmark's character escape
Description
Protect math elements from commonmark's character escape
Usage
protect_math(body, ns = md_ns())
Arguments
body |
an XML object |
ns |
an XML namespace object (defaults: |
Details
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.
Value
a copy of the modified XML object
Note
this function is also a method in the yarn object.
Examples
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)
[Package tinkr version 0.2.0 Index]