Es ist durchaus möglich, dass dies bereits irgendwo existiert, aber Sie können eine Funktion schreiben, um eine Formel mit mathjax zu rendern und sie im Viewer (wenn Sie rududio verwenden) oder in Ihrem Webbrowser anzuzeigen. Dies würde helfen, wenn Sie wollten in Ihrem Browser bearbeiten/Prüfformeln on the fly denke, ich
form1 <- '$$A=\\frac{B}{C}$$'
form2 <- '$$
\\frac{1}{\\displaystyle 1+
\\frac{1}{\\displaystyle 2+
\\frac{1}{\\displaystyle 3+x}}} +
\\frac{1}{1+\\frac{1}{2+\\frac{1}{3+x}}}
$$'
form3 <- '\\frac{d}{dx}\\left(\\int_{0}^{x} f(u)\\,du\\right)=f(x)'
show_math(form1)
oder offen, wenn Sie nicht rstudio
show_math(form2, use_viewer = FALSE) ## opens in default browser
verwenden Sie
show_math(form1, form2, form3, css = 'color: red; font-size: 15px;')
Ich bin mir ziemlich sicher, dass Mathjax keine vollständige Unterstützung von Latexgleichungen hat. Und sicher sein, die \
in der Formel zu entkommen
Sie können auch mehr als eine einzelne Zeile, die cool ist anzuzeigen.
form4 <- "
\\forall a,b,c \\in \\mathbb{R} \\\\
\\begin{align}
a + b &= c \\\\
(a + b)(a - b) &= c(a - b) \\\\
a^2 - b^2 &= ca - cb \\\\
a^2 - ca &= b^2 - cb \\\\
a^2 - ca + \\frac{c^2}{4} &= b^2 - cb + \\frac{c^2}{4} \\\\
(a - \\frac{c}{2})^2 &= (b - \\frac{c}{2})^2 \\\\
a - \\frac{c}{2} &= b - \\frac{c}{2} \\\\
a &= b \\qquad \\qquad \\blacksquare \\\\
\\end{align}
"
show_math(form4)
show_math <- function(..., css, use_viewer = !is.null(getOption('viewer'))) {
mj <- "<script>
(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>"
## view text strings as html in viewer/browser
view_html <- function(..., viewer) {
x <- c(...)
if (is.null(x)) return(invisible())
htmlFile <- tempfile(fileext = '.html')
writeLines(x, con = htmlFile)
if (viewer)
tryCatch(rstudio::viewer(htmlFile),
error = function(e) {
message('Viewer not available - opening in browser.\n',
'If using Rstudio, try installing the \'rstudio\' package.',
domain = NA)
browseURL(htmlFile)
})
else browseURL(htmlFile)
invisible(x)
}
## use \[ expr \] instead of $$ expr $$
check_expr <- function(x)
sprintf('\\[%s\\]', gsub('^\\$+|\\$+$', '', x))
x <- paste(sapply(c(...), check_expr), collapse = '<br />')
if (!nzchar(x)) return(invisible())
if (missing(css)) css <- ''
## setting the default to larger font since @Molx has bad eyes :}
## this can still be over-ridden by passing font-size: whatever; to css
view_html(sprintf('<span class="math" style="font-size: 24px; %s;">\n', css),
x, '\n</span>\n', mj, viewer = use_viewer)
}
Anzeige es wo genau? Hast du "plotmath" zum Plotten von Annotationen angeschaut? – MrFlick
Überall eigentlich .. ein Grundstück, Rahmen usw. – user2266881