emacsd / init-auctex.el

;;; init-auctex.el
;; Copyright (C) Yagnesh Raghava Yakkala.
;;    File: init-auctex.el
;; Created: Tuesday, August  2 2011
;; License: GPL v3 or later.
;; You should get a copy from <>

;;; Description:

(add-to-list 'load-path "~/.emacs.d/el-get/auctex/preview/")
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)

(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)

(add-hook 'LaTeX-mode-hook
            (define-key LaTeX-mode-map (kbd "<M-.>") 'TeX-complete-symbol)
            (TeX-PDF-mode t)
            (setq TeX-save-query  nil )
            (setq TeX-master (guess-TeX-master (buffer-file-name)))
            (setq TeX-show-compilation t) ; show the compilation buffer

(add-hook 'LaTeX-mode-hook
          (lambda ()

;; from emacs wiki
(defun guess-TeX-master (filename)
  "Guess the master file for FILENAME from currently open .tex files."
  (let ((candidate nil)
        (filename (file-name-nondirectory filename)))
      (dolist (buffer (buffer-list))
        (with-current-buffer buffer
          (let ((name (buffer-name))
                (file buffer-file-name))
            (if (and file (string-match "\\.tex$" file))
                  (goto-char (point-min))
                  (if (re-search-forward
                       (concat "\\\\input{" filename "}") nil t)
                      (setq candidate file))
                  (if (re-search-forward
                        "\\\\include{" (file-name-sans-extension
                                        filename) "}") nil t)
                       candidate file))))))))
    (if candidate
         "TeX master document: %s" (file-name-nondirectory candidate)))

;;; auto completion support
(defun ac-latex-mode-setup ()         ; add ac-sources to default ac-sources
  (setq ac-sources
           ac-source-latex-commands  ac-source-math-unicode)

(add-hook 'LaTeX-mode-hook
          (lambda ()
            (require 'ac-math)

;;; init-auctex.el ends here