[Tex/LaTex] Annoying emacs autoformatting in LaTeX mode

emacs

Typing, for example,

a^3

emacs would automatically change the source (!) to

This causes all sorts of problems with spacing, double superscripts, etc.

How can I turn off any such WYSIWYG behaviour?

Here is a LaTeX example (copy-paste from emacs)

\begin{equation}
  E(M) =  \pm 2\sqrt{\epsilon_0² + 16 t²-8t\epsilon_0}
\end{equation}

If I look at the file with more, I have for the same equation

\begin{equation}
  E(M) =  \pm 2\sqrt{\epsilon_0<B2> + 16 t<B2>-8t\epsilon_0}
\end{equation}

Best Answer

Emacs will never automatically change the source. Your issue is either fontification, in which case you should be seeing a superscript caret '^' as well as the superscript '3', or you have enabled preview mode, which displays the LaTeX output of math environments in your buffer.

In the first case, assuming you are using Auctex (the recommended LaTeX editing environment), you can turn off fontification for scripts in the customization system:

M-x customize-variable font-latex-fontify-script <RET>

Then set the value to off or nil, and fontification will no longer apply to superscripts.

If you don't see the little caret, then you must have preview mode on. You should be able to remove all previews from the buffer using the preview menu on the menu bar, or by calling M-x preview-clearout-document. If you do have preview mode on, take a look at your .emacs and remove the line that is loading it.