Latex – quick & beautiful

Beside the latest Git source of auctex (due to compatibility issues with the installed version of texlive on Fedora 20, Debian Jessie and Arch Linux) I use the external packages auto-complete, ac-math, yasnippet and tex-smart-umlauts. The last one automatically converts German umlauts to the format \”a and vice versa. You always see and type umlaut character and Emacs does the rest for you.

Additionally I use yasnippets and auto-completion mode thus I am lazy and want to write as quick as my mind flows.

For spell checking flyspell and hunspell via ispell.el jumps in just because hunspell (from Libreoffice) is the most advanced spell checker available on GNU/Linux.

Last but not least I like the preview feature from auctex. It get’s you a WYSIWYG editor for Latex and by pressing C-c you can compile the current file and view it in an external program like Adobe Acrobat reader.

Here’s my complete config for copy & paste

(add-to-list 'load-path "~/.emacs.d/extensions/auctex")
(add-to-list 'load-path "~/.emacs.d/extensions/ac-math")
(load "~/.emacs.d/extensions/auctex/tex-site.el" nil t t)
(require 'reftex)
(require 'preview-latex)

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-electric-escapy t)
(setq reftex-plug-into-AUCTeX t)
(setq TeX-PDF-mode t)
(setq TeX-show-compilation nil)
(setq TeX-toggle-debug-boxes nil)
(setq file_line_error_style t)
(setq TeX-view-program-list '(("Acrobat" "acroread %o")))
(setq TeX-view-program-selection '((output-pdf "Acrobat")))

(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)

; snippets
(require 'yasnippet)

; auto-completion
(require 'ac-math)
(add-to-list 'ac-modes 'LaTeX-mode)
(add-to-list 'ac-modes 'latex-mode)

(defun ac-LaTeX-mode-setup () ; add ac-sources to default ac-sources
(setq ac-sources
(append '(ac-source-math-unicode ac-source-math-latex ac-source-latex-commands ac-source-yasnippet)
(add-hook 'LaTeX-mode-hook 'ac-LaTeX-mode-setup)

;; Make RefTeX faster
(setq reftex-enable-partial-scans t)
(setq reftex-save-parse-info t)
(setq reftex-use-multiple-selection-buffers t)

(require 'tex-smart-umlauts)
(add-hook 'LaTeX-mode-hook #'tex-smart-umlauts-decode)

(setq latex-mode-hook
'(lambda ()
(setq ac-delay 0.2)
(define-key LaTeX-mode-map "\C-cu" 'LaTeX-find-matching-begin)
(define-key LaTeX-mode-map "\C-cd" 'LaTeX-find-matching-end)
(define-key LaTeX-mode-map "\C-ci" 'LaTeX-insert-item)

; spell checking
(require 'ispell)

(setq ispell-dictionary-base-alist
"[a-zäöüßA-ZÄÖÜ]" "[^a-zäöüßA-ZÄÖÜ]" "[']" nil
("-d" "de_DE" "-i" "iso-8859-1") nil iso-8859-1)

"[a-zA-Z]" "[^a-zA-Z]" "[']" nil
("-d" "en_US" "-i" "iso-8859-1") nil iso-8859-1)

"[a-zA-Z]" "[^a-zA-Z]" "[']" nil
("-d" "en_GB" "-i" "iso-8859-1") nil iso-8859-1)


(eval-after-load "ispell"
(setq ispell-dictionary "de_DE")
;(setq ispell-extra-args '("-t")) ; input is tex or latex
(setq ispell-silently-savep t) ; save personal dict without confirmation

(setq-default ispell-program-name "hunspell")
(setq ispell-really-hunspell t)

And here’s a tiny cheat sheet (not complete but the most usable keybindings)

C-c C-s insert section with label
C-c C-e insert new environment
C-u C-c C-e change current environment
C-c u jump to begin block
C-c d jump to end block
C-c * mark current section
C-c . mark current environment
C-c i insert \item
C-c < insert \index
C-c C-f C-b font bold
C-c C-f C-i font italics
C-c C-l show compiler output
C-c C-r compile region
C-c ` goto error
C-c ( insert a label
C-c ) list all labels and make ref entry
C-c = show toc to navigation
C-c return insert macro
M-x reftex-change-label globally rename a label
M-x reftex-goto-label goto label definition
M-x reftex-search-document Grep a label through all files

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s