From the introduction in the AUCTeX manual:
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.‘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.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).
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).
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 (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 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.
To compile documents to PDF by default add the following to your ~/.emacs.
(setq TeX-PDF-mode t)
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.
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.
pstricks.el has been added to the latest auctex cvs version with some changes to make it work better. (2009-06-25)
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")))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.
auto-complete-auctex gives a pretty interface to auctex completions using auto-complete.el and yasnippet.
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.
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):
The “completion browser” menu is particularly useful when hunting for that LaTeX command whose name you can’t quite remember:
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:
Several ac-sources for the marvelous auto-completion package are available here.

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.
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.
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*"))
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:
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 quotedThe 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.
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)))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.
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.
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.)
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.
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.
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?
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