;; .emacs ;;; uncomment this line to disable loading of "default.el" at startup ;; (setq inhibit-default-init t) ;; turn on font-lock mode (when (fboundp 'global-font-lock-mode) (global-font-lock-mode t)) ;; enable visual feedback on selections ;(setq transient-mark-mode t) ;; default to better frame titles (setq frame-title-format (concat "%b - emacs@" (system-name))) ;; default to unified diffs (setq diff-switches "-u") ;; always end a file with a newline ;(setq require-final-newline 'query) ;(set-default-font "-adobe-courier-medium-r-normal--14-100-100-100-m-90-iso10646-1") ;;use AucTex (require 'tex-site) ;;============================================================================ ;;My functions for LaTeX ;;============================================================================ (defun latex () "Runs LaTeX on the current buffer." ;Don't know why I need this,but I do (interactive) ;If the buffer has been modified then save the buffer (if (buffer-modified-p) (save-buffer)) ;Set the variable curr-buf to the current buffer name (setq curr-buf (buffer-name)) ;Set the variable cmd to the string latex current buffer (setq cmd (concat "latex " curr-buf)) ;Run LaTeX on the current buffer from the shell (shell-command cmd) ;Messes with the size of the windows, tries to make it look better (if (< (window-height) 55) (enlarge-window (- 55 (window-height)))) ;Switch to next window (other-window 1) ;Moves point to the end of the buffer (end-of-buffer) ;Switch to the previous window (other-window -1) ;Displays message in the ?status bar? (message "Finished running LaTeX on %s" curr-buf)) (defun metatex () "Runs metapost on filename.mp if the current buffer is filename.tex." (interactive) (if (buffer-modified-p) (save-buffer)) (setq curr-buf-tex (buffer-name)) (setq l-curr-buf-tex (length curr-buf-tex)) (setq curr-buf-mp (concat 'string (subseq curr-buf-tex 0 (- l-curr-buf-tex 3)) "mp")) (setq cmd (concat 'string "mpost " curr-buf-mp)) (shell-command cmd) (dvipdf)) (defun dvipdf () "Runs dvipdf on the current buffer (first striping off the tex extension)." (interactive) ;Runs command latex above (latex) (setq curr-buf (buffer-name)) ;Gets length of buffer name (setq curr-buf-length (length curr-buf)) ;Chops off the last for charaecters of curr-buf (should be .tex) (setq curr-buf (substring curr-buf 0 (- curr-buf-length 4))) (setq cmd (concat "dvipdf " curr-buf)) (shell-command cmd) (if (< (window-height) 60) (enlarge-window (- 60 (window-height)))) (message "Ran dvipdf on %s" (concat curr-buf ".dvi"))) (defun viewdvi () "Runs kdvi on the LaTeX output of the current buffer." (interactive) (setq curr-buf (buffer-name)) (setq curr-buf-length (length curr-buf)) (setq curr-buf (substring curr-buf 0 (- curr-buf-length 3))) (setq cmd (concat "kdvi " curr-buf "dvi &")) (let ((window-c (current-window-configuration))) (shell-command cmd) (set-window-configuration window-c))) (defun viewpdf () "Runs gv on the LaTeX output of the current buffer." (interactive) (setq curr-buf (buffer-name)) (setq curr-buf-length (length curr-buf)) (setq curr-buf (substring curr-buf 0 (- curr-buf-length 3))) (setq cmd (concat "gv " curr-buf "pdf &")) (let ((window-c (current-window-configuration))) (shell-command cmd) (set-window-configuration window-c))) (defun tth () "Runs tth on the current buffer." (interactive) (setq curr-buf (buffer-name)) (setq cmd (concat "tth " curr-buf)) (shell-command cmd) (setq curr-buf-length (length curr-buf)) (setq curr-buf (subseq curr-buf 0 (- curr-buf-length 3))) (setq cmd (concat 'string "firefox " curr-buf "html &")) (shell-command cmd) (message "Ran tth on %s" curr-buf)) (defun mpost () "Runs metapost on the current buffer." (interactive) (if (buffer-modified-p) (save-buffer)) (setq curr-buf (buffer-name)) (setq cmd (concat "mpost " curr-buf)) (shell-command cmd) (if (< (window-height) 60) (enlarge-window (- 60 (window-height)))) (message "Ran MetaPost on %s" curr-buf)) (defun dfrac () "Prints \dfrac{}{} at point." (interactive) (insert "\\dfrac{}{}") (backward-char 3)) (defun frac () "Prints \frac{}{} at point." (interactive) (insert "\\frac{}{}") (backward-char 3)) (defun sqrt () "Prints \\sqrt{} at point." (interactive) (insert "\\sqrt{}") (backward-char 1)) (defun math-mode () "Prints $$ at point." (interactive) (insert "$$") (backward-char 1)) (defun dmath-mode () "Prints $$$$ at point." (interactive) (insert "$$$$") (backward-char 2)) (defun big-parenthesis () "Prints \left(\right) at point." (interactive) (insert "\\left(\\right)") (backward-char 7)) (defun begin-enumerate () "Begins enumerate enviorment at point." (interactive) (insert "\\begin{enumerate}") (indent-for-tab-command) (newline-and-indent) (newline) (insert "\\end{enumerate}") (indent-for-tab-command) (previous-line 1) (insert "\\item ") (indent-for-tab-command)) (defun begin-multicols () "Begins a multicol at point." (interactive) (insert "\\begin{multicols}") (indent-for-tab-command) (newline-and-indent) (newline) (insert "\\end{multicols}") (indent-for-tab-command) (previous-line 2) (end-of-line) (insert "{}") (backward-char 1)) (defun mptexwrapper () "Wraps Metapost output in a TeX file for compliation." (interactive) (setq curr-buf (buffer-name)) (setq curr-buf-length (length curr-buf)) (setq curr-buf (substring curr-buf 0 (- curr-buf-length 3))) (find-file (concat curr-buf "-temp.tex")) (beginning-of-buffer) (setq beg (point)) (end-of-buffer) (setq end (point)) (kill-region beg end) (insert "\\documentclass[11pt]{article}\n\n") (insert "\\pagestyle{empty}\n") (insert "\\usepackage{epsfig}\n\n") (insert "\\newlength{\\h}\n\n") (insert "\\setlength\\h{2in}\n\n") (insert "\\begin{document}\n\n") (setq dirlist (directory-files default-directory)) ;;First pass through dirlist gets all files with 1 digit extension (dolist (mpfile dirlist) (if (string-match (concat curr-buf "\\.[1-9]$") mpfile) (insert (concat mpfile ": \\epsfig{file=" mpfile ",height=\\h}\\\\\n")))) ;;Second pass through dirlist gets all files with 2 or more digit extension (dolist (mpfile dirlist) (if (string-match (concat curr-buf "\\.[0-9]\\{2,\\}$") mpfile) (insert (concat mpfile ": \\epsfig{file=" mpfile ",height=\\h}\\\\\n")))) ;;NOTE: Since regexs are being quoted all backslashes must be doubled! (insert "\\end{document}") (dvipdf) (viewpdf) (message "Ran MetaPost on %s" (concat default-directory "mptest"))) (defun mpost-mptexwrapper () "Calls metapost and mptexwrapper." (interactive) (mpost) (mptexwrapper)) (add-hook 'TeX-mode-hook '(lambda () ;(define-key LaTeX-mode-map [f1] 'TeX-command-master) (define-key LaTeX-mode-map [f1] 'latex) (define-key LaTeX-mode-map [f2] 'dvipdf) (define-key LaTeX-mode-map [f3] 'metatex) (define-key LaTeX-mode-map [f11] 'viewdvi) (define-key LaTeX-mode-map [f12] 'viewpdf) (define-key LaTeX-mode-map "\M-xt" 'tth) (define-key LaTeX-mode-map "\M-d" 'dfrac) (define-key LaTeX-mode-map "\M-f" 'frac) (define-key LaTeX-mode-map "\M-s" 'sqrt) (define-key LaTeX-mode-map "\M-m" 'math-mode) (define-key LaTeX-mode-map "\C-\M-m" 'dmath-mode) (define-key LaTeX-mode-map "\M-9" 'big-parenthesis) (define-key LaTeX-mode-map "\M-xe" 'begin-enumerate) (define-key LaTeX-mode-map "\M-xc" 'begin-multicols))) (add-hook 'metapost-mode-hook '(lambda () (define-key meta-mode-map [f1] 'mpost) (define-key meta-mode-map [f2] 'mptexwrapper) (define-key meta-mode-map [f3] 'mpost-mptexwrapper))) (custom-set-variables ;; custom-set-variables was added by Custom -- don't edit or cut/paste it! ;; Your init file should contain only one such instance. '(LaTeX-item-indent -1) '(auto-compression-mode t nil (jka-compr)) '(case-fold-search t) '(current-language-environment "UTF-8") '(default-input-method "rfc1345") '(global-font-lock-mode t nil (font-lock)) '(show-paren-mode t nil (paren)) '(tex-dvi-view-command "kdvi" t) '(transient-mark-mode t)) (custom-set-faces ;; custom-set-faces was added by Custom -- don't edit or cut/paste it! ;; Your init file should contain only one such instance. )