Programmatic Lecture Slides Made Even More Difficult with R Markdown

In Easy Lecture Slides Made Difficult, I showed how to use markdown to make slides while still retaining some aesthetic flexibility. All that was required was a handful of TeX Macros, a little python script, a few Makefiles, and a maniacal commitment to automation. That was an enjoyable trip into the abyss, but what if your slides regularly include the results of calculations, data visualizations, or computational examples? Then it is time to, how do they say it these days, dive deeper. Thanks to R Markdown and knitr, it is possible to build on the pandoc/beamer system I described before to incorporate program code and its results. Call it, uh, Presentationally Literate Programming.

I am spurred to describe my approach by two things: first, I have had a whole semester of teaching Literary Data to work out the kinks; in that graduate course I regularly used R markdown-based slides to present new material. (Here are a couple examples: slides on network visualization, April 23, 2015; slides on topic modeling and PCA for literary texts, April 16, 2015.) Second, I was just at a conference where almost everyone’s presentation had slides with R output in them, but it seemed like people might…benefit…from an example showing how to make the aesthetics of the R output and the slides more consistent with one another. I’ll also show how the same R markdown can be the basis of slides, speaker notes, and a handout for audience members to take notes on. And I’ll show the settings for incorporating program code into the slides, which I used in my teaching. At the end of this post, I imagine you will question my sanity. The whole setup can be found in this repository subdirectory on github.

[Update, November 2015. I’ve made a slightly easier-to-use version of the same setup available as an R package here.]

read more…

Easy Lecture Slides Made Difficult with Pandoc and Beamer

Markdown for slides is a great idea. Don’t painfully lay out each slide, click by click: just write down an outline and let a program generate the slides for you. The almighty Pandoc does this very well. You write plain text, and a single pandoc command produces slides in one of a number of nice HTML formats (like reveal.js or slidy), ready to be uploaded, or in PDF.

I switched over to this way of doing things last year. It was a relief to stop fighting with Keynote,1 which is nice as presentation programs go but still exhausting: it constantly makes wrong guesses about formatting; putting text where you want is a struggle, and inevitably imprecise. And, worst of all, adding notes for myself to slides is pretty hopeless. I always ended up having to create two parallel versions of each class: the slides, and my own notes. That involved a lot of redundant work. By contrast, once I started writing my slides and notes together, I got my materials for class together quite a bit faster. Whether the temptation to further procrastination/tinkering was really healthy is a separate issue.

Anyway, markdown for slides with pandoc is pretty simple and easy-to-use, but because I wanted some features that the HTML formats do not easily support, I was tempted into going with pandoc’s capacity to generate LaTeX slides using the beamer package. Getting what I want out of that setup is what makes easy slides difficult. (If you want easy slides made easy, consider Ben Schmidt’s suggestions.) Here’s what I do these days. All the bits and pieces for doing this can be found in my repository of TeX stuff on github, in the lecture-slides directory. [Edit, May 18, 2016: I now use a slightly tidier set-up, available in a new repository.] For a sample of the kind of results I get, see the slides from my Early Twentieth-Century Fiction course this semester, for example a lecture on Djuna Barnes.

read more…

LaTeX and My Book: Postscript

So now that my book is in print (read it! buying links on the book page!), I wanted to indulge an urge to look back at the technical, or rather TeXnical, aspects of producing the book. I had the quixotic determination to write the book in LaTeX and to take advantage of what LaTeX can do right through production, and, through the hard work of various parties at Oxford U.P., I had the chance to do so.

This is going to be a nerdy post. You’ve been warned. I’ve also added an equally nerdy e-colophon page describing the technology I used to make the book.

read more…

On Wishing Death to Word

So I keep seeing links to this denunciation of the dysfunction of Microsoft Word in Slate: Tom Scocca, “Death to Word”.

One heartily endorses the sentiment. Scocca’s example of what pasted Microsoft Word XML looks like is comedy gold (and all too familiar from student blog posts). The heart sinks, however, when it turns out that the only alternative Scocca knows to mention is TextEdit, even though his explicit concern is with the crippling defects of Word when it comes to moving documents between print and HTML. In other words, the entire universe of text editing software (as opposed to word processors) is invisible to the writer of the article. No doubt he can’t imagine any way to break Word’s near-monopoly, let alone that there are both open-source and commercial systems of long standing that are much more versatile.

read more…

Percent-Ampersand Is Not Shebang

%& is not a shebang.

Somewhere on the internets I picked up the idea that the first line of a tex file should specify what flavor of TeX it’s written in, where flavor was one of TeX, LaTeX, XeLaTeX, XeTeX, etc. I think was imagining that it was some kind of TeX-internal version of the “shebang” #! that tells a Unix shell what program to use to execute a script. Indeed my standard template file had such a line (but not any more).

Wrong.

read more…

Funny old thing (LaTeX class for Yale PhD thesis)

Here’s a funny thing. This is a LaTeX document class file for a Yale Ph.D. dissertation: mythesis.cls. When I submitted mine, I discovered an older document class other people had worked on, and tweaked it to bring it up to the 2006 spec. Might be useful for current Yalies (if they somehow find this page by googling) or others TeXing their dissertations. Invoke with \documentclass[12pt]{mythesis}.

I’m adding it to the small github repository in which I’m going to start keeping tex sources for people to play with.

Coming next: a document class/style file/sample source for a student paper. One day I am going to persuade a student to TeX a paper.

I can dream, anyway.

How to Begin

So you just want to begin. The TeX Users Group website has a Getting Started Page with the essentials: introductory documents, examples, and, most importantly, links to the software itself: TeX Live on Unix, MacTeX on Mac, proTeXt on Windows (all free, and rather enormous, downloads). If you are on a Mac, look for the TeXShop application; if you are on Windows, look for TeXnicCenter. If Unix, pffft; open up an xterm and vim/emacs. However you do things, here is a file to start playing around with: xelatex.sample.tex. If your setup is working like mine—and if you have the fonts I use—you should be able to typeset it with XeLaTeX and get a result that looks like this: xelatex.sample.pdf.

read more…

biber first aid for “data source not found”

I don’t know what causes it, but every now and then biber gives up working on my system. Then I start getting error messages like data source /var/folders/m6/bn7r45zx6cx55rr9g4qh6s6w0000gn/T/par-agoldst/cache-87e533530c5239fb9f8e3ff008979f1f16ea0e5e//inc/lib/Biber/LaTeX/recode_data.xml not found in .

There is a magic incantation, which I found somewhere on the biber sourceforge forums, to get biber to clear the cobwebs by reinstalling itself using perl’s PAR tool, as it does the first time it is run on a new system. Just clear the PAR cache, whose location under /var is helpfully specified in the error message:

 sudo rm -rf /var/folders/m6/bn7r45zx6cx55rr9g4qh6s6w0000gn/T/par-agoldst

You will have different stuff in /var/folders.../par-<username>.

Since I’ve seen other people complaining of this, I’m convinced it’s not my fault but the result of some deeply buried sporadic bug in biber. I’d try harder to figure it out, but it’s just too easy to make this one go away when it pops up once every few months. TeX is hacking, people!