LaTeX

LaTeX is a typesetting tool. You write your text using a particular markup language, and then you process your text into something nice-looking and printable.

Here’s how such (fragment of) LaTeX source might look like:

\chapter{Introduction}
\label{sec:einl}

\emph{Performance ist ein subjektives Mass für die Geschwindigkeit,
mit der eine Applikation verwendet werden kann.} Die Bewertung der
Performance kann nur relativ sein: Das System ist schneller als
vorher, als auf einer anderen Maschine, als mit der alten Version.

There are numerous books and documentation available on using LaTeX. A free LaTeXManual is available for use in Emacs InfoMode.

In order to facilitate working with LaTeX documents, files with the .latex and .ltx extension are put into latex-mode. Files with the .tex extension are examined to determine which mode is appropriate and if indeterminate are put into latex-mode. tex-mode is more generic (ie. less features) because in the end LaTeX is just a collection of TeX macros.

When editing a latex document, you can run the command ‘M-x imenu-add-menubar-index’ to give you a quick menu of your document headings. Very nice, and you can even add it to the reftex hooks on load (you do use reftex and AUCTeX, don’t you?):

  (add-hook 'reftex-load-hook 'imenu-add-menubar-index)
  (add-hook 'reftex-mode-hook 'imenu-add-menubar-index)

