简体   繁体   English

R,簿记 package,强制 LaTex 进入 ZE1E1D3D40573127E9ZEE0408 块

[英]R, bookdown package, force LaTex inside R chunk

I'm writing a bookdown that should render both in HTML and PDF, so in some places i've got a chunk like:我正在写一本应该在 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}
")}

Sometimes (i think) Pandoc gets it wrongly and adds \textbackslash before my LaTeX codes (i can see that in.tex file) and it goes literal.有时(我认为)Pandoc 会错误地理解它并在我的 LaTeX 代码之前添加 \textbackslash (我可以看到那个 in.tex 文件)并且它是字面的。

I know a can use LaTeX chunks {=latex} in order to avoid that.我知道可以使用 LaTeX 块 {=latex} 来避免这种情况。 But since i'm already in a R chunk, how do i force Pandoc to understand LaTeX?但由于我已经在 R 块中,我如何强制 Pandoc 理解 LaTeX?

knitr::raw_latex() instead of cat() did the trick. knitr::raw_latex()而不是 cat() 成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM