# RefTex Multiple files problems

I have multi files and each file refers to the master file properly and the document can be compiled without problems .... RefTeX can only refer to the environments , figures, equations, etc when it is stated in the master file ... rather than this C-c ) can't see the other labels in any other file than the master ... kindly advise.

The following are the minimal files

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

\documentclass{book}
\begin{document}
\chapter{chapter 1 }
\label{cha:chapter-1}
\ref{cha:chapter-1}

\end{document}


and the second file slave.tex

\chapter{Chapter 2 }
\label{cha:chapter-2}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% End:


init.el

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-save-query nil)
(setq TeX-PDF-mode t)
(setq-default TeX-master nil)
(require 'tex-site)
(setq reftex-enable-partial-scans t)
(setq reftex-save-parse-info t)
(setq reftex-use-multiple-selection-buffers t)
(setq reftex-plug-into-AUCTeX t)
(autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
(autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
(autoload 'reftex-label "reftex-label" "Make label" nil)
(autoload 'reftex-reference "reftex-reference" "Make label" nil)
(autoload 'reftex-citation "reftex-cite" "Make citation" nil)
(autoload 'reftex-index-phrase-mode "reftex-index" "Phrase Mode" t)
(add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
(setq LaTeX-eqnarray-label "eq"
LaTeX-equation-label "eq"
LaTeX-figure-label "fig"
LaTeX-table-label "tab"
LaTeX-myChapter-label "chap"
TeX-auto-save t
TeX-newline-function 'reindent-then-newline-and-indent
TeX-parse-self t
TeX-style-path
'("style/" "auto/"
"/usr/share/emacs21/site-lisp/auctex/style/"
"/var/lib/auctex/emacs21/"
"/usr/local/share/emacs/site-lisp/auctex/style/")
LaTeX-section-hook
LaTeX-section-title
LaTeX-section-toc
LaTeX-section-section
LaTeX-section-label))
"latex"
"cleveref"
(lambda ()
(if (boundp 'reftex-ref-style-alist)
'reftex-ref-style-alist
'("Cleveref" "cleveref"
(("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
'("cref" TeX-arg-ref)
'("Cref" TeX-arg-ref)
'("cpageref" TeX-arg-ref)
'("Cpageref" TeX-arg-ref)))))
(require 'predictive)
(setq predictive-main-dict 'rpg-dictionary
predictive-auto-learn t
predictive-use-auto-learn-cache nil
predictive-which-dict t)

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(TeX-source-correlate-method (quote synctex))
'(TeX-source-correlate-start-server t)
'(TeX-view-program-list (quote (("Okular" "okular -unique %o#src:%n%b"))))
'(TeX-view-program-selection (quote ((output-pdf "Okular") ((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "Evince") (output-html "xdg-open"))))
'(inhibit-startup-screen t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.


The reference only can see the labels in the master file , and C-c ) when invoked from the slave.tex can't recognize the label to the chapter in the same file..... ;; If there is more than one, they won't work right. )

Edit 1: Forgot to mention that I import and include the slave into the master file. It is pretty complex on my side as with this minimal file, I am able to reference whatever exists in master only or slave only. On the main document I am building, I am able to reference only whatever is in the master!

Edit 2: The problem was mainly due to using \import to include the files rather than \input. I noticed also that there is a need to reset RefTex every time I try to add a new file. I will try also to check \cite and whether it is updated in the new scheme. I will also keep using the init.el that you sent... again thanks a lot Jon and I do appreciate this feedback and resolution very much...

• Is user33833 = mosalem2003? – dustin Jul 18 '13 at 16:26
• @mosalem2003 -- You don't need to use the init.el file I included in my answer below: I only included it to show that the answer will even work with your original init file (myinit.el is identical except for all the predictive stuff, which I don't have on my computer). One other point, if my answer resolved the problem in your opinion, you should click on the checkmark beside the answer to mark it as 'resolved'; you can additionally 'upvote' it if you like, but marking the problem as solved gets this question off the unanswered list. – jon Jul 19 '13 at 14:48

The basic problem is that the masterfile does not actually make any reference to the supposed sub-file, so it is impossible for any program to know it needs to think about a masterfile-subfile relationship. In AUCTeX' case, parsing kind of works from the subfile because it has a variable informing AUCTeX of the masterfile (but you'll note that AUCTeX/RefTeX do not parse the subfile itself, so it is hardly that useful).

But things work as expected if you do \include or \input a file in the subfile. E.g.:

masterfile.tex

\documentclass{book}
\begin{document}
\chapter{chapter 1}
\label{cha:chapter-1}

\input{subfile}% <-- crucial!

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


subfile.tex

\chapter{Chapter 2}
\label{cha:chapter-2}
\label{anotherlabel}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "masterfile"
%%% End:


Now C-c ) <SPC> should give a list of (in this case) three labels. This will even work with the init file provided above, although I had to comment out a few things. You can use the following to test (assuming the provided file is called myinit.el):

emacs -q -l myinit.el masterfile.tex


myinit.el

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-save-query nil)
(setq TeX-PDF-mode t)
(setq-default TeX-master nil)
(require 'tex-site)
(setq reftex-enable-partial-scans t)
(setq reftex-save-parse-info t)
(setq reftex-use-multiple-selection-buffers t)
(setq reftex-plug-into-AUCTeX t)
(autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
(autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
(autoload 'reftex-label "reftex-label" "Make label" nil)
(autoload 'reftex-reference "reftex-reference" "Make label" nil)
(autoload 'reftex-citation "reftex-cite" "Make citation" nil)
(autoload 'reftex-index-phrase-mode "reftex-index" "Phrase Mode" t)
(add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
(setq LaTeX-eqnarray-label "eq"
LaTeX-equation-label "eq"
LaTeX-figure-label "fig"
LaTeX-table-label "tab"
LaTeX-myChapter-label "chap"
TeX-auto-save t
TeX-newline-function 'reindent-then-newline-and-indent
TeX-parse-self t
TeX-style-path
'("style/" "auto/"
"/usr/share/emacs21/site-lisp/auctex/style/"
"/var/lib/auctex/emacs21/"
"/usr/local/share/emacs/site-lisp/auctex/style/")
LaTeX-section-hook
LaTeX-section-title
LaTeX-section-toc
LaTeX-section-section
LaTeX-section-label))
"latex"
"cleveref"
(lambda ()
(if (boundp 'reftex-ref-style-alist)
'reftex-ref-style-alist
'("Cleveref" "cleveref"
(("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
'("cref" TeX-arg-ref)
'("Cref" TeX-arg-ref)
'("cpageref" TeX-arg-ref)
'("Cpageref" TeX-arg-ref)))))
;; NOTE: the following lines are commented out:
;; (require 'predictive)
;; (setq predictive-main-dict 'rpg-dictionary
;;      predictive-auto-learn t
;;      predictive-use-auto-learn-cache nil
;;      predictive-which-dict t)

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(TeX-source-correlate-method (quote synctex))
'(TeX-source-correlate-start-server t)
'(TeX-view-program-list (quote (("Okular" "okular -unique %o#src:%n%b"))))
'(TeX-view-program-selection (quote ((output-pdf "Okular") ((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "Evince") (output-html "xdg-open"))))
'(inhibit-startup-screen t))
;(custom-set-faces <-- COMMENTED; otherwise file won't load properly
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.