(require (quote TeX-mode)) (autoload (quote bibtex-goto-error) "BibTeX-misc") (setq max-lisp-eval-depth 1000) (defconst tex-bib-regexp-all "\\\\cite{\\|\\\\nocite{\\|\\\\input\\|\\\\cite\\[.*\\]{") (defconst tex-bib-regexp-cite "\\\\cite{\\|\\\\nocite{\\|\\\\cite\\[.*\\]{") (defvar tex-bib-cite-list nil "\ List of (CITE-FLAG (ENT1 ENT2 ... ENTn) START END) to be replaced by act") (defvar tex-bib-cite-tags nil "\ List of (ENTRY (Fn STARTn ENDn) ... (F1 START1 END1)), used in correcting errors.") (defvar tex-bib-err-list nil "\ List of \\cite errors") (defvar tex-bib-fn-list nil "\ List of buffer names of involving files") (defvar tex-bib-rec-list nil "\ List of recovering information") (defvar tex-bib-ref-list nil "\ List of symbolic/actual cross references") (defvar tex-bib-to-bibtex nil "\ Flag set t if bibtex-mode is loaded here.") (defvar tex-bib-abbrev (progn (if (not (boundp (quote bibtex-abbrev-files))) (run-hooks (quote bibtex-mode-hook))) (if (not (boundp (quote bibtex-abbrev-files))) (setq bibtex-abbrev-files nil)) bibtex-abbrev-files) "\ List of abbreviation files to be included in any \\bibliography commands") (defun tex-bib-document nil "\ Make a bibliography for the TeX/LaTeX document rooted at the master." (interactive) (byte-code " " [nil tex-check-master-file tex-bib-buffer] 3)) (defun tex-bib-buffer nil "\ Make a bibliography for the TeX/LaTeX document rooted at current file." (interactive) (byte-code "ˈ !\"O P P P P  ! ! %!! \")  ! ! !&. " [=buff= =base= =aux= =bbl= =ref= =blg= regexp tex-bib-regexp-all =bibmsg= cont doc-type nil file-name-nondirectory buffer-file-name 0 string-match ".tex" ".aux" ".bbl" ".ref" ".blg" tex-check-document-type get-buffer-create concat "Making bibliography for " " document rooted at \"" "\"..." message sit-for 1 tex-bib-recover tex-get-include-files "%s%s" =done= (byte-code " ! !ĉՍq b#)'!\\!5Ă=!!ĉ  ĉ!!) e!x     \"!\"8\" qdb% ) \")\"" [t regexp =bbl= normal nil tex-error-pos tex-bib-to-bibtex bibtex-bibs bibtex-error-pos tex-bib-err-list tex-bib-regexp-cite tex-include-files tex-bib-fn-list =bibmsg= doc-type tex-formatter-specs =aux= =blg= tex-bib-mkaux get-buffer-create abort (byte-code "!" [normal t tex-bib-bibtex abort] 3) "*shell*" re-search-forward "^ --line\\|^ : Warning:\\|---line" y-or-n-p "Errors detected in .bib files, correct them? " boundp load "BibTeX-mode" message "Use C-c C-@ to go to next .bib error." recursive-edit "Returning to bibliography making..." sit-for 1 "Citation errors detected, correct them? " tex-bib-correct-error "%scontinuing" string-equal 2 assoc "tex" tex-bib-mkbbl-tex tex-bib-mkbbl-latex tex-bib-sym2act tex-bib-write-ref tex-bib-input-bbl insert-string "\\rm " "* " "*" shell-send-input tex-bib-save throw =done= "done" "abort (on request)"] 29) kill-buffer] 21)) (defun tex-bib-recover (&optional buff base) "\ Recover symbolic references from the current actual refernces." (interactive) (byte-code "ň!   \"O P P !db R# !db#n!n[ł^!\"nlłncdb#!nł!\"nłc ! q ! U!b ! ! !!!t !)-" [buff base bbl ref refbuf nil t tex-bib-fn-list tex-bib-rec-list message "Recovering symbolic references..." buffer-name 0 string-match ".tex" ".bbl" ".ref" get-buffer-create re-search-backward "\\\\input *" "\\|\\\\input *{" beginning-of-line kill-line 1 "\\\\bibliography *{" "^\\|\\w" forward-char zap-to-char 92 32 search-backward "\\bibliographystyle" file-exists-p erase-buffer insert-file-contents buffer-size error "Recovering symbolic references...abort (missing recovery information.)" read tex-bib-act2sym "Recovering symbolic references...done" "Recovering symbolic references...no .ref file" "Recovering symbolic references...no .bbl file referenced" kill-buffer] 28)) (defun tex-bib-act2sym nil (byte-code "!lj@!@ \"!>!qN !K !qNɉ b @ @ # #!!\" 8! AV \" \"!AA).!" [fn nd lst pair act exist tex-bib-fn-list t tex-bib-rec-list nil message "Recovering symbolic references..." file-name-nondirectory "Recovering symbolic references---doing \"%s\"..." file-exists-p find-file-noselect 1 "Recovering symbolic references---doing %s in \"%s\"..." search-forward delete-region match-beginning 0 match-end insert-string "Recovering symbolic references---doing \"%s\"...done" ding "Recovering symbolic references---doing \"%s\"...file not found" sit-for "Recovering symbolic references...done"] 20)) (defun tex-bib-sym2act nil (byte-code "! Ɖ=@ -@ ! )AA, !!" [fn-list tex-bib-fn-list sym-list fn nd tex-bib-rec-list nil tex-bib-cite-list message "Substituting actuals for symbolics..." file-name-nondirectory tex-bib-sym2act-replace reverse "Substituting actuals for symbolics...done"] 6)) (defun tex-bib-sym2act-replace nil (byte-code "   \" !qb  @ @ 8 8 8 8b \"cى @ #\"  \" Q \"! Am! \"cT`\" Q O%DB\" \" P DB A (B \". " [lst nil item cite note entries begin end syment symref act nd fn sym-list tex-bib-ref-list tex-bib-rec-list message "Substituting actuals for symbolics---doing \"%s\"..." find-file-noselect 1 2 3 4 delete-region "~[" "" "Substituting actuals for symbolics---doing {%s} in \"%s\"..." tex-bib-match-sym insert "," ding "WARNING: %s not in .bbl file...ignored" sit-for delete-char -1 ", " 93 buffer-substring concat "\\cite" "[" "]" "{" "}" tex-bib-comment-out "%" "Substituting actuals for symbolics---doing \"%s\"...done"] 21)) (defun tex-bib-match-sym (sym lst) (byte-code "Í)" [pair nil here (byte-code "\"@ 8\" @\"A" [lst pair sym string-equal 1 throw here] 5)] 2)) (defun tex-bib-mkaux (regexp) "\ Make .aux file to be BibTeXed." (byte-code "\"q )‰‰‰ j @ A!\"L‚f!q# !#))+ ) ! !\"" [=aux= tex-bib-cite-list nil tex-bib-cite-tags tex-bib-fn-list =fnlst= =fn= =fnnd= tex-include-files regexp message "Making \"%s\" for BibTeX..." widen erase-buffer file-name-nondirectory string-match ".bbl$" find-file-noselect "Making %s for BibTeX---doing \"%s\"..." tex-bib-mkaux-scan "Making %s for BibTeX---doing \"%s\"...done" tex-bib-mkaux-data tex-bib-mkaux-style tex-bib-mkaux-cleanup reverse "Making \"%s\" for BibTeX...done"] 17)) (defun tex-bib-mkaux-scan (regexp) (byte-code "b #G!Њ `S)#).C Tf U@ B ) ) W !\"r B  B ," [=cites= nil =inputs= bslash =char= regexp t =fnlst= tex-bib-cite-list tex-bib-fn-list =fn= 1 re-search-forward match-beginning 0 re-search-backward "^%\\|[^\\]%" beginning-of-line 105 tex-bib-scan-input tex-bib-scan-citation append reverse tex-bib-mkaux-data tex-bib-mkaux-style] 12)) (defun tex-bib-scan-input nil (byte-code " `)`!`S!h`V5 \" b!)E‚hUw!h UhUhUp`Sq`\" UUU`S`\"P  \"  B ." [eol arg nil act eoi pos char =bbl= t tex-bib-path =inputs= end-of-line re-search-forward "[^ {]" "\\.\\| \\| \\|}\\|$" tex-check-input-arg "\\input format error" looking-at 46 " \\| \\|}\\|$" buffer-substring 32 9 125 ".tex" vortex-file-exists-p] 11)) (defun tex-bib-scan-citation nil "\ Each element of lst is (CITE NOTE (R1 R2 ... Rn) BEGIN END) where CITE is t if it comes from \\cite, nil if from \\nocite, NOTE is the optional note field such as [pp.1-5], Ri is the ith entry in \\cite{R1,R2,...,Rn}, BEGIN is the position of \\ and END the is position after }" (byte-code "Ǎ-" [note =start= =end= =pos1= entries nil ok (byte-code " b#`T`)!`)#)0!1‰ U  %B" [=start= bslash nil t =end= note entries =cites= =char= re-search-backward "[^ ~]" search-forward "}" "\\[ *\\(.*\\) *\\]" vortex-match-string 1 tex-bib-cite-args list 99] 11)] 5)) (defun tex-bib-cite-args nil (byte-code "ō+" [lst nil string pos2 abort (byte-code "#l`S#hUhUd!`T) \" # Qqdb #)TǂX \") Bh!!" [=end= t =pos1= pos2 string item =aux= nil lst re-search-forward "\\w" " *,\\| *}\\|[^,] +[^,}]" 44 125 re-search-backward "[^,} ]" buffer-substring tex-bib-mktags "\\citation{" "}" search-forward insert-string " " tex-bib-cite-error reverse] 10)] 3)) (defun tex-bib-cite-error (lst) (byte-code " #`S\" S ʼn \"C  #  #! !hUR_ \"nb#`)+" [only1 nil pos err =end= t lst tex-bib-err-list =pos1= =fnnd= =cites= re-search-forward "," buffer-substring tex-bib-mktags ding message "{%s} in \"%s\" contains illegal white space..." sit-for 1 tex-bib-correct-error search-backward "\\" 37 throw ok search-forward "}"] 13)) (defun tex-bib-mktags (string start end) "\ Register current entry and file name in tex-bib-cite-tags. Each element of tex-bib-cite-tags is (ENTRY (Fn start end) ... (F1 start end))." (byte-code "ō+" [prev nil tag entry done (byte-code ":@ @\"+ ! E ABBAB\"\" BA ED B!" [tex-bib-cite-tags tag string entry prev =fn= start end string-equal throw done append reverse] 11)] 3)) (defun tex-bib-comment-out (start end) (byte-code "bl c bc)" [end nil start 10 37] 1)) (defun tex-bib-mkaux-data nil (byte-code "db#!! ! `) !\" #4 !\" ! \" !bn?H # \"qdbndf #)!\"!!\"\" b Qc )," [nil t file-string bmark epos bol =aux= re-search-backward "\\\\bibliography *{ *\\(.*\\) *}" tex-bib-check-abbrev vortex-match-string 1 make-marker match-end 0 beginning-of-line set-marker match-beginning search-backward "%" delete-region marker-position newline insert "% \\bibliography{" "}" "\\\\bibdata{\\(.*\\)}" push-mark mark "\\bibdata{" "} " pop-mark] 29)) (defun tex-bib-check-abbrev (file-string) (byte-code "! \"#" [file-string tex-bib-abbrev mapconcat (lambda (fn) (substring fn 0 (string-match ".bib" fn))) tex-bib-add-missing-strings vortex-parse-comma-list ","] 6)) (defun tex-bib-add-missing-strings (main-list new-strings) (byte-code "? !@ \" A\"!@ A\"B" [new-strings main-list t vortex-memq tex-bib-add-missing-strings] 6)) (defun tex-bib-mkaux-style nil (byte-code "db#q! ! 8!*4!! ! qdbnHJ #k#_h #!p#))" [string nil t =aux= =fnnd= re-search-backward "\\\\bibliographystyle *{\\(.*\\)}" vortex-match-string 1 beginning-of-line looking-at ".*% *\\\\bibliographystyle" "^ *\\\\bibliographystyle" search-forward "\\bibliographystyle" search-backward "\\" newline insert-string "% " "\\bibstyle{" message "Style %s in file \"%s\" inconsistent...ignored" sit-for insert "} "] 18)) (defun tex-bib-mkaux-cleanup nil (byte-code "q U\")Nj" [=aux= nil buffer-size 0 throw =done= "abort (no citations)" ((byte-code "qb! d%" [=aux= nil 1 insert-string "\\relax " tex-bib-mkaux-cleanup-data tex-bib-mkaux-cleanup-style write-region no-message] 9))] 4)) (defun tex-bib-mkaux-cleanup-data nil (byte-code "dbn #M qdbn(* \" \":  $q $)" [nil t =buff= bibs =base= tex-bib-abbrev =aux= newline re-search-backward "\\\\bibdata{.*}" read-string "Base names of .bib files (as f1,f2,...): " string-equal "" insert "% \\bibliography{" "} " "\\bibdata{"] 11)) (defun tex-bib-mkaux-cleanup-style nil (byte-code "db#q qdbn ! \"1̉U \">ΉU \"KЉU \"U҉nb #g # q #)" [nil t =buff= style =aux= re-search-backward "\\\\bibstyle{.*}" newline read-string "Style [RET=plain 1=unsrt 2=alpha 3=abbrv else]: " string-equal "" "plain" "1" "unsrt" "2" "alpha" "3" "abbrv" insert-string "% \\bibliographystyle{" "} " " % \\bibliographystyle{" "\\bibstyle{"] 13)) (defun tex-bib-bibtex (abort) "\ Execute \"bibtex pre\" at shell, where pre is the prefix of FN." (byte-code "ʋ)" [normal t =base= =buff= tex-error-pos nil =aux= =blg= tex-bib-err-list abort ((byte-code "\" !!db!\"` !*ÂK !! ! % É bÉ#i!BTdbt %  \"" [=base= =buff= tex-error-pos nil =aux= =blg= normal tex-bib-err-list t abort message "Sending `bibtex %s' to shell..." tex-shell-init pop-to-buffer "*shell*" recenter 0 insert-string "bibtex " shell-send-input y-or-n-p "Continue act/sym substitution? [Wait till finish if `y'] " stop-shell-subjob sleep-for 1 "kill %" insert "\\rm " "* " "*" re-search-forward "database entry for \"\\(\\w.*\\)\"" vortex-match-string throw] 22))] 1)) (defun tex-bib-get-tag (entry) (byte-code " ō*" [lst tex-bib-cite-tags tag nil done (byte-code "!@ @\" A\"A" [lst tag entry string-equal throw done] 5)] 2)) (defun tex-bib-correct-error nil (byte-code "!    J @ A B  !B B ! @A@ !q !  \"@  @ 8 8 ! W U b \" cAy A \"P). !" [=prev= nil =tags= =err= =entry= =start= =end= lst tag epos fn nd tex-bib-err-list message "Correcting citation errors..." tex-bib-err-cmd tex-bib-get-tag tex-bib-err-sort find-file-noselect file-name-nondirectory "Correcting citation errors---doing \"%s\"..." 1 2 integerp 0 -1 tex-bib-err-comment-out tex-bib-err-delete delete-region "Correcting citation errors---doing \"%s\"...done" "Correcting citation errors...done"] 15)) (defun tex-bib-err-sort (tags) "\ Each element in TAGS is (ENTRY (Fn START END) ....). Sort them with fn being the key." (byte-code "n@ @ A c @@!O A#BBZ ABDB A'A." [=tags= nil tag entry fl fn f1 f2 tags tex-bib-err-tags tex-bib-err-order] 8)) (defun tex-bib-err-order (entry ele lst) (byte-code "Í)" [front nil ok (byte-code "0@ @ 8V\" ! BB\"\", BA B B!" [lst tag ele front entry 1 throw ok append reverse] 8)] 2)) (defun tex-bib-err-tags (fn) (byte-code "č*" [front nil tag ok (byte-code "- @@\" A\" A\") BA ć" [=tags= fn tag front nil string-equal throw ok append] 7)] 2)) (defun tex-bib-err-comment-out nil (byte-code " \" b \"!! `\"!!!4!` \"!`!`T!x!c bcnbcdc!!sĂuc! ! \" $*" [string =start= =end= cite nil buffer-substring delete-region looking-at " *," search-forward "," re-search-backward "\\w\\|{" forward-char 1 search-backward "\\" forward-word "{\\W*}" "[?]" "%" " %" "}" " *$" 10 next-line beginning-of-line open-line insert 37] 25)) (defun tex-bib-err-delete nil (byte-code " \"b!!`\"!!!-!`\"" [=start= =end= delete-region looking-at " *," search-forward "," re-search-backward "\\w\\|{" forward-char 1] 11)) (defun tex-bib-err-cmd nil (byte-code " Q !rȍ*" [cmd msg =err= nil "Correcting {" "} [SPC DEL r l c d ?=help]" message done (byte-code " U5 Â-!Â-!! !É\" U~ AR @ BB Av!\\Âv!! B! @C A\" U A Q \"\" U Aٍ!r U A\" U A\" Uߋ \"!!r" [t cmd tex-bib-err-list nil =prev= =err= msg 32 y-or-n-p "No more next error, done? " message "Wrapping around..." sit-for 1 reverse throw done 127 "No more previous error, done? " 114 read-string "Replacing " " by: " 108 abort (byte-code "\"@\"" [nil throw done tex-cite-lookup abort] 5) 99 -1 100 -2 63 ((byte-code " !r" [msg cmd tex-bib-error-help message] 4)) ding "%s...WHAT?"] 22)] 3)) (defun tex-bib-error-help nil (byte-code "! Vb!b!" [pop-to-buffer "--- TeX Citation Correction Help ---" buffer-size 0 1 insert-string " SPC -- Show the next citation error. DEL -- Show the previous citation error. r -- Replace. l -- Lookup in .bib files. c -- Comment out the entry. d -- Delete the entry. ? -- This help message." other-window] 5)) (defun tex-bib-mkbbl-tex nil "\ Creates a .tex file as the bibliography." (byte-code "\"‰q !db!! `d\"b#7 ;\"`\"!#!! !D B!#u!wdb! !I)# T! #! !D B!#!db! !*b!d%)\"" [=bbl= tex-bib-ref-list nil t act n message "Making \"%s\" as reference file..." erase-buffer insert-file-contents search-backward "\\end" previous-line 1 end-of-line delete-region search-forward "\\bibitem" beginning-of-line error "Making \"%s\" as reference file...abort (.bbl file is empty)" looking-at "\\\\bibitem\\[.*\\]" re-search-forward "\\\\bibitem\\[\\(.*\\)\\]{\\(.*\\)}" tex-bib-fix-etal vortex-match-string 2 insert-string "{" re-search-backward "\\w" "}" 0 concat insert 91 93 "{\\(.*\\)}" "\\let\\em\\it \\def\\etalchar#1{$^{#1}$} \\def\\newblock{\\hskip .11em plus .33em minus -.07em} \\def\\bibitem[#1]#2#3{{\\bigskip \\item{\\hbox to .6in{\\hss[#1]}}#3\\par}} " write-region no-message "Making \"%s\" as reference file...done"] 40)) (defun tex-bib-fix-etal (citation) (byte-code "  \"% !O !!O !O%& !)" [md citation match-data string-match "{\\\\etalchar{\\(.\\)}}" concat 0 match-beginning "{$^{" 1 match-end "}$}" nil store-match-data] 14)) (defun tex-bib-mkbbl-latex nil (byte-code "\"‰q !b#$ (\"!Q#N!!! D B*0q#pT!!D BT)))\"" [=bbl= tex-bib-ref-list nil t act sym n message "Making %s as reference file..." erase-buffer insert-file-contents 1 search-forward "\\bibitem" beginning-of-line error "Making \"%s\" as reference file...abort (.bbl file is empty)" looking-at "^\\\\bibitem\\[.*\\]" re-search-forward "\\\\bibitem\\[\\(.*\\)\\]{\\(.*\\)}" tex-bib-fix-etal vortex-match-string 2 0 "\\\\bibitem{\\(.*\\)}" concat "Making %s as reference file...done"] 17)) (defun tex-bib-write-ref nil (byte-code "q !\" !\"d%)" [=ref= tex-bib-fn-list tex-bib-rec-list nil erase-buffer insert prin1-to-string 10 write-region 1 no-message] 11)) (defun tex-bib-input-bbl nil (byte-code "db# # $)" [nil t =bbl= tex-postamble re-search-backward "\\\\end\\|\\\\bye\\|\\\\end{document}\\|\\\\input.*-.*$" insert "\\input " " " " \\input "] 7)) (defun tex-bib-save (&optional quiet) (interactive) (byte-code "È DÂ! \"*Â0 B͍>ÂA!PMÂP!-" [lst tex-bib-fn-list asknot nil fn msg char quiet message "Saving all files..." vortex-memq buffer-file-name finish (byte-code "/@  !P!& !q % !)A" [lst fn asknot tex-confirm "Save file " file-name-nondirectory find-file-noselect buffer-modified-p write-file] 8) "Saving all files...done" "No files changed due to bibliography making"] 7)) (defvar tex-bib-bibtex-buffer-name "TeX-bib-BibTeX") (defvar tex-bib-scan-regexp (concat "\\(" (mapconcat (quote (lambda (x) x)) (quote ("\\\\cite" "\\\\nocite" "\\\\input\\|\\\\include" "\\\\verb\\*?" "\\\\begin{verbatim\\*?}" "\\\\bibliography")) "\\)\\|\\(") "\\)")) (defvar tex-bib-aux-regexp (concat "\\\\\\(citation\\|bibdata\\|bibstyle\\|bibcite\\)" "{.*}\\({.*}\\)? ")) (defun tex-bib-preprocess nil "\ Emulate running latex-bibtex-latex on the current master document." (interactive) (byte-code "ˆ !\"O\" !#\" !\" !\"*" [buffer-name file-base nil tex-visit-master-file file-name-nondirectory buffer-file-name 0 string-match ".tex" message "Making .aux file for \"%s\"" tex-bib-write-aux tex-bib-scan-file "Running BibTeX for \"%s\"" tex-bib-run-bibtex "Placing cross-references in .aux file for \"%s\"" tex-bib-update-aux "Bibliography preprocessing for \"%s\" ... done."] 14)) (defun tex-bib-write-aux (buffer-name file-base scan-data) (byte-code " P! @ ! 8 \"q db 8\" @# @!#! )!+" [aux-buffer file-base bibstyle scan-data buffer-name bibdata t find-file-noselect ".aux" tex-bib-get-bibstyle 1 tex-bib-get-bibdata tex-bib-clean-aux mapcar (lambda (cite-data) (insert "\\citation" "{" (nth 5 cite-data) "} ")) 2 insert "\\bibstyle{" "} " "\\bibdata{" tex-bib-check-abbrev set-buffer-modified-p save-buffer kill-buffer] 12)) (defun tex-bib-clean-aux nil "\ Removes all bibliography commands from the current buffer, which must be a .aux file." (byte-code "eb#!!\"" [tex-bib-aux-regexp nil t re-search-forward delete-region match-beginning 0 match-end] 7)) (defun tex-bib-get-bibdata (buffer-name file-base) (byte-code " \"\"  Q!;dbn?% `!# `SpF))@F))" [bibs file-base buffer-name begin nil read-string "Base names of .bib files (as f1,f2,...): " string-equal "" y-or-n-p "Should this \\bibliography command be placed in " "?" newline insert "\\bibliography{" tex-bib-check-abbrev "} "] 10)) (defun tex-bib-get-bibstyle (buffer-name) (byte-code "!\"ȉ5\"ʉ5\"+̉5\"5Ή Q!_dbn?K `# `SpF))dF))" [style buffer-name begin nil read-string "Style [RET=plain 1=unsrt 2=alpha 3=abbrv else]: " string-equal "" "plain" "1" "unsrt" "2" "alpha" "3" "abbrv" y-or-n-p "Should this \\bibliographystyle be placed in " "?" newline insert "\\bibliographystyle{" "} "] 12)) (defun tex-bib-scan-file (file-base) (byte-code "peb #2 Ҋ `S)#!)1ł-!F !\"C\"-![ !\"C\"-! \"?uP!   !q !  @  8   8\"))))-! h!!-!#-!-! !!b    `F),  P!   `F+!q  !8\"p!)*)) ) E," [buffer bibstyle bibdata cite-list tex-bib-scan-regexp nil t md child-file-name child-file retval file-base begin arg bbl-file re-search-forward match-data re-search-backward "[^\\]%" beginning-of-line store-match-data match-beginning 1 nconc tex-bib-cite-data 2 tex-bib-nocite-data 3 tex-bib-get-input-arg string-match "\\." ".tex" vortex-file-readable-p find-file-noselect tex-bib-scan-file 4 forward-char search-forward char-to-string 5 "\\\\end{verbatim\\*?}" 6 looking-at "style" match-end 0 tex-bib-get-braced-arg ".bbl" kill-buffer] 40)) (defun tex-bib-get-braced-arg nil (byte-code "!!b!!\"" [looking-at "[ ]* ?[ ]*{\\([^}]+\\)}" match-end 0 buffer-substring match-beginning 1] 7)) (defun tex-bib-get-input-arg nil (byte-code "  !!b!!\")" [braced-arg tex-bib-get-braced-arg looking-at "[ ]* ?[ ]*\\(\\S +\\)" match-end 1 buffer-substring match-beginning] 8)) (defun tex-bib-cite-data (begin buffer) (byte-code "!3!!!\"!#!!\"! ! ` &*" [note cite-string t begin buffer looking-at "\\([ ]* ?[ ]*\\(\\[[^]]*\\]\\)\\)?[ ]* ?[ ]*{\\([^}]+\\)}" match-beginning 2 buffer-substring match-end tex-bib-strip-comments 3 list vortex-parse-comma-list] 19)) (defun tex-bib-strip-comments (string) (byte-code " #\" !OP! OP +" [comment-regexp start result string "%.* " 0 "" string-match match-beginning match-end nil] 7)) (defun tex-bib-nocite-data (begin buffer) (byte-code " ! ` &)" [cite-string nil begin buffer tex-bib-get-braced-arg list vortex-parse-comma-list] 10)) (defun tex-bib-run-bibtex (file-base) (byte-code "! $ !=! !=* \"1!!)" [tex-bib-bibtex-buffer-name process file-base t vortex-init-process-buffer start-process "bibtex" run process-status sit-for 1 exit tex-bib-bibtex-errors pop-to-buffer error "BibTeX stopped running unexpectedly ... Abort!"] 9)) (defun tex-bib-bibtex-errors (buffer-name bt-process) "\ Throws an error if bibtex had any problems. Should do some real error checking, but doesn't." (byte-code "!=? \"! !!)" [bt-process bt-window buffer-name t process-exit-status 0 display-buffer y-or-n-p "BibTeX found some problems. continue anyway?" delete-window error "Aborting ..."] 6)) (defun tex-bib-update-aux (file-base) (byte-code " P! P! qdbqeb#S T!!5!! qI !%*q! q! !+" [bbl-buffer file-base aux-buffer count nil t key cite-string find-file-noselect ".bbl" ".aux" 0 re-search-forward "\\\\bibitem\\(\\[\\(.*\\)\\]\\)?{\\([^}]*\\)}" vortex-match-string 3 match-beginning 2 tex-bib-fix-etal insert "\\bibcite{" "}{" int-to-string "} " kill-buffer set-buffer-modified-p save-buffer] 15)) (defconst tex-bib-scratch-buffer-name "TeX-bib Scratch") (defun tex-bib-unify nil "\ Compose a one-file BibTeX database for this document" (interactive) (byte-code "Lj!ʋ" [scratch-buffer tex-bib-scratch-buffer-name buffer-name file-base biblio-data uid-list file-list nil message "Bib Unification: scanning document for citations ..." ((byte-code " ! ! \"O ! ! !Ҏ! #!\"!!).)" [scratch-buffer tex-bib-scratch-buffer-name buffer-name file-base biblio-data uid-list file-list nil tex-visit-master-file generate-new-buffer file-name-nondirectory buffer-file-name 0 string-match ".tex" tex-bib-scan-file tex-bib-extract-uids tex-bib-extract-files ((byte-code "! !" [nil scratch-buffer set-buffer-modified-p kill-buffer] 3)) message "Bib Unification: collecting references ..." tex-bib-extract-references "Bib Unification: collecting abbreviations ..." tex-bib-extract-abbreviations tex-bib-write-scratch "Bib Unification: done."] 15))] 2)) (defun tex-bib-extract-uids (biblio-data) (byte-code " 8\" ) @ \"? @ B A ," [raw-cite-list biblio-data simple-cite-list final-cite-list nil p 2 vortex-mapcan (lambda (cite) (nth 2 cite)) vortex-memq] 5)) (defun tex-bib-extract-files (biblio-data) (byte-code "8@!" [biblio-data vortex-parse-comma-list 1] 3)) (defun tex-bib-extract-references (uid-list file-list scratch-buffer) (byte-code "6@P \" ?@Q! !q \"\")A)* H !?H!" [file-list raw-file-name file-name tex-bib-path bib-buffer uid-list nil ".bib" vortex-file-readable-p error "Could not find file \"" "\"." find-file-noselect delq mapcar (lambda (uid) (tex-bib-search-and-copy-reference uid bib-buffer scratch-buffer)) beep y-or-n-p "Not all references found. Continue anyway?" "Bibliography composition ... aborted."] 9)) (defun tex-bib-search-and-copy-reference (uid bib-buffer scratch-buffer) (byte-code "bč  " [nil uid 1 found (byte-code "#2! 88\"- q @ 8#c q\")" [uid nil t entry-data scratch-buffer bib-buffer search-forward bibtex-current-entry string-match 2 3 insert-buffer-substring 1 " " throw found] 9)] 2)) (defun tex-bib-write-scratch (scratch-buffer) (byte-code "!!? # q!)" [file-name nil scratch-buffer read-file-name "File for storing references: " file-writable-p beep "File not writable. Alternate file? " write-file] 8)) (defun tex-bib-extract-abbreviations (file-list scratch-buffer) (byte-code " ! * @P \" !\"\"+ A9 ?9!??!)" [abbrev-list scratch-buffer file-list raw-file-name file-name tex-bib-path bib-buffer nil tex-bib-abbrev-list ".bib" vortex-file-readable-p find-file-noselect delq mapcar (lambda (abbrev) (tex-bib-search-and-copy-abbreviation abbrev bib-buffer scratch-buffer)) beep y-or-n-p "Not all abbreviations found. Continue anyway?" error "Bibliography composition ... aborted."] 9)) (defun tex-bib-search-and-copy-abbreviation (abbrev bib-buffer scratch-buffer) (byte-code "qeb Q#?!!b `)q #cq+@ ))" [bib-buffer case-fold-search t abbrev nil string-start left-brace right-brace scratch-buffer re-search-forward "@string\\s *\\([{(]\\)\\s *" "\\s *=" match-beginning 0 1 forward-sexp insert-buffer-substring " "] 8)) (defun tex-bib-abbrev-list (scratch-buffer) (byte-code "qeb eb\"+ 88b̍eb ," [scratch-buffer abbrev-list nil current-entry current-field case-fold-search t newline bibtex-next-entry 1 3 past-end (byte-code "!K@ 8V\"88!8@b@#?< \"?< \"?F B)" [current-field current-entry nil field-text t tex-bib-month-regexp abbrev-list bibtex-next-field-data 1 throw past-end downcase 2 3 re-search-backward "[\"{]" string-match vortex-memq] 9)] 6))