Skip to content
Prev 315563 / 398503 Next

Sweave, Texshop, and sync with included Rnw file

Sweave produces foo-concordance.tex from foo.Rnw, and writes
\input{foo-concordance.tex} in the LaTeX output. You can turn on the
concordance option in knitr as well. Since you do not use RStudio, you
have a couple of more steps to go:

1. borrow \Sconcordance from Sweave.sty;
2. manually \input{foo-concordance.tex};
3. set the option concordance=TRUE in opts_knit;

The rest of steps are the same as Sweave -- you compile the output by
`pdflatex --synctex=1 foo.tex`, and run patchDVI on the results. I do
not use TeXShop, so I'm not sure if it really works.

\documentclass{article}
% from Sweave.sty in R
\newcommand{\Sconcordance}[1]{%
  \ifx\pdfoutput\undefined%
  \csname newcount\endcsname\pdfoutput\fi%
  \ifcase\pdfoutput\special{#1}%
  \else%
   \begingroup%
     \pdfcompresslevel=0%
     \immediate\pdfobj stream{#1}%
     \pdfcatalog{/SweaveConcordance \the\pdflastobj\space 0 R}%
   \endgroup%
  \fi}
\input{foo-concordance.tex}

<<setup, include=FALSE>>=
opts_knit$set(concordance=TRUE)
@

\begin{document}

<<>>=
for (i in 1:5) {
  print(i)
}
@

\end{document}

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
On Thu, Jan 17, 2013 at 7:45 PM, huang min <minhuangr at gmail.com> wrote: