Writing papers with LaTeX nowacki.org

I write a fair amount, primarily in the form of journal articles or other scientific writing output. For anything more than the most minimal documents I use LaTeX. My preferred editor is TeXShop. I generally keep program defaults, although one big recommendation is to use Single Window Mode: do this by clicking Window -> Use One Window. Additionally, in TeXShop Preferences, enable Use One Window in Preview -> Opening Source and Preview. This way, fewer windows clutter up your workspace: if you have multiple documents open, the source and preview windows won’t get mixed up.

Git

Anything that approaches the length of a paper gets its own Git repository and accompanying Git remote. At the end of each day—sometimes more often—I make sure to commit my changes to the repo and push to the remote. This helps to keep a full record of changes to your paper. When using Git in this fashion I recommend using one sentence per line, and two newlines between paragraphs. This way Git will provide readable diffs between paper versions. I generally tag releases for different milestones, like initial submission to a journal, resubmission after reviewer comments, and so on. Put everything in the repo, including things like review comments, figures, and comments from coauthors.

Git LFS

In newer projects, I have been using Git LFS to store figures. Small changes in a big PNG figure, for example, can lead to a massive increase in the size of the repo. To avoid this, install Git LFS (git lfs install), and in your repository, add figures to LFS using something like:

git lfs track "figures/cool_figure.pdf"
git add .gitattributes

Then commit as usual.

Bibliographies

I use Zotero to take care of my bibliography, along with the Better BibTex for Zotero plugin. I suggest creating a collection within Zotero for your paper, and drag publications used for that paper into this folder. You can then export that collection’s citations to a .bib file and save in your manuscript directory. Do this by right-clicking it in the left pane of Zotero and choosing “Export Collection…”, and selecting Better BibTex. Each time I add a new reference in Zotero, I re-export the .bib file to the paper directory.

Figures

For figures, use PDF as much as possible. Have a working figures folder that is separate from your paper figure folder. As you start referencing figures in your paper, copy them into a figures/ folder within your paper folder and include in your figure code block. As you update figures (changing units, adding subplots, or whatever) copy the new version into you paper’s figures/ folder. Commit the new figure versions to your Git repo just like you commit text changes.

Coauthors

Even though I think LaTeX is superior to word processors like Word for composing journal articles, the utility of Track Changes is undeniable, especially when working with coauthors. When a paper is nearing the point where it will be shared with coauthors for their input, I use Pandoc to create a .docx version of the paper. (I recommend installing Pandoc via Homebrew on macOS.) The pandoc-converted version will take care of simple math, tables, figures, figure references, and citations. It may still look a little wonky, but it will be totally usable for Word track-changes edits from your coauthors. And if you send both the .docx and the .pdf output from LaTeX, they can see what complex math or tables should look like in the PDF.

Here’s the code I use to generate a .docx from LaTeX source:

pandoc -F pandoc-crossref -F pandoc-citeproc INPUT.tex -o OUTPUT.docx

&c

Counting words is pretty tricky with LaTeX, but you can get a good idea using TeXcount. It’s probably already on your system. Type which texcount to see.

For referencing figures and tables, I have settled on the cleveref package, replacing \ref{...} with \cref{...}.

Updated 2022-12-13