Compiler Error with Emacs

When I compile my document with latex on the terminal, there is no problems. Everything is fine. However, When I try it via Emacs (Cntrl C-C, which makes a call to Latex) I get the folowing error saying:

Missing \begin{document}


I'm a little confused. What happens?

Here is an example:

\documentclass[onecolumn,amsmath,amssymb,aps,pra,floatfix,]{revtex4-1}
\usepackage[utf8]{inputenc}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{float}
\usepackage[tight,footnotesize]{subfigure}
\usepackage{color}
\begin{document}
\title{Title}
% \author{Totoro}
\date{\today}
\maketitle

\section{Introduction}

We consider the simplified equation of motion.

\end{document}


Here how it looks like:

As I said, compiling the document with latex from a terminal works fine. Normally, I use Emacs for editing and compiling. So this strange behavior is extremly inconvient!

-
What route are you using from the command line? And what is the key binding '\C-c\C-c' set to? Is it running the same command your calling from the command line? – A.Ellett Jan 13 at 5:03
If, when you write your document, you use multiple files, it could be the case that you're trying to compile from a file which is not the master file. – A.Ellett Jan 13 at 7:24
We really need a minimal (not) working example here. On a well-formed document, what you describe should work. – Tyler Jan 13 at 13:14
Your MWE works for me both on the command line and when called from emacs. I'd have to say that problem probably has something to do with the way you've configured emacs (custimizations etc.). You might have some stray mark in your file that you didn't copy into the above MWE that is getting in the way. Sorry I can't help you more. – A.Ellett Jan 13 at 18:09
Re @A.Ellett: You can add some lines at the end of the (La)TeX file to tell it where the master is. It is 4 lines: %%% Local variables://%%% mode: latex//%%% TeX-master: masterfile//%%% End: (the "//" represent newlines). For the masterfile, it says t instead of its name. – vonbrand Jan 19 at 1:58
show 1 more comment