Created
July 13, 2021 00:02
-
-
Save jmcastagnetto/e1f985c210b4b0251d8665f484d751b8 to your computer and use it in GitHub Desktop.
Testing the rOpenSci {katex} package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Testing rOpenSci katex" | |
author: "Jesus M. Castagnetto" | |
date: "2021-07-12" | |
output: | |
html_document: | |
mathjax: null | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE, comment = "") | |
library(katex) | |
``` | |
## Tests | |
Equations from: https://www.intmath.com/cg5/katex-mathjax-comparison.php | |
```{r} | |
tex1 <- "\\frac{1}{\\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{\\frac25 \\pi}} \\equiv 1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}} {1+\\frac{e^{-8\\pi}} {1+\\cdots} } } }" | |
eq1 <- katex_html(tex1, include_css = TRUE) | |
``` | |
Equation 1: `r eq1` | |
```{r} | |
tex2 <- "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)" | |
eq2 <- katex_html(tex2, include_css = FALSE) | |
``` | |
Equation 2: `r eq2` | |
```{r} | |
tex3 <- "1 + \\frac{q^2}{(1-q)}+\\frac{q^6}{(1-q)(1-q^2)}+\\cdots = \\prod_{j=0}^{\\infty}\\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \\text{ for }\\lvert q\\rvert < 1." | |
eq3 <- katex_html(tex3, include_css = FALSE) | |
``` | |
Equation 3: `r eq3` | |
```{r} | |
tex4 <- "\\int u \\frac{dv}{dx}\\,dx=uv-\\int \\frac{du}{dx}v\\,dx" | |
eq4 <- katex_html(tex4, include_css = FALSE) | |
``` | |
Equation 4: `r eq4` | |
```{r} | |
tex5 <- "S (\\omega)=\\frac{\\alpha g^2}{\\omega^5} \\,e ^{[-0.74\\bigl\\{\\frac{\\omega U_\\omega 19.5}{g}\\bigr\\}^{-4}]}" | |
eq5 <- katex_html(tex5, include_css = FALSE) | |
``` | |
Equation 5: `r eq5` | |
## A bit more complex latex environments need mathml | |
The following **Mathml** output works in Firefox, but not on the Brave or Chromium browsers. | |
```{r} | |
tex6 <- "f(n) = \\begin{cases} \\frac{n}{2}, & \\text{if } n\\text{ is even} \\\\ 3n+1, & \\text{if } n\\text{ is odd} \\end{cases}" | |
eq6 <- katex_mathml(tex6, include_css = FALSE) | |
``` | |
Equation 6: `r eq6` | |
```{r} | |
tex7 <- "\\begin{aligned} | |
\\dot{x} & = \\sigma(y-x) \\\\ | |
\\dot{y} & = \\rho x - y - xz \\\\ | |
\\dot{z} & = -\\beta z + xy | |
\\end{aligned}" | |
eq7 <- katex_mathml(tex7, include_css = FALSE) | |
``` | |
Equation 7: `r eq7` | |
```{r} | |
tex8 <- "\\begin{pmatrix} | |
a_{11} & a_{12} & a_{13}\\\\ | |
a_{21} & a_{22} & a_{23}\\\\ | |
a_{31} & a_{32} & a_{33} | |
\\end{pmatrix}" | |
eq8 <- katex_mathml(tex8, include_css = FALSE) | |
``` | |
Equation 8: `r eq8` | |
Author
jmcastagnetto
commented
Jul 13, 2021
This solution to this issue was resolved by @jeroen in the gist https://gist.github.com/jeroen/3209a68bc7d1b1562e8234b154d7ab6b, and the issue related to this ropensci/katex#3 was fixed in the commit ropensci/katex@44f0f45
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment