Skip to content

Commit 8300fa0

Browse files
author
rstudio
committed
merge upstream
2 parents d3c90bb + e6da408 commit 8300fa0

File tree

33 files changed

+5573
-50
lines changed

33 files changed

+5573
-50
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Date: 2014-03-14
66
Author: Who wrote it
77
Maintainer: Who to complain to <yourfault@somewhere.net>
88
Description: More about what it does (maybe more than one line)
9-
License: What license is it under?
9+
License: GPL-3
1010
Imports:
1111
rmarkdown
12+
RoxygenNote: 5.0.1

NAMESPACE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Generated by roxygen2 (4.1.0): do not edit by hand
1+
# Generated by roxygen2: do not edit by hand
22

33
export(acm)
44
export(acs)
55
export(ctex_template)
66
export(elsevier)
7+
export(frontiers_article)
78
export(jss_article)
89
export(plos_article)
910
export(rjournal_article)
11+
export(tufte_ebook)
1012
export(use_r_abstract)

R/frontiers_article.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#' @export
2+
frontiers_article <- function(keep_tex = TRUE,
3+
includes = NULL){
4+
template <- system.file("rmarkdown", "templates", "frontiers_article",
5+
"resources", "template.tex",
6+
package = "rticles")
7+
base <- rmarkdown::pdf_document(template = template,
8+
keep_tex = keep_tex,
9+
includes = includes,
10+
highlight = "tango")#,
11+
# pandoc_args = c("--latex-engine=xelatex"))
12+
13+
# Mostly copied from knitr::render_sweave
14+
base$knitr$opts_knit$out.format <- "sweave"
15+
16+
base$knitr$opts_chunk$prompt <- TRUE
17+
base$knitr$opts_chunk$comment <- NA
18+
base$knitr$opts_chunk$highlight <- FALSE
19+
20+
hook_chunk <- function(x, options) {
21+
if (knitr:::output_asis(x, options)) return(x)
22+
paste0('\\begin{CodeChunk}\n', x, '\\end{CodeChunk}')
23+
}
24+
hook_input <- function(x, options) {
25+
paste0(c('\\begin{CodeInput}', x, '\\end{CodeInput}', ''),
26+
collapse = '\n')
27+
}
28+
hook_output <- function(x, options) {
29+
paste0('\\begin{CodeOutput}\n', x, '\\end{CodeOutput}\n')
30+
}
31+
32+
base$knitr$knit_hooks$chunk <- hook_chunk
33+
base$knitr$knit_hooks$source <- hook_input
34+
base$knitr$knit_hooks$output <- hook_output
35+
base$knitr$knit_hooks$message <- hook_output
36+
base$knitr$knit_hooks$warning <- hook_output
37+
base$knitr$knit_hooks$plot <- knitr:::hook_plot_tex
38+
base
39+
}

