CommunityData:Build papers

When creating LaTeX documents, the final PDF output must be built from an input file. For many of our projects, this process is even more complicated and we use Makefiles to manage more complex workflows. This document is intended to give an overview of the basic process and to identify good practices for quantitative projects.

Project Creation
Follow the directions for installing the LaTeX templates. Once they are installed, you can run something like:

cd ~/Projects new_knitr_document project_name

This will create a new project called.

This project will include a Makefile and all of the pieces needed to create a document.

Zotero
The next step is to set up your references. Often, this means creating a new directory in Zotero. Follow the directions on the CommunityData:Zotero page. You should export your Zotero directory as Better BibLaTeX to the refs.bib file, and check "Keep updated" for Zotero to automatically update that file whenever the directory changes.

Making the paper

 * 1) The first time you're building the paper, you can just run   or  . After that, you probably want to run  . This should work whether you're using an .Rtex (knitr) or .tex (LaTeX) file.

If you need to output a Word document (e.g., for a journal submission), see the LaTeX to Word page.

Git
At this point, you should put your project into git. See CommunityData:Git for instructions.

Overleaf
If you're using Overleaf for your papers, that's great. Many of us use Overleaf at some point in our writing process. This section describes a reasonable workflow for putting papers on Overleaf.

Dropbox Sync
Overleaf is actually really good at allowing for a combination online/offline workflow, and keeping documents in sync. Most of us have this set up through Dropbox sync. In your Overleaf account settings you can set this up. Once you do that, all of your Overleaf projects will appear in.

If you don't want to fiddle with account settings on Overleaf, you can also simply:


 * Get Better Bibtex on your Desktop Zotero app.
 * Export your collection/library to "auto" update (See this below) to an auto-syncing Dropbox folder.
 * Follow the instructions here to link the .bib file that is auto-exported by Better Bibtex and synced to Dropbox to your Overleaf, but note the changes for Dropbox: https://www.overleaf.com/learn/how-to/How_can_I_upload_files_from_Google_Drive%3F
 * When there are changes made on Zotero, note that you need to "refresh" the file on Overleaf to get the updated/synced file.

Creating a Project
Overleaf supports the entire pipeline that we typically use when building TeX papers from a local computer, including knitr and Makefiles. Therefore, the best way to put a complicated project onto Overleaf is to create it on your computer first. You can do this by going to the  directory in Dropbox and using the   command. This will both give you a new document with all of the needed resources and will create a new project on Overleaf

Data and Code
You should not put your entire project on Overleaf. If you follow the suggested directory structure below, then Overleaf should just contain the  directory. The code and data should live somewhere else, typically.

The one problem with this is that you likely want the whole project, including the paper, in the same place, and updated in a git repository. One approach to this is to include an option in the Makefile which will copy the Dropbox version into the canonical directory.

The bibliography file
The Best Practice is still to use Zotero to manage your bibliography. If you have installed Better Bibtex (and if you haven't, then you should!), then you can export your bibliography and keep it updated. You right-click on the collection you want to export, choose the format (likely Better BibTex), and select "keep updated"



You should export it into the  file in your Dropbox Overleaf project, and then Better Bibtex and Dropbox will keep it updated on Overleaf for you.

Style notes and more details (add as needed)

 * The typical directory structure that I use is something like:

/code 01_script.py     02_script.py      03_analysis.R      README /data /raw_data raw_data_file.csv measures.csv analyzed_data.RData /paper /data analyzed_data.RData (symlinked) /figures (any figures not created with knitr) paper.Rtex

The code all lives in one place, with a README that explains what the pieces do. Don't underestimate the importance of a README and well-commented code. Your future self will thank you.

The data lives in another place, with raw_data which is read-only (and may or may not be stored in git, depending on the size). This raw data is used to create measures (and possibly some intermediate files). Analysis is done on the measures file, and stored in an RData file.

It is tempting to put as much of the analysis workflow as possible into the .Rtex file but these files can quickly become difficult to compile and unwieldy. It's often better to do the heavy lifting in a separate script, import an .RData file in the paper, and do things like creating plots and running simple statistical tests in the paper itself.


 * You may need to use natbib for some journal submission styles. The stackexchange page linked above helps to explain how to do that (but if anyone wants to give more detailed instructions, please do!).