zap until-condition docs
[emacs.git] / lisp / textmodes / refbib.el
blob975c9396d49bceabd0501f75ab54aeaefb5f9996
1 ;;; refbib.el --- convert refer-style references to ones usable by Latex bib
3 ;; Copyright (C) 1989, 2001-2013 Free Software Foundation, Inc.
5 ;; Author: Henry Kautz <kautz@research.att.com>
6 ;; Maintainer: FSF
7 ;; Keywords: bib, tex
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Use: from a buffer containing the refer-style bibliography,
27 ;; M-x r2b-convert-buffer
28 ;; Program will prompt for an output buffer name, and will log
29 ;; warnings during the conversion process in the buffer *Log*.
31 ;;; Change Log:
33 ;; HISTORY
34 ;; 9/88, created H.Kautz
35 ;; modified 1/19/89, allow books with editor but no author;
36 ;; added %O ordering field;
37 ;; appended invalid multiple fields, instead of
38 ;; discarding;
39 ;; added rule, a tech report whose %R number
40 ;; contains "ISBN" is really a book
41 ;; added rule, anything with an editor is a book
42 ;; or a proceedings
43 ;; added 'manual type, for items with institution
44 ;; but no author or editor
45 ;; fixed bug so trailing blanks are trimmed
46 ;; added 'proceedings type
47 ;; used "organization" field for proceedings
48 ;; modified 2/16/89, updated help messages
49 ;; modified 2/23/89, include capitalize stop words in r2b stop words,
50 ;; fixed problems with contractions (e.g. it's),
51 ;; caught multiple stop words in a row
52 ;; modified 3/1/89, fixed capitalize-title for first words all caps
53 ;; modified 3/15/89, allow use of " to delimit fields
54 ;; modified 4/18/89, properly "quote" special characters on output
56 ;;; Code:
58 ;**********************************************************
59 ; User Parameters
61 (defgroup refbib nil
62 "Convert refer-style references to ones usable by Latex bib."
63 :prefix "r2b-"
64 :group 'wp)
66 (defcustom r2b-trace-on nil
67 "Non-nil means trace conversion."
68 :type 'boolean
69 :group 'refbib)
71 (defcustom r2b-journal-abbrevs
74 "Abbreviation list for journal names.
75 If the car of an element matches a journal name exactly, it is replaced by
76 the cadr when output. Braces must be included if replacement is a
77 {string}, but not if replacement is a bibtex abbreviation. The cadr
78 may be eliminated if is exactly the same as the car.
79 Because titles are capitalized before matching, the abbreviation
80 for the journal name should be listed as beginning with a capital
81 letter, even if it really doesn't.
82 For example, a value of '((\"Aij\" \"{Artificial Intelligence}\")
83 \(\"Ijcai81\" \"ijcai7\")) would expand Aij to the text string
84 \"Artificial Intelligence\", but would replace Ijcai81 with the
85 BibTeX macro \"ijcai7\"."
86 :type '(repeat (list string string))
87 :group 'refbib)
89 (defcustom r2b-booktitle-abbrevs
92 "Abbreviation list for book and proceedings names.
93 If the car of an element matches a title or booktitle exactly, it is
94 replaced by the cadr when output. Braces must be included if
95 replacement is a {string}, but not if replacement is a bibtex
96 abbreviation. The cadr may be eliminated if is exactly the same as
97 the car.
98 Because titles are capitalized before matching, the abbreviated title
99 should be listed as beginning with a capital letter, even if it doesn't.
100 For example, a value of '((\"Aij\" \"{Artificial Intelligence}\")
101 \(\"Ijcai81\" \"ijcai7\")) would expand Aij to the text string
102 \"Artificial Intelligence\", but would replace Ijcai81 with the
103 BibTeX macro \"ijcai7\"."
104 :type '(repeat (list string string))
105 :group 'refbib)
107 (defcustom r2b-proceedings-list
109 "Assoc list of books or journals which are really conference proceedings,
110 but whose name and whose abbrev expansion (as defined in `r2b-journal-abbrevs'
111 and `r2b-booktitle-abbrevs') does not contain the words \"conference\" or
112 \"proceedings\". (Those cases are handled automatically.)
113 The entry must match the given data exactly.
114 Because titles are capitalized before matching, the items in this list
115 should begin with a capital letter.
116 For example, suppose the title \"Ijcai81\" is used for the proceedings of
117 a conference, and its expansion is the BibTeX macro \"ijcai7\". Then
118 `r2b-proceedings-list' should be '((\"Ijcai81\") ...). If instead its
119 expansion were \"Proceedings of the Seventh International Conference
120 on Artificial Intelligence\", then you would NOT need to include Ijcai81
121 in `r2b-proceedings-list' (although it wouldn't cause an error)."
122 :type '(repeat (list string string))
123 :group 'refbib)
125 (defvar r2b-additional-stop-words
126 "Some\\|What"
127 "Words not to be used to build the citation key.
128 This is in addition to the `r2b-capitalize-title-stop-words'.")
130 (defcustom r2b-delimit-with-quote t
131 "If true, then use \" to delimit fields, otherwise use braces."
132 :type 'boolean
133 :group 'refbib)
135 ;**********************************************************
136 ; Utility Functions
138 (defvar r2b-capitalize-title-stop-words
139 (concat
140 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
141 "by\\|with\\|that\\|its")
142 "Words not to be capitalized in a title (unless the first word).")
144 (defvar r2b-capitalize-title-stop-regexp
145 (concat "\\(" r2b-capitalize-title-stop-words "\\)\\(\\b\\|'\\)"))
147 (defun r2b-capitalize-title-region (begin end)
148 "Like `capitalize-region', but don't capitalize stop words, except the first."
149 (interactive "r")
150 (let ((case-fold-search nil) (orig-syntax-table (syntax-table)))
151 (unwind-protect
152 (save-restriction
153 (set-syntax-table text-mode-syntax-table)
154 (narrow-to-region begin end)
155 (goto-char (point-min))
156 (if (looking-at "[A-Z][a-z]*[A-Z]")
157 (forward-word 1)
158 (capitalize-word 1))
159 (while (re-search-forward "\\<" nil t)
160 (if (looking-at "[A-Z][a-z]*[A-Z]")
161 (forward-word 1)
162 (if (let ((case-fold-search t))
163 (looking-at r2b-capitalize-title-stop-regexp))
164 (downcase-word 1)
165 (capitalize-word 1)))
167 (set-syntax-table orig-syntax-table))))
170 (defun r2b-capitalize-title (s)
171 "Like `capitalize', but don't capitalize stop words, except the first."
172 (with-current-buffer (get-buffer-create "$$$Scratch$$$")
173 (erase-buffer)
174 (insert s)
175 (r2b-capitalize-title-region (point-min) (point-max))
176 (buffer-string)))
178 ;*********************************************************
179 (defun r2b-reset ()
180 "Unbind defvars, for debugging."
181 (interactive)
182 (makunbound 'r2b-journal-abbrevs)
183 (makunbound 'r2b-booktitle-abbrevs)
184 (makunbound 'r2b-proceedings-list)
185 (makunbound 'r2b-capitalize-title-stop-words)
186 (makunbound 'r2b-capitalize-title-stop-regexp)
187 (makunbound 'r2b-additional-stop-words)
188 (makunbound 'r2b-stop-regexp))
190 (defvar r2b-stop-regexp
191 (concat "\\`\\(\\("
192 r2b-additional-stop-words "\\|" r2b-capitalize-title-stop-words
193 "\\)\\('\\w*\\)?\\W+\\)*\\([A-Z0-9]+\\)"))
196 (defun r2b-trace (&rest args)
197 (if r2b-trace-on
198 (progn
199 (apply (function message) args)
200 (sit-for 0))))
202 (defun r2b-match (exp)
203 "Returns string matched in current buffer."
204 (buffer-substring (match-beginning exp) (match-end exp)))
206 (defcustom r2b-out-buf-name "*Out*"
207 "Name of buffer for output from refer-to-bibtex."
208 :type 'string
209 :group 'refbib)
211 (defcustom r2b-log-name "*Log*"
212 "Name of buffer for logs errors from refer-to-bibtex."
213 :type 'string
214 :group 'refbib)
216 (defvar r2b-in-buf nil)
217 (defvar r2b-out-buf nil)
218 (defvar r2b-log nil)
220 (defvar r2b-error-found nil)
222 (defvar r2b-variables) (defvar r2bv-address) (defvar r2bv-annote)
223 (defvar r2bv-author) (defvar r2bv-booktitle) (defvar r2bv-date)
224 (defvar r2bv-decade) (defvar r2bv-editor) (defvar r2bv-entry-kind)
225 (defvar r2bv-institution) (defvar r2bv-journal) (defvar r2bv-keywords)
226 (defvar r2bv-kn) (defvar r2bv-month) (defvar r2bv-note)
227 (defvar r2bv-number) (defvar r2bv-ordering) (defvar r2bv-organization)
228 (defvar r2bv-pages) (defvar r2bv-primary-author) (defvar r2bv-publisher)
229 (defvar r2bv-school) (defvar r2bv-title) (defvar r2bv-title-first-word)
230 (defvar r2bv-tr) (defvar r2bv-type) (defvar r2bv-volume)
231 (defvar r2bv-where) (defvar r2bv-year)
233 (setq r2b-variables '(
234 r2b-error-found
235 r2bv-author
236 r2bv-primary-author
237 r2bv-date
238 r2bv-year
239 r2bv-decade
240 r2bv-month
241 r2bv-title
242 r2bv-title-first-word
243 r2bv-editor
244 r2bv-annote
245 r2bv-tr
246 r2bv-address
247 r2bv-institution
248 r2bv-keywords
249 r2bv-booktitle
250 r2bv-journal
251 r2bv-volume
252 r2bv-number
253 r2bv-pages
254 r2bv-booktitle
255 r2bv-kn
256 r2bv-publisher
257 r2bv-organization
258 r2bv-school
259 r2bv-type
260 r2bv-where
261 r2bv-note
262 r2bv-ordering
265 (defun r2b-clear-variables ()
266 "Set all global vars used by r2b to nil."
267 (let ((vars r2b-variables))
268 (while vars
269 (set (car vars) nil)
270 (setq vars (cdr vars)))))
272 (defun r2b-warning (&rest args)
273 (setq r2b-error-found t)
274 (princ (apply (function format) args) r2b-log)
275 (princ "\n" r2b-log)
276 (princ "\n" r2b-out-buf)
277 (princ "% " r2b-out-buf)
278 (princ (apply (function format) args) r2b-out-buf))
280 (defun r2b-get-field (var field &optional unique required capitalize)
281 "Set VAR to string value of FIELD, if any. If none, VAR is set to
282 nil. If multiple fields appear, then separate values with the
283 '\\nand\\t\\t', unless UNIQUE is non-nil, in which case log a warning
284 and just concatenate the values. Trim off leading blanks and tabs on
285 first line, and trailing blanks and tabs of every line. Log a warning
286 and set VAR to the empty string if REQUIRED is true. Capitalize as a
287 title if CAPITALIZE is true. Returns value of VAR."
288 (let (item val (not-past-end t))
289 (r2b-trace "snarfing %s" field)
290 (goto-char (point-min))
291 (while (and not-past-end
292 (re-search-forward
293 (concat "^" field "\\b[ \t]*\\(.*[^ \t\n]\\)[ \t]*") nil t))
294 (setq item (r2b-match 1))
295 (while (and (setq not-past-end (zerop (forward-line 1)))
296 (not (looking-at "[ \t]*$\\|%")))
297 (looking-at "\\(.*[^ \t\n]\\)[ \t]*$")
298 (setq item (concat item "\n" (r2b-match 1)))
300 (if (null val)
301 (setq val item)
302 (if unique
303 (progn
304 (r2b-warning "*Invalid multiple field %s %s" field item)
305 (setq val (concat val "\n" item))
307 (setq val (concat val "\n\t\tand " item))
311 (if (and val capitalize)
312 (setq val (r2b-capitalize-title val)))
313 (set var val)
314 (if (and (null val) required)
315 (r2b-require var))
318 (defun r2b-set-match (var n regexp string )
319 "Set VAR to the Nth subpattern in REGEXP matched by STRING, or nil if none."
320 (set var
321 (if (and (stringp string) (string-match regexp string))
322 (substring string (match-beginning n) (match-end n))
323 nil)
327 (defvar r2b-month-abbrevs
328 '(("jan") ("feb") ("mar") ("apr") ("may") ("jun") ("jul") ("aug")
329 ("sep") ("oct") ("nov") ("dec")))
331 (defun r2b-convert-month ()
332 "Try to convert `r2bv-month' to a standard 3 letter name."
333 (if r2bv-month
334 (let ((months r2b-month-abbrevs))
335 (if (string-match "[^0-9]" r2bv-month)
336 (progn
337 (while (and months (not (string-match (car (car months))
338 r2bv-month)))
339 (setq months (cdr months)))
340 (if months
341 (setq r2bv-month (car (car months)))))
342 (progn
343 (setq months (car (read-from-string r2bv-month)))
344 (if (and (numberp months)
345 (> months 0)
346 (< months 13))
347 (setq r2bv-month (car (nth months r2b-month-abbrevs)))
348 (progn
349 (r2b-warning "* Ridiculous month")
350 (setq r2bv-month nil))
356 (defun r2b-snarf-input ()
357 "Parse buffer into global variables."
358 (let ((case-fold-search t))
359 (r2b-trace "snarfing...")
360 (sit-for 0)
361 (set-buffer r2b-in-buf)
362 (goto-char (point-min))
363 (princ " " r2b-log)
364 (princ (buffer-substring (point) (progn (end-of-line) (point))) r2b-log)
365 (terpri r2b-log)
367 (r2b-get-field 'r2bv-author "%A")
368 (r2b-get-field 'r2bv-editor "%E")
369 (cond
370 (r2bv-author
371 (r2b-set-match 'r2bv-primary-author 1
372 "\\b\\(\\w+\\)[ \t]*\\($\\|,\\)" r2bv-author)
374 (r2bv-editor
375 (r2b-set-match 'r2bv-primary-author 1
376 "\\b\\(\\w+\\)[ \t]*\\($\\|,\\)" r2bv-editor)
379 (setq r2bv-primary-author "")
383 (r2b-get-field 'r2bv-date "%D" t t)
384 (r2b-set-match 'r2bv-year 0 "[12][0-9][0-9][0-9]" r2bv-date)
385 (and (null r2bv-year)
386 (r2b-set-match 'r2bv-year 1 "[^0-9]\\([0-9][0-9]\\)$" r2bv-date)
387 (setq r2bv-year (concat "19" r2bv-year)))
388 (r2b-set-match 'r2bv-decade 1 "..\\(..\\)" r2bv-year)
389 (r2b-set-match 'r2bv-month 0
390 "[0-9]+/\\|[a-zA-Z]+" r2bv-date)
391 (if (and (stringp r2bv-month) (string-match "\\(.*\\)/$" r2bv-month))
392 (setq r2bv-month (substring r2bv-month 0 (match-end 1))))
393 (r2b-convert-month)
395 (r2b-get-field 'r2bv-title "%T" t t t)
396 (r2b-set-match 'r2bv-title-first-word 4
397 r2b-stop-regexp
398 r2bv-title)
400 (r2b-get-field 'r2bv-annote "%X" t )
401 (r2b-get-field 'r2bv-tr "%R" t)
402 (r2b-get-field 'r2bv-address "%C" t)
403 (r2b-get-field 'r2bv-institution "%I" t)
404 (r2b-get-field 'r2bv-keywords "%K")
405 (r2b-get-field 'r2bv-booktitle "%B" t nil t)
406 (r2b-get-field 'r2bv-journal "%J" t nil t)
407 (r2b-get-field 'r2bv-volume "%V" t)
408 (r2b-get-field 'r2bv-number "%N" t)
409 (r2b-get-field 'r2bv-pages "%P" t)
410 (r2b-get-field 'r2bv-where "%W" t)
411 (r2b-get-field 'r2bv-ordering "%O" t)
416 (defun r2b-put-field (field data &optional abbrevs)
417 "Print bibtex FIELD = {DATA} if DATA not null; precede
418 with a comma and newline; if ABBREVS list is given, then
419 try to replace the {DATA} with an abbreviation."
420 (if data
421 (let (match nodelim multi-line index)
422 (cond
423 ((and abbrevs (setq match (assoc data abbrevs)))
424 (if (null (cdr match))
425 (setq data (car match))
426 (setq data (car (cdr match))))
427 (setq nodelim t))
428 ((and (not (equal data ""))
429 (not (string-match "[^0-9]" data)))
430 (setq nodelim t))
432 (setq index 0)
433 (while (string-match "[\\~^]" data index)
434 (setq data (concat (substring data 0 (match-beginning 0))
435 "\\verb+"
436 (substring data (match-beginning 0) (match-end 0))
438 (substring data (match-end 0))))
439 (setq index (+ (match-end 0) 7)))
440 (setq index 0)
441 (while (string-match "[$&%#_{}]" data index)
442 (setq data (concat (substring data 0 (match-beginning 0))
443 "\\"
444 (substring data (match-beginning 0))))
445 (setq index (+ (match-end 0) 1)))
446 (setq index 0)
447 (if r2b-delimit-with-quote
448 (while (string-match "\"" data index)
449 (setq data (concat (substring data 0 (match-beginning 0))
450 "{\"}"
451 (substring data (match-end 0))))
452 (setq index (+ (match-end 0) 2))))
454 (princ ", \n ")
455 (princ field)
456 (princ " =\t")
457 (if (not nodelim)
458 (if r2b-delimit-with-quote
459 (princ "\"")
460 (princ "{")))
461 (string-match ".*" data)
462 (if (> (match-end 0) 59)
463 (princ "\n"))
464 (princ data)
465 (if (not nodelim)
466 (if r2b-delimit-with-quote
467 (princ "\"")
468 (princ "}")))
473 (defun r2b-require (vars)
474 "If any of VARS is null, set to empty string and log error."
475 (cond
476 ((null vars))
477 ((listp vars) (r2b-require (car vars)) (r2b-require (cdr vars)))
479 (if (null (symbol-value vars))
480 (progn
481 (r2b-warning "*Missing value for field %s" vars)
482 (set vars "")
488 (defmacro r2b-moveq (new old)
489 "Set NEW to OLD and set OLD to nil."
490 (list 'progn (list 'setq new old) (list 'setq old 'nil)))
492 (defun r2b-isa-proceedings (name)
493 "Return t if NAME is the name of proceedings."
494 (and
495 name
497 (string-match "proceedings\\|conference" name)
498 (assoc name r2b-proceedings-list)
499 (let ((match (assoc name r2b-booktitle-abbrevs)))
500 (and match
501 (string-match "proceedings\\|conference" (car (cdr match)))))
504 (defun r2b-isa-university (name)
505 "Return t if NAME is a university or similar organization,
506 but not a publisher."
507 (and
508 name
509 (string-match "university" name)
510 (not (string-match "press" name))
514 (defun r2b-barf-output ()
515 "Generate bibtex based on global variables."
516 (let ((standard-output r2b-out-buf) (case-fold-search t) match)
518 (r2b-trace "...barfing")
519 (sit-for 0)
520 (set-buffer r2b-out-buf)
522 (setq r2bv-kn (concat r2bv-primary-author r2bv-decade
523 r2bv-title-first-word))
525 (setq r2bv-entry-kind
526 (cond
527 ((r2b-isa-proceedings r2bv-journal)
528 (r2b-moveq r2bv-booktitle r2bv-journal)
529 (if (r2b-isa-university r2bv-institution)
530 (r2b-moveq r2bv-organization r2bv-institution)
531 (r2b-moveq r2bv-publisher r2bv-institution))
532 (r2b-moveq r2bv-note r2bv-tr)
533 (r2b-require 'r2bv-author)
534 'inproceedings)
535 ((r2b-isa-proceedings r2bv-booktitle)
536 (if (r2b-isa-university r2bv-institution)
537 (r2b-moveq r2bv-organization r2bv-institution)
538 (r2b-moveq r2bv-publisher r2bv-institution))
539 (r2b-moveq r2bv-note r2bv-tr)
540 (r2b-require 'r2bv-author)
541 'inproceedings)
542 ((and r2bv-tr (string-match "phd" r2bv-tr))
543 (r2b-moveq r2bv-school r2bv-institution)
544 (r2b-require 'r2bv-school )
545 (r2b-require 'r2bv-author)
546 'phdthesis)
547 ((and r2bv-tr (string-match "master" r2bv-tr))
548 (r2b-moveq r2bv-school r2bv-institution)
549 (r2b-require 'r2bv-school )
550 (r2b-require 'r2bv-author)
551 'mastersthesis)
552 ((and r2bv-tr (string-match "draft\\|unpublish" r2bv-tr))
553 (r2b-moveq r2bv-note r2bv-institution)
554 (r2b-require 'r2bv-author)
555 'unpublished)
556 (r2bv-journal
557 (r2b-require 'r2bv-author)
558 'article)
559 (r2bv-booktitle
560 (r2b-moveq r2bv-publisher r2bv-institution)
561 (r2b-moveq r2bv-note r2bv-tr)
562 (r2b-require 'r2bv-publisher)
563 (r2b-require 'r2bv-author)
564 'incollection)
565 ((and r2bv-author
566 (null r2bv-editor)
567 (string-match "\\`personal communication\\'" r2bv-title))
568 'misc)
569 ((r2b-isa-proceedings r2bv-title)
570 (if (r2b-isa-university r2bv-institution)
571 (r2b-moveq r2bv-organization r2bv-institution)
572 (r2b-moveq r2bv-publisher r2bv-institution))
573 (r2b-moveq r2bv-note r2bv-tr)
574 'proceedings)
575 ((or r2bv-editor
576 (and r2bv-author
578 (null r2bv-tr)
579 (string-match "\\bisbn\\b" r2bv-tr))))
580 (r2b-moveq r2bv-publisher r2bv-institution)
581 (r2b-moveq r2bv-note r2bv-tr)
582 (r2b-require 'r2bv-publisher)
583 (if (null r2bv-editor)
584 (r2b-require 'r2bv-author))
585 'book)
586 (r2bv-tr
587 (r2b-require 'r2bv-institution)
588 (if (string-match
589 "\\`\\(\\(.\\|\n\\)+\\)[ \t\n]+\\([^ \t\n]\\)+\\'"
590 r2bv-tr)
591 (progn
592 (setq r2bv-type (substring r2bv-tr 0 (match-end 1)))
593 (setq r2bv-number (substring r2bv-tr
594 (match-beginning 3)))
595 (setq r2bv-tr nil))
596 (r2b-moveq r2bv-number r2bv-tr))
597 (r2b-require 'r2bv-author)
598 'techreport)
599 (r2bv-institution
600 (r2b-moveq r2bv-organization r2bv-institution)
601 'manual)
603 'misc)
606 (r2b-require '( r2bv-year))
608 (if r2b-error-found
609 (princ "\n% Warning -- Errors During Conversion Next Entry\n"))
611 (princ "\n@")
612 (princ r2bv-entry-kind)
613 (princ "( ")
614 (princ r2bv-kn)
616 (r2b-put-field "author" r2bv-author )
617 (r2b-put-field "title" r2bv-title r2b-booktitle-abbrevs)
618 (r2b-put-field "year" r2bv-year )
620 (r2b-put-field "month" r2bv-month r2b-month-abbrevs)
621 (r2b-put-field "journal" r2bv-journal r2b-journal-abbrevs)
622 (r2b-put-field "volume" r2bv-volume)
623 (r2b-put-field "type" r2bv-type)
624 (r2b-put-field "number" r2bv-number)
625 (r2b-put-field "booktitle" r2bv-booktitle r2b-booktitle-abbrevs)
626 (r2b-put-field "editor" r2bv-editor)
627 (r2b-put-field "publisher" r2bv-publisher)
628 (r2b-put-field "institution" r2bv-institution)
629 (r2b-put-field "organization" r2bv-organization)
630 (r2b-put-field "school" r2bv-school)
631 (r2b-put-field "pages" r2bv-pages)
632 (r2b-put-field "address" r2bv-address)
633 (r2b-put-field "note" r2bv-note)
634 (r2b-put-field "keywords" r2bv-keywords)
635 (r2b-put-field "where" r2bv-where)
636 (r2b-put-field "ordering" r2bv-ordering)
637 (r2b-put-field "annote" r2bv-annote)
639 (princ " )\n")
644 (defun r2b-convert-record (output)
645 "Transform current bib entry and append to buffer OUTPUT.
646 Do `\\[r2b-help]' for more info."
647 (interactive
648 (list (read-string "Output to buffer: " r2b-out-buf-name)))
649 (let (rec-end rec-begin not-done)
650 (setq r2b-out-buf-name output)
651 (setq r2b-out-buf (get-buffer-create output))
652 (setq r2b-in-buf (current-buffer))
653 (set-buffer r2b-out-buf)
654 (goto-char (point-max))
655 (setq r2b-log (get-buffer-create r2b-log-name))
656 (set-buffer r2b-log)
657 (goto-char (point-max))
658 (set-buffer r2b-in-buf)
659 (setq not-done (re-search-forward "[^ \t\n]" nil t))
660 (if not-done
661 (progn
662 (re-search-backward "^[ \t]*$" nil 2)
663 (re-search-forward "^%")
664 (beginning-of-line nil)
665 (setq rec-begin (point))
666 (re-search-forward "^[ \t]*$" nil 2)
667 (setq rec-end (point))
668 (narrow-to-region rec-begin rec-end)
669 (r2b-clear-variables)
670 (r2b-snarf-input)
671 (r2b-barf-output)
672 (set-buffer r2b-in-buf)
673 (widen)
674 (goto-char rec-end)
681 (defun r2b-convert-buffer (output)
682 "Transform current buffer and append to buffer OUTPUT.
683 Do `\\[r2b-help]' for more info."
684 (interactive
685 (list (read-string "Output to buffer: " r2b-out-buf-name)))
686 (with-current-buffer (setq r2b-log (get-buffer-create r2b-log-name))
687 (erase-buffer))
688 (widen)
689 (goto-char (point-min))
690 (message "Working, please be patient...")
691 (sit-for 0)
692 (while (r2b-convert-record output) t)
693 (message "Done, results in %s, errors in %s"
694 r2b-out-buf-name r2b-log-name))
696 (defvar r2b-help-message
697 " Refer to Bibtex Bibliography Conversion
699 A refer-style database is of the form:
701 %A Joe Blow
702 %T Great Thoughts I've Thought
703 %D 1977
704 etc.
706 This utility converts these kind of databases to bibtex form, for
707 users of TeX and LaTex. Instructions:
708 1. Visit the file containing the refer-style database.
709 2. The command
710 M-x r2b-convert-buffer
711 converts the entire buffer, appending its output by default in a
712 buffer named *Out*, and logging progress and errors in a buffer
713 named *Log*. The original file is never modified.
714 Note that results are appended to *Out*, so if that buffer
715 buffer already exists and contains material you don't want to
716 save, you should kill it first.
717 3. Switch to the buffer *Out* and save it as a named file.
718 4. To convert a single refer-style entry, simply position the cursor
719 at the entry and enter
720 M-x r2b-convert-record
721 Again output is appended to *Out* and errors are logged in *Log*.
723 This utility is very robust and pretty smart about determining the
724 type of the entry. It includes facilities for expanding refer macros
725 to text, or substituting bibtex macros. Do M-x describe-variable on
726 r2b-journal-abbrevs
727 r2b-booktitle-abbrevs
728 r2b-proceedings-list
729 for information on these features.
731 Please send bug reports and suggestions to
732 Henry Kautz
733 kautz@research.att.com
734 allegra!kautz")
737 (defun r2b-help ()
738 "Print help describing the `refbib' package."
739 (interactive)
740 (with-output-to-temp-buffer "*Help*"
741 (princ r2b-help-message)
742 (with-current-buffer standard-output
743 (help-mode))))
745 (provide 'refbib)
746 (provide 'refer-to-bibtex)
748 ;;; refbib.el ends here