knitr 1.5 / patchDVI 1.9 doesn't seem to generate a concordance acceptable to evince + emacs

StackOverflow https://stackoverflow.com/questions/19499689

Domanda

Setup : here is sessionInfo() :

R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=fr_FR.UTF-8        LC_COLLATE=fr_FR.UTF-8    
 [5] LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8   
 [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] patchDVI_1.9 knitr_1.5   

loaded via a namespace (and not attached):
[1] compiler_3.0.2 evaluate_0.5.1 formatR_0.9    highr_0.2.1    stringr_0.6.2 
[6] tcltk_3.0.2    tools_3.0.2   

I am trying to get emacs and AucTeX to synchronize my .Rnw source file with evince to go to comiled text from source and back.

I have already checked that the synchronization works fine between a .tex source and a PDF.

My .Rnw file starts with :

\documentclass[a4paper,twoside,12pt]{article}
\synctex=1 %% Should force concordance generation
\pdfcompresslevel=0 %% Should force avoidance of PDF compression, which patchDVI does
\pdfobjcompresslevel=0 %% not handle
<<include=FALSE>>= %% Modificaton of what Sweave2kinitr does
## opts_chunk$set(concordance=TRUE, self.contained=TRUE) ## No possible effect
opts_knit$set(concordance=TRUE, self.contained=TRUE) ## Seems reasonable
@
%% \SweaveOpts{concordance=TRUE} %% That's where inspiration came from

Consider the following log (unrelevant parts edited) :

> options("knitr.concordance")
$knitr.concordance
[1] TRUE

> opts_knit$get("concordance")
[1] TRUE
> knit("IntroStat.Rnw")


processing file: IntroStat.Rnw
  |......................                                           |  33%
  ordinary text without R code

  |...........................................                      |  67%
label: unnamed-chunk-1 (with options) 
List of 1
 $ include: logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: IntroStat.tex

[1] "IntroStat.tex"
> system("pdflatex -synctex=1 IntroStat.tex")

[ Edited irrelevancies ]

SyncTeX written on IntroStat.synctex.gz.

Note : a concordance has *been* generated !!! **

Transcript written on IntroStat.log.

Let's do that again to fix references :

> system("pdflatex -synctex=1 IntroStat.tex")

[ Edited irrelevancies ]

Output written on IntroStat.pdf (1 page, 136907 bytes).
SyncTeX written on IntroStat.synctex.gz.

Note : a concordance has *been* generated *again* !!! **

Transcript written on IntroStat.log.
> patchDVI("IntroStat.pdf")
[1] "0 patches made. Did you set \\SweaveOpts{concordance=TRUE}?"

* This I do not understand *

> patchSynctex("IntroStat.synctex.gz")
[1] "0 patches made. Did you set \\SweaveOpts{concordance=TRUE}?"

* Ditto *

It appears that something in the set of tools does not work as advertized : either dviPatch does not recognize legal concordance \specials or pdflatex dfoes not generate them. It does generate something, however...

I checked that the resulting PDF enables evince to synchronize with the .tex file, but not in the .Rnw file. Furthermore, when the .Rnw file is open in emacs, starting the viewer with 'C-c C-v View" in AucTeX indeed starts the viewer (after requesting to open a server, which I authorize), but the viewers is empty, and i get this : "TeX-evince-sync-view: Couldn't find the Evince instance for file:///home/charpent/Boulot/Cours/ODF/Chapitres/Ch3-StatMath/IntroStat.Rnw.pdf" in the "Messages" buffer.

So we have a second problem here.

A third one would be to integrate all of this transparently in the AucTeX production chain, but this is another story...

I'd really like to keep emacs as my main tool for R/\LaTeX/Sage work, rather tha switch to RStudio, which probably won't like much SageTeX and othe various tools I need on a daily/weekly basis...

Any thoughts ?

È stato utile?

Soluzione

Maybe this https://github.com/jan-glx/patchKnitrSynctex will help. I tried it on a simple file, and it does work.

As for the second and third problems, I have this script (note that I source the above code from jan-glx; modify path accordingly):

#!/bin/bash
FILE=$1
BASENAME=$(basename $FILE .Rnw)
Rscript -e 'library(knitr); opts_knit$set("concordance" = TRUE); knit("'$1'")'
pdflatex --synctex=1 --file-line-error --shell-escape "${1%.*}"
Rscript -e "source('~/Sources/patchKnitrSynctex.R'); patchKnitrSynctex('${1%.*}.tex')"
ln -s $BASENAME.synctex.gz $BASENAME.Rnw.synctex.gz
ln -s $BASENAME.pdf $BASENAME.Rnw.pdf

The links are my kludgy way of getting around the "Couldn't find the instance (...) ".

If you have your .Rnw in an Emacs buffer, go to a shell buffer, and call that script. When finished, C-c C-v from Emacs will open your configured PDF viewer (okular in my case). In the PDF, shift + left mouse click (okular at least) will bring you to the right place in the Emacs .Rnw buffer.

This is not ideal: if you jump to an error, it goest to the .tex, not the .Rnw. And I'd like to be able to invoke it via C-c C-c or similar (but I don't know how ---elisp ignorance).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top