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 citationBetter 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 BibTexand export todissertation.bibfile (which is assigned tocite_bibvariable 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
localandglobalvariable 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.
Subdissertation_quick_fixes()'----' resize figuresDimshpAsWord.ShapeDimishpAsWord.InlineShapeDimwidth_inAsIntegerwidth_in=6' iterate over all shapesForEachshpInActiveDocument.Shapesshp.LockAspectRatio=Trueshp.Width=InchesToPoints(width_in)Next' iterate over all inline shapesForEachishpInActiveDocument.InlineShapesIfishp.Width>0Thenishp.LockAspectRatio=Trueishp.Width=InchesToPoints(width_in)EndIfNext'----' add page and line numbers, line space' add page numbersActiveDocument.Sections(1).Footers(1).PageNumbers.AddPageNumberAlignment:=_wdAlignPageNumberRight,FirstPage:=True' add line numbersWithActiveDocument.PageSetup.LineNumbering.Active=True.StartingNumber=1.CountBy=1.RestartMode=wdRestartContinuous.DistanceFromText=InchesToPoints(0)EndWith' make line spacing 1.5 for Normal styleActiveDocument.Styles("Normal").ParagraphFormat.LineSpacingRule=wdLineSpace1pt5' make other styles single spacedDimvFontsAsVariantDimvFAsVariantvFonts=Array("Image Caption","Table Caption","Compact","Bibliography","TOC 1","TOC 2","TOC 3","TOC 4","TOC 5")ForEachvFInvFontsDebug.PrintvFActiveDocument.Styles(vF).ParagraphFormat.LineSpacingRule=wdLineSpace1Next'----' add table of contents after 1st paragraphDimtoc_strAsStringDimrngAsObjecttoc_str="Table of Contents"' set location in docSetrng=ActiveDocument.range(_Start:=ActiveDocument.Paragraphs(1).range.End,_End:=ActiveDocument.Paragraphs(1).range.End)' add tocActiveDocument.TablesOfContents.Addrng,_UseFields:=True,_UseHeadingStyles:=True,_LowerHeadingLevel:=3,_UpperHeadingLevel:=1' prefix toc with stringWithActiveDocument.Paragraphs(1).range.InsertParagraphAfter.InsertAfter(toc_str).InsertParagraphAfterEndWith' make toc boldWithSelection.Find.Replacement.Font.Bold=True.ExecuteFindText:=toc_str,replaceWith:=toc_strEndWithEndSub