Unleashing dynamic LaTeX: latexmk, gnuplot, R (knitr) and pgfplotstables

One of the nice things of LaTeX is that it allows you to separate the content and the formatting/layout of your documents. Need a new column layout? Just add an option in the document class. Your image needs to be wider? Change it, LaTeX adjusts its position in the document. In other words you only need to worry about what you’re doing right now and nothing more.

However, this philosophy doesn’t extend to all aspects of LaTeX. What if you’re writing a technical document and a graphic must be regenerated if the data files change? What if those data files should also be summed up in a table and some key values discussed in the document? You’d probably end up re-running your R and gnuplot scripts, and copy-pasting the results. This isn’t a bad thing if you only have to do it once or twice, but it can get annoying quickly.

The solution: again, separate content and presentation. If you have to do some calculations to get the data you need in your document, write those calculations in the document and let LaTeX (with knitr, as we’ll see later) recreate them if needed. If you have some plots generated by gnuplot or tables from some data file, again, let your document typesetting system take care of filling them.
Continue reading