Let’s imagine a situation. You generate some number(s) in R or Python or whatever and want to include these numbers in a LaTeX document. Most people (I assume) just copy/paste the numbers from the console to the document.1 This means that if you update the analysis, your document may be reporting incorrect information.
There are some solutions to this, of course. One solution is to mix the code together with the document (rmarkdown users will be familiar with this).
This is a post in a series of posts about using pandoc to convert between markdown, latex, word, and pdf. It should stand on its own, but you may want to go though the posts sequentially.
Intro OK, you have installed pandoc to convert your markdown or latex file to docx and sent it off to your adviser for comments. Now they send that file back, with comments in the word document and changes made using Word’s “track changes” feature.
This is a post in a series of posts about using pandoc to convert between r/markdown, latex, word, and pdf. It should stand on its own, but you may want to go though the posts sequentially.
Even though word processors are stupid, MS Word’s ubiquity means that occasionally I have to convert a latex or markdown document to a docx file for a colleague who insists on using Word’s “comments” feature or for submission to a journal that doesn’t accept pdfs (though thankfully, the vast majority do today).
I’m all the time asked something along the lines of “Hey, you taught me markdown/latex, but my adviser wants to give me comments in Word. How can I make that happen?”
The answer, unfortunately, is a little complicated. The best way to do this is to use pandoc, an absolutely wonderful program that converts between all kinds of markup formats (including between markdown, latex, and docx documents).1 Pandoc is very powerful, but a little overwhelming, especially if you aren’t used to working with command line applications.
Combining code and the document that you’re writing is called “literate programming”. It’s one of the best practices associated with reproducible research, which is a hot topic in political science and other disciplines. This post isn’t about why you should do this, it’s just about how to do it.
I’m going to talk about how to combine R code with markdown via rmarkdown and LaTeX via knitr. There are other ways of doing this (such as org-mode in emacs), so this isn’t supposed to be a comprehensive guide to all of the ways of doing this.
Another grad student and I hosted a workshop on Introduction to LaTeX today. We just went over the very basics, but the materials are online on my github. Feel free to email me with questions or fork and make a pull request with suggestions or improvements!
Having a super powerful text editor can make your life much easier. There are quite a few out there, but there’s only that can do it all: Emacs.
In this post, I’ll outline how to get started with emacs. There are plenty of tutorials out there, but I’d say that the best way to learn is just to jump in. Thus, I will not spend a whole lot of time describing what M-x does (the answer is everything).
So as a grad student, I write a lot. Like, a lot a lot. And as a part of that, I cite a lot of articles and books. And there are, of course, those few articles that I find myself citing in nearly every paper I write. So ideally, I could have one central repository for all of the papers that I want to be able to cite, and reference that from whatever paper I’m working on.
I hope that my last post convinced everyone that they need to use at least some kind of version control. Near the end of that post, I noted that git (and Github) are geared towards plain text files. In this post, I hope to convince you that plain text is your friend. If you’re coming from word processing land (like Microsoft Word or similar), then there can be a bit of a learning curve.