Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita8a1daf

Browse files
authored
Merge pull request#30 from jonathan-g/devel
Proposed changes for flexible styling in tintPdf and tintBook
2 parentsda953d8 +346c4c3 commita8a1daf

File tree

10 files changed

+379
-33
lines changed

10 files changed

+379
-33
lines changed

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ language: c
44

55
sudo:required
66

7-
dist:trusty
7+
dist:xenial
88

99
before_install:
1010
-curl -OLs https://eddelbuettel.github.io/r-travis/run.sh && chmod 0755 run.sh

‎ChangeLog‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2018-11-20 Jonathan Gilligan <jonathan.gilligan@gmail.com>
2+
3+
* R/pdf.R:
4+
* Added options for user-specified LaTeX templates in YAML block to
5+
override the built-in ones for tintPdf and tintBook;
6+
* Made YAML output option latex_engine work correctly.
7+
* Added documentation for new capabilities with YAML style options
8+
and custom LaTeX templates.
9+
10+
* R/html.R: Updated documentation for tint* functions.
11+
12+
* inst/rmarkdown/templates/tintBoot/resources/tintBook-template.tex:
13+
Updated template to allow user-specified fonts and link color.
14+
* inst/rmarkdown/templates/tintBoot/resources/tintBook-template.tex:
15+
Same.
16+
17+
* DESCRIPTION: Add myself as a co-author, bump version number.
18+
19+
* man/Custom-templates.Rd: New documentation for using custom templates.
20+
* man/YAML-metadata.Rd: New documentation on new YAML style options.
21+
* man/tintHtml.Rd: Updated documentation on tint* functions.
22+
123
2018-04-08 Dirk Eddelbuettel <edd@debian.org>
224

325
* DESCRIPTION (Version, Date): Release 0.1.0

‎DESCRIPTION‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
Package: tint
22
Type: Package
33
Title: 'tint' is not 'Tufte'
4-
Version: 0.1.0
5-
Date: 2018-04-08
6-
Author: Dirk Eddelbuettel
7-
Maintainer: Dirk Eddelbuettel <edd@debian.org>
4+
Version: 0.1.0.9000
5+
Date: 2018-11-20
6+
Authors@R:
7+
c(person("Dirk", "Eddelbuettel", role = c("cre", "aut"),
8+
email = "edd@debian.org"),
9+
person("Jonathan", "Gilligan", role = c("aut"),
10+
email = "jonathan.gilligan@gmail.com",
11+
comment = c(ORCID="0000-0003-1375-6686")))
812
Description: A 'tufte'-alike style for 'rmarkdown'.
913
URL: http://dirk.eddelbuettel.com/code/tint.html
1014
BugReports: https://github.com/eddelbuettel/tint/issues

