繁体   English   中英

knitr / pandoc:支持关键字的文章模板:和linespacing:

[英]knitr/pandoc: article template supporting keywords: and linespacing:

我正在使用最新的R Studio,R 3.2.5,rmarkdown 0.9.6,它与pandoc 1.15.2一起编写期刊文章。 提交要求: linespacing: 1.43keywords:在摘要下方的行。

当我单击Knit PDF我得到默认模板"C:\\R\\R-3.2.5\\library\\rmarkdown\\rmd\\latex\\default-1.15.2.tex"它不支持YAML标题中的这些字段。 我看到default-1.17.02.tex支持linespacing: ,但不支持keywords:

我试图修改后一个模板来添加关键字处理,这似乎很简单。 模板的相关部分,我称之为modified-template-1.17.0.2.tex

$if(title)$
\maketitle
$endif$
$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$
\providecommand{\keywords}[1]{\textbf{\textit{Keywords---}} #1}
$if(keywords)$
    \keywords{$keywords$}
$endif$

我使用下面的YAML标题,并且pandoc找到了它; 但是,它生成.tex语法错误,与keywords: field无关。 我认为rmarkdown模板特定于pandoc的版本,但我pandoc

有人能帮忙吗?

---
title: "My title"
author: ME
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
  pdf_document:
    fig_caption: yes
    keep_tex: yes
    number_sections: yes
    template: "modified-template-1.17.0.2.tex"
keywords: Box M test, HE plots, MANOVA, graphics, ...
abstract: "This paper explores a variety of fascinating topics ... "
---

注意添加:我尝试修改default-1.15.2.tex模板,如上所述。 我的结果是一样的,我得到的错误是:

! Undefined control sequence.
l.527 {\centering \includegraphics

pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43

还有一个测试:我只是在我的本地文件夹中使用了标准default-1.15.2.tex模板的副本 ,其中包含YAML行

    template: "default-1.15.2.tex"

这也给出了同样的错误,所以我对原因感到困惑。

对于后人,一个似乎有效的解决方案是将default-1.17.02.tex复制到工作目录并修改它以包含关键字参数。 在重命名的modified-1.17.02.tex ,在作者名称的if块之后添加:

$if(keywords)$
    pdfkeywords={$for(keywords)$$keywords$$sep$; $endfor$},
$endif$

然后在文档中,在if块之后放置摘要:

\providecommand{\keywords}[1]{\textbf{\textit{Keywords---}} #1}
$if(keywords)$
    \keywords{$keywords$}
$endif$

在项目Rmd文件中,我们只需要指定我们使用自定义模板,指定graphics = true(环绕\\includegraphics错误)和关键字本身:

---
title: "My title"
author: ME
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
  pdf_document:
    template: modified-template-1.17.0.2.tex
graphics: yes
keywords: keyword 1; keyword 2; et cetera
abstract: "Abstract here."
---

Body of article here.

编译产生一个标题页面,其中包含关键字字段:

编译测试文件

编辑:OP也提到行间距。 使用1.17.02.tex样式时(如果可以通过手动安装或使用最新的RStudio预览版本获得最新版本的Pandoc自动使用),则可以通过设置linestretch: 1来完成调整行间距的linestretch: 1对于单个空间和linestretch: 2表示YAML标头中的任意位置。

这是keywords:的答案keywords:问题。 它无疑是一个kludge,但不需要更改模板:只需在YAML标题的摘要中包含关键字作为附加段落。

abstract: "This paper explores a variety of topics ...


**Keywords**: Box's M test; HE plots; MANOVA; graphics
"

要格式化为单独的段落需要两个空行

暂无
暂无

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

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