Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have lots of LaTeX files, and my AucTeX has been set up to automatically open up all *.tex files in LaTeX-mode. But more recently I've started using ConTeXt, and for those files (which also end in .tex) I'd like to use ConTeXt-mode. Is there any way of embedding something in the file which will tell Emacs to open up the correct mode?

I can start a file with, for example

-*- mode: context; -*-

which works well, but even if it's the very first line in the file, ConTeXt still parses it and writes it to the output, although it comes way before \starttext.

Does anybody have any better suggestions? I suppose the sensible thing would be to move all ConTeXt files into one directory tree, and set up a .dir-locals.el file in that directory, which would tell Emacs to open up all .tex files using ConTeXt mode. But I'd still like to be able to do it on a file-by-file basis.

FWIW, I'm using Linux.

Thanks!

share|improve this question
6  
By the way: are there really no acceptable answers for all the 8 questions you have asked up to now? If there are, please click the accept button on the best answer each (it's the checkmark like symbol below the up/down icons). –  Paŭlo Ebermann Mar 19 '11 at 1:17

2 Answers 2

up vote 4 down vote accepted

Can't you simply put a % in front of this line?

I'm using this in the last some lines of my files, for example.

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

But

% -*- mode: context; -*-

in the first line should work, too.

share|improve this answer

As an alternative to manually setting the mode file local variable (which is preferred because it does not rely on heuristics), AucTeX automatically recognizes the TeX format! It knows about LaTeX (detected via \documentclass), ConTeXt (detected via \starttext) and Plain TeX. For example, you can do the following:

  1. Create a file abc.tex. AucTeX starts in LaTeX mode by default.
  2. Enter \starttext.
  3. Hit C-c C-n to force reparsing of the buffer.
  4. AucTeX automatically detects that you plan to write a ConTeXt document and switches to ConTeXt mode.
  5. Hit M-x add-file-local-variable RET mode RET RET to add the mode as a file-local variable. Then the file will always trigger ConTeXt mode even if the auto-recognition fails.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.