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

eMarch 1 : Add AucTeX local variables to your LaTeX file

trombineI 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"

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)

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).

Categories: emacs, LaTeX, Linux
  1. March 1, 2013 at 3:21 pm

    Kudos to you sir, for all the years I’ve used Linux I am still not comfortable using emacs.

    Maybe I should add that to my list.

  2. March 3, 2013 at 1:34 am

    That eval line is great. I’ve been splitting my tex files up, but they keep defaulting to dvi, which was kinda annoying. Do you AucTeX math mode shortcuts much? They seem pretty powerful, but honestly, a few YASnippets do the trick for me.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: