EasyPG 1.07 Released
[packages] / xemacs-packages / auctex / style / natbib.el
1 ;;; natbib.el --- AUCTeX style for `natbib.sty' version 8.31b
2
3 ;; Copyright (C) 1997, 1998, 2004, 2007, 2014, 2016 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
30  "natbib"
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              ;; 2.4 Extended Citation Commands
43              ("citenum" . 0)
44              ;; 2.5 Forcing Upper Cased Name
45              ("Citet" . 1) ("Citet*" . 1) ("Citealt" . 1) ("Citealt*" . 1)
46              ("Citep" . 2) ("Citep*" . 2) ("Citealp" . 2) ("Citealp*" . 2)
47              ;; 2.6 Citation Aliasing
48              ("citetalias" . 1) ("citepalias" . 2))))
49
50      ;; Add these symbols
51      (apply
52       #'TeX-add-symbols
53       (mapcar
54        (lambda (cmd)
55          (cond
56           ((= (cdr cmd) 0)
57            ;; No optional arguments
58            (list (car cmd) 'TeX-arg-cite))
59           ((= (cdr cmd) 1)
60            ;; Just one optional argument, the post note
61            (list
62             (car cmd)
63             '(TeX-arg-conditional TeX-arg-cite-note-p (["Post-note"]) nil)
64             'TeX-arg-cite))
65           ((= (cdr cmd) 2)
66            ;; Pre and post notes
67            (list
68             (car cmd)
69             '(TeX-arg-conditional TeX-arg-cite-note-p ([LaTeX-arg-natbib-notes]) nil)
70             'TeX-arg-cite))))
71        citecmds))
72
73      ;; Make an entry in TeX-complete-list
74      (add-to-list
75       'TeX-complete-list
76       (list
77        (concat "\\\\\\("
78                (mapconcat (lambda (x) (regexp-quote (car x)))
79                           citecmds "\\|")
80                "\\)\\(\\[[^]\n\r\\%]*\\]\\)*{\\([^{}\n\r\\%,]*,\\)*\\([^{}\n\r\\%,]*\\)")
81        4 'LaTeX-bibitem-list "}")))
82
83    ;; Add the other symbols
84    (TeX-add-symbols
85     ;; 2.4 Extended Citation Commands
86     '("citetext" "Text")
87
88     ;; 2.6 Citation Aliasing
89     '("defcitealias" TeX-arg-cite "Alias")
90
91     ;; 2.9 Selecting Citation Punctuation
92     '("setcitestyle" (TeX-arg-key-val
93                       (;; Citation mode (fourth argument of \bibpunct):
94                        ("authoryear") ("numbers") ("super")
95                        ;; Braces (first and second arguments of \bibpunct):
96                        ("round") ("square") ("open") ("close")
97                        ;; Between citations (third argument of \bibpunct):
98                        ("semicolon") ("comma") ("citesep")
99                        ;; Between author and year (fifth argument of \bibpunct):
100                        ("aysep")
101                        ;; Between years with common author (sixth argument of \bibpunct):
102                        ("yysep")
103                        ;; Text before post-note (optional argument of \bibpunct):
104                        ("notesep"))))
105     '("bibpunct" ["Post note separator"]
106       "Opening bracket"
107       "Closing bracket"
108       "Punctuation between multiple citations"
109       "style [n]umeric [s]uperscript [a]uthor-year"
110       "Punctuation between author and year"
111       "Punctuation between years for common authors")
112
113     '("citestyle" (TeX-arg-eval completing-read
114                                 (TeX-argument-prompt optional nil "Style")
115                                 '("plain" "plainnat" "agu" "egu"
116                                   "agms" "dcu" "kluwer" "cospar" "nature")))
117
118     ;; 2.12 Other Formatting Options
119     "bibsection"
120     "bibpreamble"
121     "bibfont"
122     "citenumfont"
123     "bibnumfmt"
124
125     ;; 2.13 Automatic Indexing of Citations
126     '("citeindextrue")
127     '("citeindexfalse")
128     '("citeindextype"))
129
130    ;; 2.12 Other Formatting Options
131    (LaTeX-add-lengths "bibhang" "bibsep")
132
133    ;; Fontification
134    (when (and (fboundp 'font-latex-add-keywords)
135               (eq TeX-install-font-lock 'font-latex-setup))
136      (font-latex-add-keywords '(("cite"           "*[[{")
137                                 ("citet"          "*[[{")
138                                 ("citealt"        "*[[{")
139                                 ("citep"          "*[[{")
140                                 ("citealp"        "*[[{")
141                                 ("citeauthor"     "*[[{")
142                                 ("citefullauthor" "[[{")
143                                 ("citeyear"       "[[{")
144                                 ("citeyearpar"    "[[{")
145                                 ("shortcites"     "{")
146                                 ("citenum"        "{")
147                                 ("Citet"          "*[[{")
148                                 ("Citealt"        "*[[{")
149                                 ("Citep"          "*[[{")
150                                 ("Citealp"        "*[[{")
151                                 ("Citeauthor"     "*[[{")
152                                 ("citetalias"     "*[[{")
153                                 ("citepalias"     "*[[{"))
154                               'reference)
155      (font-latex-add-keywords '(("defcitealias"   "{{")
156                                 ("bibpunct"       "[{{{{{{")
157                                 ("setcitestyle"   "{")
158                                 ("citestyle"      "{"))
159                               'function))
160
161    ;; Tell RefTeX
162    (when (and LaTeX-reftex-cite-format-auto-activate
163               (fboundp 'reftex-set-cite-format))
164      (reftex-set-cite-format 'natbib)))
165  LaTeX-dialect)
166
167 (defun LaTeX-arg-natbib-notes (optional)
168   "Prompt for two note arguments a natbib citation command.
169 If OPTIONAL is non-nil, insert them in brackets, otherwise in
170 braces."
171   (let ((pre (TeX-read-string
172               (TeX-argument-prompt optional nil "Pre-note")))
173         (post (TeX-read-string
174                (TeX-argument-prompt optional nil "Post-note"))))
175     (TeX-argument-insert pre optional)
176     (TeX-argument-insert post optional)
177     ;; pre is given, post is empty: Make sure that we insert an
178     ;; extra pair of `[]', otherwise pre becomes post
179     (when (and pre (not (string= pre ""))
180                (string= post ""))
181       (insert LaTeX-optop LaTeX-optcl))))
182
183 (defvar LaTeX-natbib-package-options '("numbers" "super" "authoryear"
184                                        "round" "square" "angle" "curly"
185                                        "comma" "colon" "nobibstyle"
186                                        "bibstyle" "openbib" "sectionbib"
187                                        "sort" "sort&compress"
188                                        "longnamesfirst" "nonamebreak")
189   "Package options for the natbib package.")
190
191 ;; natbib.el ends here