Starter Kit LaTeX
This is part of the Emacs Starter Kit.
Starter Kit LaTeX
Support for editing LaTeX.
Load Packages
- Load AucTeX
(load "auctex-pkg.el" nil t t)
- Load Preview LaTeX
(load "preview.el" nil t t)
- Load RefTeX
(add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t) (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil) (autoload 'reftex-citation "reftex-cite" "Make citation" nil) (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t) (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode ;; Make RefTeX faster (setq reftex-enable-partial-scans t) (setq reftex-save-parse-info t) (setq reftex-use-multiple-selection-buffers t) (setq reftex-plug-into-AUCTeX t) ;; Make RefTeX work with Org-Mode ;; use 'C-c (' instead of 'C-c [' because the latter is already ;; defined in orgmode to the add-to-agenda command. (defun org-mode-reftex-setup () (load-library "reftex") (and (buffer-file-name) (file-exists-p (buffer-file-name)) (reftex-parse-all)) (define-key org-mode-map (kbd "C-c (") 'reftex-citation)) (add-hook 'org-mode-hook 'org-mode-reftex-setup) ;; RefTeX formats for biblatex (not natbib) (setq reftex-cite-format '( (?\C-m . "\\cite[]{%l}") (?t . "\\textcite{%l}") (?a . "\\autocite[]{%l}") (?p . "\\parencite{%l}") (?f . "\\footcite[][]{%l}") (?F . "\\fullcite[]{%l}") (?x . "[]{%l}") (?X . "{%l}") )) (setq font-latex-match-reference-keywords '(("cite" "[{") ("cites" "[{}]") ("footcite" "[{") ("footcites" "[{") ("parencite" "[{") ("textcite" "[{") ("fullcite" "[{") ("citetitle" "[{") ("citetitles" "[{") ("headlessfullcite" "[{"))) (setq reftex-cite-prompt-optional-args nil) (setq reftex-cite-cleanup-optional-args t)
- Load ebib
ebib is a bibtex database manager that works inside emacs. It can talk to org-mode. See the ebib project page for more. When Ebib is loaded, you can run it withM-x ebib.(autoload 'ebib "ebib" "Ebib, a BibTeX database manager." t) (setq ebib-preload-bib-files '("/Users/kjhealy/Documents/bibs/socbib.bib")) (add-hook 'LaTeX-mode-hook #'(lambda () (local-set-key "\C-cb" 'ebib-insert-bibtex-key)))
Configure AucTeX
- Use pdfLaTeX
- Take this out to compile to DVI, instead.
(add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)
- Configure Biber
Allow AucTeX to use biber as well as/instead of bibtex.;; Biber under AUCTeX (defun TeX-run-Biber (name command file) "Create a process for NAME using COMMAND to format FILE with Biber." (let ((process (TeX-run-command name command file))) (setq TeX-sentinel-function 'TeX-Biber-sentinel) (if TeX-process-asynchronous process (TeX-synchronous-sentinel name file process)))) (defun TeX-Biber-sentinel (process name) "Cleanup TeX output buffer after running Biber." (goto-char (point-max)) (cond ;; Check whether Biber reports any warnings or errors. ((re-search-backward (concat "^(There \\(?:was\\|were\\) \\([0-9]+\\) " "\\(warnings?\\|error messages?\\))") nil t) ;; Tell the user their number so that she sees whether the ;; situation is getting better or worse. (message (concat "Biber finished with %s %s. " "Type `%s' to display output.") (match-string 1) (match-string 2) (substitute-command-keys "\\\\[TeX-recenter-output-buffer]"))) (t (message (concat "Biber finished successfully. " "Run LaTeX again to get citations right.")))) (setq TeX-command-next TeX-command-default)) (eval-after-load "tex" '(add-to-list 'TeX-command-list '("Biber" "biber %s" TeX-run-Biber nil t :help "Run Biber")) )
- Use latexmk for compilation by default
(eval-after-load "tex" '(add-to-list 'TeX-command-list '("latexmk" "latexmk -synctex=1 -shell-escape -pdf %s" TeX-run-TeX nil t :help "Process file with latexmk")) ) (eval-after-load "tex" '(add-to-list 'TeX-command-list '("xelatexmk" "latexmk -synctex=1 -shell-escape -xelatex %s" TeX-run-TeX nil t :help "Process file with xelatexmk")) ) (add-hook 'TeX-mode-hook '(lambda () (setq TeX-command-default "latexmk")))
- Set a Path to Executables (optional)
- The location of the LaTeX excecutables is system dependent. AUCTeX calls everything through a shell, so you may or may not need this. This source-code block is turned off by default as it should be added to the user's personal configuration as needed.
(setenv "PATH" (concat "/usr/texbin:" (getenv "PATH")))
Configure RefTeX
- Default Bibliography
- This is important when editing source code in Org-babel, since the LaTeX source code block being edited probably doesn't include the \bibliography{} command that RefTeX uses to find bibliographic database(s). Make certain also that RefTeX has a path to the bibliographic databases. This source-code block is turned off be default as it should be configured by the user in a personal file/directory.
(setq reftex-default-bibliography (quote ("user.bib" "local.bib")))
Configure Org-babel
- Add LaTeX to the list of languages Org-babel will recognize.
(require 'ob-latex)
;; (org-babel-add-interpreter "latex")
;; (add-to-list 'org-babel-tangle-langs '("latex" "tex"))
- Add LaTeX to a list of languages that raise noweb-type errors.
(add-to-list 'org-babel-noweb-error-langs "latex")