-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
01-how-to-use.Rmd
205 lines (159 loc) · 7.71 KB
/
01-how-to-use.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
---
#########################################
# options for knitting a single chapter #
#########################################
output:
bookdown::pdf_document2:
template: templates/template.tex
bookdown::html_document2: default
bookdown::word_document2: default
documentclass: book
bibliography: [bibliography/references.bib, bibliography/additional-references.bib]
---
# How to use
\minitoc <!-- this will include a mini table of contents-->
## How `oxforddown` is structured
``` markdown
.
+-- index.Rmd
+-- _bookdown.yml
+-- 00-introduction.Rmd
| ...
+-- 07-conclusion.Rmd
+-- front-and-back-matter
| +-- _abstract.Rmd
| +-- 98-appendices.Rmd
| ...
+-- bibliography
| +-- references.bib
| ...
+-- figures
| ...
+-- docs
| +-- _main.pdf
| ...
+-- scripts_and_filters
| +-- knit-functions.R
| ...
+-- templates
| +-- template.tex
| ...
```
### index.Rmd: **metadata and layout options**
In index.Rmd, set your thesis' basic metadata (e.g., title, author name)
``` yaml
title: |
`oxforddown`: \
An Oxford University Thesis \
Template for R Markdown
author: Author Name
college: Your College
```
Also set filepath(s) to your abstract, acknowledgements, abbreviations, and bibliography (one or more **.bib** files):
```{verbatim}
abstract: |
`r paste(readLines("front-and-back-matter/_abstract.Rmd"), collapse = '\n ')`
acknowledgements: |
`r paste(readLines("front-and-back-matter/_acknowledgements.Rmd"), collapse = '\n ')`
dedication: For Yihui Xie
abbreviations: |
`r paste(readLines("front-and-back-matter/_abbreviations.Rmd"), collapse = '\n ')`
#######################
## bibliography path ##
#######################
bibliography: [bibliography/references.bib, bibliography/additional-references.bib]
```
Finally, **index.Rmd** is also where you customise layout options.
For example, in PDF output what should the heading for the bibliography section say?
How should page numbers be positioned?
Should line numbers be shown?
In HTML output, what CSS files should be used for styling?
``` yaml
### citation and bibliography style ###
bibliography-heading-in-pdf: Works Cited
...
### position of page numbers ###
ordinary-page-number-foot-or-head: foot #'foot' puts page number in footer, 'head' in header
ordinary-page-number-position: C
...
includeline-num: false #show line numbering in PDF?
...
bookdown::bs4_book:
css:
- templates/bs4_style.css
- templates/corrections.css # remove to stop highlighting corrections
```
### other **.Rmd** files in root folder: thesis chapters
- each chapter of your thesis should have its own **.Rmd** file in the root directory
- when you knit **index.Rmd**, these chapters are merged together in alphabetical order, based on their filenames
### **front-and-back-matter/**
- this folder holds the front and back matter of your thesis
- it has **.Rmd** files for your abstract, acknowledgements, abbreviations, and a welcome note that is included in HTML output.
Note how these files start with an underscore (e.g. **\_abstract.Rmd**).
This means they will not automatically be merged into the thesis -- they are explicitly included in **index.Rmd**
- **98-appendices** and **99-references.Rmd** are automatically merged into thesis, however - therefore their file names start with a high number, so that they will be included by the very end (merging is done alphabetically)
- **99-references.Rmd** sole purpose is to set the heading for the references section in HTML and Word output
### **\_bookdown.yml**: build options
- Set output directory for your thesis files (**docs/** is the default, as it makes it easy to publish HTML output on GitHub pages)
- Should R Markdown automatically merge **.Rmd** files in alphabetical order?
Alternatively, specify explicitly which files should be included.
### **scripts-and-filters**
- **knit-function.R** has the functions that are used when you build the entire thesis by knitting **index.Rmd**
- **create_chunk_options.R** lets you include cute quotes at the start of a chapter in PDF output
- **colour_and_highlight.lua** lets you color text or apply background color to text
### **templates**
- **template.tex** is the LaTeX template used to build the entire thesis to PDF in the OxThesis layout (relies on **ociamthesis.cls**)
- **brief-template.tex** is the LaTeX template used to build a single chapter to PDF in the OxThesis layout (relies on **ociamthesis.cls**)
- **beltcrest.pdf**: the oxford logo used on the front page of the PDF output
## Building your entire thesis
- Build the entire thesis by opening **index.Rmd** and clicking the 'knit' button.
- The generated thesis files are saved in the **docs/** folder
- To choose output formats, go to the top of **index.Rmd**'s YAML header and edit the line `thesis_formats <- "pdf";` to the format(s) you want (options are "pdf", "bs4", "gitbook", and "word")
- You can build to multiple formats simultaneously with, e.g., `thesis_formats <- c("pdf", "bs4", "word")`
- If you want to customise the build function, edit **scripts_and_filters/knit-functions.R**
#### PDF output
``` yaml
knit: (function(input, ...) {
thesis_formats <- "pdf";
...
```
When you build the entire thesis to PDF, Latex generates a whole bunch of auxillary files - these are automatically removed after the build process end by the custom knit function that is used when you knit **index.Rmd**.
To change how this removal is done, edit **scripts_and_filters/knit-functions.R**.
The line `file.remove(list.files(pattern = "*\\.(log|mtc\\d*|maf|aux|bcf|lof|lot|out|toc)$"))` within `if ("pdf" %in% output_format){` is the one that removes files after PDF output is generated.
#### BS4 book output (HTML)
``` yaml
knit: (function(input, ...) {
thesis_formats <- "bs4";
...
```
- NOTE: the [bs4 book output](https://pkgs.rstudio.com/bookdown/reference/bs4_book.html) requires the `downlit` and `bslib` R packages (install them with `install.packages`)
- Note also that to deploy a BS4 book on GitHub Pages, there must be a **.nojekyll** file in the **docs/** folder, otherwise GitHub does some voodoo that causes some filepaths not to work. This file is generated automatically by `oxforddown`s knitting function.
#### Gitbook output (HTML)
``` yaml
knit: (function(input, ...) {
thesis_formats <- "gitbook";
...
```
- Note that to deploy a gitbook on GitHub Pages, there must be a **.nojekyll** file in the **docs/** folder, otherwise GitHub does some voodoo that causes some filepaths not to work. This file is generated automatically by `oxforddown`s knitting function.
#### Word output
``` yaml
knit: (function(input, ...) {
thesis_formats <- "word";
...
```
- Note that the Word output has no templates behind it, and many things do not work (e.g. image rotation, highlighting corrections). **I encourage pull requests that optimise the Word output, e.g. by using tools from the [`officer`](https://github.com/davidgohel/officer) package.**
## Building a single chapter
To knit an individual chapter without compiling the entire thesis you:
1. open the **.Rmd** file of a chapter
2. add a YAML header specifying the output format(s) (e.g. `bookdown::word_document2` for a word document you might want to upload to Google Docs for feedback from collaborators)
3. click the `knit` button (the output file is then saved in the root folder)
As shown in the sample chapters' YAML headers, to output a single chapter to PDF, use e.g.:
``` yaml
output:
bookdown::pdf_document2:
template: templates/brief_template.tex
citation_package: biblatex
documentclass: book
bibliography: references.bib
```
The file **templates/brief_template.tex** formats the chapter in the OxThesis style but without including the front matter (table of contents, abstract, etc).