2013-06-12 23:40:20 +02:00
|
|
|
;;==============================================================================
|
2014-02-21 15:23:25 +01:00
|
|
|
;; TeX
|
2013-06-12 23:40:20 +02:00
|
|
|
;;==============================================================================
|
2013-09-17 15:43:45 +02:00
|
|
|
;; The default tex-mode and AucTeX may seem quite disappointing. Let's use
|
|
|
|
;; custom KISS functions for everything.
|
2013-06-12 23:40:20 +02:00
|
|
|
|
2014-02-27 10:27:47 +01:00
|
|
|
;; Interesting options for the tex compiler:
|
|
|
|
;; * -file-line-error-style: change the style of error report to
|
|
|
|
;; display file name and line first.
|
|
|
|
;; * -halt-on-error: default.
|
|
|
|
;; * -interaction <mode>: like -halt-on-error, you can set the way
|
|
|
|
;; the compilers behave on errors. Possible values for <mode> are
|
|
|
|
;; 'batchmode', 'errorstopmode', 'nonstopmode' and 'scrollmode'.
|
|
|
|
;; * -shell-escape: allow the use of \write18{<external command>}
|
|
|
|
;; from within TeX documents. This is a potential security issue.
|
|
|
|
;; * -synctex=1: enable SyncTeX support.
|
|
|
|
;; You may use file local variable for convenience:
|
|
|
|
;; % -*- tex-start-options: \"-shell-escape\"
|
|
|
|
;; Note that -shell-escape can also be toggled with universal
|
|
|
|
;; argument.
|
|
|
|
|
2013-09-17 15:43:45 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; CUSTOM
|
2014-02-21 15:23:25 +01:00
|
|
|
|
|
|
|
(defcustom masterfile nil
|
|
|
|
"The file that should be compiled. Useful for modular documents."
|
|
|
|
:safe 'stringp)
|
|
|
|
|
2013-09-17 15:43:45 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; VARIABLES
|
|
|
|
|
2014-02-21 15:23:25 +01:00
|
|
|
(defvar tex-extension-list nil
|
|
|
|
"List of known TeX exentsions. This list is used by `tex-clean'
|
2013-09-17 15:43:45 +02:00
|
|
|
to purge all matching files.")
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; FUNCTIONS
|
2013-07-04 10:37:18 +02:00
|
|
|
(defun tex-set-compiler ()
|
2014-02-26 18:04:00 +01:00
|
|
|
"Set `compile-command' for TeX-based document.
|
|
|
|
Use a prefix argument to append the '-shell-escape' option to the
|
|
|
|
compile options. This will enable the use of '\write18{<external
|
2013-06-12 23:40:20 +02:00
|
|
|
command>}' from within TeX documents, which need to allow
|
|
|
|
external application to be called from TeX.
|
|
|
|
|
|
|
|
This may be useful for some features like GnuPlot support with TikZ.
|
|
|
|
|
|
|
|
WARNING: the -shell-escape option is a potential security issue."
|
|
|
|
(interactive)
|
2013-09-17 15:43:45 +02:00
|
|
|
(hack-local-variables)
|
2014-02-27 10:27:47 +01:00
|
|
|
(let (;; Master file.
|
2013-06-12 23:40:20 +02:00
|
|
|
(local-master
|
2014-02-27 10:27:47 +01:00
|
|
|
(if masterfile masterfile buffer-file-name))
|
2013-06-12 23:40:20 +02:00
|
|
|
|
|
|
|
;; Support of prefix argument to toggle -shell-escape.
|
|
|
|
(local-shell-escape
|
|
|
|
(if (equal current-prefix-arg '(4)) "-shell-escape" "")))
|
|
|
|
|
2013-07-04 10:37:18 +02:00
|
|
|
(set (make-local-variable 'compile-command)
|
2014-02-27 10:27:47 +01:00
|
|
|
(concat tex-command
|
|
|
|
" " tex-start-options
|
|
|
|
" " local-shell-escape
|
|
|
|
" " tex-start-commands
|
|
|
|
" " (shell-quote-argument local-master)))))
|
2013-06-12 23:40:20 +02:00
|
|
|
|
|
|
|
(defun tex-clean ()
|
|
|
|
"Remove all TeX temporary files. This command should be safe,
|
|
|
|
but there is no warranty."
|
|
|
|
(interactive)
|
2013-09-17 15:43:45 +02:00
|
|
|
(hack-local-variables)
|
2014-03-08 17:45:29 +01:00
|
|
|
(let ((master (concat
|
|
|
|
(if masterfile
|
|
|
|
(file-name-sans-extension masterfile)
|
|
|
|
(file-name-sans-extension buffer-file-name))
|
|
|
|
".")))
|
2014-02-21 15:57:54 +01:00
|
|
|
(mapcar
|
2014-03-08 17:45:29 +01:00
|
|
|
;; Delete file if it exists.
|
|
|
|
(lambda (argfile)
|
|
|
|
(when (and (file-exists-p argfile) (file-writable-p argfile))
|
2014-02-21 15:57:54 +01:00
|
|
|
(delete-file argfile)
|
|
|
|
(message "[%s] deleted." argfile)))
|
|
|
|
(mapcar
|
|
|
|
;; Concat file name with extensions.
|
2014-03-08 17:45:29 +01:00
|
|
|
(lambda (arg) (concat master arg))
|
2014-02-21 15:57:54 +01:00
|
|
|
tex-extension-list))))
|
2013-06-12 23:40:20 +02:00
|
|
|
|
|
|
|
(defun tex-pdf-compress ()
|
2014-02-18 12:13:18 +01:00
|
|
|
"Use `masterfile' variable as default value for `pdf-compress'."
|
2013-06-12 23:40:20 +02:00
|
|
|
(interactive)
|
2014-02-26 18:04:00 +01:00
|
|
|
(require 'tool-pdf)
|
2013-09-17 15:43:45 +02:00
|
|
|
(hack-local-variables)
|
2014-03-10 12:59:51 +01:00
|
|
|
(let ((local-master (if masterfile masterfile buffer-file-name)))
|
2014-02-18 12:13:18 +01:00
|
|
|
(pdf-compress local-master)))
|
2013-06-12 23:40:20 +02:00
|
|
|
|
|
|
|
(defun tex-pdf-view ()
|
2014-02-21 15:23:25 +01:00
|
|
|
"Use `masterfile' variable as default value for `pdf-view'."
|
2013-06-12 23:40:20 +02:00
|
|
|
(interactive)
|
2014-02-26 18:04:00 +01:00
|
|
|
(require 'tool-pdf)
|
2013-09-17 15:43:45 +02:00
|
|
|
(hack-local-variables)
|
2014-03-10 12:59:51 +01:00
|
|
|
(let ((local-master (if masterfile masterfile buffer-file-name)))
|
2014-02-21 15:23:25 +01:00
|
|
|
(pdf-view local-master)))
|
2013-09-21 13:03:55 +02:00
|
|
|
|
2013-09-17 15:43:45 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2014-02-18 12:13:18 +01:00
|
|
|
;; TeX setup
|
2013-09-26 12:07:33 +02:00
|
|
|
|
2014-02-27 10:27:47 +01:00
|
|
|
(setq tex-start-options "-file-line-error-style -interaction=nonstopmode -synctex=1")
|
|
|
|
(setq tex-start-commands nil)
|
|
|
|
|
2014-02-26 18:04:00 +01:00
|
|
|
(add-hook-and-eval
|
2014-02-20 14:35:19 +01:00
|
|
|
'tex-mode-hook
|
|
|
|
(lambda ()
|
2013-06-12 23:40:20 +02:00
|
|
|
(dolist (key '("\C-c\C-f" "\C-c\C-b"))
|
|
|
|
(local-unset-key key))
|
2013-11-11 13:51:16 +01:00
|
|
|
(set-face-attribute 'tex-verbatim nil :family "freemono")
|
2013-07-04 10:37:18 +02:00
|
|
|
(set (make-local-variable 'compilation-scroll-output) t)
|
|
|
|
(set (make-local-variable 'compilation-hide-window) t)
|
2013-10-30 15:57:50 +01:00
|
|
|
(set (make-local-variable 'paragraph-start) "
|
|
|
|
")
|
|
|
|
;; (set (make-local-variable 'use-hard-newlines) t)
|
2013-09-21 13:03:55 +02:00
|
|
|
(local-set-key (kbd "<f9>") 'tex-pdf-view)
|
2014-02-27 10:27:47 +01:00
|
|
|
(setq tex-command "pdftex")
|
2014-02-20 14:35:19 +01:00
|
|
|
(tex-set-compiler)))
|
2014-02-18 12:13:18 +01:00
|
|
|
|
2014-03-10 12:59:51 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Skeletons
|
|
|
|
|
|
|
|
(define-skeleton tex-array
|
|
|
|
"Insert skel."
|
|
|
|
"Format: "
|
|
|
|
"$$\\begin{array}{" @ str "}" \n
|
|
|
|
_ \n
|
|
|
|
"\\end{array}$$" > \n)
|
|
|
|
|
|
|
|
(define-skeleton tex-bf "Insert skel." nil "{\\bf{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-binom "Insert skel." nil "\\binom{" @ _ "}{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-coprod "Insert skel." nil "\\coprod_{" @ _ "}^{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-em "Insert skel." nil "{\\em{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-footnote "Insert skel." nil "\\footnote{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-href "Insert skel." "Desc: " "\\href{" @ _ "}{" @ str "}" @)
|
|
|
|
(define-skeleton tex-it "Insert skel." nil "{\\it{" @ _ "}" @)
|
|
|
|
|
|
|
|
(define-skeleton tex-main "Insert skel." nil
|
|
|
|
"\\input eplain" \n
|
|
|
|
@ > _ \n
|
|
|
|
"\\bye" > @)
|
|
|
|
|
|
|
|
(define-skeleton tex-prod "Insert skel." nil "\\prod_{" @ _ "}^{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-sum "Insert skel." nil "\\sum_{" @ _ "}^{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-tt "Insert skel." nil "{\\tt{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-url "Insert skel." nil "\\url{" @ _ "}" @)
|
|
|
|
|
2014-02-12 17:48:29 +01:00
|
|
|
(provide 'mode-tex)
|