/dissertation

PhD dissertation at Duke University

Primary LanguageHTMLGNU General Public License v2.0GPL-2.0

dissertation

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.

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:

Rendering

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:

      1. Export: "Default Output Format" to Pandoc citation

      2. Better Bib(La)tex: "Citation key format" to [auth:lower]_[veryshorttitle:lower]_[year]

    • Process:

      1. Place all references used by dissertation into its own dedicated collection (eg "dissertation").

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

      3. Right-click on collection > Export Collection and choose Better BibTex and export to dissertation.bib file (which is assigned to cite_bib variable in make.R).

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

      5. Run ./make.R to generate collated document in all formats.

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

TODO

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.

Rendering Inspirations

Here are a few related resources from which I borrowed.

Word Tweaks

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