【发布时间】:2019-05-17 16:26:18
【问题描述】:
我想将 LaTeX 环境(例如,algorithmic 来自 algorithmicx、mini 来自 optidef、dcases 来自 mathtools 等)包含在我的 .Rmd 预订文件中。这对于 pdf 输出没有问题。但这些不会呈现为 html 或 docx 输出。
我目前的破解解决方案:
- 生成 .pdf 输出。
- 截屏、编辑、将感兴趣的图像保存为 png
- 包含以输出不是 LaTeX 为条件的图像
缺点:
- 显然无法扩展
- docx 和 html 输出中的图像很难看
- 带有图形交叉引用的螺钉
必须有更好的方法,对吗?我在想有一种方法可以告诉 rmarkdown/LaTeX,当呈现为 pdf 时,某些代码块应该以某种图像格式保存。这样,它们可以作为图像添加回文档,条件是输出文档是 docx 或 html。这可能吗?
更新:An answer to Standalone diagrams with TikZ 提出了一种涉及 LaTeX standalone 包的方法。但不幸的是,在standalone does not work with algorithms 发现这不适用于algorithm 环境。有什么想法吗?
index.Rmd
---
title: "Bookdown"
header-includes:
- \usepackage{float}
- \floatplacement{figure}{!htb}
- \usepackage{algorithm}
- \usepackage{algpseudocode}
output:
bookdown::gitbook:
split_by: none
bookdown::pdf_book:
fig_caption: yes
keep_tex: yes
toc: no
bookdown::word_document2: default
site: bookdown::bookdown_site
---
```{r setup, include=FALSE, }
knitr::opts_chunk$set(echo = TRUE)
```
Hello zero
# First Chapter
Hello one
\begin{algorithm}
\caption{My Algo}
\begin{algorithmic}[1]
\State Do this.
\State Do that.
\end{algorithmic}
\end{algorithm}
```{r myalgo, echo=FALSE, eval = !knitr:::is_latex_output(), fig.cap="Must have text here. For cross-referencing to work."}
knitr::include_graphics("myalgo.png")
```
Hello two.
Check out this picture: \@ref(fig:myalgo)
myalgo.png
【问题讨论】:
标签: r latex r-markdown bookdown