Home > emacs, LaTeX, Linux > eMarch 1 : Add AucTeX local variables to your LaTeX file

I just thought about a fancy way to present some of my favorite emacs tips. So every Friday of marsh, I’ll try to give an emacs tips I like.

English is obviously not my maternal tongue, so I really need some word spelling software. When I first started using LaTeX with emacs, I thought that this was impossible. I was really wrong, in fact if ispell and FlySpell you can have a first help against misspelling. Type in emacs M-x Flyspell-mode. In order to change the dictionnary, type M-X change-dictionnary and choose the correct language.

Second point, if you really want to take advantage of LaTeX power, you should split your source in several files, that will be called from a “main” or “master ” file which in turn have the “\include” instruction to include each of your file. With this scheme, if you edit one file and want to check your output, you should always compile (from) the main file. AucTeX, allow you to declare the master file from its menu (command, Master File).  Then, when you  compile your source code, no matter which file you are visiting, the master file will be compiled.

Now the awesome tips, an even better way to proceed is to add local variables to the end of each of your latex file. Like this :

```%%%Local Variables:
%%%TeX-master: "MasterDocument"
%%%End:```

The latter indicate that the file “MasterDocument.sty”, is the master file to compile and from which the actual file will be called. Likewise, the following code :

```%%%Local Variables:
%%% mode: latex
%%% eval: (TeX-PDF-mode 1)
%%% ispell-local-dictionary: "en_US"
%%% eval: (flyspell-mode 1)
%%%End:```

Will ask AucTeX to use pdfTeX for compilation and to switch to the “en_US” dictionary, with flyspell mode enabled by default, every time you open your file.

Note since emacs 24.1 you should use eval to use the Tex-PDF Minor-mode (earlier version allowed the ” %%% mode: Tex-pdf ” syntax).