AUCTeX

From the introduction in the AUCTeX manual:

AUCTeX is a comprehensive customizable integrated environment for writing input files for TeX/LaTeX/ConTeXt/Texinfo using Emacs or XEmacs.
It lets you process your source files by running TeX and related tools (such as output filters, post processors for generating indices and bibliographies, and viewers) from inside Emacs. AUCTeX lets you browse through the errors TeX reported, while it moves the TextCursor directly to the reported error, and displays some documentation for that particular error. This will even work when the document is spread over several files.
One component of AUCTeX that LaTeX users will find attractive is preview-latex, a combination of folding and in-source previewing that provides true “What You See Is What You Get” experience in your sourcebuffer, while letting you retain full control. preview-latex comes with its own manual.
AUCTeX automatically indents your ‘LaTeX-source’, not only as you write it – you can also let it indent and format an entire document. It has a special outline feature, which can greatly help you ‘getting an overview’ of a document.
Apart from these special features, AUCTeX provides a large range of handy Emacs macros, which in several different ways can help you write your documents fast and painlessly.

AUCTeX’s home page can be found at http://www.gnu.org/software/auctex/ and there is a summary project page on Freshmeat at http://freshmeat.net/projects/auctex/.

C-c C-c to run LaTeX over your document, then, once it has compiled correctly, C-c C-c again to view it, or if it failed to compile correctly, C-c ` to see the errors.

If you use XEmacs, AUCTeX and MikTeX on Windows you may run into the problem that firing the command C-c C-c leads to the ErrorCantFindFile.

It works well with RefTeX (there is an option in RefTeX to plug it in into AUCTeX).

Using Yap under MikTeX

To use yap as viewer put this into ~/.emacs to enable MikTeX integration.

    (load "auctex.el" nil t t)
    (require 'tex-mik)

Inverse searching using YAP can be enabled if you go to View\Options\Inverse DVI Search. Add a new entry for emacs, specify the path to emacsclientw, "C:\Program Files\Emacs\emacs\bin\emacsclientw.exe" (no quotes required), and the arguments for emacsclientw, '+%l "%f"' (no single quotes, but include the double quotes).

Customary Customization

To edit LaTeX documents, you will probably want to include the following in your ~/.emacs.

    (setq TeX-auto-save t)
    (setq TeX-parse-self t)
    (setq-default TeX-master nil)
    (add-hook 'LaTeX-mode-hook 'visual-line-mode)
    (add-hook 'LaTeX-mode-hook 'flyspell-mode)
    (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
    (add-hook 'LaTeX-mode-hook 'turn-on-reftex)
    (setq reftex-plug-into-AUCTeX t)

You may prefer auto-fill-mode instead of visual-line-mode.

preview-latex

preview-latex (also known as PreviewLaTeX) is an integrated part of AUCTeX as of version 11.80, which allows you to see previews of math, figures, tables, graphics and other things directly in an Emacs 21 buffer. It was released separately in the past, but always required AUCTeX to run.

CDLaTeX

CDLaTeX is a minor mode, supporting fast insertion of environment templates and math stuff in LaTeX, written by CarstenDominik. CDLaTeX tries to be quick, with very few and easy to remember keys, and intelligent on-the-fly help. As a minor mode, you can use it in AUCTeX.

PDFLaTeX

To compile documents to PDF by default add the following to your ~/.emacs.

    (setq TeX-PDF-mode t)

If it doesn’t work, try this :

    (require 'tex)
    (TeX-global-PDF-mode t)

SwifTeX

SwifTeX (by the author of !docTeX, the mode for editing self-documenting LaTeX code) is derived from the LaTeX mode in “tex-mode.el” (distributed with Emacs) using the autoloaded function `define-derived-mode'. It has untested option to derive from AUCTeX’s LaTeX-mode.

Synchronize with Zotero

Zotero is an excellent bibliography manager. With zotexo.el you can associate a zotero collection with your .tex file and make it automatically synchronize with zotero.

Add-Ons

pstricks.el has been added to the latest auctex cvs version with some changes to make it work better. (2009-06-25)

TeX Documentation

C-c ? (or M-x TeX-doc) gives documentation for the symbol at point, or for any package, command or document.

On my system (MacTeX 2008, Aquamacs) I can only get documentation for packages, it seems. Does anyone know how to set up AUCTeX so that we get a more emacs-lisp-like documentation system? (Eg., documentation for every TeX command, from \emph{} to \citep{} to \operatorname{} …)

I also wish I could access a more emacs-lisp-like documentation system.

Well, I guess this won’t be as naturally done as in elisp. But there is latex-doc package that tries to do that. See: http://www.ee.usyd.edu.au/~thlai/emacs/index.html

Latex2e-help-texinfo comes with latex documentation in .info format http://www.ctan.org/tex-archive/info/latex2e-help-texinfo/. It also contains ltx-help.el which defines latex-help function. I’ve just put latex2e.info in my info directory following the instructions on info installation from emacs FAQ. Put ltx-help.el in my .emacs.d. Then corrected slightly the reg expressions in latex-help-get-cmd-alist function to recognize all the entries in the doc index and oala, help of all latex commands is under my fingertips (C-c i to be more specific). Here is the version of latex-help-get-cmd-alist function which worked for me:

  (defun latex-help-get-cmd-alist () ;corrected version:
  "Scoop up the commands in the index of the latex info manual.
   The values are saved in `latex-help-cmd-alist' for speed."
    ;; mm, does it contain any cached entries
    (if (not (assoc "\\begin" latex-help-cmd-alist))
        (save-window-excursion
  	(setq latex-help-cmd-alist nil)
  	(Info-goto-node (concat latex-help-file "Command Index"))
          (end-of-buffer)
          (while (re-search-backward "^\\* \\(.+\\): *\\(.+\\)\\." nil t)
            (setq key (ltxh-buffer-substring (match-beginning 1) (match-end 1)))
            (setq value (ltxh-buffer-substring (match-beginning 2) (match-end 2)))
            (setq latex-help-cmd-alist
                  (cons (cons key value) latex-help-cmd-alist))))
      )
    latex-help-cmd-alist
    )

PS: quite surprised though, latex-help is not integrated in auctex. Did I miss something?

Another change seems to be required in the latex-help function, since try-completion returns the actual match in case of a partial match, but only t in case of a perfect match. This causes ltx-help to sometimes land on the top page, instead of the actual target node. Changed the let* in latex-help as follows (ugly, but seems to work). Feedback appreciated.

    (let* ((cw (latex-help-guess))
	   (cww (concat "\\" cw))
	   (cmd-alist (latex-help-get-cmd-alist))
           ; changes start here
           (node (try-completion cw cmd-alist))
           ; try-completion returns actual string in case of partial match
           ; but returns t in case of exact match
           (nodename1 (if (equal node t) cw node))
           (nodename2 (if (equal nodename1 nil) 
                          (try-completion cww cmd-alist) nodename1))
	   (guess (cond ((equal nodename2 t) cww)
                        ((equal nodename2 nil) nil)
                        (t nodename2)))
           ; changes end here
	   (val (completing-read (if guess ...

Yes, InfoLook.

    (info-lookup-add-help
     :mode 'latex-mode
     :regexp ".*"
     :parse-rule "\\\\?[a-zA-Z]+\\|\\\\[^a-zA-Z]"
     :doc-spec '(("(latex2e)Concept Index" )
                 ("(latex2e)Command Index")))

Abbrev mode and AUCTeX

By default, AUCTeX shares its abbreviations with the major mode text-mode. This means that abbreviations saved with C-x a l (add-mode-abbrev) are saved in the table text-mode-abbrev-table and become available in all buffers using text-mode. This may not be the expected behavior. Here is how to define abbreviations that work in auctex modes only, without interfering with the standard text-mode. In the InitFile, put:

   (define-abbrev-table 'TeX-mode-abbrev-table (make-abbrev-table))
   (add-hook 'TeX-mode-hook (lambda ()
      (setq abbrev-mode t)
      (setq local-abbrev-table TeX-mode-abbrev-table)))

Abbrevs defined from a file in one of the auctex modes will then be stored in the default .abbrev_defs file using the table TeX-mode-abbrev-table instead of text-mode-table.

Autocomplete mode and AUCTeX

auto-complete-auctex gives a pretty interface to auctex completions using auto-complete.el and yasnippet.

Predictive Completion and AUCTeX

PredictiveMode integrates with AUCTeX “out-of-the-box”. It provides predictive completion for normal text, as usual. But when PredictiveMode is used in LaTeX-mode, in addition it provides context-sensitive predictive completion for LaTeX commands, environments, math commands, cross-reference labels, and more besides.

PredictiveMode also knows about a number of additional LaTeX packages, so if you include them in your document using LaTeX’s \usepackage command, PredictiveMode will automatically include commands from that package in the completions it offers. Adding support for new packages is often as easy as writing a list of the new commands, and generating an appropriately named dictionary from it. (The PredictiveMode user manual explains in more detail how to add support for new LaTeX packages; if you add support for a new package, consider contributing it so it can be included in the PredictiveMode package.)

In other words, PredictiveMode provides full “Intellisense” features for writing LaTeX documents in Emacs.

The following screen-shots show this in action, and also demonstrate some of the different (configurable) ways in which the possible completion candidates can be displayed.

PredictiveModeTooltip

PredictiveMode knows where the preamble of your document starts and ends, it knows where LaTeX expects an environment name, it knows where LaTeX expects text commands and where maths commands are required, and it will offer appropriate completions in each section (completions for LaTeX environments displayed here in a pop-up frame):

PredictiveModePopupFrame

The “completion browser” menu is particularly useful when hunting for that LaTeX command whose name you can’t quite remember:

PredictiveModeCompletionBrowser

LaTeX label definitions also are automatically recognized by PredictiveMode, so that completing within a cross-referencing command such as \ref only brings up valid labels:

PredictiveModeDynamicCompletion

Mathematical Symbols

LaTeX-math-mode

AUCTeX has a built-in way to enter math symbols quickly: see the Entering Mathematics section of the manual.

One downside is that it doesn’t insert Unicode symbols. This gist lets you define which symbols insert Unicode symbols, so e.g. ` a would insert α instead of \alpha.

Auto-Completion

Several ac-sources for the marvelous auto-completion package are available here.

https://ac-math.googlecode.com/svn/trunk/latex-symbols.png

It allows for a context dependent completion of LaTeX tags and unicode symbols. In order to make full use of unicode functionality you need to use unicode-math package.

Company-math

The author of ac-math provides ‘company-math’ (get source at Melpa or here) which is an alternative autocompletion using CompanyMode. It is also nice to display unicode math symbols in Emacs LaTeX documents which can be texed with XeTeX or LuaTeX using the unicode-math package (see company-math).

Anything and LaCarte for Math Input

LaCarte offers a great facility for navigating menus; Anything - fast display and reg-exp filtering. Combined and specialized for ‘Math’ sub-menu give a nifty symbol lookup and insertion mechanism.

AnythingLacarteMath

To make it work, install Anything and LaCarte and put this in your .emacs:

  (require 'anything-config)
  (require 'lacarte)
  (setq LaTeX-math-menu-unicode t)
  (define-key LaTeX-mode-map [?\M-`] 'anything-math-symbols)
  (defvar anything-c-source-lacarte-math
    '((name . "Math Symbols")
      (init . (lambda()
                (setq anything-c-lacarte-major-mode major-mode)))
      (candidates
       . (lambda () (if (eq anything-c-lacarte-major-mode 'latex-mode)
                        (delete '(nil) (lacarte-get-a-menu-item-alist LaTeX-math-mode-map)))))
      (action . (("Open" . (lambda (candidate)
   (call-interactively candidate)))))))
  (defun anything-math-symbols ()
    "Anything for searching math menus"
    (interactive)
    (anything '(anything-c-source-lacarte-math)
              (thing-at-point 'symbol) "Symbol: "
              nil nil "*anything math symbols*"))

If you are willing to have all other menus in your anything buffer and M-` global, install the Anything source http://www.emacswiki.org/emacs/AnythingSources#toc37 and put this in your .emacs:

  (global-set-key [?\M-`]     'anything-menus)
  (defun anything-menus ()
    "My anything for searching menus"
    (interactive)
    (anything '(anything-c-source-lacarte-math
                anything-c-source-lacarte)
               (thing-at-point 'symbol) "Menu item: "
               nil nil "*anything menu*"))

Smart quotes

For similar behavior in non-TeX-modes, see TypographicalPunctuationMarks.

By default, the ‘"’ key in AUCTeX is quite clever and inserts “``” and “''” according to context (which LaTeX converts to and ). The strings TeX-open-quote and TeX-close-quote holds the opening and closing sequences inserted and may be changed, e.g.,

    (setq TeX-open-quote "<<")
    (setq TeX-close-quote ">>")

Also, we can make the ‘"’ and ‘'’ keys even smarter by advising their functions:

Wrapping the region in double quotes

The command TeX-insert-quote, bound to ‘"’, inserts opening and closing quotes according to context. We can extend it to work with active regions too, so that if we have selected a word,

    this [word] is quoted

where ‘[’ and ‘]’ are the start and end of the region, hitting ‘"’ gives

    this ``word'' is quoted

The following defadvice, which employs skeletons, accomplishes this:

    (defadvice TeX-insert-quote (around wrap-region activate)
      (cond
       (mark-active
        (let ((skeleton-end-newline nil))
          (skeleton-insert `(nil ,TeX-open-quote _ ,TeX-close-quote) -1)))
       ((looking-at (regexp-opt (list TeX-open-quote TeX-close-quote)))
        (forward-char (length TeX-open-quote)))
       (t
        ad-do-it)))
    (put 'TeX-insert-quote 'delete-selection nil)

This also makes the ‘"’ key “move over” existing quotation marks. E.g., if point is at the beginning of ``word'', hitting " places it at the first letter.

Inserting and wrapping single quotes

It’s nice to have the same behavior for the ‘'’ key – inserting “`” or “'” according to context, and wrapping the region in single quotes:

    (defun TeX-insert-single-quote (arg)
      (interactive "p")
      (cond
       (mark-active
        (let ((skeleton-end-newline nil))
          (skeleton-insert
           `(nil ?` _ ?') -1)))
       ((or (looking-at "\\<")
            (looking-back "^\\|\\s-\\|`"))
        (insert "`"))
       (t
        (self-insert-command arg))))
    (add-hook 'LaTeX-mode-hook
              '(lambda ()
                 (local-set-key "'" 'TeX-insert-single-quote)))

Local variables

Local variables can be very useful, mostly when you are using non default settings. For example, if you are using xetex, on files encoded in unicode utf-8, with a master file named mymaster.tex, a local dictionary, and want to revert search you can add these lines at the very end of any file:

     \end{document}
     %
     % These lines tells gnu-emacs to typeset with the xetex engine
     % which requires Unicode encoding only (utf-8)
     % ^c^t^s for toggling synctex. 
     % ^-Shift-Click to move from pdf to source, Command-Shift-Click on OSX
     %%% Local Variables:
     %%% TeX-engine: xetex
     %%% TeX-source-correlate-method-active: synctex
     %%% ispell-local-dictionary: "francais"
     %%% coding: utf-8
     %%% TeX-master: "mymaster.tex"
     %%% End:

Automagic detection of master file

When editing a multifile document, it is necessary to set the TeX-master variable for AUCTeX and RefTeX to work properly. Whilst this can be done using file-local variables, it has the disadvantage of adding noise in your source files. An alternative is to add the following line to your LaTeX-mode-hook:

    (setq TeX-master (guess-TeX-master (buffer-file-name)))

Of course, you also need to define this guess-TeX-master function, for example with the following snippet:

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

Feel free to improve this function to suit your needs (for example by adding support for other forms of the the “include” syntax), but it works quite well for me. Note that it will return nil for files that do not get included in other files, which is the case for single file documents, or for the master files themselves. In this case, the TeX-master variable gets set to nil, which works.

Synctex and Zathura

AUCTeX 11.89.3+ has Zathura Pdf viewer ready in the TeX-view-program-selection. Just customize the output-pdf with Zathura instead of Evince. Verify that your Zathura implementation is compiled with WITH_SYNCTEX by testing the availability of the option --synctex-forward . The following command should not say that the option is unknown (some Linux distros do not include this option),

$ zathura --synctex-forward

Then with AUCTeX ‘Tex-Source-Correlate enabled’ (which corresponds to adding option --synctex=1 to the TeX engine) pdftex or xetex (or xelatex or whatever TeX engine) will create a ‘synctex pdf’ and a .synctex.gz file. Then, verify with a similar command

$ zathura --synctex-forward 1440:0:foo.tex foo.pdf

that zathura is open and that line 1440 is highlighted. Then Ctrl_left click the pdf on a different line or page; it should open emacs with buffer foo.tex positioned at the corresponding line 1440.

If it does not work, some indication below could help you.

The above command corresponds to the ‘forward’ mode or ‘synctex view’ which looks into file ‘foo.synctex.gz’ the position in the output foo.pdf corresponding to line 1440 and column 0 of input file ‘foo.tex’. You get this information with the command

$ synctex view -i 1440:0:foo.tex -o foo.pdf
This is SyncTeX command line utility, version 1.2
SyncTeX result begin
Output:foo.pdf
Page:38
x:221.279541
y:332.136200
h:117.828148
v:346.835083
W:441.891846
H:32.012672
before:
offset:0
middle:
after:
SyncTeX result end

Once you know the page number (38), the position x (221.279541) and y (332.136200), you can use the ‘backward’ mode with the ‘synctex edit’ command

$ synctex edit -o 38:221.279541:332.136200:foo.pdf
This is SyncTeX command line utility, version 1.2
SyncTeX result begin
Output:foo.pdf
Input:./foo.tex
Line:1440
Column:-1
Offset:0
Context:
SyncTeX result end

The above command retrieves the corresponding line (1440) of the source texfile (foo.tex) which will be opened by the editor. You can add the ‘-x editor command’ option corresponding to emacs

$ synctex edit -o 38:221.279541:332.136200:foo.pdf -x "emacsclient +%{line} %{input}"

The emacsclient should be installed and running. You can run it from emacs with the command “M-x server-start”.

If you have multiple emacs daemons running, use the following to make sure the emacsclient connects to the correct instance:

(add-to-list 'TeX-expand-list
             '("%sn" (lambda () server-name)))
(add-to-list 'TeX-view-program-list
             '("Zathura"
               ("zathura %o"
                (mode-io-correlate " --synctex-forward %n:0:%b -x \"emacsclient --socket-name=%sn --no-wait +%{line} %{input}\""))
               "zathura"))

Synctex and Evince

Recent versions of the document reader Evince (since 2.32) have support for backward search; i.e. you press Ctrl and the left mouse button within a PDF document to be taken back to the corresponding line of the .tex source file that generated the PDF. This requires synctex.

Since AUCTeX 11.87, enabling this feature is as easy as enabling TeX-source-correlate-mode. The following is only needed with older AUCTeX.

(Original solution due to Tassilo Horn: http://permalink.gmane.org/gmane.emacs.auctex.general/4074)

Evince works by sending a message via DBus that we can configure Emacs to pick up on. Unfortunately, the contents of the message seem to have changed somewhere between versions 2.32 and 3.2. The following code works for me with the newer version.

(require 'dbus)

(defun un-urlify (fname-or-url)
  "A trivial function that replaces a prefix of file:/// with just /."
  (if (string= (substring fname-or-url 0 8) "file:///")
      (substring fname-or-url 7)
    fname-or-url))

(defun th-evince-sync (file linecol &rest ignored)
  (let* ((fname (un-urlify file))
         (buf (find-buffer-visiting fname))
         (line (car linecol))
         (col (cadr linecol)))
    (if (null buf)
        (message "[Synctex]: %s is not opened..." fname)
      (switch-to-buffer buf)
      (goto-line (car linecol))
      (unless (= col -1)
        (move-to-column col)))))

(defvar *dbus-evince-signal* nil)

(defun enable-evince-sync ()
  (require 'dbus)
  (when (and
         (eq window-system 'x)
         (fboundp 'dbus-register-signal))
    (unless *dbus-evince-signal*
      (setf *dbus-evince-signal*
            (dbus-register-signal
             :session nil "/org/gnome/evince/Window/0"
             "org.gnome.evince.Window" "SyncSource"
             'th-evince-sync)))))

(add-hook 'LaTeX-mode-hook 'enable-evince-sync)

If the path has space, it might be problematic (for me it is). So I fixed as follows:

(fname (replace-regexp-in-string "%20" " " (un-urlify file)))

– Kiwon

There is a more generic fix that works for spaces, accents, and probably all sorts of weird characters:

(fname (url-unhex-string (un-urlify file)))

– Schnouki

That code was based upon a version by Tassilo Horn, which worked for me with older versions of Evince. The code below is his version.

(require 'dbus)
(defun th-evince-sync (file linecol)
   (let ((buf (get-buffer file))
         (line (car linecol))
         (col (cadr linecol)))
     (if (null buf)
         (message "Sorry, %s is not opened..." file)
       (switch-to-buffer buf)
       (goto-line (car linecol))
       (unless (= col -1)
         (move-to-column col)))))

(when (and
       (eq window-system 'x)
       (fboundp 'dbus-register-signal))
  (dbus-register-signal
   :session nil "/org/gnome/evince/Window/0"
   "org.gnome.evince.Window" "SyncSource"
   'th-evince-sync))

You may want to add “(select-frame-set-input-focus (selected-frame))” after “(switch-to-buffer buf)” if you want the emacs window to be automatically brought up when clicking in evince.

– Bangsheng

Finally, in your .tex buffer you need to do M-x TeX-source-correlate-mode so that the synctex information is written when you compile your documents. You can enable that with C-c C-t C-s.

Evince (and other viewers) in 11.85 (Debian Squeeze)

AUCTeX 11.85 does this differently than later versions. All viewers are set with the TeX-output-view-style variable:

(setq TeX-output-view-style
      (quote
       (("^pdf$" "." "evince -f %o")
        ("^html?$" "." "iceweasel %o"))))

for example. (Solution based on code here: https://cosinepi.wordpress.com/2010/09/10/emacs-configurations-auctex/ which was designed for windows configuration.)

Synctex and Sumatra PDF

On Windows, Sumatra PDF serves a similar purpose to Evince by also allowing forward and backward searches (and unlike Adobe Acrobat Reader, won’t lock the PDF while while the viewer is open). The forward searches can be done either through command-line arguments or through the ddeclient.

Unfortunately, configuration can be tricky to get right, mainly because there are so many steps. See Emacs AUCTeX and PDF Synchronization on Windows for using the command-line mode in Sumatra PDF to configure AUCTex and Emacs or Configuring editors with SumatraPDF if for some reason you need to use DDE.

When correctly configured, you can perform a forward search (from within Emacs) by using AUCTeX’s built-in View command: C-c C-v. To perform inverse search (from within Sumatra PDF), simply double-click the area of text. This also works with multi-file LaTeX projects.

Synctex and Okular

The default PDF Viewer of KDE, Okular, can also be configured with Synctex in both directions (when you click on Shift + Left mouse button you go to the good line in the tex file, and when you do C-c C-c ⇒ View you open (or update) the pdf document at the good line).

To do so you have to do two things : first configure Okular by going into “Configuration/Configure Okular/Editor” and put in the “Editor” list the value “Emacs client” (you should see in the “Command” section the text “emacsclient -a emacs --no-wait +%l %f”).

After that put in your .emacs

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;;;;;;;;;;;;;;;        LaTeX         ;;;;;;;;;;;;;;;;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ##### Don't forget to configure
;; ##### Okular to use emacs in
;; ##### "Configuration/Configure Okular/Editor"
;; ##### => Editor => Emacsclient. (you should see
;; ##### emacsclient -a emacs --no-wait +%l %f
;; ##### in the field "Command".

;; ##### Always ask for the master file
;; ##### when creating a new TeX file.
(setq-default TeX-master nil)

;; ##### Enable synctex correlation. From Okular just press
;; ##### Shift + Left click to go to the good line.
(setq TeX-source-correlate-mode t
      TeX-source-correlate-start-server t)

;; ### Set Okular as the default PDF viewer.
(eval-after-load "tex"
  '(setcar (cdr (assoc 'output-pdf TeX-view-program-selection)) "Okular"))

Discussion

Would it be possible to make a skeleton pair that would automatically match a ‘\(’ with a ‘\)’? The same should be true for ‘\[’ and ‘\]’. Thanks!

Rest of discussion moved to AutoPairs.

Internal version of TeX-texify

To run LaTeX and BibTeX on a document one has to press C-c C-c multiple times. On the page [[1]] there is a section TeX-texify: Get everything done for a LaTeX-file with the elisp function TeX-texify which gets this job done. Someone asked me whether this function can be included into AUCTeX.

Should it?

Problem of synctex

If somebody has a problem with synctex, i.e. hanging or wrong page search, try the following:

(require 'tex)
(defun TeX-synctex-output-page ()
  "Return the page corresponding to the current source position.
This method assumes that the document was compiled with SyncTeX
enabled and the `synctex' binary is available."
  (let ((synctex-output
	 (with-output-to-string
	   (call-process "synctex" nil (list standard-output nil) nil "view"
			 "-i" (format "%s:%s:%s" (line-number-at-pos)
				      (current-column)
				      ;; The real file name (not symbolic) fixed
				      ;; for the synctex path bug
                                      (concat (file-name-directory (file-truename (buffer-file-name)))
                                              "./"
                                              (file-name-nondirectory (buffer-file-name))))
			 "-o" (TeX-active-master (TeX-output-extension))))))
    (if (string-match "Page:\\([0-9]+\\)" synctex-output)
	(match-string 1 synctex-output)
      "1")))

Because synctex includes a redundant string “./” in the path, this codes will help. – Kiwon

Useful configuration

To highlight (or font-lock) the “\section{title}” lines:

(font-lock-add-keywords
   'latex-mode
   `((,(concat "^\\s-*\\\\\\("
               "\\(documentclass\\|\\(sub\\)?section[*]?\\)"
               "\\(\\[[^]% \t\n]*\\]\\)?{[-[:alnum:]_ ]+"
               "\\|"
               "\\(begin\\|end\\){document"
               "\\)}.*\n?")
      (0 'your-face append))))

CategoryModes CategoryTex