The goal of parseLatex
is to provide a parser for a
subset of LaTeX syntax that is more complete than what is handled by the
tools::parseLatex()
parser.
Perhaps some day it will handle all LaTeX inputs, but that’s not
likely. For now, I’m aiming to handle anything that
knitr::kable()
and the kableExtra
functions
will produce, plus related code.
A website describing the current state is here: https://dmurdoch.github.io/parseLatex/ .
You can install the development version of parseLatex from GitHub with:
# install.packages("pak")
::pak("dmurdoch/parseLatex") pak
This is a basic example.
library(parseLatex)
library(kableExtra)
<- kbl(mtcars[1:2, 1:2], format = "latex")
latex cat(latex)
#>
#> \begin{tabular}[t]{l|r|r}
#> \hline
#> & mpg & cyl\\
#> \hline
#> Mazda RX4 & 21 & 6\\
#> \hline
#> Mazda RX4 Wag & 21 & 6\\
#> \hline
#> \end{tabular}
<- parseLatex(latex)
parsed # This is a blank followed by a table; drop the blank
<- parsed[[find_env(parsed, "tabular")]]
table # Get the alignment options from the content
brace_options(get_contents(table))
#> {l|r|r}
tableCell(table, 2,2) # The title counts!
#> 21
tableCell(table, 2,2) <- "Changed!"
table#> ENVIRONMENT: \begin{tabular}[t]{l|r|r}
#> \hline
#> & mpg & cyl\\
#> \hline
#> Mazda RX4 & Changed! & 6\\
#> \hline
#> Mazda RX4 Wag & 21 & 6\\
#> \hline
#> \end{tabular}
kableExtra
does with tables, and try to make
that easier.