;;;This goes in the init.el in emacs.d ;;; START MMMMODE STUFF MMMMODE CONFLICTS WITH DYNAMIC COMPLETE IF IT TURNED ON GLOBALLY (require 'mmm-mode) (require 'mmm-vars) (setq mmm-global-mode 'maybe) (setq mmm-submode-decoration-level 0) ;; (mmm-add-group 'latex-stats '((r-tag :submode R-mode :face mmm-code-submode-face :delimiter-mode nil :front "begin{Rcode}" :back "end{Rcode}" :back-offset (backward-char -1) :insert ((?R R-tag nil @ "%%%%%%%%%%%%%%%%%%% R %%%%%%%%%%%%%%%%%%%%" @ \n @ "\\begin{Rcode}" @ "\n" _ "\n" @ "\\end{Rcode}" @ \n @ "%%%%%%%%%%%%%%%%%%% CODE %%%%%%%%%%%%%%%%%%%%" @ \n @ )) ) (sta-tag :submode STA-mode :face mmm-code-submode-face :delimiter-mode nil :front "begin{Statacode}" :back "end{Statacode}" :back-offset (backward-char -1) :insert ((?S STATA-tag nil @ "%%%%%%%%%%%%%%%%%%% STATA %%%%%%%%%%%%%%%%%%%%" @ \n @ "\\begin{Statacode}" @ "\n" _ "\n" @ "\\end{Statacode}" @ \n @ "%%%%%%%%%%%%%%%%%%% CODE %%%%%%%%%%%%%%%%%%%%" @ \n @)) ) (lambda() (flyspell-mode 0) ) )) (add-to-list 'mmm-mode-ext-classes-alist '(nil "-swv.tex" latex-stats)) (setq TeX-view-program-list '(("Okular" "okular %o#src:%n%b"))) ;; This goes in the file that is sourced when latex mode is loaded (add-to-list 'TeX-command-list (list "Rubber" "rubber -d %s.tex" 'TeX-run-silent nil t) ) (defun do-view() "run okular on file" (interactive) (TeX-command "View" 'TeX-master-file) (message "done") ) (defun do-rubber() "run statweave on file" (interactive) (TeX-command "Rubber" 'TeX-master-file) (message "done") ) (add-to-list 'TeX-command-list '("View" "%V" TeX-run-discard nil t)) ;; This function will execute statweave if it finds a statweave command in the tex file, otherise it will execute rubber (pdflatex) (defun my-second-main-function () (interactive) (save-buffer) (if (string-match "\\.tex" buffer-file-name) (progn (point-to-register e) "This will see if the file have any statweave commands and if so will execute statweave first before executing pdflatex" (beginning-of-buffer) (if (or (search-forward "\\begin{Statacode}" nil t) (search-forward "\\begin{Rcode}" nil t) (search-forward "\\Rexpr" nil t) ) (progn "execute statweave now on the file" (save-window-excursion (switch-to-buffer "*myoutputbuffer*") (erase-buffer) (switch-to-buffer "*statweavebuffer*");; stataweave buffer (erase-buffer) ) (setq cmd-statweave (concat "statweave --target tex " (buffer-name))) (do-not-ask-shell-command cmd-statweave "*statweavebuffer*") (save-window-excursion (switch-to-buffer "*myoutputbuffer*") (insert "***************** HERE IS THE STATWEWAVE OUTPUT FOR YOUR BUFFER *****************\n") (insert-buffer "*statweavebuffer*")) (setq TeX-master (replace-regexp-in-string "-swv" "" (buffer-file-name))) )) (register-to-point e) ;; "now execute latex" (do-rubber) ;; "now view it in okular" ;; (do-view) ) (message "This is not a tex file so I saved it for you") ) )