the default device is NULL in opts_chunk, which will be changed to pdf for LaTeX output, and png/svg for HTML output

this allows one to opts_chunk$set(dev) before knit(); previously, if you set dev=pdf before knitting an Rmd document, the device will be restored to png forcibly, which is bad when we want to convert markdown to LaTeX through pandoc
factor out the code to crop images to plot_crop(); we can use it separately later