# Forward search from dependent file, b/w emacs and Sumatra on Win7?

I have GNU Emacs 24.4.1 (i686-pc-mingw32) with AUCTeX 11.88.9. In a recent document, I've noticed that the forward search (source to pdf) from a file that has been included in main.tex via the \input command, does not take me exactly to the corresponding line in the output pdf file. Indeed, if I type C-c C-v in the dependent file, emacs says "there's no dependent.pdf".

I've also noticed that the preview-latex feature of AUCTeX does NOT work if I call it from inside the dependent file. Only if I type C-c C-p C-s from main.tex, the math expressions are correctly visualized in the dependent file.

It seems the Forward search is somehow disconnected. The Backward search (pdf to source), on the other hand, works fine – if I double-click a line in the pdf, I'm taken to the dependent file without any trouble.

I have copy/pasted the following lines in my .emacs file from this well-known discussion in StackOverflow:

(setq TeX-PDF-mode t)
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list
'(("Sumatra PDF" ("\"C:/Program Files/SumatraPDF/SumatraPDF.exe\" -reuse-instance"  (mode-io-correlate " -forward-search %b %n ") " %o"))))

'(progn
(assq-delete-all 'output-pdf TeX-view-program-selection)


I don't know if I should post this question in the TeX.SX but I wouldn't know where else to find a better crowd, skilled both in elisp and LaTeX.

PS. Given this other question, it seems I'm not the only one with this problem, except I'm not using arara.

## SNAPSHOTS

I think AUCTeX is working in my emacs, otherwise I wouldn't have these menus and toolbars with a tex file open, right?

List of local variables as they appear at the bottom of the dependent file.

• Did you set master file inside included files? – giordano Nov 1 '15 at 20:03
• Yes, I have %%% Local Variables:, %%% mode: latex, %%% TeX-master: main.tex and finally %%% End: in successive lines, at the bottom of the dependent file. However I have noticed that everytime I open the dependent file w/o opening main.tex, emacs warns me: "The local variable list in dependent.tex contains values that may not be safe ( * ). Do you want to apply it? You can type 'y' to apply the local variables list, 'n' to ignore the local variable list. '!' to apply the local variables list, and permanently mark these values (*) as safe. mode: latex, ( * )TeX-master: main\.tex" – WobblyWindows Nov 2 '15 at 9:40
• Are you sure you're using AUCTeX? That message usually pops out when you try to open with Emacs' built-in TeX mode a TeX file which has AUCTeX's local variables. – giordano Nov 2 '15 at 10:16
• I think I am using AUCTeX and RefTeX. Maybe I need to set '!' next time it asks me that question. Perhaps once it's a permanent value it will correctly implement Forward search from a dependent file. I don't know, I'm just speculating here. How can I check whether I'm using AUCTeX or emacs' in-built TeX mode? Do I have to add any code-lines in the .emacs configuration file? – WobblyWindows Nov 2 '15 at 18:05
• I started learning Elisp just to understand how AUCTeX works and improve it. Looking at its code is a good exercise: it's a large package but easy to read. And Elisp is a very nice language, also because is very well documented: you find a function or a variable you don't know and you can immediately read their documentation with C-h f or C-h v without the need to randomly look up for the on the Internet. – giordano Nov 3 '15 at 10:13

The problem was you didn't set properly the master file. In included files, TeX-master variable should be a string with the relative path to the main file without extension (yes, that's a bad limitation). But usually you don't have to set TeX-master manually: following the suggestions of the very first lines of the AUCTeX manual add the following lines to your init file
(setq TeX-parse-self t)       ; Enable parse on load.

Actually, to solve this problem you only need the last line, but the two others are necessary if you want to exploit all AUCTeX's features. By setting TeX-master to the default value of nil, every time you open a new *TeX file you'll be prompted to select the master file and AUCTeX will set the right value for the variable (t if the master file is the file you're viewing, the quoted relative path to the master file otherwise).
In addition, you can set the master file using AUCTeX built-in completion with C-c _ (bound to M-x TeX-master-file-ask RET).