(require (quote TeX-mode)) (defvar tex-insp-old-master "" "\ Last document master filename.") (defvar tex-insp-old-dir "" "\ Last document directory.") (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-insp-page-alist nil) (defvar tex-insp-base-ext "++") (defvar tex-insp-context (progn (if (not (boundp (quote bibtex-context))) (run-hooks (quote bibtex-mode-hook))) (if (not (boundp (quote bibtex-context))) (setq bibtex-abbrev-files "")) bibtex-context)) (defvar tex-insp-dvi2x-process nil) (defconst tex-insp-dvi2x-buffer "TeX-insp-dvi2x-output") (defvar tex-insp-dvi2x-host nil) (defvar tex-insp-dvi2x-file nil) (setq tex-insp-dvi2x-flags (concat "-P" tex-insp-dvi2x-flags)) (defun tex-insp-inspect nil "\ Display in the other window the corresponding content of the closest citation in the preceding text. Returns an error if no citations are found in the preceding text. Thus, if tex-insp-inspect is started at the end of buffer, each citation can be inspected in a reverse order." (interactive) (byte-code "Lj \"O P !?! !)  @=2 88 8 \" ?D!S O \"S \"*+" [master base bbl-file prior-citation entry-id tex-insp-use-dvi t nil tex-check-master-file 0 string-match ".tex" ".bbl" file-exists-p error "Biblography file not created yet." find-file-noselect tex-insp-prior-citation symbolic 1 tex-insp-actual-to-symbolic "Apparent citation not found in .bbl file." tex-insp-inspect-dvi tex-insp-display-bbl] 12)) (defun tex-insp-display-bbl (bbl-file entry-id) (byte-code "!b # !" [bbl-file entry-id nil t find-file-other-window 1 search-forward tex-insp-adjust-window other-window] 5)) (defun tex-insp-actual-to-symbolic (key base) (byte-code " !\"8" [key base 1 assoc tex-insp-get-reclist] 5)) (defun tex-insp-adjust-window nil (byte-code "!!`)`\"\\ Z!*" [end no recenter 0 forward-paragraph 1 count-lines 2 enlarge-window window-height] 7)) (defun tex-insp-get-reclist (ref-file) (byte-code " P  \" \"#ȂR  !?6\"!q b ! !)) !*" [ref-file base master-file tex-insp-old-master tex-insp-old-dir default-directory tex-bib-fn-list tex-bib-rec-list nil buf ".ref" tex-check-master-file string-equal file-exists-p error "Bibliography cross reference file %s doesn't exist." find-file-noselect 1 read tex-insp-match-lst buffer-name] 11)) (defun tex-insp-match-lst (fn) (byte-code " ō*" [fns tex-bib-fn-list lst tex-bib-rec-list found (byte-code " @\" @\"A A" [fns fn lst string-match throw found] 5)] 2)) (defconst tex-insp-cite-regexp "\\(\\\\\\(no\\)?cite\\)\\|\\(\\[\\)" "\ Matches cite, ocite, and [.") (defconst tex-insp-symbolic-regexp "\\\\\\(no\\)?cite\\s *\\(\\[.*\\]\\)?\\s *{\\([^}]*\\)}" "\ Matches any symbolic citation. Group 3 matches the entry identifiers.") (defconst tex-insp-actual-regexp "\\[\\(.*\\)\\]" "\ Matches any bracketed text. Group 1 matches the string between brackets.") (defun tex-insp-prior-citation (&optional orig-point) (byte-code "?` #/! !\",!,!\"5b!" [orig-point tex-insp-cite-regexp nil t re-search-backward match-beginning 1 tex-insp-check-symbolic 3 tex-insp-check-actual error "No citations found in preceding text."] 9)) (defun tex-insp-check-symbolic (cite-begin orig-point) (byte-code "b $" [cite-begin orig-point tex-insp-symbolic-regexp tex-insp-check-support 3 symbolic] 5)) (defun tex-insp-check-actual (cite-begin orig-point) (byte-code "b#)!=! \"\" $" [cite-begin nil t orig-point tex-insp-actual-regexp re-search-backward "\\\\cite\\s *" match-end 0 tex-insp-check-symbolic match-beginning tex-insp-check-support 1 actual] 9)) (defun tex-insp-check-support (orig-point regexp match-num type) (byte-code "!B !W !\" !? !!!!э;!b @D> !*E !" [regexp orig-point match-num cite-list cite-end type looking-at match-beginning string-equal "" vortex-match-string tex-insp-prior-citation reverse vortex-parse-comma-list match-end 0 found (byte-code "(@Q #) !Y @\"$A" [cite-list cite-end t orig-point re-search-forward "[{,[]\\(" "\\)[],}]" match-end 1 throw found] 6) 1] 13)) (defun tex-insp-reread-file nil "\ Makes the dvi2x process used for reference inspection return to the file of references" (interactive) (byte-code " &" [nil tex-dvisend tex-insp-dvi2x-host tex-insp-dvi2x-file tex-insp-page-alist start-process "dvisend" "-m ChangeDocument"] 7)) (defun tex-insp-make-page-alist (inspbbl) (byte-code " !q #)!!\" TDB *" [new-alist nil pageno inspbbl t tex-insp-page-alist 1 find-file-noselect beginning-of-buffer re-search-forward "\\\\bibitem\\(\\[.*\\]\\)?{\\(.*\\)}" buffer-substring match-beginning 2 match-end] 10)) (defun tex-insp-newbbl (bbl inspbbl) (byte-code "! !q !! \" " [bbl inspbbl find-file-noselect erase-buffer insert-buffer get-file-buffer beginning-of-buffer replace-string "\\bibitem" "\\pagebreak \\bibitem" clear-visited-file-modtime save-buffer] 10)) (defun tex-insp-newtex (insptex) (byte-code "!q  Q& " [insptex tex-insp-context find-file-noselect erase-buffer insert "\\documentstyle{article} " "\\oddsidemargin = -.75in " "\\topmargin = -1in " "\\input " " " "\\begin{document} " "\\bibliography{} " "\\end{document} " clear-visited-file-modtime save-buffer] 10)) (defun tex-insp-run-latex (inspbase) (byte-code "! $!=! )!" [latex-process nil inspbase message "Reformatting references ..." start-process "latex" process-status run sit-for 1 "Reformatting references ... done"] 6)) (defun tex-insp-find-dvi2x-port nil (byte-code "qdb!!" [tex-insp-dvi2x-buffer tex-insp-dvi2x-host re-search-backward "^.*:.*$" vortex-match-string 0] 4)) (defun tex-insp-run-dvi2x (dvi-file reread) (byte-code "? !=@! ! & q =6!!$ !!= \"?q &!=m!])  % ! ! ! " [tex-insp-dvi2x-process tex-insp-dvi2x-buffer tex-softcopy tex-insp-dvi2x-flags dvi-file tex-insp-dvi2x-file process nil tex-dvisend tex-insp-dvi2x-host reread t exit process-status message "Restarting dvi2x ..." vortex-init-process-buffer start-process "tex-insp-dvi2x" "=700x200" buffer-size 0 "Place dvi2x window ..." sit-for 1 tex-insp-find-dvi2x-port "" run string-equal "dvisend" "-m ChangeDocument" "-m RereadDocument" get-buffer kill-buffer tex-insp-run-dvi2x] 20)) (defun tex-insp-inspect-dvi (base entry-id) (byte-code "=? !p P P P P P   \"9 \"! ?G  \"?N! \"\\ !  \"n !͉ \" \"8!&)+," [window-system orig-buffer bbl base inspbase tex-insp-base-ext reread-dvi nil inspbbl insptex inspdvi tex-insp-page-alist tex-insp-dvi2x-file t page entry-id tex-insp-dvi2x-buffer tex-dvisend tex-insp-dvi2x-host x error "Must be using X window system to use dvi inspection." ".bbl" ".tex" ".dvi" file-newer-than-file-p tex-insp-newbbl tex-insp-make-page-alist string-equal tex-insp-newtex tex-insp-run-latex tex-insp-run-dvi2x 1 assoc start-process "dvisend" "-m" "GotoPage" int-to-string] 21))