# Changing AUCTeX viewer results in errors claiming TeX-engine is wrongly set, although it is set correctly

This question was completely rewritten, see the previous version.

I have this XeLaTeX file:

\documentclass{article}
\usepackage{fontspec}

\begin{document}
\thispagestyle{empty}
\pagestyle{empty}

äätewää--llll
\end{document}


which produces the (intended) image when compiled with C-c C-a:

my init.el used for that is:

(require 'package)
("melpa" . "http://melpa.milkbox.net/packages/")
))
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar tmtxt/packages
'( auctex))
(dolist (p tmtxt/packages)
(when (not (package-installed-p p))
(package-install p)))

(setq-default TeX-engine 'xetex)
(setq-default TeX-PDF-mode t)


all the above is expected so far

However, if i change my init.el to use a different viewer (latex-preview-pane-mode):

(require 'package)
("melpa" . "http://melpa.milkbox.net/packages/")
))
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar tmtxt/packages
'( auctex))
(dolist (p tmtxt/packages)
(when (not (package-installed-p p))
(package-install p)))

(setq-default TeX-engine 'xetex)
(setq-default TeX-PDF-mode t)

(custom-set-variables
'(TeX-view-program-list
(quote (("preview-pane-mode" latex-preview-pane-mode))))

'(TeX-view-program-selection
(quote
(((output-dvi has-no-display-manager)
"dvi2tty")
((output-dvi style-pstricks)
"dvips and gv")
(output-dvi "xdvi")
(engine-omega "Atril")
(output-pdf "preview-pane-mode")
(output-html "xdg-open"))))
)


i receive with the same XeLaTeX source as above the following error:

!...............................................
! For immediate help type H <return>.
!
! See the fontspec documentation for further information.
!
! instead of plain "latex" or "pdflatex".
! You must change your typesetting engine to, e.g., "xelatex" or "lualatex"
!
! The fontspec package requires either XeTeX or LuaTeX to function.
!
! Fatal fontspec error: "cannot-use-pdftex"
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

• What command have you bound to C-c a? That key combination is not bound in standard auctex – it is reserved for private keybindings. (Same with C-c followed by any letter.) Also, do check that the variable is really set as you wanted it to. Use C-h v for this. – Harald Hanche-Olsen Apr 16 '16 at 12:04
• Ah, sry. I confused the keybinding, I meant C-c C-a (TeX-command-run-all). But i don't know where I have that keybinding from (I didn't define it in my init.el), I've read that probably on the internet somewhere. The variable TeX-engine is set when I open a tex file. – toogley Apr 16 '16 at 14:05
• Additionally: I've made a small but important error in my tex source code - However the given error message is still correct. – toogley Apr 16 '16 at 14:32
• Ah, the C-c C-a keybinding is standard with auctex. I am not sure what you are saying about TeX-engine. Can you check its value after opening the TeX file, in the TeX file's buffer? Just in case some hook goes and changes it buffer-locally or something. – Harald Hanche-Olsen Apr 16 '16 at 15:06
• C-c C-c executes the command returned by the expansion of %(latex). I really can't understand what's the problem. You should provide a full recipe to reproduce your problem starting from emacs -Q, otherwise it'll very difficult for anyone to help you. – giordano Apr 16 '16 at 15:48