Yes, you can create LaTeX documents directly in Emacs, and doing so gives you a powerful, integrated writing environment with syntax highlighting, PDF preview, and advanced editing features. This guide explains the main methods—AUCTeX, Org-mode, and plain LaTeX editing—and shows you how to set up a workflow that fits your needs.
Why Use Emacs for LaTeX?
Emacs is a highly extensible text editor that has been around since the 1970s. Its combination of keyboard-driven editing, scripting in Emacs Lisp, and a large ecosystem of packages makes it a favorite among academics, scientists, and technical writers who work with LaTeX. The primary advantages are:
- Integrated workflow: You can edit, compile, and view your PDF without leaving the editor.
- Powerful editing: Commands like
latex-modeor AUCTeX provide syntax highlighting, auto-completion, and shortcuts for inserting environments and math. - Customizability: You can tailor keybindings, snippets, and build commands to match your exact preferences.
- Org-mode integration: Org-mode lets you write in a lightweight markup and export to LaTeX/PDF, which many find more readable than raw LaTeX.
Setting Up AUCTeX (The Most Complete LaTeX Mode)
AUCTeX is the most feature-rich LaTeX editing mode for Emacs. It provides:
- Automatic insertion of environments (e.g.,
\begin{itemize}) - Keyboard shortcuts for common commands (e.g.,
C-c C-efor environment,C-c C-cto compile) - Syntax highlighting and indentation
- Preview of math formulas inline (via
preview-latex)
To install AUCTeX, use Emacs’ package manager (M-x package-install RET auctex). After installation, opening a .tex file will automatically activate AUCTeX mode. You can then compile with C-c C-c and view the PDF with C-c C-v (if you have a PDF viewer configured).
Using Org-mode for LaTeX Export
Org-mode is a powerful outlining and note-taking system that can export to LaTeX and PDF. This is an excellent choice if you prefer a simpler markup than raw LaTeX. You write in plain text with simple markers:
#+TITLE: My Document* Sectionfor headings- itemfor lists$x^2$for inline math
To export, press C-c C-e l o (export to LaTeX and open) or C-c C-e l p (export to PDF). Org-mode also supports LaTeX-specific blocks like #+BEGIN_LaTeX for raw LaTeX code, and you can set LaTeX class options in the header. This method is great for those who want to focus on content without worrying about LaTeX syntax.
Choosing Between AUCTeX and Org-mode
The choice depends on your comfort level and needs:
- AUCTeX is ideal if you already know LaTeX or need fine control over the LaTeX code. It offers the most direct editing experience with all LaTeX features accessible.
- Org-mode is better for writers who want a cleaner, more readable source and are willing to trade some direct control for simplicity. It also works well for documents that mix prose, code, and data.
Many users use both: Org-mode for drafts and AUCTeX for final formatting. You can also embed LaTeX in Org-mode and export directly to PDF.
Common Problems and Solutions
Here are typical issues you might encounter and how to fix them:
- PDF viewer not opening: Emacs needs to know which viewer to use. In AUCTeX, set the
TeX-view-program-selectionvariable. In Org-mode, setorg-latex-pdf-processandorg-file-apps. - Compilation errors: Check the
*TeX Output*buffer (AUCTeX) or*Org PDF LaTeX Output*(Org-mode) for error messages. Common causes: missing packages (install via your LaTeX distribution’s package manager) or syntax errors in your document. - Math preview not working: Ensure you have
preview-latexinstalled (it comes with AUCTeX) and that your LaTeX distribution supports it. You may need to runM-x preview-installonce. - Slow performance on large documents: Emacs can handle large files, but syntax highlighting and previews can slow down. Consider disabling preview-latex for large files or using
M-x normal-modeto reset.
Alternatives and Comparisons
Emacs is not the only way to edit LaTeX. Other popular editors include:
- TeXstudio / TeXmaker: Standalone LaTeX editors with a GUI, built-in PDF viewer, and auto-completion. They are easier for beginners but less customizable than Emacs.
- Visual Studio Code with LaTeX Workshop: A modern editor with a rich extension ecosystem. It offers a good balance of usability and features, but it is not as keyboard-centric as Emacs.
- Overleaf: A web-based LaTeX editor that simplifies collaboration and compilation. It requires an internet connection and offers less control over the editing environment.
Compared to these, Emacs has a steeper learning curve but offers unmatched extensibility and keyboard efficiency. If you already use Emacs for other tasks, it makes sense to use it for LaTeX too.
Cost and Setup Considerations
Emacs is free and open-source software, available for Windows, macOS, and Linux. There is no cost to download or use it. However, you will need a LaTeX distribution (e.g., TeX Live, MiKTeX) to compile documents, which is also free. The main investment is time: learning Emacs and configuring it to your liking can take a few days to weeks, depending on your experience.
Frequently Asked Questions
How do I start a new LaTeX document in Emacs?
Simply open a new file with a .tex extension (e.g., C-x C-f mydoc.tex). Emacs will automatically enter LaTeX mode (AUCTeX if installed). You can then type your LaTeX code or use C-c C-e to insert environments.
Can I use Emacs for collaborative LaTeX writing?
Yes, but you’ll need a version control system like Git. Emacs has built-in support for Git via Magit, and you can use services like GitHub or GitLab to collaborate. Alternatively, you can use Emacs with a real-time collaboration package like togetherly, but it’s less mature than web-based tools.
Is Emacs good for large documents like a thesis?
Yes. Emacs handles large files well, and AUCTeX provides features like multi-file support with \include and \input. You can also use RefTeX (included with AUCTeX) for cross-referencing and citations.
How do I change the PDF viewer in Emacs?
In AUCTeX, use M-x customize-variable RET TeX-view-program-selection and choose your preferred viewer. In Org-mode, set org-file-apps to associate .pdf files with your viewer. For example, add (add-to-list 'org-file-apps '("pdf" . "evince %s")) to your init file.
Can I use Emacs on Windows?
Yes, Emacs is fully supported on Windows. Download the installer from the official GNU site, and install a LaTeX distribution like MiKTeX. Some keybindings may differ slightly, but the core functionality is the same.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Backup Not Enough Space? Fix It Now200.00 GB
- Approximate Match Lookup: Conditional Formatting
- GST on Delivery Charges in India: E-Commerce Rules
- NFC Reader on Your Phone: 9 Things You’re Not Doing
- Smart TV DNS Settings: Why They Change & How to Fix
- RabbitMQ Hosting for Startups: Managed vs Self-Hosted