‎R/html.R‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@
44
#' Richard Feynman, but with an updated font choice.
55
#'
66
#' @param ... Other arguments to be passed to \code{\link{pdf_document}} or
7-
#' \code{\link{html_document}} (note you cannot use the \code{template}
8-
#' argument in \code{tintPdf} or the \code{theme} argument in
9-
#' \code{tintHHtml()}; these arguments have been set internally)
7+
#' \code{\link{html_document}}
8+
#'
9+
#'
10+
#' \strong{Note:} For \code{tintPdf} and \code{tintBook}, you can
11+
#' specify a custom \code{template} argument to replace the default.
12+
#' You \emph{cannot} use the \code{theme} argument in \code{tintHHtml()}
13+
#' because this argument has been set internally.
14+
#'
1015
#' @references See \url{http://rstudio.github.io/tufte} for an example.
1116
#' @examples library(tint)
1217
#'
1318
#' @details \code{tintHtml} provides the HTML format based on the Tufte CSS
1419
#' \url{https://edwardtufte.github.io/tufte-css/} with fonts set according to
15-
#' \url{http://nogginfuel.com/envisioned-css/}. \code{tintPdf} provides a similar
16-
#' PDF format using the same font family and styling applied to the
17-
#' Tufte-LaTeX \url{https://tufte-latex.github.io/tufte-latex/} class. \code{tintBook}
18-
#' is a (currently rather experimental) pdf book variant.
20+
#' \url{http://nogginfuel.com/envisioned-css/}.
21+
#' \code{tintPdf} provides a similar PDF format using the same font family and
22+
#' styling applied to the Tufte-LaTeX
23+
#' \url{https://tufte-latex.github.io/tufte-latex/} class.
24+
#' \code{tintBook} is a (currently rather experimental) pdf book variant.
25+
#'
26+
#' @seealso \link{Custom-templates}, \link{YAML-metadata}.
1927
tintHtml<-function(...) {
2028

2129
html_document2=function(...,extra_dependencies=list()) {

‎R/pdf.R‎

Lines changed: 152 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,181 @@
1+
#' Customizing PDF document styles
2+
#'
3+
#' Using YAML metadata to customize PDF documents.
4+
#'
5+
#' You can easily customize fonts and a few other style attributes of
6+
#' PDF documents (\code{tintPdf} and \code{tintBook}) with
7+
#' YAML metadata
8+
#'
9+
#' @section Changing the fonts:
10+
#'
11+
#' You can use the fonts from the default \code{tufte} styles by setting
12+
#' \code{defaultfonts: true}
13+
#'
14+
#' You can choose custom LaTeX font packages using \code{latexfonts}:
15+
#' \preformatted{
16+
#' latexfonts: "bera"
17+
#' }
18+
#' will use Bera Serif fonts. You can also specify multiple fonts
19+
#' (for instance serif, sans-serif, and typewriter families)
20+
#' \preformatted{
21+
#' latexfonts:
22+
#' - "bera"
23+
#' - "FiraSans"
24+
#' - "FiraSansMono"
25+
#' }
26+
#' will use the Bera Serif font for regular text, Fira Sans Regular for
27+
#' sans serif, and Fira Sans Mono for typewriter.
28+
#'
29+
#' You can also pass options to the packages:
30+
#' \preformatted{
31+
#' latexfonts:
32+
#' - package: newtxmath
33+
#' options:
34+
#' - cmintegrals
35+
#' - cmbraces
36+
#' - package: ebgaramond-maths
37+
#' - package: nimbusmononarrow
38+
#' }
39+
#' will use EB Garamond, with matching maths fonts from the \code{newtxmath}
40+
#' package, and Nimbus Mono Narrow for the typewriter font.
41+
#'
42+
#' If you want to specify a sans-serif font for the main text, many
43+
#' packages allow you to do this with options:
44+
#' The default for tint is to use the equivalent of
45+
#' \preformatted{
46+
#' latexfonts:
47+
#' - package: roboto
48+
#' options:
49+
#' - sfdefault
50+
#' - condensed
51+
#' }
52+
#' where \code{sfdefault} specifies that the default text font should be Roboto.
53+
#' Other packages use different options, such as Lato, another sans-serif
54+
#' font, which you would specify as the main font like this:
55+
#' \preformatted{
56+
#' latexfonts:
57+
#' - package: lato
58+
#' options: default
59+
#' }
60+
#'
61+
#'
62+
#' @section Link Color:
63+
#'
64+
#' Changing the link color
65+
#'
66+
#' By default, tint uses a grayish-blue color for hyperlinks. If you want to
67+
#' change this, you can use the YAML \code{linkcolor} variable either as a
68+
#' string with three numbers (red, green, and blue) separated by commas:
69+
#' \preformatted{
70+
#' linkcolor: "0.3,0.3,0.6"
71+
#' }
72+
#' which gives a subtler bluish-gray,
73+
#' or as a list of three colors:
74+
#' \preformatted{
75+
#' linkcolor:
76+
#' - 0.5
77+
#' - 0.2
78+
#' - 0.5
79+
#' }
80+
#' which gives a mauve color.
81+
#'
82+
#' @seealso \link{Custom-templates}
83+
#' @name YAML-metadata
84+
NULL
85+
86+
#' Custom document templates
87+
#'
88+
#' Using custom document templates
89+
#'
90+
#' If you want to make more significant changes to the document styles,
91+
#' you can make custom Pandoc templates, using the examples provided with
92+
#' this package.
93+
#'
94+
#' You will need to have some expertise with LaTeX to do this, but you
95+
#' can take the templates, such as \code{tintPdf-template.tex}
96+
#' or \code{tintBook-template.tex}, which you can locate on your computer with
97+
#' \preformatted{
98+
#' system.file("rmarkdown", "templates", "tintPdf", "resources",
99+
#' "tintPdf-template.tex", package="tint")
100+
#' }
101+
#' and
102+
#' \preformatted{
103+
#' system.file("rmarkdown", "templates", "tintBook", "resources",
104+
#' "tintBook-template.tex", package="tint")
105+
#' }
106+
#'
107+
#' Copy those files to the folder where your RMarkdown file is located and edit them and then
108+
#' tell tint to use your custom template instead of its built-in ones by using
109+
#' the YAML attribute \code{template} in your \code{output} block:
110+
#' \preformatted{
111+
#' output:
112+
#' tint::tintPdf:
113+
#' template: "my-custom-template.tex"
114+
#' }
115+
#'
116+
#' @seealso \link{YAML-metadata}
117+
#' @name Custom-templates
118+
NULL
119+
120+
1121
#' @inheritParams rmarkdown::pdf_document
2122
#' @rdname tintHtml
3123
tintPdf<-function(fig_width=4,fig_height=2.5,fig_crop=TRUE,
4124
dev='pdf',highlight='tango',
5125
citation_package='natbib',latex_engine='pdflatex',...) {
6126
tintPdfCreate('tufte-handout',fig_width,fig_height,fig_crop,
7-
dev,highlight,citation_package,...)
127+
dev,highlight,citation_package,
128+
latex_engine=latex_engine,...)
8129
}
9130

10131
#' @inheritParams rmarkdown::pdf_document
11132
#' @rdname tintHtml
12133
tintBook<-function(fig_width=4,fig_height=2.5,fig_crop=TRUE,
13134
dev='pdf',highlight='tango',
14135
citation_package='natbib',latex_engine='pdflatex',...) {
15-
tintPdfCreate('tufte-book',fig_width,fig_height,fig_crop,
16-
dev,highlight,citation_package,
17-
template_resources("tintBook","tintBook-template.tex"),...)
136+
# The manipulation of the ellipsis argument below allows us to
137+
# inject a default template argument if one is not present, but
138+
# to use an optional supplied argument.
139+
args=list(...)
140+
if (!"template"%in% names(args)) {
141+
args$template= template_resources('tintBook','tintBook-template.tex')
142+
}
143+
args= c(list(documentclass="tufte-book",fig_width=fig_width,
144+
fig_height=fig_height,fig_crop=fig_crop,
145+
dev=dev,highlight=highlight,
146+
citation_package=citation_package,
147+
latex_engine=latex_engine),
148+
args)
149+
do.call(tintPdfCreate,args)
18150
}
19151

20152

21153
tintPdfCreate<-function(documentclass= c('tufte-handout','tufte-book'),
22154
fig_width=4,fig_height=2.5,fig_crop=TRUE,
23-
dev='pdf',highlight='default',citation_package='natbib',
155+
dev='pdf',highlight='default',
156+
citation_package='natbib',latex_engine="pdflatex",
24157
template= template_resources('tintPdf','tintPdf-template.tex'),...) {
25158

26159
## resolve default highlight
27160
if (identical(highlight,'default'))highlight='pygments'
28-
161+
162+
# The template argument can either be a filename or a string specifying a
163+
# function call.
164+
# To decide which it is, we decide that it's a function call if both:
165+
# There's no file at that path;
166+
# The string looks like a legal function call: starts with a lexically
167+
# legal name followed by an open parenthesis, some stuff, and then ends with
168+
# a closing parenthesis.
169+
if (!file.exists(template)&&
170+
grepl("^[a-zA-Z_.][a-zA-Z0-9_.:]+\\(.*\\)$",template)) {
171+
template= eval(parse(text=template))
172+
}
173+
29174
## call the base pdf_document format with the appropriate options
30175
format<-rmarkdown::pdf_document(fig_width=fig_width,fig_height=fig_height,
31176
fig_crop=fig_crop,dev=dev,highlight=highlight,
32177
citation_package=citation_package,
178+
latex_engine=latex_engine,
33179
template=template,...)
34180

35181
## LaTeX document class

‎inst/rmarkdown/templates/tintBook/resources/tintBook-template.tex‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
1+
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$if(defaultfonts)$fonts,$else$nofonts,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
22

33
% ams
44
\usepackage{amssymb,amsmath}
@@ -121,12 +121,26 @@
121121

122122
%% -- tint overrides
123123
%% fonts, using roboto (condensed) as default
124+
$if(defaultfonts)$
125+
% Using default fonts.
126+
$else$
127+
$if(latexfonts)$
128+
$if(latexfonts.include)$
129+
\input{$latexfonts.include$}
130+
$else$
131+
$for(latexfonts)$
132+
\usepackage$if(latexfonts.options)$[$for(latexfonts.options)$$latexfonts.options$$sep$,$endfor$]$endif${$if(latexfonts.package)$$latexfonts.package$$else$$latexfonts$$endif$}
133+
$endfor$
134+
$endif$
135+
$else$
124136
\usepackage[sfdefault,condensed]{roboto}
125137
%% also nice: \usepackage[default]{lato}
138+
$endif$
139+
$endif$
126140

127141
%% colored links, setting 'borrowed' from RJournal.sty with 'Thanks, Achim!'
128142
\RequirePackage{color}
129-
\definecolor{link}{rgb}{0.1,0.1,0.8}%% blue with some grey
143+
\definecolor{link}{rgb}{$if(linkcolor)$$for(linkcolor)$$linkcolor$$sep$,$endfor$$else$0.1,0.1,0.8$endif$}%% blue with some grey
130144
\hypersetup{
131145
colorlinks,%
132146
citecolor=link,%

‎inst/rmarkdown/templates/tintPdf/resources/tintPdf-template.tex‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
1+
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$if(defaultfonts)$fonts,$else$nofonts,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
22

33
% ams
44
\usepackage{amssymb,amsmath}
@@ -118,12 +118,26 @@
118118

119119
%% -- tint overrides
120120
%% fonts, using roboto (condensed) as default
121+
$if(defaultfonts)$
122+
% Using default fonts.
123+
$else$
124+
$if(latexfonts)$
125+
$if(latexfonts.include)$
126+
\input{$latexfonts.include$}
127+
$else$
128+
$for(latexfonts)$
129+
\usepackage$if(latexfonts.options)$[$for(latexfonts.options)$$latexfonts.options$$sep$,$endfor$]$endif${$if(latexfonts.package)$$latexfonts.package$$else$$latexfonts$$endif$}
130+
$endfor$
131+
$endif$
132+
$else$
121133
\usepackage[sfdefault,condensed]{roboto}
122134
%% also nice: \usepackage[default]{lato}
135+
$endif$
136+
$endif$
123137

124138
%% colored links, setting 'borrowed' from RJournal.sty with 'Thanks, Achim!'
125139
\RequirePackage{color}
126-
\definecolor{link}{rgb}{0.1,0.1,0.8}%% blue with some grey
140+
\definecolor{link}{rgb}{$if(linkcolor)$$for(linkcolor)$$linkcolor$$sep$,$endfor$$else$0.1,0.1,0.8$endif$}%% blue with some grey
127141
\hypersetup{
128142
colorlinks,%
129143
citecolor=link,%

‎man/Custom-templates.Rd‎

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp