我有一个大文件,必须同时以pdf和docx格式编译。作为统一两个输出的一种方式,我想知道是否可以根据所选的输出运行代码。我做了一个最小的可复制示例。
---
title: MyTest
output:
word_document:
fig_caption: yes
toc: no
pdf_document:
latex_engine: xelatex
---
```{r setup_docx, include=FALSE}
library(knitr)
library(captioner)
knitr::opts_chunk$set(fig.path = 'images/',
echo = FALSE,
warning = FALSE,
message = FALSE,
include = TRUE)
```
# In Office Word the following is required
```{r figs, include=FALSE}
# Figures Required for Word Output
fig_nums <- captioner()
fig_nums("AppleFig", "This is the caption of my AppleFig")
```
These can be seen in `r fig_nums("AppleFig",display="cite")`
```{r, fig.cap=fig_nums("AppleFig")}
knitr::include_graphics("images/AppleFig.png")
```
```{r setup_pdf, include=FALSE}
library(knitr)
knitr::opts_chunk$set(fig.align='center',
fig.pos = 'H',
fig.path = 'images/',
echo = FALSE,
warning = FALSE,
message = FALSE,
include = TRUE,
out.width=".9\\textwidth")
```
# For LATEX
These can be seen in \ref{fig:AppleFig}
```{r, fig.cap="\\label{fig:AppleFig}This is the caption of my AppleFig."}
knitr::include_graphics("images/AppleFig.png")
```
目前,我有2个文档运行代码的每个部分。有没有办法让我根据输出选择运行哪些块?
如果可能的话,我的下一个步骤将是尝试为
ref\{figs:
至fig_nums("
好奇地希望从论坛中获得一些意见,我认为如果有可能,这对许多人来说将非常有用。