R/jss_article.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ jss_article <- function() {
1111
base$knitr$opts_chunk$comment <- NA
1212
base$knitr$opts_chunk$highlight <- FALSE
1313

14+
base$knitr$opts_chunk$dev.args <- list(pointsize = 11)
15+
base$knitr$opts_chunk$fig.width <- 4.9 # 6.125" * 0.8, as in template
16+
base$knitr$opts_chunk$fig.height <- 3.675 # 4.9 * 3:4
17+
base$knitr$opts_chunk$fig.align <- "center"
18+
1419
hook_chunk <- function(x, options) {
1520
if (knitr:::output_asis(x, options)) return(x)
1621
paste0('\\begin{CodeChunk}\n', x, '\\end{CodeChunk}')
@@ -28,6 +33,7 @@ jss_article <- function() {
2833
base$knitr$knit_hooks$output <- hook_output
2934
base$knitr$knit_hooks$message <- hook_output
3035
base$knitr$knit_hooks$warning <- hook_output
36+
base$knitr$knit_hooks$plot <- knitr:::hook_plot_tex
3137

3238
base
3339
}

R/tufte_ebook.R

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
#' Tufte e-Book format (PDF)
3+
#'
4+
#' Template for creating an e-book based on the style of
5+
#' Edward R. Tufte and Richard Feynman.
6+
#'
7+
#' @inheritParams pdf_document
8+
#'
9+
#' @param latex_engine LaTeX engine for producing PDF output. Options are
10+
#' "pdflatex", "lualatex", and "xelatex". Note that lualatex may have
11+
#' problems with text spacing, and that pdflatex may have memory issues
12+
#' when using tikzDevice.
13+
#'
14+
#' @export
15+
tufte_ebook <- function( toc = TRUE,
16+
toc_depth = 3,
17+
number_sections = TRUE,
18+
fig_width = 4,
19+
fig_height = 2.5,
20+
fig_crop = TRUE,
21+
highlight = "default",
22+
keep_tex = FALSE,
23+
latex_engine = "xelatex",
24+
includes = NULL,
25+
pandoc_args = NULL,
26+
...
27+
) {
28+
29+
# resolve default highlight
30+
if (identical(highlight, "default"))
31+
highlight <- "pygments"
32+
33+
# get the tufte handout template
34+
template <- system.file(
35+
"rmarkdown/templates/tufte_ebook/resources/tufte-ebook.tex",
36+
package = "rticles"
37+
)
38+
39+
# call the base pdf_document format with the appropriate options
40+
format <- rmarkdown::pdf_document(fig_width = fig_width,
41+
fig_height = fig_height,
42+
fig_crop = fig_crop,
43+
highlight = highlight,
44+
keep_tex = keep_tex,
45+
latex_engine = latex_engine,
46+
includes = includes,
47+
pandoc_args = pandoc_args,
48+
toc = toc,
49+
toc_depth = toc_depth,
50+
template = template,
51+
number_sections = number_sections,
52+
...
53+
)
54+
55+
56+
# create knitr options (ensure opts and hooks are non-null)
57+
knitr_options <- rmarkdown::knitr_options_pdf(fig_width, fig_height, fig_crop)
58+
if (is.null(knitr_options$opts_knit))
59+
knitr_options$opts_knit <- list()
60+
if (is.null(knitr_options$knit_hooks))
61+
knitr_options$knit_hooks <- list()
62+
63+
# set options
64+
knitr_options$opts_chunk$tidy <- TRUE
65+
knitr_options$opts_knit$width <- 45
66+
67+
# set hooks for special plot output
68+
knitr_options$knit_hooks$plot <- function(x, options) {
69+
70+
# determine caption (if any)
71+
caption <- ifelse(is.null(options$fig.cap),
72+
"",
73+
paste("\\caption{", options$fig.cap, "}\n", sep = ""))
74+
75+
# determine figure type
76+
if (isTRUE(options$fig.margin))
77+
figtype <- "marginfigure"
78+
else if (isTRUE(options$fig.fullwidth))
79+
figtype <- "figure*"
80+
else
81+
figtype <- "figure"
82+
83+
# return the latex
84+
paste(sprintf('\\begin{%s}\n \\includegraphics{%s}\n%s\\end{%s}\n',
85+
figtype, x, caption, figtype))
86+
}
87+
88+
# override the knitr settings of the base format and return the format
89+
format$knitr <- knitr_options
90+
format
91+
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
### Overview
22

3-
The **rticles** package includes a set of [R Markdown](http://rmarkdown.rstudio.com) templates that enable authoring of R related journal and conference submissions. Available templates include:
3+
The **rticles** package includes a set of [R Markdown](http://rmarkdown.rstudio.com) templates that enable authoring of R related journal and conference submissions, and creating e-books. Available templates include:
4+
5+
- [Tuftish e-book] e-books formatted based on the style of Edward R. Tufte and Richard Feynman
46

57
- [JSS](http://www.jstatsoft.org/) articles
68

inst/rmarkdown/templates/acm/resources/template.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
\documentclass{acm_proc_article-sp}
2+
\usepackage[utf8]{inputenc}
23

34
\renewcommand{\paragraph}[1]{\vskip 6pt\noindent\textbf{#1 }}
45
\usepackage{hyperref}
56
\usepackage{graphicx}
67
\usepackage{url}
78

9+
\providecommand{\tightlist}{%
10+
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
11+
812
$if(title)$
913
\title{$title$}
1014
$endif$

inst/rmarkdown/templates/acs/resources/template.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
\documentclass[journal=$journal$,manuscript=$type$]{achemso}
2+
\usepackage[utf8]{inputenc}
23
\usepackage[version=3]{mhchem}
34
\usepackage{amsmath}
45
\newcommand*\mycommand[1]{\texttt{\emph{#1}}}
6+
\providecommand{\tightlist}{%
7+
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
58
$for(author)$
69
\author{$author.name$}
710
$if(author.aff)$

inst/rmarkdown/templates/ctex/resources/default.latex

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ $endif$
3434
$if(monofont)$
3535
\setmonofont[Mapping=tex-ansi]{$monofont$}
3636
$endif$
37+
$if(CJKmainfont)$
38+
\usepackage{xeCJK}
39+
\setCJKmainfont[$CJKoptions$]{$CJKmainfont$}
40+
$endif$
3741
\fi
3842
% use upquote if available, for straight quotes in verbatim environments
3943
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
@@ -45,10 +49,29 @@ $endif$
4549
$if(geometry)$
4650
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
4751
$endif$
52+
\ifxetex
53+
\usepackage[setpagesize=false, % page size defined by xetex
54+
unicode=false, % unicode breaks when used with xetex
55+
xetex]{hyperref}
56+
\else
57+
\usepackage[unicode=true]{hyperref}
58+
\fi
59+
\usepackage[usenames,dvipsnames]{color}
60+
\hypersetup{breaklinks=true,
61+
bookmarks=true,
62+
pdfauthor={$author-meta$},
63+
pdftitle={$title-meta$},
64+
colorlinks=true,
65+
citecolor=$if(citecolor)$$citecolor$$else$blue$endif$,
66+
urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
67+
linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
68+
pdfborder={0 0 0}}
69+
\urlstyle{same} % don't use monospace font for urls
4870
$if(lang)$
4971
\ifxetex
5072
\usepackage{polyglossia}
5173
\setmainlanguage{$mainlang$}
74+
\setotherlanguages{$for(otherlang)$$otherlang$$sep$,$endfor$}
5275
\else
5376
\usepackage[shorthands=off,$lang$]{babel}
5477
\fi
@@ -59,9 +82,9 @@ $if(natbib)$
5982
$endif$
6083
$if(biblatex)$
6184
\usepackage{biblatex}
62-
$if(biblio-files)$
63-
\bibliography{$biblio-files$}
64-
$endif$
85+
$for(bibliography)$
86+
\addbibresource{$bibliography$}
87+
$endfor$
6588
$endif$
6689
$if(listings)$
6790
\usepackage{listings}
@@ -80,7 +103,7 @@ $if(tables)$
80103
\usepackage{longtable,booktabs}
81104
$endif$
82105
$if(graphics)$
83-
\usepackage{graphicx}
106+
\usepackage{graphicx,grffile}
84107
\makeatletter
85108
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
86109
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
@@ -99,9 +122,9 @@ $if(strikeout)$
99122
% avoid problems with \sout in headers with hyperref:
100123
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
101124
$endif$
102-
\setlength{\parindent}{0pt}
103-
\setlength{\parskip}{6pt plus 2pt minus 1pt}
104125
\setlength{\emergencystretch}{3em} % prevent overfull lines
126+
\providecommand{\tightlist}{%
127+
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
105128
$if(numbersections)$
106129
\setcounter{secnumdepth}{5}
107130
$else$
@@ -122,6 +145,16 @@ $for(header-includes)$
122145
$header-includes$
123146
$endfor$
124147

148+
% Redefines (sub)paragraphs to behave more like sections
149+
\ifx\paragraph\undefined\else
150+
\let\oldparagraph\paragraph
151+
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
152+
\fi
153+
\ifx\subparagraph\undefined\else
154+
\let\oldsubparagraph\subparagraph
155+
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
156+
\fi
157+
125158
\begin{document}
126159
$if(title)$
127160
\maketitle
@@ -151,15 +184,15 @@ $endif$
151184
$body$
152185

153186
$if(natbib)$
154-
$if(biblio-files)$
187+
$if(bibliography)$
155188
$if(biblio-title)$
156189
$if(book-class)$
157190
\renewcommand\bibname{$biblio-title$}
158191
$else$
159192
\renewcommand\refname{$biblio-title$}
160193
$endif$
161194
$endif$
162-
\bibliography{$biblio-files$}
195+
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
163196

164197
$endif$
165198
$endif$

inst/rmarkdown/templates/ctex/skeleton/skeleton.Rmd

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ output:
1212
number_sections: yes
1313
template: !expr rticles::ctex_template()
1414
toc: yes
15-
classoption: "hyperref`r if (.Platform$OS.type != 'windows') ',nofonts'`"
15+
classoption: "hyperref,"
1616
---
1717

1818
# 引言
@@ -33,14 +33,9 @@ classoption: "hyperref`r if (.Platform$OS.type != 'windows') ',nofonts'`"
3333

3434
# 字体和选项
3535

36-
LaTeX包[**ctex**](http://ctan.org/pkg/ctex)支持若干种字体选项,例如winfonts、adobefonts等,这些选项要么不跨平台通用,要么不免费。那么中文字体问题咋整?下面我们介绍两个解决办法:
36+
LaTeX包[**ctex**](http://ctan.org/pkg/ctex)支持若干种字体选项,如果你是**ctex**老用户,请注意这里我们要求的最低版本是2.2,你可能需要升级你的LaTeX包。从版本2.0开始,**ctex**支持根据不同操作系统自动选择中文字体,简直是为人类进步作出了巨大贡献,我们再也不必费尽口舌向用户解释“啊,你用Windows啊,那么你该使用什么字体;啊,你用Mac啊,又该如何如何”。
3737

38-
1. 装鸵鸟,把头埋沙子里,自己默念一百遍“别人都不用Windows,我只管我的系统上的字体能用就好了”;
39-
2. 找一个大家都能用的中文字体,当然它得是免费的^[从隔壁王大爷那里“免费”复制过来的不算免费],不然无法推广;
40-
41-
## 管它什么跨平台
42-
43-
如果不管跨平台通用,那问题会非常简单。下面是Windows用户所需要的YAML元数据,主要设置三项参数:文档类为`ctexart`(当然也可以是别的类),`latex_engine`为XeLaTeX(真的,别纠结你的旧爱PDFLaTeX了),`template`为这个**rticles**包所带的LaTeX模板(当然你也可以用你自定义的模板)。
38+
下面的YAML元数据应该能满足多数用户的需求,主要设置三项参数:文档类为`ctexart`(当然也可以是别的类),`latex_engine`为XeLaTeX(真的,别纠结你的旧爱PDFLaTeX了),`template`为这个**rticles**包所带的LaTeX模板(当然你也可以用你自定义的模板)。
4439

4540
```yaml
4641
---
@@ -54,29 +49,7 @@ output:
5449

5550
这里`template`参数用了一点YAML黑魔法,主要是R包yaml发明的,`!expr`表示这个取值是通过运行R代码得到的,若不知道`rticles::ctex_template()`是什么意思,在R里面运行一下就知道了。其它参数都是普通的`pdf_document`参数,参见文档**rmarkdown**包的文档,这里就不赘述了。
5651

57-
关于Mac和Linux用户,目前有两种选择:要么复制别人的中文字体,例如Adobe中文字体,然后用`classoption`指定选项`adobefonts`,例如:
58-
59-
```yaml
60-
---
61-
classoption: adobefonts
62-
# 其它选项都跟上面一样
63-
---
64-
```
65-
66-
要么下载[Fandol字体](http://ctan.org/pkg/fandol)^[http://ctan.org/tex-archive/fonts/fandol],它号称是免费的,不过我们也没太搞清楚它的来头。把那些.otf字体文件下载下来之后一个个安装上,苹果用户猛击鼠标安装即可,Linux用户可以把字体保存到`~/.fonts`文件夹下,然后命令行切换到那里,运行`fc-cache -fv`。YAML元数据中唯一需要修改的地方就是`classoption: nofonts`,这样ctex包会自动使用Fandol字体。
67-
68-
```yaml
69-
---
70-
classoption: nofonts
71-
# 其它选项都跟上面一样
72-
---
73-
```
74-
75-
未来Mac用户也许还有第三种选择,就是用macfonts选项,不过截止到记者写稿之日,这个选项还没有发布到CTAN上,想吃螃蟹的用户只能去ctex的SVN库中去找。
76-
77-
## 不,我要普渡众生
78-
79-
客官若是想要找一种普渡众生的方案,我们给您最好的建议就是早点发财或成名,然后号召某中文字体生产厂商开源一种好看的中文字体,或斥资买断再开彼源兮,这样我们灰头土脸的小码农们也好大胆放心宣传。
52+
Windows和Mac用户应该都已经有自带的中文字体了。Linux用户可以另外下载[Fandol字体](http://ctan.org/pkg/fandol)^[http://ctan.org/tex-archive/fonts/fandol],它号称是免费的,不过我们也没太搞清楚它的来头。把那些.otf字体文件下载下来保存到`~/.fonts`文件夹下,然后命令行切换到那里,运行`fc-cache -fv`
8053

8154
# R代码段
8255

0 commit comments

Comments
 (0)