This repository is for drafting my PhD dissertation at Duke University.
UPDATE 2015-09-01: Switching to simple Word docx and hosting privately on Dropbox for the simple reason that I can move around content much more fluidly.
Here's the draft dissertation rendered in various formats: for different purposes.
- dissertation.html: quick web view (reference links via doi)
- dissertation.docx: track changes for committee feedback
- dissertation.pdf: final grad school submission
The outputs are binary (including HTML which has embedded images and javascript), so the files were placed into Dropbox for download (since Github more suitable for versioned text files). The Rmarkdown files here are collated into a single dissertation.Rmd, which is most easily viewed through Github as markdown dissertation.md. The pdf takes special handling to conform to the Duke Graduate School. See ./make.R and ./make_config.R for details on how these individual Rmarkdown files are collated and rendered into the various forms.
Prefixes to Rmarkdown files (*.Rmd) are simple letters for sorting front matter (a_*), core chapters (c_*) and back matter (x_*).
Here's the draft defense presentation:
For a simplified example on how this dissertation was rendered into multiple formats, see https://github.com/bbest/rmarkdown-example.
This dissertation is rendered into a scientifically reproducible document using the following free software:
-
RStudio: excellent free, cross-platform R integrated development environment for writing code and text.
-
Rmarkdown: versatile "literate programming" R package for weaving chunks of R code with formatted text (markdown), built into RStudio.
-
Pandoc: the standalone conversion engine used by the rmarkdown package.
-
Zotero: excellent free bibliographic management software, like Endnote. With the BetterBibtex extension, I can simply drag and drop from a Zotero collection to get the inline citation and pandoc will later generate the full bibliography at the end of the document. To get this to work:
-
Install Zotero Better Bibtex
-
In Zotero Preferences, set:
-
Export: "Default Output Format" to
Pandoc citation
-
Better Bib(La)tex: "Citation key format" to
[auth:lower]_[veryshorttitle:lower]_[year]
-
-
Process:
-
Place all references used by dissertation into its own dedicated collection (eg "dissertation").
-
Drag and drop references from this collection into the document editor (I like RStudio or Sublime). This will add a text citation, eg
@worm_impacts_2006
. -
Right-click on collection > Export Collection and choose
Better BibTex
and export todissertation.bib
file (which is assigned tocite_bib
variable in make.R). -
You can get a quick formatted view of the document as you write with 'Knit HTML' button (or Ctrl+Shift+Y of RStudio shortcuts). Note that the *.html files are ignored by git in .gitignore.
-
Run ./make.R to generate collated document in all formats.
-
Repeat as you write. For more, see pandoc citations.
-
-
Aside. It is possible to your entire Zotero library using AutoZotBib, but my library is too large to practically use this.
From stackoverflow: How to set different global options in knitr and RStudio for word and html?.
Try putting this code chunk at the beginning of the Rmd document.
library(knitr)
output <- opts_knit$get("rmarkdown.pandoc.to")
if (output=="html") opts_chunk$set(fig.width=11, fig.height=11)
if (output=="docx") opts_chunk$set(fig.width=6, fig.height=6)
One of the package options returned by opts_knit$get() is markdown.pandoc.to. This is evidently set to "html", "docx", or "latex" depending on the chosen output format (HTML, Word, or PDF). So you can test that and set the chunk options fig.width and fig.height accordingly.
Here are a few related resources from which I borrowed.
- UC Berkeley: uses Rmarkdown templates
- Duke theses: latex formatting specific to Duke
- thesis-markdown-pandoc: pandoc commands
- knitr-examples / 070-caption-num.Rmd: trick with use of
local
andglobal
variable assignment for caption counter - brew: Creating Repetitive Reports: used to substitute variables
dissertation.brew.tex
->dissertation.tex
.
Here's a little macro to resize images and add a table of contents. Works in Office 2011 for Mac. Tools > Macro > Macros.. Enter "dissertation_quick_fixes", Create. Then replace with the following code and Run. Should save to your Normal.dot so only need to create the macro once, then available to run on any document.
Sub dissertation_quick_fixes()
'----
' resize figures
Dim shp As Word.Shape
Dim ishp As Word.InlineShape
Dim width_in As Integer
width_in = 6
' iterate over all shapes
For Each shp In ActiveDocument.Shapes
shp.LockAspectRatio = True
shp.Width = InchesToPoints(width_in)
Next
' iterate over all inline shapes
For Each ishp In ActiveDocument.InlineShapes
If ishp.Width > 0 Then
ishp.LockAspectRatio = True
ishp.Width = InchesToPoints(width_in)
End If
Next
'----
' add page and line numbers, line space
' add page numbers
ActiveDocument.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _
wdAlignPageNumberRight, FirstPage:=True
' add line numbers
With ActiveDocument.PageSetup.LineNumbering
.Active = True
.StartingNumber = 1
.CountBy = 1
.RestartMode = wdRestartContinuous
.DistanceFromText = InchesToPoints(0)
End With
' make line spacing 1.5 for Normal style
ActiveDocument.Styles("Normal").ParagraphFormat.LineSpacingRule = wdLineSpace1pt5
' make other styles single spaced
Dim vFonts As Variant
Dim vF As Variant
vFonts = Array("Image Caption", "Table Caption", "Compact", "Bibliography", "TOC 1", "TOC 2", "TOC 3", "TOC 4", "TOC 5")
For Each vF In vFonts
Debug.Print vF
ActiveDocument.Styles(vF).ParagraphFormat.LineSpacingRule = wdLineSpace1
Next
'----
' add table of contents after 1st paragraph
Dim toc_str As String
Dim rng As Object
toc_str = "Table of Contents"
' set location in doc
Set rng = ActiveDocument.range( _
Start:=ActiveDocument.Paragraphs(1).range.End, _
End:=ActiveDocument.Paragraphs(1).range.End)
' add toc
ActiveDocument.TablesOfContents.Add rng, _
UseFields:=True, _
UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1
' prefix toc with string
With ActiveDocument.Paragraphs(1).range
.InsertParagraphAfter
.InsertAfter (toc_str)
.InsertParagraphAfter
End With
' make toc bold
With Selection.Find
.Replacement.Font.Bold = True
.Execute FindText:=toc_str, replaceWith:=toc_str
End With
End Sub