使用 r-markdown 在 HTML 中渲染 LaTeX 表格
Render LaTeX tables in HTML using r-markdown
我正在尝试在 RMD 文件中呈现以下 table:
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|}
\hline
\ \hline
\end{tabular}
\end{table}
到目前为止没有成功。 rmarkdown 无法将 LaTeX 环境(方程式除外)编译为 HTML 有什么根本原因吗?
在降价文档中,预期的输入标记语言是(r)markdown. You should not expect pandoc
to automatically recognize arbitrarily mixed markup languages. LaTeX math markup can only be used in markdown documents because there is a rmarkdown extension来处理这个问题。
但是,仍然可以使用 LaTeX table,就像 rmarkdown 文档中问题中显示的那样。我在中演示了"inverse"(RNW文档中的降价table)。请注意,这是一种相当实验性的方法,在其他情况下可能会失败。
解释了函数 tex2markdown
背后的思想 。
---
output: html_document
---
# My document
This is `rmarkdown`.
This table is converted from LaTeX:
```{r, results = "asis", echo = FALSE, message = FALSE}
library(knitr)
tex2markdown <- function(texstring) {
writeLines(text = texstring,
con = myfile <- tempfile(fileext = ".tex"))
texfile <- pandoc(input = myfile, format = "html")
cat(readLines(texfile), sep = "\n")
unlink(c(myfile, texfile))
}
textable <- "
\begin{table}[]
\centering
\caption{Food order}
\begin{tabular}{| l | l |}
\hline
Hamburgers & 3 \\
Hot dogs & 2 \\ \hline
\end{tabular}
\end{table}
"
tex2markdown(textable)
```
---
Time for *lunch*.
并非所有 LaTeX 功能都可以转换为 HTML,但对于简单的任务,这应该可行。请注意,反斜杠需要通过额外的反斜杠进行转义。
这主要是概念验证。对于生产,在 RNW 文档中使用 LaTeX tables,在 RMD 文档中使用 markdown tables!
我正在尝试在 RMD 文件中呈现以下 table:
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|}
\hline
\ \hline
\end{tabular}
\end{table}
到目前为止没有成功。 rmarkdown 无法将 LaTeX 环境(方程式除外)编译为 HTML 有什么根本原因吗?
在降价文档中,预期的输入标记语言是(r)markdown. You should not expect pandoc
to automatically recognize arbitrarily mixed markup languages. LaTeX math markup can only be used in markdown documents because there is a rmarkdown extension来处理这个问题。
但是,仍然可以使用 LaTeX table,就像 rmarkdown 文档中问题中显示的那样。我在
解释了函数 tex2markdown
背后的思想
---
output: html_document
---
# My document
This is `rmarkdown`.
This table is converted from LaTeX:
```{r, results = "asis", echo = FALSE, message = FALSE}
library(knitr)
tex2markdown <- function(texstring) {
writeLines(text = texstring,
con = myfile <- tempfile(fileext = ".tex"))
texfile <- pandoc(input = myfile, format = "html")
cat(readLines(texfile), sep = "\n")
unlink(c(myfile, texfile))
}
textable <- "
\begin{table}[]
\centering
\caption{Food order}
\begin{tabular}{| l | l |}
\hline
Hamburgers & 3 \\
Hot dogs & 2 \\ \hline
\end{tabular}
\end{table}
"
tex2markdown(textable)
```
---
Time for *lunch*.
并非所有 LaTeX 功能都可以转换为 HTML,但对于简单的任务,这应该可行。请注意,反斜杠需要通过额外的反斜杠进行转义。
这主要是概念验证。对于生产,在 RNW 文档中使用 LaTeX tables,在 RMD 文档中使用 markdown tables!