1 How to use

1.1 How oxforddown is structured

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

1.1.1 index.Rmd: metadata and layout options

In index.Rmd, set your thesis’ basic metadata (e.g., title, author name)

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

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?

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

1.1.2 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

1.1.3 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

1.1.4 _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.

1.1.5 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

1.1.6 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

1.2 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

1.2.0.1 PDF output

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.

1.2.0.2 BS4 book output (HTML)

knit: (function(input, ...) {
    thesis_formats <- "bs4";
    ...
  • NOTE: the bs4 book output 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 oxforddowns knitting function.

1.2.0.3 Gitbook output (HTML)

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 oxforddowns knitting function.

1.2.0.4 Word output

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

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

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