katex {katex} | R Documentation |
Tex math rendering in R
Description
Converts tex-style math expressions to html and mathml for use in manual pages or
markdown documents.
The conversion is done in R using V8 ("server-side"), hence the resulting fragment can
be inserted into an HTML document without the need for a JavaScript library like MathJax.
Only the katex.css
style file is required in the final html document.
Use math_to_rd for embedding math into R documentation (.rd
) pages.
Usage
katex_html(
tex,
displayMode = TRUE,
...,
include_css = FALSE,
preview = interactive()
)
katex_mathml(tex, displayMode = TRUE, ...)
example_math()
Arguments
tex |
input string with tex math expression. |
displayMode |
render math in centered 2D layout, similar to |
... |
additional html rendering options passed to katex.render |
include_css |
adds the katex css file to the output.
This is only required once per html webpage. Set to |
preview |
open an HTML preview page showing the snipped in the browser |
Details
Refer to the upstream katex support table for the full list of supported tex functions that can be rendered to html using katex.
By default, katex_html returns a mix of HTML for visual rendering and includes
MathML for accessibility. To only get html, pass output="html"
in the extra options,
see also the katex documentation.
Value
a string with a html/mathml fragment
See Also
Other katex:
math_to_rd()
,
pandoc
Examples
# Basic examples
html <- katex_html(example_math())
mathml <- katex_mathml(example_math())
# Example from katex.org homepage:
macros <- list("\\f" = "#1f(#2)")
math <- "\\f\\relax{x} = \\int_{-\\infty}^\\infty \\f\\hat\\xi\\,e^{2 \\pi i \\xi x} \\,d\\xi"
html <- katex_html(math, macros = macros)
mathml <- katex_mathml(math, macros = macros)