【问题标题】:R, bookdown package, force LaTex inside R chunkR,bookdown 包,在 R 块中强制 LaTex
【发布时间】:2020-05-18 23:26:33
【问题描述】:

我正在写一个应该以 HTML 和 PDF 呈现的 bookdown,所以在某些地方我有一个类似的块:

{r echo=FALSE, results='asis'}

if(knitr::is_html_output()) {

  cat("
      text with HTML coding, as <br> etc.
")} else {

  cat("
      \\begin{flushleft}
      left aligned text with LaTex coding, as \\break. 
      \\end{flushleft}
")}

有时(我认为)Pandoc 会错误地理解它并在我的 LaTeX 代码之前添加 \textbackslash(我可以在 .tex 文件中看到它)并且它是字面的。

我知道可以使用 LaTeX 块 {=latex} 来避免这种情况。但是由于我已经在 R 块中,我如何强制 Pandoc 理解 LaTeX?

【问题讨论】:

    标签: r latex r-markdown bookdown


    【解决方案1】:

    knitr::raw_latex() 而不是 cat() 成功了。

    【讨论】:

      猜你喜欢
      • 2023-02-01
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 2017-04-10
      • 2018-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多