如何使用相同的R标记源转到HTML、Word、github标记和PDF
我正在尝试将相同的R标记源文档呈现为MS word、git hub标记、HTML和PDF。编译选项位于.Rmd文件的头中,输出的选择在命令行通过如何使用相同的R标记源转到HTML、Word、github标记和PDF,r,markdown,r-markdown,knitr,pandoc,R,Markdown,R Markdown,Knitr,Pandoc,我正在尝试将相同的R标记源文档呈现为MS word、git hub标记、HTML和PDF。编译选项位于.Rmd文件的头中,输出的选择在命令行通过render()函数确定。我希望本文件包括所有版本中的数字和方程式编号,并具有交叉参考 我的.Rmd文件中有一个等式: (\#eq:eq) A=\frac{\pi}{27d^2} (让我们暂时忽略包装器。) 这从文本中交叉引用为(例如等式\@ref(eq:eq)) main.rmd中的我的标题如下所示: output: bookdown::pdf_
render()
函数确定。我希望本文件包括所有版本中的数字和方程式编号,并具有交叉参考
我的.Rmd文件中有一个等式:
(\#eq:eq)
A=\frac{\pi}{27d^2}
(让我们暂时忽略包装器。)
这从文本中交叉引用为(例如等式\@ref(eq:eq))
main.rmd
中的我的标题如下所示:
output:
bookdown::pdf_document2:
latex_engine: pdflatex
toc: true
number_sections: true
fig_caption: true
keep_tex: true
citation_package: natbib
bookdown::html_document2:
number_sections: true
toc: true
toc_float:
collapsed: false
smooth_scroll: false
md_document:
variant: gfm
fig_caption: yes
keep_md: yes
number_sections: true
bookdown::word_document2:
number_sections: true
reference_docx: defaulto
当我使用word进行渲染时
rmarkdown::render("main.rmd",
output_format=c('word_document2'),
run_pandoc = TRUE,
clean=TRUE)
如果我使用$
作为包装器,我会在Word文档中看到表达式标签。方程式编号已给出,但不是交叉参考。我必须使用\begin{equation}\结束{equation}
以使其作为交叉引用
当我呈现到HTML时,任何一个包装器选项都会为我提供合理的输出
rmarkdown::render("main.rmd",
output_format=c('bookdown::html_document2'),
run_pandoc = TRUE,
clean=TRUE)
当我渲染到标记时
rmarkdown::render("main.rmd",
rmarkdown::md_document(variant = "gfm"),
run_pandoc = TRUE,
clean=TRUE,
knit_root_dir= getwd())
当我使用´´´\开始{等式}时,我没有得到任何输出\结束{等式}。在那里我使用了$$$$
获取任何输出,我在文本中看到等式@ref(eq:eq)
,即交叉引用根本不呈现
PDF使用
rmarkdown::render("main.rmd",
output_format=c('bookdown::pdf_document2'),
run_pandoc = TRUE,
knit_root_dir= getwd())
。。。在这两种情况下似乎都很有效
所以。。。问题:我无法使用相同的公式格式转到markdown、HTML和word from.Rmd。是否有一种解决方案可以在.Rm源代码中实现,或者在调用render()
时实现
MWE
可能会有帮助。我也发现了。不幸的是,在降价时似乎有东西坏了。
title: "MWE"
author: "Me, myself, and I"
date: '`r Sys.Date()`'
output:
bookdown::pdf_document2:
latex_engine: pdflatex
toc: true
number_sections: true
fig_caption: true
keep_tex: true
citation_package: natbib
bookdown::html_document2:
number_sections: true
toc: true
toc_float:
collapsed: false
smooth_scroll: false
md_document:
variant: gfm
fig_caption: yes
keep_md: yes
number_sections: true
bookdown::word_document2:
number_sections: true
reference_docx: default
fontsize: 11pt
geometry: margin=1in
graphics: yes
bibliography: main.bib
linkcolor: blue
urlcolor: red
citecolor: cyan
link_citations: true
# Test{sec:test}
This should be a cross-reference to Equation \@ref(eq:eq).
$$
(\#eq:eq)
A=\frac{\pi}{27d^2}
$$