8
A
回答
13
這很可能已經存在,但您可以編寫一個函數來使用mathjax渲染公式,並在查看器(如果您使用rstudio)或Web瀏覽器中顯示它。這將有助於如果你想編輯/在飛行校驗公式我想
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)
或打開瀏覽器,如果你不rstudio
show_math(form2, use_viewer = FALSE) ## opens in default browser
show_math(form1, form2, form3, css = 'color: red; font-size: 15px;')
我很確定mathjax沒有完全支持乳膠方程。並且一定要逃過\
的公式
您還可以顯示多個很酷的單行。
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)
}
1
對於您可以將圖形標籤只需使用expression
與?plotmath
業務就像@MrFlick提到的
plot(1, main=expression(A==frac(B, C)))
相關問題
- 1. 公式顯示問題 - Mathjax/Latex
- 2. 使用CUBEVALUE公式的優雅方式
- 3. 在Rails 4中顯示相應text_field_tag值的優雅方式
- 4. WordPress的LaTex公式
- 5. 如何優雅地設計表示ADDRESS的數據庫模式?
- 6. 如何在bash中優雅地存儲和回顯多行?
- 7. 如何優雅地死去?
- 8. 在ActionScript中顯示公式
- 9. 如何在以下示例中優雅地分解兩個類?
- 10. 在Android中顯示LaTex
- 11. 在WP8中顯示LaTeX?
- 12. 如何評估JavaScript中的LaTeX公式?
- 13. 如何優雅的第一次顯示彈出式導軌
- 14. 在頁面上顯示URL的優雅方式
- 15. 顯示日期只有一次[優雅的方式在蜂巢
- 16. 在HTML文件中包含LaTeX公式?
- 17. 在Java中顯示的列表,如優雅的Python
- 18. 在R中合併數據幀的優雅方式?
- 19. 用org-latex-preview居中顯示等式?
- 20. 我們可以使用Latex在android項目中顯示數學公式嗎?
- 21. 在ACE中優雅地終止線程
- 22. 在PowerShell腳本中優雅地停止
- 23. 在webapp中優雅地關閉ExecutorService?
- 24. 優雅地退出線程在Ruby中
- 25. 運行R時,如何優雅地退出Emacs-ESS?
- 26. 如何在LaTeX文檔中顯示LaTeX代碼?
- 27. 優雅的方式
- 28. 優雅的方式
- 29. 在視圖中優雅地顯示由ID映射的數據對象
- 30. 顯示日期只有一次[優雅的方式]
顯示它到底在哪?你看過'plotmath'來繪製註釋嗎? – MrFlick
任何地方其實..一個情節,框架等 – user2266881