简体   繁体   English

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

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

I'm using the latest R Studio, R 3.2.5, rmarkdown 0.9.6, which comes with pandoc 1.15.2 to write a journal article. 我正在使用最新的R Studio,R 3.2.5,rmarkdown 0.9.6,它与pandoc 1.15.2一起编写期刊文章。 Submission requires: linespacing: 1.43 and a keywords: line just below the abstract. 提交要求: linespacing: 1.43keywords:在摘要下方的行。

When I click Knit PDF I get the default template "C:\\R\\R-3.2.5\\library\\rmarkdown\\rmd\\latex\\default-1.15.2.tex" which does not support these fields in the YAML header. 当我单击Knit PDF我得到默认模板"C:\\R\\R-3.2.5\\library\\rmarkdown\\rmd\\latex\\default-1.15.2.tex"它不支持YAML标题中的这些字段。 I see that default-1.17.02.tex supports linespacing: , but not keywords: . 我看到default-1.17.02.tex支持linespacing: ,但不支持keywords:

I tried to modify the latter template to add keywords handling, which seemed pretty straight-forward. 我试图修改后一个模板来添加关键字处理,这似乎很简单。 The relevant portion of the template, that I called modified-template-1.17.0.2.tex is 模板的相关部分,我称之为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$

I used the YAML header below, and pandoc found it; 我使用下面的YAML标题,并且pandoc找到了它; however, it generated .tex syntax errors, unrelated to the keywords: field. 但是,它生成.tex语法错误,与keywords: field无关。 I'm thinking that the rmarkdown templates are specific to the version of pandoc , but I have no way to tell. 我认为rmarkdown模板特定于pandoc的版本,但我pandoc

can anyone help with this? 有人能帮忙吗?

---
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 ... "
---

Note added: I tried this modifying the default-1.15.2.tex template as described above. 注意添加:我尝试修改default-1.15.2.tex模板,如上所述。 My result is the same, and the error I get is: 我的结果是一样的,我得到的错误是:

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

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

One more test: I simply used a copy of the standard default-1.15.2.tex template in my local folder, with the YAML line 还有一个测试:我只是在我的本地文件夹中使用了标准default-1.15.2.tex模板的副本 ,其中包含YAML行

    template: "default-1.15.2.tex"

This also gives the same error, so I am mystified as to the cause. 这也给出了同样的错误,所以我对原因感到困惑。

For posterity, one solution that seems to work is to copy default-1.17.02.tex to the working directory and modify it to include the keywords argument. 对于后人,一个似乎有效的解决方案是将default-1.17.02.tex复制到工作目录并修改它以包含关键字参数。 In the renamed modified-1.17.02.tex , add this after the if block for the author name: 在重命名的modified-1.17.02.tex ,在作者名称的if块之后添加:

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

And then later in the document, after the if block for placing the abstract: 然后在文档中,在if块之后放置摘要:

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

In the project Rmd file, we just need to specify that we are using our custom template, specify that graphics = true (to circumnavigate the \\includegraphics error) and the keywords themselves: 在项目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.

Compiling yields a title page with the keywords field present: 编译产生一个标题页面,其中包含关键字字段:

编译测试文件

EDIT: The OP also mentioned line spacing. 编辑:OP也提到行间距。 When using the 1.17.02.tex style (used automatically if the most recent version of Pandoc is available, either through manual install or by using the latest RStudio preview build), the ability to adjust the line spacing is done by setting linestretch: 1 for single space, and linestretch: 2 for double anywhere in the YAML header. 使用1.17.02.tex样式时(如果可以通过手动安装或使用最新的RStudio预览版本获得最新版本的Pandoc自动使用),则可以通过设置linestretch: 1来完成调整行间距的linestretch: 1对于单个空间和linestretch: 2表示YAML标头中的任意位置。

This is an answer to the keywords: problem. 这是keywords:的答案keywords:问题。 It is admittedly a kludge, but doesn't require changing the template: Simply include the keywords as an additional paragraph in the abstract in the YAML header. 它无疑是一个kludge,但不需要更改模板:只需在YAML标题的摘要中包含关键字作为附加段落。

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


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

To format as a separate paragraph required two blank lines 要格式化为单独的段落需要两个空行

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

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