Wednesday, June 25, 2014

TexShop engines for Knitr w/ and w/o pstricks

Two years ago, I've posted a link that explains how to set up a painless compilation of Sweave documents in TexShop: http://cameron.bracken.bz/sweave-for-texshop

Since I've switched to Knitr last year, I wanted to share a couple of tricks of using a TexShop+Knitr combination.

First, setting up a Knitr engine in TexShop is analogous to the recipe from the above link: create a file Knitr.engine in your ~/Library/TexShop/Engines/ directory with the following content:

#!/bin/bash

export PATH=$PATH:/usr/texbin:/usr/local/bin
Rscript -e "library(knitr); knit('$1')"

Now if you (re-)open TexShop, you should have Knitr in your list of engines located next to the Typeset button on the top. This worked well for me until today, when I needed to combine Knitr code with some old LaTeX code of mine that used "pstricks" package. Since pdflatex does not work with "pstricks" (there something called PDFTricks, but I haven't tried it), I needed to create another engine in my ~/Library/TexShop/Engines/ directory that I called KnitrDviPs:

Rscript -e "library(knitr); knit('$1')"
latex "${1%.*}"
bibtex "${1%.*}"
latex "${1%.*}"
latex "${1%.*}"
dvips -t letter -o "${1%.*}.ps" "${1%.*}"
pstopdf "${1%.*}.ps"

This engine goes through a less efficient "dvi->ps->pdf" route. However, this still doesn't do the trick just yet, because by default Knitr does not produce postscript files of all embedded figures. So you have to add a "postscript" device to your Knitr document using Knitr chunk options. For example, somewhere near the beginning of your Knitr document you can put the following command:

opts_chunk$set(fig.path='figures/', fig.align='center', dev=c('pdf', 'postscript'))

Now you have two Knitr engines: one that goes through pdflatex and another that goes through "dvi->ps->pdf".

Monday, May 5, 2014

Fundraising for victims of May 2nd, 2014 events in Odessa, Ukraine (updated on May 19, 2014)

Many of you have seen the news about violent clashes that occurred in Odessa, Ukraine on May 2nd, 2014. During these clashes, my very close childhood friend was shot from a machine gun and now he is fighting for his life in one of the hospitals in Odessa. I don’t know all the details yet, but it appears that my friend was wounded by a pro-russian activist during the initial stage of the unrest, when heavily armed pro-russian activists attacked a peaceful demonstration for the unity of Ukraine. The crossed out information hasn't been confirmed. I still don't know all the details, but if you feel that you were mislead by the crossed out sentence, send me a note by email.

My friend’s family has enough financial resources to give him medical care, but my friend’s father says that he sees many families of victims of the clashes that don’t have money to pay for medical expenses. The Ukrainian government promised to help all victims, but their help may arrive too late, if it ever arrives. Since I have a unique opportunity to reach out to the victims’ families in need through my relatives and friends in Odessa, I’ve decided to try to raise funds to provide medical care to the wounded in clashes on May 2nd, 2014. The funds will be distributed to the wounded without
any regard to their political convictions.

If you would like to help me in this fundraising campaign, please donate to my PayPal account using a link on my web page:

http://www.stat.washington.edu/vminin/

-Vladimir

Update 1 (05/06/2014): funds raised so far - ~$1,500; wholehearted thanks to everyone, you are amazing! I've made the first transfer of $1,000 to Odessa today.

Update 2 (05/06/2014): I was on the phone with Odessa today. Hospitals are in dire need of many pieces of medical equipment to treat hundreds of wounded. There is a local fundraising effort going on to buy this equipment and we were offered to join this effort. This would be a slight deviation of the initial plan of distributing funds to the wounded directly. However, I was told that there is where the help is needed the most at the moment, so I support this suggestion. Still, I will ask my contacts in Odessa to give money directly to the families of wounded that need assistance first, and use the rest for medical equipment. Important: if you are not comfortable with this plan or have any hesitation about how your donation will be spent, please contact me by email so I can give you more information and/or refund you.

Update 3 (05/09/2014): funds raised - ~$2,000; again, thank you!

Update 4 (05/09/2014): I am happy to report that I got in touch with a local volunteer in Odessa, whom I personally know and who is involved in distributing financial assistance to the wounded on May 2nd in Odessa. So we are back to the original plan -- providing money directly to the families of wounded!

Update 5 (05/09/2014): Since we have reached a plateau in the total funds raised, I've decided to take a pause, to stop soliciting/receiving donations, and to concentrate on distributing the money we have collected so far. If I have time and energy, I may try for a second round of fundraising. I will be updating this post with details of how the donations are being spent in Odessa.

Update 6 (05/19/2014): I've got an update on how the first transfer (~1,000) to Odessa was spent! First, medical bills, amounting to ~$485 were payed for a person in need who was hurt on May 2, 2014 in Odessa and remains in critical condition. Next, our local volunteer used ~$460 to purchase painkillers for the wounded that still need medical attention. The small remainder of the transferred sum was used to help offset the cost of medical treatment for children of three military personnel relocated from Crimea after the Russian invasion.