]> code.delx.au - gnu-emacs-elpa/blob - packages/auctex/style/natbib.el
Update AUCTeX ELPA package to the new 11.87 release.
[gnu-emacs-elpa] / packages / auctex / style / natbib.el
1 ;;; natbib.el --- Style hook for the natbib package
2
3 ;; Copyright (C) 1997, 1998, 2004, 2007 Free Software Foundation, Inc.
4
5 ;; Authors: Berwin Turlach <statba@nus.edu.sg>
6 ;; Carsten Dominik <dominik@strw.leidenuniv.nl>
7 ;; Maintainer: auctex-devel@gnu.org
8 ;; Keywords: tex
9
10 ;; This file is part of AUCTeX.
11
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 ;; 02110-1301, USA.
26
27 ;;; Code:
28
29 (TeX-add-style-hook "natbib"
30 (function
31 (lambda ()
32 ;; The number in the cdr of the following list indicates how many
33 ;; optional note arguments we consider useful. Prompting for those
34 ;; arguments will still depend upon `TeX-arg-cite-note-p'.
35 (let ((citecmds
36 '(("cite" . 0)
37 ("citet" . 1) ("citet*" . 1) ("citealt" . 1) ("citealt*" . 1)
38 ("citep" . 2) ("citep*" . 2) ("citealp" . 2) ("citealp*" . 2)
39 ("citeauthor" . 0) ("citeauthor*" . 0) ("citefullauthor" . 0)
40 ("citeyear" . 0) ("citeyearpar" . 0)
41 ("shortcites" . 0))))
42
43 ;; Add these symbols
44 (apply
45 'TeX-add-symbols
46 (mapcar
47 (lambda (cmd)
48 (cond
49 ((= (cdr cmd) 0)
50 ;; No optional arguments
51 (list (car cmd) 'TeX-arg-cite))
52 ((= (cdr cmd) 1)
53 ;; Just one optional argument, the post note
54 (list
55 (car cmd)
56 '(TeX-arg-conditional TeX-arg-cite-note-p (["Post-note"]) nil)
57 'TeX-arg-cite))
58 ((= (cdr cmd) 2)
59 ;; Pre and post notes
60 (list
61 (car cmd)
62 '(TeX-arg-conditional TeX-arg-cite-note-p (natbib-note-args) nil)
63 'TeX-arg-cite))))
64 citecmds))
65
66 ;; Add the other symbols
67 (TeX-add-symbols
68 '("citetext" "Text")
69 '("bibpunct" ["Post note separator"]
70 "Opening bracket"
71 "Closing bracket"
72 "Punctuation between multiple citations"
73 "style [n]umeric [s]uperscript [a]uthor-year"
74 "Punctuation between author and year"
75 "Punctuation between years for common authors")
76 '("citestyle" "Style")
77 '("citeindextrue")
78 '("citeindexfalse")
79 '("citeindextype"))
80
81 ;; Make an entry in TeX-complete-list
82 (add-to-list
83 'TeX-complete-list
84 (list
85 (concat "\\\\\\("
86 (mapconcat (lambda (x) (regexp-quote (car x)))
87 citecmds "\\|")
88 "\\)\\(\\[[^]\n\r\\%]*\\]\\)*{\\([^{}\n\r\\%,]*,\\)*\\([^{}\n\r\\%,]*\\)")
89 4 'LaTeX-bibitem-list "}")))
90
91 ;; Fontification
92 (when (and (fboundp 'font-latex-add-keywords)
93 (eq TeX-install-font-lock 'font-latex-setup))
94 (font-latex-add-keywords '(("cite" "*[[{")
95 ("citet" "*[[{")
96 ("citealt" "*[[{")
97 ("citep" "*[[{")
98 ("citealp" "*[[{")
99 ("citeauthor" "*[[{")
100 ("citefullauthor" "[[{")
101 ("citeyear" "[[{")
102 ("citeyearpar" "[[{")
103 ("shortcites" "{"))
104 'reference))
105
106 ;; Tell RefTeX
107 (if (fboundp 'reftex-set-cite-format)
108 (reftex-set-cite-format 'natbib)))))
109
110 (defun natbib-note-args (optional &optional prompt definition)
111 "Prompt for two note arguments a natbib citation command."
112 (if TeX-arg-cite-note-p
113 (let* ((pre (read-string
114 (TeX-argument-prompt optional optional "Pre-note")))
115 (post (read-string
116 (TeX-argument-prompt optional optional "Post-note"))))
117 (if (not (string= pre "")) (insert "[" pre "]"))
118 (if (not (string= post ""))
119 (insert "[" post "]")
120 ;; Make sure that we have an empty post note if pre is not empty
121 (if (string= pre "") (insert "[]"))))))
122
123 (defvar LaTeX-natbib-package-options '("numbers" "super" "authoryear"
124 "round" "square" "angle" "curly"
125 "comma" "colon" "nobibstyle"
126 "bibstyle" "openbib" "sectionbib"
127 "sort" "sort&compress"
128 "longnamesfirst" "nonamebreak")
129 "Package options for the natbib package.")
130
131 ;; natbib.el ends here