Emacs (AUCTeX / YaTeX)

There are two main ways to write LaTeX in Emacs: AUCTeX, the comprehensive TeX/LaTeX environment, and YaTeX (野鳥), which is strong on Japanese. Both are keyboard-driven and let you compile, complete, cross-reference, and preview straight from the editor. The learning curve is steep, but once it fits your hands it is very fast. This page walks through AUCTeX setup, its companion RefTeX, and preview-latex for rendering math inline in the buffer, then turns to YaTeX for Japanese.

What AUCTeX is

Emacs does not typeset TeX itself. The actual compiling is done by a distribution you install on your machine — TeX Live (or MacTeX / MiKTeX). AUCTeX is the package that bridges the editor and that distribution: it spawns latex or latexmk as a child process, catches errors and jumps to the offending line, and adds completion of environments and macros, syntax highlighting, document folding, and math-input help. The one prerequisite is that latexmk --version works in a terminal — that is, the TeX commands are on your PATH.

Historically AUCTeX has two main modes: **LaTeX-mode for LaTeX documents and TeX-mode** for raw TeX / plain TeX. Open a .tex file and AUCTeX inspects it to enter the right one. Its distribution recently changed: version 13.3 (January 2024) was the last standalone tar.gz release, and since then AUCTeX ships from GNU ELPA, Emacs’s built-in package archive (the 14.x series as of 2026). So installing it today is a one-liner with package.el, as shown below.

If Emacs key notation is unfamiliar: C-c means Control held with c, C-c C-c means press c then c again while holding Control, and M-x means Meta (Alt or ESC) + x. Almost every AUCTeX command lives on a key starting with C-c.

AUCTeX setup

Installation has two steps. First install a distribution such as TeX Live (in 2026, TeX Live 2026) and put it on your PATH. Then install AUCTeX from inside Emacs. GNU ELPA is enabled by default, so M-x package-install RET auctex RET is all it takes. In your init.el (or ~/.emacs.d/init.el), start with TeX-PDF-mode to default to PDF output and TeX-source-correlate-mode to tie source to PDF (SyncTeX).

Here is a practical init.el using use-package. Setting TeX-source-correlate-method to synctex and turning on TeX-source-correlate-start-server enables inverse search from the viewer back to the source. It also turns on reftex-mode and LaTeX-math-mode automatically in LaTeX buffers:

