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