It would be nice to be able to render a LaTeX equation from the console for the purpose of testing an equation using Eqn() before putting the result into a document. Presently, I'm using the Lagrida LaTeX Equation Editor.

The idea is to be able to do something like:

matX <- latexMatrix()
renderMatrix(matX)

and see the result in an RStudio Viewer panel. However, I note that (unless I'm mistaken) Eqn() now no longer has an option to return the result other than via cat().

Ideas

  1. This SO question shows the use of kableExtra to render a LaTeX table

See result in a Viewer pane:

library(kableExtra)
kable(head(mtcars), booktabs = T) |>
     kable_styling(latex_options = c("striped", "scale_down")) 

Display latex code in console:

library(kableExtra)
kable(mtcars, format = "latex", booktabs = T) |>
     kable_styling(latex_options = c("striped", "scale_down")) 

For this, would need to look into the internals of kableExtra::kable() to see how this is done.

  1. The texPreview package seems to do exactly what I want. But it seems to require TexLive and the tinytex package. I'm using MikTeX and am reluctant to switch to test this.
if(!(require(texPreview))) install.packages("texPreview")
library(texPreview)

texPreview::check_requirements()
texPreview::tex_preview(matX)
  1. A function renderMatrix() to:
  2. Insert result of latexMatrix() or Eqn() into a document template
  3. Compile that with knitr
  4. Preview result with browseURL()

  5. LaTeX formula in Shiny panel shows use of a withMathJax() function.



friendly/matlib documentation built on Dec. 6, 2024, 9:25 a.m.