Initial Commit
[packages] / xemacs-packages / auctex / style / harvard.el
1 ;;; harvard.el --- Support for Harvard Citation style package for AUCTeX.
2
3 ;; Copyright (C) 1994, 1997, 2005 Free Software Foundation, Inc.
4
5 ;; Author: Berwin Turlach <statba@nus.edu.sg>
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Keywords: tex
8
9 ;; This file is part of AUCTeX.
10
11 ;; AUCTeX is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; AUCTeX is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 ;; 02110-1301, USA.
25
26 ;;; Code:
27
28 (TeX-add-style-hook "harvard"
29  (function
30   (lambda ()
31
32     (LaTeX-add-environments
33      '("thebibliography" LaTeX-env-harvardbib ignore))
34
35     (TeX-add-symbols
36      "harvardand"
37      '("citeasnoun"
38        (TeX-arg-conditional TeX-arg-cite-note-p ([ "Note" ]) nil)
39        TeX-arg-cite)
40      '("possessivecite"
41        (TeX-arg-conditional TeX-arg-cite-note-p ([ "Note" ]) nil)
42        TeX-arg-cite)
43      '("citeaffixed"
44        (TeX-arg-conditional TeX-arg-cite-note-p ([ "Note" ]) nil)
45        TeX-arg-cite "Affix")
46      '("citeyear"
47        (TeX-arg-conditional TeX-arg-cite-note-p ([ "Note" ]) nil)
48        TeX-arg-cite)
49      '("citename"
50        (TeX-arg-conditional TeX-arg-cite-note-p ([ "Note" ]) nil)
51        TeX-arg-cite)
52      '("citationstyle"
53        (TeX-arg-eval completing-read "Citation style: " '(("agsm") ("dcu"))))
54      '("citationmode"
55        (TeX-arg-eval completing-read "Citation mode: "
56                      '(("full") ("abbr") ("default"))))
57      '("harvardparenthesis"
58        (TeX-arg-eval completing-read "Harvardparenthesis: "
59                      '(("round") ("curly") ("angle") ("square"))))
60      '("bibliographystyle"
61        (TeX-arg-eval
62         completing-read "Bibliography style: "
63         '(("agsm") ("apsr") ("dcu") ("jmr") ("jphysicsB") ("kluwer") ("nederlands") ("econometrica")))
64        ignore)
65      '("harvarditem" [ "Short citation" ]
66        "Complete citation" "Year" TeX-arg-define-cite))
67
68     (setq TeX-complete-list
69           (append '(("\\\\citeasnoun\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)"
70                      1 LaTeX-bibitem-list "}")
71                     ("\\\\citeasnoun{\\([^{}\n\r\\%,]*\\)" 1
72                      LaTeX-bibitem-list "}")
73                     ("\\\\possessivecite\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)" 
74                      1 LaTeX-bibitem-list "}")
75                     ("\\\\possessivecite{\\([^{}\n\r\\%,]*\\)" 1
76                      LaTeX-bibitem-list "}")
77                     ("\\\\citename\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)"
78                      1 LaTeX-bibitem-list "}")
79                     ("\\\\citename{\\([^{}\n\r\\%,]*\\)" 1
80                      LaTeX-bibitem-list "}")
81                     ("\\\\citeaffixed\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)"
82                      1 LaTeX-bibitem-list "}")
83                     ("\\\\citeaffixed{\\([^{}\n\r\\%,]*\\)" 1
84                      LaTeX-bibitem-list "}") 
85                     ("\\\\citeaffixed{\\([^{}\n\r\\%]*,\\)\\([^{}\n\r\\%,]*\\)"
86                      2 LaTeX-bibitem-list)
87                     ("\\\\citeyear\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)"
88                      1 LaTeX-bibitem-list "}")
89                     ("\\\\citeyear{\\([^{}\n\r\\%,]*\\)" 1
90                      LaTeX-bibitem-list "}") 
91                     ("\\\\citeyear{\\([^{}\n\r\\%]*,\\)\\([^{}\n\r\\%,]*\\)"
92                      2 LaTeX-bibitem-list))
93                   TeX-complete-list))
94
95     (setq LaTeX-auto-regexp-list
96           (append '(("\\\\harvarditem{\\([a-zA-Z][^%#'()={}]*\\)}{\\([0-9][^, %\"#'()={}]*\\)}{\\([a-zA-Z][^, %\"#'()={}]*\\)}" 3 LaTeX-auto-bibitem)
97                     ("\\\\harvarditem\\[[^][\n\r]+\\]{\\([a-zA-Z][^%#'()={}]*\\)}{\\([0-9][^, %\"#'()={}]*\\)}{\\([a-zA-Z][^, %\"#'()={}]*\\)}" 3 LaTeX-auto-bibitem)
98                     )
99                   LaTeX-auto-regexp-list))
100     
101     (setq LaTeX-item-list
102           (cons '("thebibliography" . LaTeX-item-harvardbib)
103                 LaTeX-item-list))
104
105     ;; Tell RefTeX
106     (when (fboundp 'reftex-set-cite-format)
107       (reftex-set-cite-format 'harvard))))
108  LaTeX-dialect)
109
110 (defun LaTeX-env-harvardbib (environment &optional ignore)
111   "Insert ENVIRONMENT with label for harvarditem."
112   (LaTeX-insert-environment environment
113                             (concat TeX-grop "xx" TeX-grcl))
114   (end-of-line 0)
115   (delete-char 1)
116   (delete-horizontal-space)
117   (LaTeX-insert-item))
118
119 ;; Analog to LaTeX-item-bib from latex.el
120 (defun LaTeX-item-harvardbib ()
121   "Insert a new harvarditem."
122   (TeX-insert-macro "harvarditem"))
123
124 (defvar LaTeX-harvard-package-options '("full" "abbr" "default"
125                                         "agsmcite" "dcucite" "round"
126                                         "curly" "angle" "square" "none")
127   "Package options for the harvard package.")
128
129 ;; harvard.el ends here