[Tex/LaTex] How is \documentclass an “Undefined control sequence”

auctexinput-encodings

I'm using AUCTeX 11.90 on emacs (recently upgraded from elpa packages) running on Windows 7. I've created a tex file and for some reason only this one particular file gives error msgs when I compile it with pdflatex (C-c C-c): "Undefined control sequence" pointing at \documentclass[10pt]{article} How is this even possible?

I suspected some encoding conflict so I started the 1st line of the document (which btw is the result of an org file export) with: % -*- coding: utf-8; -*-

The problem nevertheless persisted. The bottom part of emacs' buffer now looks like this:

U in left-most corner of buffer


EDIT 1

Here are the first few lines from the file's log (ccna1-ch10.log):

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/W32TeX) (preloaded format=pdftex 2015.6.28)  23 MAY 2017 21:49
entering extended mode
 restricted \write18 enabled.
 file:line:error style messages enabled.
 %&-line parsing enabled.
**\input ./ccna1-ch10.tex
(./ccna1-ch10.tex
./ccna1-ch10.tex:2: Undefined control sequence.
l.2 \documentclass
                  [10pt]{article}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

Does this make sense? It stops right at the beginning, won't even go beyond \documentclass[...]{article}. May it have something to do with the .emacs file?

Best Answer

The reason for this problem, as Werner told you in his comment, is, that you are running TeX instead of LaTeX. You can advise emacs to automatically run LaTeX. To do so, you should have a look at the local variable comments of the file. They should look, e.g., like:

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

The first and the list line are only magic markers. The second line tells emacs to use the latex mode. The third line tells AucTeX, that the file itself is the main file of the document.

If your file does not have such a section, add it. If the mode line differs, change it.Then save the file and press Strg+C, Strg+N (in emacs syntax C-c C-n) or close it and load it again.

After this, C-c C-c should run LaTeX instead of (plain)TeX.

If this does not help, you can set the mode manually using M-x latex-mode.

Related Question