For high-speed access, one can bind the imenu to a right mouse click:

  (global-set-key [down-mouse-3] 'imenu)

You may use AUCTeX mode instead of LaTeX mode. AUCTeX has even more features. It is rather big, however. AUCTeX is usually included in XEmacs. There are other LaTeX modes for Emacs, for example UltraTexMode and YaTeX, but neither is under active development. SwifTeX (external link) was created to edit self-documenting LaTeX code that uses the doc package, but has also generic LaTeX mode, created using ‘define-derived-mode’. Also not under active development.

One feature in AUCTeX is autoquoting, but there is even better support for ‘magic’ quoting (a la Word) using TypographicalPunctuationMarks. This mode can be easily extended to include ‘latex’ quoting by adding it as a language.

CDLaTeX is a minor mode providing template based insertion of LaTeX environments and mathematical constructs. It tries to be quick, with very few and easy to remember keys, and intelligent on-the-fly help. You can use it on top of your favourite LaTeX mode.

RefTeX (minor mode) provides distinct support for doing labels, references and citations in LaTeX, and it provides support for generating indices. It works with both Emacs and XEmacs and runs as a minor mode with any of the LaTeX major modes around, most notably AUCTeX. It is included in both GnuEmacs and XEmacs.

Zotelo allows you to synchronize on the fly your Zotero collection with local BibTeX file. See also zotero.org plugins, zotero-plain, zotxt.

XSymbolMode gives some WYSIWYG capabilities when editing LaTeX or HTML in Emacs, but mainly it assists the input of symbols in some token languages (MarkupModes like TeX and SGML/HTML).

The LaTeXSymbols package provides commands for XEmacs (and only XEmacs--it doesn’t work with GnuEmacs) to open up a window with a table of LaTeX symbols. Similar functionality (and more) is offered by XSymbolMode.

ac-math is an AutoComplete add-on for LaTeX and Unicode symbols and LaTeX commands. ac-tex-ref.el can auto-complete \ref and \cite.

PreviewLaTeX replaces the LaTeX code (more exactly headers, tables, figures, graphics and math) by the final output in Emacs. You can revert from preview to code, make some changes and then regenerate preview at point.

WhizzyTeX minor mode provides incremental viewing of LaTeX documents using on-the-fly compilation. It also shows the point where you are in LaTeX document source. It can use DVI previewer, or it can generate .ps file and use PostScript viewer. Similar features are provided by CTAN:autoview, supposedly replaced by filewatch.

LatexMk is a kind of specialized make for LaTeX, and it can be used in “preview continuously” mode to have the preview updated automatically automatically on file save. Rubber is a more modular alternative to LatexMk.

InverseDviSearch explains how to set DVI previewer and Emacs to allow jumping from editor to related place in DVI file and vice versa.

FlyspellBabel switches FlySpell language according to Babel commands.

PredictiveMode includes extensive support for context-sensitive, predictive completion in LaTeX documents. E.g. only maths commands are suggested as completion candidates inside equation environments, only defined labels are suggested inside \ref commands, etc. It also learns which commands you use most often and offers them first. And it supports documents split over multiple files by honouring the ‘TeX-master’ variable.

LatexEnc gets a coding system from inputenc, as an alternative to an Emacs coding cookie in your document.

TexSmartUmlauts translates LaTeX encoded non-ASCII characters to their “visible” representation while restoring their original encoding when the buffer is saved.

GermanLaTeXQuotes automatically switches between german and english quotes in `latex-mode' depending on context.

OrgMode can export to LaTeX.

Discussion

Is there a way to use Rubber as default in AUCTex (e.g., “C-c C-c” → Latex or PDF calls rubber with the appropriate options)??

Yes. In my configuration, F12 previews a LaTeX document, and Shift+F12 creates a PDF. To avoid clutter, all intermediate files are kept in the /tmp folder, only the final PDF is created in the current folder. Also, the right workflow is automatically selected depending on if the file is a beamer or a normal LaTeX file.

In my .emacs file I have the following:

(defun my-latex (action)
  (interactive)
  (if (buffer-modified-p) (save-buffer))
  (let ((f1 (current-frame-configuration))
        (retcode (shell-command (concat "~/bin/my-latex " action " " buffer-file-name))))
    (if (= retcode 0) (set-frame-configuration f1))))

(add-hook 'latex-mode-hook (lambda ()
      (define-key LaTeX-mode-map (kbd "<f12>") '(lambda () (interactive) (my-latex "preview")))
      (define-key LaTeX-mode-map (kbd "<S-f12>") '(lambda () (interactive) (my-latex "create")))))

You’ll also need the following two files (my-latex and my-preview) somewhere in your path and with execution permission:

my-latex:

#! /bin/sh

action=$1
beamer=`grep -c -m 1 beamer $2`
file=`basename $2 .tex`
tmpdir="/tmp"
rubber="rubber"

if [ $beamer = "0" ]; then
    if [ $action = "preview" ]; then   # normal tex file --> preview as dvi
        $rubber --into=$tmpdir $file.tex && my-preview xdvi $tmpdir/$file.dvi
    elif [ $action = "create" ]; then  # normal tex file --> create pdf
        $rubber --into=$tmpdir $file.tex && dvips -Ppdf $tmpdir/$file.dvi && mv $file.ps $tmpdir/$file.ps && ps2pdf $tmpdir/$file.ps && my-preview acroread $file.pdf
    fi
elif [ $beamer = "1" ]; then
    if [ $action = "preview" ]; then   # beamer tex file --> preview as ps
        $rubber --into=$tmpdir $file.tex && dvips -Ppdf $tmpdir/$file.dvi && mv $file.ps $tmpdir && my-preview "gv --scale=3" $tmpdir/$file.ps
    elif [ $action = "create" ]; then  # beamer tex file --> create pdf
        $rubber --into=$tmpdir $file.tex && dvips -Ppdf $tmpdir/$file.dvi && mv $file.ps $tmpdir && ps2pdf $tmpdir/$file.ps && my-preview acroread $file.pdf
    fi
else
    echo "action ($action) or filetype ($beamer) not recognized"
fi

my-preview:

#! /bin/sh

$1 $2 2> /dev/null > /dev/null &

--FelipeCsaszar

This should do the trick:

(eval-after-load "tex"
  '(progn
     (add-to-list 'TeX-expand-list
                  '("%(RubberPDF)"
                    (lambda ()
                      (if
                          (not TeX-PDF-mode)
                          ""
                        "--pdf"))))
     (add-to-list 'TeX-command-list
                '("Rubber" "rubber %(RubberPDF) %t" TeX-run-shell nil t) t)))

It will output dvi or pdf depending on the active mode. I use the following shortcuts: F9 for Rubber and F12 for preview.

(add-hook 'TeX-mode-hook
          '(lambda ()
            (define-key TeX-mode-map (kbd "<f9>")
              (lambda ()
                (interactive)
                (save-buffer)
                (TeX-command-menu "Rubber")
                (TeX-clean)))
            (define-key TeX-mode-map (kbd "<f12>")
              (lambda ()
                (interactive)
                (TeX-view)
                [return]))))

--TiagoCamargo


I found a page containing information about how to write latin1 coded documents in LaTeX, also there’s some info about getting started with LaTeX in emacs. (The info is in Swedish) http://www.dsv.su.se/datorer/latex/#50

Hmm… I don’t already have something that handles TeX and LaTeX in Emacs… are there some .el/.elc files I need and/or settings? Presumably there’s a place on here that mentions download/setup-type stuff…

If you open a file with the suffix .tex or .latex, you should get the basic mode. For more features, use AUCTeX. – AlexSchroeder


I like to use Makefiles to run pdflatex on my .tex files, which means I can just M-x compile to generate the document. If you give pdflatex the -file-line-error option, Emacs automatically recognizes the errors and lets you jump to them just like with compiler errors.


In my thesis, I needed to translate tr_TR.UTF-8 characters into their LaTeX equivalents. Hence, I come up with below solution.

(defvar tr-utf8-to-latex-string-translation-alist
  '(("ç" . "\\c{c}")  ("Ç" . "\\c{C}")
    ("ğ" . "\\u{g}")  ("Ğ" . "\\u{g}")
    ("ı" . "{\\i}")   ("İ" . "\\.{I}")
    ("ö" . "\\\"{o}") ("Ö" . "\\\"{O}")
    ("ş" . "\\c{s}")  ("Ş" . "\\c{S}")
    ("ü" . "\\\"{u}") ("Ü" . "\\\"{U}")))

(defmacro make-string-translator (fname alist)
  `(defun ,fname (start end)
     (interactive (list (point) (mark)))
     (unless (and start end)
       (error "The mark is not set now, so there is no region!"))
     (barf-if-buffer-read-only)
     (dolist (spec ,alist)
       (replace-string (car spec) (cdr spec) nil start end))))

(make-string-translator
 tr-utf8-to-latex tr-utf8-to-latex-string-translation-alist)

– Volkan YAZICI


CategoryModes CategoryTex