使用Texshop在Knitr中同步PDF和Rnw文件

3
有人知道如何在texshop中使用knitr将synctex从pdf文件转换为Rnw文件吗?它可以从Rnw文件转换为pdf文件。非常感谢。
1个回答

1

这是我解决问题的方式。尚未在多个.Rnw文件上尝试。

  1. In TeXShop Preferences, make sure your "Sync Method" is set as "SyncTeX (TeX ≥ 2010)".

  2. On your Mac, make the directory "~/Library/TeXShop/Rscripts" and put the R file "patchKnitrSynctex.R" downloaded from https://github.com/jan-glx/patchKnitrSynctex in this directory.

  3. Create an executable file "Knitr.engine" including the following shell scripts and put it in "~/Library/TeXShop/Engines/":

    #!/bin/bash
     # export PATH=$PATH:/usr/texbin:/usr/local/bin # already on my path!
     Rscript -e "library(knitr); knit('$1')"
     latexmk -pdf -pdflatex='pdflatex -shell-escape -synctex=1 -file-line-error' "${1%.*}"
     Rscript -e "source('~/Library/TeXShop/Rscripts/patchKnitrSynctex.R', echo=FALSE, encoding='UTF-8'); patchKnitrSynctex('${1%.*}')"
    
  4. In R, install the package "patchDVI".

  5. In your .Rnw file, add "% !TEX TS-program = Knitr" on the top line of the document. Also inside the .Rnw document somewhere around the top of the document add an R code chunk

    <<setup, include=FALSE>>=
     patchDVI::useknitr()
     … #any other knitr global setups
     @
    

愉快的编织!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接