knitr/pandoc:支持关键字:和行距的文章模板: [英] knitr/pandoc: article template supporting keywords: and linespacing:

查看:107
本文介绍了knitr/pandoc:支持关键字:和行距的文章模板:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的R Studio,R 3.2.5,rmarkdown 0.9.6(随pandoc 1.15.2一起提供)来撰写期刊文章.提交要求:linespacing: 1.43和摘要下面的keywords:行.

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. Submission requires: linespacing: 1.43 and a keywords: line just below the abstract.

当我单击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:.

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. I see that default-1.17.02.tex supports linespacing:, but not keywords:.

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

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

$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:字段无关.我以为rmarkdown模板特定于pandoc的版本,但是我无话可说.

I used the YAML header below, and pandoc found it; however, it generated .tex syntax errors, unrelated to the keywords: field. I'm thinking that the rmarkdown templates are specific to the version of pandoc, but I have no way to tell.

有人可以帮忙吗?

---
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模板.我的结果是一样的,我得到的错误是:

Note added: I tried this modifying the default-1.15.2.tex template as described above. 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

另一项测试:我只是在本地文件夹中使用标准default-1.15.2.tex模板的副本,并带有YAML行

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

    template: "default-1.15.2.tex"

这也给出了相同的错误,所以我对原因还是很迷惑.

This also gives the same error, so I am mystified as to the cause.

推荐答案

对于后代来说,一种可行的解决方案是将default-1.17.02.tex复制到工作目录并对其进行修改以包含关键字参数.在重命名的modified-1.17.02.tex中,将其添加到作者姓名的if块之后:

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. In the renamed modified-1.17.02.tex, add this after the if block for the author name:

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

然后在文档的后面,放置抽象的if块之后:

And then later in the document, after the if block for placing the abstract:

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

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

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:

---
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:

OP还提到了行距.使用1.17.02.tex样式时(如果有可用的Pandoc最新版本(通过手动安装或使用最新的RStudio预览版本使用,则自动使用)),可以通过将linestretch: 1设置为单个来完成调整行距的功能.空格,linestretch: 2表示YAML标头中任意位置的两倍.

The OP also mentioned line spacing. 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.

这篇关于knitr/pandoc:支持关键字:和行距的文章模板:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