(require (quote TeX-mode)) (defconst tex-ext-regexp "\\.tex") (defconst tex-dot-regexp "\\.") (defconst tex-ext ".tex") (defconst tex-dvi-ext ".dvi") (defconst tex-pre "+") (defconst tex-post "-") (defconst tex-tmp "#") (defconst tex-partial "%") (defvar tex-x-machine "localhost:0" "\ Machine:Device pair") (defun tex-set-document-type nil "\ Sets the document type for the current buffer (i.e. LaTeX, TeX, etc.)." (interactive) (byte-code "ˆ  !!b!!\" c)+b #) *" [current-type new-type nil tex-find-doc-type-comment tex-get-doc-type match-beginning 1 delete-region match-end insert "% Document Type: " " "] 10)) (defun tex-check-document-type nil (byte-code "  !\" )" [current-type tex-find-doc-type-comment equal tex-verify-doc-type tex-set-document-type] 5)) (defun tex-find-doc-type-comment nil (byte-code "b#!))" [case-fold-search t nil 1 re-search-forward "% *Document Type: *\\(\\w+\\)" vortex-match-string] 4)) (defconst tex-doc-type-response-data (mapcar (quote (lambda (form-spec) (list (nth 4 form-spec) (nth 3 form-spec) (nth 2 form-spec)))) tex-formatter-specs)) (defun tex-get-doc-type nil (byte-code "\"" [tex-doc-type-response-data vortex-user-response "Document Type? "] 3)) (defun tex-verify-doc-type (type) (byte-code "! \"8" [type tex-formatter-specs 2 assoc downcase] 5)) (defun tex-set-master-file nil (interactive) (byte-code "È !\"!b!!\" c)<bˊ `)#5 #) *" [current-master new-master t nil tex-find-master-comment tex-get-master-file match-beginning 1 delete-region match-end re-search-forward "Document Type: .*" end-of-line forward-line insert "% Master File: " " "] 13)) (defun tex-find-master-comment nil (byte-code "b#!))" [case-fold-search t nil 1 re-search-forward "%\\s *Master File:\\s *\\(\\S +\\)\\s " vortex-match-string] 4)) (defun tex-check-master-file nil "\ Check the master file comment and return the name of the master file." (byte-code "  ! )" [current-master tex-find-master-comment tex-verify-master-file tex-set-master-file] 4)) (defun tex-visit-master-file nil "\ Check and visit the document master file in the other window." (byte-code "  !\"?!)" [master tex-check-master-file string-equal file-name-nondirectory buffer-file-name find-file-other-window] 6)) (defun tex-get-master-file (current-master) (byte-code "  ! ?\"! *" [temp-mf current-master return-mf nil file-name-nondirectory buffer-file-name tex-verify-master-file read-string "Master File: "] 7)) (defun tex-verify-master-file (filename) (byte-code "! Q!‡" [filename t nil file-exists-p y-or-n-p "Master File: " " [Not found]. Use it anyway? "] 5)) (defun tex-make-global (start end sign amble) (byte-code " ! \"O Q # #\" # q !) #*" [fn gbl tex-dot-regexp sign tex-ext amble start end file-name-nondirectory buffer-file-name 0 string-match message "Making document %s to \"%s\"..." copy-to-buffer kill-region insert " \\input " 10 write-file "Making document %s to \"%s\"...done"] 12)) (defun tex-make-preamble (start end) (interactive "r") (byte-code "È $" [start end tex-pre nil tex-make-global "preamble"] 5)) (defun tex-make-postamble (start end) (interactive "r") (byte-code "È $" [start end tex-post nil tex-make-global "postamble"] 5)) (defun tex-shell-init (fn) (byte-code "! ! O!=qdb !)8c ! ! !#TłW! ` `\") \"qł| \" !) )#q! U!!+" [proc dir fn default-directory cdir nil t shell-mode-map get-buffer-process "*shell*" file-name-directory 0 -1 process-status run beginning-of-line looking-at "^? *$" 120 shell-send-input sleep-for 1 kill-shell-input insert-string "pwd" search-backward "/" previous-line buffer-substring end-of-line string-equal "cd " shell define-key "" tex-goto-error message "Waiting for shell prompt..." buffer-size "Waiting for shell prompt...done"] 27)) (defun tex-execute (cmd fn &optional suffix &optional ow) "\ Run CMD with argument FN in the inferior shell process. If SUFFIX is non-nil, it is to be attached to the end of \"CMD FN\". If called interactively, prompt for CMD and FN. If OW is non-nil, position the cursor to the original window." (interactive "sCommand (including switches): fFilename: ") (byte-code "Ɉ! ! \" \"O R( Q \" !!db! c` !Z!)" [t file fn suffix cmd tex-dot-regexp tex-error-pos tex-error-start-pos ow nil save-some-buffers file-name-nondirectory " " 0 string-match "" message "Sending `%s' to shell..." tex-shell-init pop-to-buffer "*shell*" recenter shell-send-input other-window 1] 11)) (defun tex-execute-tmp (start end pgm doc-type &optional reg) (byte-code "  ! \"O Q0  W,  \"-ۂ4 Q@ \"?\"O   Q  Q !!! !!  & ! \"!\"8!\"8c #c!\"?\"n !!#!\"8c#! !  !! \"+\"-" [master-file fnnd fbase tex-dot-regexp tmp tex-tmp tex-ext region reg start end mbase pre tex-pre post tex-post nil t doc-type tex-formatter-specs pgm tex-check-master-file file-name-nondirectory buffer-file-name 0 string-match buffer-substring "" "\\input " " " string-equal "\\." delete-other-windows split-window-vertically split-window-horizontally other-window 1 find-file tex-mode erase-buffer insert "% Document Type: " " % Master File: " " % Temporary file originated from: " file-exists-p 7 assoc downcase tex-get-preamble "slitex" newline 2 10 8 re-search-forward "\\\\cite\\|\\\\nocite" y-or-n-p "Preprocess symbolic citations? " tex-bib-buffer tex-bib-save write-file sit-for tex-execute] 41)) (defun tex-get-preamble (master base doc-type) (byte-code "!b#< !\"$!\"P9 !\"9!\" %A #)" [master nil t doc-type base find-file 1 re-search-forward "\\\\begin{document}" string-equal downcase "latex" buffer-substring match-end 0 " " "slitex" concat "\\blackandwhite{" "} " error "Can't find preamble in %s document rooted at \"%s\"...abort"] 16)) (defun tex-format-document nil (interactive) (byte-code "ˆ ! \"8 \")" [doc-type tex-formatter-specs nil tex-check-document-type tex-execute 1 assoc downcase tex-visit-master-file] 7)) (defun tex-format-buffer nil (interactive) (byte-code "ˆ d! \"8$)" [doc-type tex-formatter-specs nil tex-check-document-type tex-execute-tmp 1 assoc downcase] 9)) (defun tex-format-region (start end) (interactive "r") (byte-code "ň  ! \"8%)" [doc-type start end tex-formatter-specs t nil tex-check-document-type tex-execute-tmp 1 assoc downcase] 9)) (defun tex-display-document (&optional machine) (interactive (byte-code " \" \"CC" [current-prefix-arg window-system tex-x-machine string-equal "x" read-string "Hostname:Device = " ""] 4)) (byte-code "ƈ  ! \"8 Q \")" [current-prefix-arg window-system tex-x-machine doc-type tex-formatter-specs machine nil tex-check-document-type tex-execute 5 assoc downcase " " tex-visit-master-file] 7)) (defun tex-display-buffer (&optional machine) (interactive (byte-code " \" \"CC" [current-prefix-arg window-system tex-x-machine string-equal "x" read-string "Hostname:Device = " ""] 4)) (byte-code "Lj d ! \"8 Q %)" [current-prefix-arg window-system tex-x-machine doc-type tex-formatter-specs machine t nil tex-check-document-type tex-execute-tmp 1 5 assoc downcase " "] 9)) (defun tex-display-region (start end &optional machine) (interactive "r") (byte-code "ʈ \" \" ω  !\"8 Q %)" [current-prefix-arg window-system tex-x-machine machine tex-x-mahcine doc-type start end tex-formatter-specs t nil string-equal "x" read-string "Hostname:Device = " "" tex-check-document-type tex-execute-tmp 5 assoc downcase " "] 11)) (defun tex-view-dvi (&optional pages &optional machine) "\ Invoke a DVI previewer or send a reread command to an existing one depending on MACHINE being non-nil. The string bound to MACHINE will be the HOSTNAME:DEVICE attribute under which the previewer is running. If PAGES is non-nil, preview partial DVI file by invoking a DVI extractor before previewing. In this case, the new DVI file will be foo%.dvi instead of foo.dvi. Queries will be issued if DVI file is older or missing." (byte-code " ! \"O P  Q   * T   &ۉ ω  }  & ۉ ω   &ۉ ω   P ! \"  $ Q!  $ Q! \"  Q!  \"." [master-file fnnd fnb tex-dot-regexp dvi tex-dvi-ext tmp tex-partial proc arg1 arg2 pages machine vortex-extractor tex-dvisend nil tex-softcopy t tex-visit-master-file file-name-nondirectory 0 string-match concat " " "; " " -c " " &" "" "&" file-exists-p file-newer-than-file-p tex-execute y-or-n-p "File " " is older than the source, preview anyway? " " is older than the source, reformat then preview? " tex-display-document ding message "File %s not previewed." " not found, format the source then preview? " "File %s not found and therefore not previewed."] 21)) (defun tex-view-all nil "\ Preview the DVI file associated with the current master file by invoking a DVI previewer. This is for use with the DVI previewer bound to tex-softcopy." (interactive) (byte-code " " [nil tex-view-dvi] 2)) (defun tex-view-partial (pages) "\ Select and preview certain pages from the DVI file associated with the current master file by invoking a DVI previewer. This is for use with the DVI previewer bound to tex-softcopy. PAGES must be given as one or more page ranges." (interactive "sSelect DVI pages: ") (byte-code "!" [pages nil tex-view-dvi] 2)) (defun tex-x-view-all (&optional machine) "\ Preview the DVI file associated with the current master file by passing a message to an existing DVI previewer. This is for use with dvi2x and dvisend by Steven Procter under X. With prefix argument, the HOSTNAME:DEVICE attribute will be queried. Without prefix argument, tex-x-machine is assumed whose default is localhost:0." (interactive (byte-code " \"C C" [current-prefix-arg tex-x-machine read-string "Hostname:Device = "] 3)) (byte-code "ň = \" \"\"$ !" [current-prefix-arg tex-x-machine window-system tex-softcopy tex-dvisend nil machine x string-match "dvi2x" string-equal "dvisend" tex-view-dvi ding message "Wrong window system or wrong DVI previewer."] 6)) (defun tex-x-view-partial (pages &optional machine) "\ Select and preview certain pages from the DVI file associated with the current master file by passing a message to an existing DVI previewer. This is for use with dvi2x and dvisend by Steven Procter under X. PAGES must be given as one or more page ranges. With prefix argument, the HOSTNAME:DEVICE attribute will be queried. Without prefix argument, tex-x-machine is assumed whose default is localhost:0." (interactive (byte-code "! \" D" [current-prefix-arg tex-x-machine read-string "Select DVI pages: " "Machine:Device = "] 5)) (byte-code "Lj = \" \" \"$ !" [current-prefix-arg tex-x-machine window-system tex-softcopy tex-dvisend pages machine nil x string-match "dvi2x" string-equal "dvisend" tex-view-dvi ding message "Wrong window system or wrong DVI previewer."] 6)) (defun tex-print-all (&optional prefix-arg) (interactive "P") (byte-code "Έ !   Q\" \"1A5 PQ    M QNP$-" [command-args prefix-arg master-file printer vortex-printer-query vortex-printer-list vortex-default-printer printer-data vortex-printer-data print-command vortex-default-print-command tex-dvi-ext vortex-printer-queue t nil read-string "Printer command args: " tex-visit-master-file "Which printer? " ": " assoc " " tex-execute "; " ""] 11)) (defun tex-print-partial (prefix-arg pages) (interactive "P sSelect DVI pages: ") (byte-code "Ԉ !  Q \"  \",A0 PQ !    \"O  P  Q w Qx& $." [command-args prefix-arg printer vortex-printer-query vortex-printer-list vortex-default-printer printer-data vortex-printer-data print-command vortex-default-print-command fnnd fnb tex-dot-regexp dvi tex-dvi-ext tmp tex-partial vortex-extractor pages vortex-printer-queue nil t read-string "Printer command args: " "Which printer? " ": " assoc " " file-name-nondirectory buffer-file-name 0 string-match tex-execute concat "; " ""] 22)) (defvar tex-error-pos nil "\ Position of last TeX error in *shell*") (defun tex-goto-error nil "\ Position point to next TeX/AmSTeX/LaTeX/BibTeX error." (interactive) (byte-code "ˈ!   \"  #Qq # V!db U bg#d` g!#) !!TbgU肉 ! !\"! T ! ! \"#!   db!! `)# ! \") \" \"." [tex-bib-to-bibtex ori win2 doc-type msg match line string fn shell-mode-map tex-error-pos nil t pos boundp bibtex-goto-error buffer-file-name / window-height 2 tex-check-document-type "Positioning to next " "TeX" " error..." "*shell*" define-key "" tex-goto-error buffer-size 0 pop-to-buffer re-search-backward "^This is TeX" error "Don't know how to locate next error...abort" re-search-forward "l\\.\\([1-9][0-9]*\\) [.]*\\(.*\\)$\\|line \\([1-9][0-9]*\\) [.]*\\(.*\\)$" message match-beginning 46 1 3 string-to-int buffer-substring match-end "^!" recenter tex-get-error-filename find-file-other-window goto-line search-forward end-of-line "%sdone" "%sno more" " %snot found"] 34)) (defvar tex-error-start-pos 1) (defun tex-scan-parens (&optional bound) (byte-code "Í))" [n 0 found (byte-code "A #9hU2 S U%`S\"/ W/\"6 T=\"" [t bound n nil re-search-forward "(\\|)" 41 0 throw found] 7)] 2)) (defun tex-get-error-filename nil (byte-code "`č)*" [pos fn nil done (byte-code "0 #)! !& !\"Ă& \",!" [t tex-error-start-pos fn pos nil re-search-backward "(\\([^)^ ^ ][^)^ ^ ]*\\)" vortex-match-string 1 file-exists-p tex-scan-parens throw done error "Can't find any files name...(tex-get-error-filename)"] 8)] 2)) (defconst tex-comment-string "%") (defconst tex-comment-char 37) (defun tex-comment-region (start end &optional n) "\ Comment out all lines in region between START and END by inserting a TeX comment sign in front of each line. With positive prefix argument N, insert that many %'s. Otherwise, insert just one." (interactive "r P") (byte-code "ň!] \" b ` V1! c )*!" [n comment-string tex-comment-char end start nil message "Commenting region..." 1 make-string beginning-of-line forward-line -1 "Commenting region...done"] 7)) (defun tex-uncomment-region (start end &optional n) "\ Uncomment all lines in region between START and END by deleting the leading % from each line, if any. With prefix argument N being positive, delete that many %'s, if any." (interactive "r P") (byte-code "ň!] \" b` W< P!4 \"!!)*!" [n comment-string tex-comment-char start end nil message "Uncommenting region..." 1 make-string beginning-of-line looking-at " *" zap-to-char delete-char next-line "Uncommenting region...done"] 9)) (defvar tex-include-files nil "\ List of files included.") (defun tex-get-include-files (&optional quiet) (byte-code "  ? \" \"8\") CL \" \" D \"H \"B+) ?X\")" [doc-type quiet only incl lst tex-formatter-specs tex-include-files tex-check-document-type message "Looking for associated %s files..." nil string-equal 2 assoc "tex" buffer-file-name tex-includeonly tex-include tex-latex-include mapcar (lambda (x) (if (and x (string-match "\\." x)) x (concat x tex-ext))) "Looking for associated %s files...done"] 13)) (defun tex-includeonly (doc-type quiet) (byte-code "? \"b͊#`)#ъ `S)#/‚!`S!`T) WR#y `S\"\"O B!`SE? \" !," [quiet doc-type nil t lst pos bound fn tex-ext-regexp message "Looking for associated %s files (\\includeonly)..." 1 search-forward "\\includeonly" re-search-forward "\\\\begin\\|\\\\input\\|\\\\include\\W" re-search-backward "^%\\|[^\\]%" beginning-of-line "\\w" up-list ",\\|}" buffer-substring 0 string-match "Looking for associated %s files (\\includeonly)...done" reverse] 15)) (defun tex-include (doc-type quiet) (byte-code "b ? \"#uΊ `S)#)/q!!)U`S!`S\"  \"Ok ! \"O P B ? \"!+" [lst nil fn pos quiet doc-type t tex-ext-regexp 1 message "Looking for associated %s files (\\include)..." re-search-forward "\\\\include *{ *\\w\\|\\\\bibliography *{ *\\w" re-search-backward "^%\\|[^\\]%" beginning-of-line skip-chars-backward "^\\" looking-at "include" buffer-substring " \\|}\\|," 0 string-match file-name-nondirectory buffer-file-name "\\." ".bbl" "Looking for associated %s files (\\include)...done" reverse] 17)) (defun tex-latex-include (only inc) (byte-code " @ \" PA \"BA \")" [only fn inc tex-ext vortex-memq tex-latex-include] 5)) (defun tex-check-input-arg (pos msg) (byte-code "p!P!\"! b )`Zb" [msg nil pos switch-to-buffer y-or-n-p ", ignore? " message "Entering recursive edit, use ESC C-c to return..." recursive-edit 7] 6)) (defun tex-get-input-files (msg fnnd) (byte-code "b #)T #P!͊ `S)#)6L E BL#!+)" [lst nil bslash fn tex-input t msg fnnd 1 re-search-forward match-beginning 0 re-search-backward "^%\\|[^\\]%" beginning-of-line tex-scan-input message "%s, doing \"%s\"..." reverse] 11)) (defun tex-scan-input nil (byte-code " `)`!`S!h`V3 \" U_!h UR UR UZ`S[`\"| Up Up Ux`Sy`\"P \" ." [eol eoi pos char arg fn tex-inputs-path end-of-line nil re-search-forward "[^ {]" "\\.\\| \\| \\|}\\|$" tex-check-input-arg "\\input format error" 46 " \\|^t\\|}\\|$" buffer-substring 32 9 125 ".tex" vortex-file-exists-p] 10)) (defun tex-confirm (pmt &optional spc &optional del &optional ret &optional esc) "\ Request for confirmation on PMT. SPC or `y' means yes, DEL or `n' means no, RET or `a' sets the flag ASKNOT and will not ask any more, ESC or `d' means done (perhaps prematurely), and LFD or `r' enters recursive edit (ESC C-c returns to current state). The caller must have the variable `asknot' bound in a let expression and the symbol `finish' bound in a catch clause whose body is a while statement." (byte-code "      & ' ! ! ! !&Ӎ-" [spc del ret esc pmt 121 110 97 100 concat "? [" "SPC/" char-to-string " " "DEL/" "RET/" "ESC/" "C-r]" right (byte-code " !r U U\" U( U2\" U< UK\" UU Ue!b\" Uv! ) \"!" [t pmt ans spc del nil ret asknot esc message 32 throw right 127 13 27 y-or-n-p "Done (perhaps prematurely), are you sure? " finish 18 "Entering recursive edit...(return to current state ESC C-c)" recursive-edit ding "%s...WHAT?" sit-for 1] 13)] 20))