init.el
;; GNU ELPA is enabled by default; ensure it is initialised.
(require 'package)
(package-initialize)

(use-package tex
  :ensure auctex
  :hook ((LaTeX-mode . TeX-source-correlate-mode)   ; SyncTeX
         (LaTeX-mode . reftex-mode)                  ; cross-references
         (LaTeX-mode . LaTeX-math-mode))             ; ` math shortcuts
  :config
  (setq TeX-auto-save t           ; write parse data (the auto/ dir)
        TeX-parse-self t          ; scan the file for \usepackage etc.
        TeX-PDF-mode t)           ; produce PDF, not DVI
  ;; Tie source lines to PDF positions and run a server for inverse search.
  (setq TeX-source-correlate-method 'synctex
        TeX-source-correlate-start-server t))

TeX-parse-self and TeX-auto-save tell AUCTeX to parse the document — pulling in the macros from packages you \usepackage — and to cache the result in an auto/ directory. The payoff is completion that adapts to the packages you actually load.

The heart of compiling is **C-c C-c** (TeX-command-master). Press it and the minibuffer asks what to run next, proposing a default based on the document’s state (first LaTeX, LaTeX again if references are unresolved, BibTeX if there is a bibliography, then View). Accepting with Enter and repeating is the basic loop. By contrast, **C-c C-a** (TeX-command-run-all) chains the needed steps automatically until an error or completion, and on success opens the viewer for you. When you just want to push through to a finished PDF, C-c C-a is the quick path.

To standardize on latexmk as the compiler, install the auctex-latexmk package and call (auctex-latexmk-setup). That adds a **LatexMk** entry to the C-c C-c choices, and setting TeX-command-default to "LatexMk" makes it the default. Because latexmk inspects dependencies and re-runs exactly as many times as needed, you never count passes for cross-references or the table of contents. auctex-latexmk also inherits AUCTeX’s TeX-PDF-mode and TeX-source-correlate-mode, adding PDF output and -synctex=1 automatically.

init.el
(use-package auctex-latexmk
  :ensure t
  :after tex
  :config
  ;; Make latexmk pick up TeX-PDF-mode (pass -pdf when PDF output is on).
  (setq auctex-latexmk-inherit-TeX-PDF-mode t)
  (auctex-latexmk-setup)
  ;; Offer LatexMk as the default action for C-c C-c.
  (setq-default TeX-command-default "LatexMk"))

Engine and bibliography details are cleanest in a .latexmkrc at the project root (independent of AUCTeX’s settings; the latexmk launched from C-c C-c reads it too). For Japanese, for instance, assign upLaTeX + dvipdfmx to $latex / $dvipdf and choose $pdf_mode = 3. See the build-tools page for the details.

The AUCTeX keys you reach for daily, gathered in a table (the name column is the literal key sequence):

KeyCommandWhat it does
C-c C-cTeX-command-masterChoose and run the next step (LaTeX → View, …)
C-c C-aTeX-command-run-allRun the whole chain to completion, then view
C-c `TeX-next-errorJump to the next error (backquote)
C-c C-eLaTeX-environmentInsert an environment (\begin..\end)
C-c C-mTeX-insert-macroInsert a macro by name (prompts for args)
C-c C-fTeX-fontInsert a font macro: \textbf, \emph, …

RefTeX — cross-references and citations

RefTeX is a companion focused on managing \label, \ref, and \cite. It is separate from AUCTeX and bundled with Emacs itself (no separate install). Turn on reftex-mode in LaTeX buffers as in the init.el above and let it cooperate with AUCTeX, and labelling and referencing become dramatically easier.

The crux is that you never have to invent labels by hand. **C-c (** (reftex-label) looks at where you are (figure, table, equation, section) and proposes a sensibly prefixed label (fig:, tab:, eq:, …) to insert. To refer back, **C-c )** (reftex-reference) just lets you pick from existing labels. For citations, **C-c [** (reftex-citation) searches your .bib by regular expression and inserts \cite{...} for the entry you choose. And **C-c =** (reftex-toc) opens a table-of-contents buffer for the whole document in another window, so you can jump to a section or survey the structure.

For deep integration with AUCTeX, set reftex-plug-into-AUCTeX. AUCTeX’s own \label insertion and \ref/\cite completion then go through RefTeX, and the two packages feel like one. Even in multi-file projects (\include/\input), RefTeX follows the master file to gather all labels and all citations across the whole document.

init.el
(use-package reftex
  :ensure nil                 ; bundled with Emacs
  :hook (LaTeX-mode . turn-on-reftex)
  :config
  (setq reftex-plug-into-AUCTeX t   ; cooperate with AUCTeX
        reftex-cite-format 'natbib)) ; or 'biblatex, etc.

preview-latex — inline preview

preview-latex actually typesets math, figures, tikzpictures, and the like with LaTeX, then overlays the result as an image right there in the source buffer. It ships with AUCTeX, so there is nothing extra to install. The source of a $...$, \[...\], or equation environment stays editable, yet shows as set math when you want to check it — a WYSIWYG-like feel while staying plain text.

Commands start with C-c C-p (Preview). **C-c C-p C-p** (preview-at-point) previews just the object at the cursor (press again to return to source). **C-c C-p C-b does the whole buffer, C-c C-p C-d the whole document, and C-c C-p C-r a selected region. C-c C-p C-c C-p** clears previews in a region. Under the hood it runs LaTeX to generate the images, so the first pass takes a moment.

preview-latex relies on Ghostscript and dvipng (or a PDF-to-image step) to make the images, so those must be present in your distribution (TeX Live normally has them). It pays off most in documents heavy with long equations or commutative diagrams, where you want to see the set result at a glance as you write.

YaTeX (野鳥) — the Japanese-oriented choice

YaTeX (野鳥, “wild bird”) is a LaTeX major mode for Emacs by Yuuji Hirose. Internationally AUCTeX is the more common choice, but in Japan YaTeX enjoys durable popularity and abundant Japanese documentation. The latest is 1.84 (February 2025). Install it from MELPA with M-x package-install RET yatex RET (or, manually, drop it in site-lisp and extend load-path).

Its philosophy differs a little from AUCTeX, leaning on “type the first few letters plus completion” to insert macros and environments fast. The prefix is C-c by default. **C-c b** is begin-type completion (environments, \begin{...}...\end{...}), **C-c s** is section-type (\section, …), **C-c l** is large-type (size/face like \large), and **C-c m** is maketitle-type (argument-less macros such as \maketitle, \item). Typesetting starts with **C-c C-t**: C-c C-t j typesets and C-c C-t p previews (launches the viewer).

A few variables anchor the Japanese setup. YaTeX-kanji-code is the kanji encoding on save; since UTF-8 is now standard, set it to nil (respect the file’s existing encoding) if you do not want files silently re-encoded. tex-command is the typesetting command actually invoked — e.g. "latexmk", "lualatex -synctex=1", or "uplatex". Setting bibtex-command and makeindex-command to upbibtex and upmendex makes Japanese bibliographies and indexes work. Here is a minimal init.el:

init.el
(use-package yatex
  :ensure t                       ; from MELPA
  :mode ("\\.tex\\'" . yatex-mode)
  :config
  (setq YaTeX-kanji-code nil      ; keep the file's own encoding (UTF-8)
        tex-command "latexmk"     ; or "lualatex -synctex=1", "uplatex"
        bibtex-command "upbibtex"
        makeindex-command "upmendex"
        ;; Use C-c C-t style prefixes (C-c C-t j, C-c C-t p, ...).
        YaTeX-inhibit-prefix-letter t))

Setting YaTeX-inhibit-prefix-letter to t makes the typeset keys **C-c C-t ...** (the modifier-held Emacs idiom) rather than C-c t .... YaTeX also ships a sister mode for HTML, yahtml. AUCTeX and YaTeX are best committed to one or the other rather than mixed: choose AUCTeX for mostly-English work or to use preview-latex/RefTeX to the full, and YaTeX to write Japanese documents quickly.