Skip to content

Instantly share code, notes, and snippets.

@air-drummer
Last active August 29, 2015 14:08
Show Gist options
  • Save air-drummer/18a7899cfce85398fc3f to your computer and use it in GitHub Desktop.
Save air-drummer/18a7899cfce85398fc3f to your computer and use it in GitHub Desktop.
latexmk engine + knitr (Mac OS)
#There isn't a built-in engine for knitr, but it's easy to make one.
#The engine itself is just a shell script. Here's my belt-and-braces version that believes you are on a unix machine
#but doubts that your paths are set up properly:
#!/bin/bash
export PATH=$PATH:/usr/texbin:/usr/local/bin
if (Rscript -e "library(knitr); knit('$1')") then
latexmk -pdf "${1%.*}"
fi
#In brief, this tries to run the R code in double quotes on the first argument ($1) which is the name of the .Rnw file.
#If this succeeds then the transformation from latex+R to pure latex must have been successful, so we can call latexmk on the
#resulting file. latexmk runs latex, then biber, then latex, then latex again, then... until all the citations are cited,
#the contents are tabled, and all the cross references are happy again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment