[ESS] A RefTeX question with Sweave multi-file (variable reftex-file-extensions)

Laurent ESS laurentESS at free.fr
Fri Dec 14 23:22:08 CET 2012


Le 12/12/2012 15:21, Vitalie Spinu a écrit :
> Hi Laurent,
>
> Sorry for being late on this. I hope you have solved this yourself. If
> not, the solution is to customize reftex-include-file-commands and add
> SweaveInput to the list. It started working for me after a restart.
>
> I didn't know about this till today, when I finally dived into it. I was
> not even aware that reftex can recognize \input and \include. It never
> worked for me. The reason is that reftex requires the file name to end
> with .tex, but latex doesn't. So I was never appending .tex and, as a
> consequence, was never seeing the full contents.
>
> On a related theme, I have a problem with "C-c =" in slave
> documents. That is, contents is blank when I invoke C-c = form the
> included files.  Does it work for you?
>
>      Thanks,
>      Vitalie
>
>    >> Laurent ESS <laurentESS at free.fr>
>    >> on Sun, 29 Jul 2012 23:19:09 +0200 wrote:
>
>    > Hi,
>
>    >     I try for the first time to create a multi files Sweave document. All work
>    > fine to generate the pdf file. But I have an issue with the "C-c =" command when
>    > I want to work with the TOC for the file included par \SweaveInput. I use the
>    > latest Vincent Goulet emacs distribution, my OS is MS windows 7.
>
>    > As I read on the Sweave FAQ, I put in my .emacs.el, the code below :
>    > -----------------------------------------------------------------------------------
>    > (defun Rnw-mode ()
>    >   (require 'ess-noweb)
>    >   (noweb-mode)
>    >   (if (fboundp 'R-mode)
>    >        (setq noweb-default-code-mode 'R-mode)))
>    >  (add-to-list 'auto-mode-alist '("\\.Rnw\\'" . Rnw-mode))
>    >  (add-to-list 'auto-mode-alist '("\\.Snw\\'" . Rnw-mode))
>
>    > ;; Make TeX and RefTeX aware of rnw and Rnw files
>    > (setq reftex-file-extensions
>    >       '(("rnw" "Rnw" "tex" ".tex" ".ltx") ("bib" ".bib")))
>    > (setq TeX-file-extensions
>    >    '("rnw" "Rnw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))
>    > ------------------------------------------------------------------------------------------------------------
>
>    > When I use C-c = the files are not found (I set the variable
>    > reftex-toc-include-file-boundaries to see the name of every file in the TOC) :
>
>    > output (see below for the structure of my files ) :
>    > -------------------------------------------------------------------------------------------------------------
>    >  File main.rnw starts here
>    >      1 Introduction
>    >  File file2 was not found
>    >      2 Conclusion
>    >  File main.rnw ends here
>
>    > --------------------------------------------------------------------------------------------------------------
>    > My main file : main.rnw
>    > ---------------------------
>    > \begin{document}
>    >   \section{introduction}
>
>    >    \SweaveInput{addfile1.rnw}
>    >     \include{addfile2.tex}
>
>    >     \section{conclusion}
>    > \end{document}
>    > ;;; Local Variables: ***
>    > ;;; TeX-master: t ***
>    > ;;; End: ***
>    > --------------------------------
>
>    > My file included with \SweaveInput : addfile1.rnw
>
>    >  \section{addfile1}
>
>    > <<plot1,echo=TRUE>>=
>    > plot(1:10)
>    > @
>    > %%% Local Variables:
>    > %%% TeX-master: "main.rnw"
>    > %%% End:
>
>    > ------------------------------------------------
>
>    > My file included with \Include : addfile2.tex
>
>    >   \section{addfile2}
>
>    > %%% Local Variables:
>    > %%% TeX-master: "main.rnw"
>    > %%% End:
>
>    > When I use C-c = the files are not found.
>
>    >  File main.rnw starts here
>    >      1 Introduction
>    >  File file2 was not found
>    >      2 Conclusion
>    >  File main.rnw ends here
>    > -------------------------------------------------------------------------------------------------------------
>
>    > If I comment the reftex-file-extensions line :
>
>    > ;; Make TeX and RefTeX aware of Snw and Rnw files
>    > ;;(setq reftex-file-extensions
>    > ;;      '(("rnw" "Rnw" "tex" ".tex" ".ltx") ("bib" ".bib")))
>    > (setq TeX-file-extensions
>    >    '("rnw" "Rnw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))
>
>    > ------------------------------------------------------------------------------
>    > When I use C-c = addfile2.tex is found but not the addfile1.rnw :
>    > ------------------------------------------------------------------------------
>    > output :
>    > -----------
>    > File main.rnw starts here
>    >      1 Introduction
>    >  File addfile2.tex starts here
>    >       2 addfile2
>    >  File addfile2.tex ends here
>    >       3 conclusion
>    >  File main.rnw ends here
>    > -------------------------------------------------------------------------------
>
>    > So, I try to set the variable  reftex-file-include-commands to ("include"
>    > "input" "SweaveInput"), but it doesn't work.
>
>    > I have been searching for a day (I don't know very well emacs-Auctex-Reftex).
>
>    > Thank you very much for your help.
>
>    > Best regards
>    > Laurent
>
>    > ______________________________________________
>    > ESS-help at r-project.org mailing list
>    > https://stat.ethz.ch/mailman/listinfo/ess-help
>
>
Hi Vitalie,

   First of all, thank you very, very much for your answer. Since there 
were no answer to my question I thought that I had disturbed the mailing 
list (I thought it was not the good place for my question) and I was a 
little confused !

For my problem, I finally understood that reftex requires the file name 
to end with .tex whereas latex works with \input command 
(\input{file.tex} works) but not with \include command 
(\include{file.tex} doesn't work). So, I decided to work only with the 
\input command giving the name of the file with the .tex extension. If I 
have to use the \include command I write it twice :
\include{file} : in order to include the file
\include{file.tex} : it doesn't include the file but reftex works.

I set the variable reftex-file-include-commands to ("include" "input" 
"SweaveInput") as you say, and the variable 
reftex-toc-include-file-boundaries to t in order to see the names of 
every slave file in the TOC, I find that is very convenient.

All work fine when I am in the master file but when I am :

1. in a .rnw file, C-c = shows only the sections of the .rnw file :

  File testrnw.rnw starts here
      1 section 1 testrnw.rnw file
  File testrnw.rnw ends here

The end of my testrnw.rnw file :

%%% Local Variables:
%%% TeX-master: "masterfile.rnw"
%%% End:

2. in a .tex file, C-c = shows all the sections of every slave file but 
the variable reftex-toc-include-file-boundaries doesn't work for the 
.rnw files. There is no longer the sentences : "File testrnw.rnw starts 
here" and  "File testrnw.rnw ends here" but we see the sections.


Also, don't forget to type r to refresh the toc in the toc buffer to see 
the good result of the C-c = command during the tests !

Thanks,
Laurent



More information about the ESS-help mailing list