2017-10-08 20:36:28 +02:00
|
|
|
;;; TeX
|
|
|
|
|
|
|
|
;;; The default tex-mode and AucTeX may seem quite disappointing. Let's use
|
|
|
|
;;; custom KISS functions for everything.
|
|
|
|
|
|
|
|
;;; 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.
|
2014-02-27 10:27:47 +01:00
|
|
|
|
2017-06-16 21:33:53 +02:00
|
|
|
(define-keys tex-mode-map
|
|
|
|
"C-c C-f" nil
|
|
|
|
"C-c C-b" nil
|
2017-06-18 17:18:56 +02:00
|
|
|
"<f5>" 'tex-pdf-view
|
|
|
|
"C-<f6>" 'compile
|
|
|
|
"<f6>" 'tex-compile)
|
2017-05-15 07:46:20 +02:00
|
|
|
|
2017-05-08 11:51:23 +02:00
|
|
|
(defvar-local tex-masterfile nil
|
|
|
|
"The file that should be compiled. Useful for modular documents.")
|
2014-02-21 15:23:25 +01:00
|
|
|
|
2017-05-11 19:38:01 +02:00
|
|
|
(defcustom tex-compilation-delay 2
|
|
|
|
"Seconds before hiding the compilation window."
|
2017-05-24 00:27:02 +02:00
|
|
|
:type 'number
|
|
|
|
:group 'tex)
|
2016-10-14 14:03:30 +02:00
|
|
|
|
2017-05-08 11:51:23 +02:00
|
|
|
(defcustom tex-extension-list nil
|
2014-02-21 15:23:25 +01:00
|
|
|
"List of known TeX exentsions. This list is used by `tex-clean'
|
2017-05-11 19:38:01 +02:00
|
|
|
to purge all matching files."
|
2017-05-24 00:27:02 +02:00
|
|
|
:type '(repeat list)
|
|
|
|
:group 'tex)
|
2013-09-17 15:43:45 +02:00
|
|
|
|
2017-05-08 11:51:23 +02:00
|
|
|
(defcustom tex-index-command "makeindex"
|
2017-05-11 19:38:01 +02:00
|
|
|
"The TeX index file generator."
|
2017-05-24 00:27:02 +02:00
|
|
|
:type 'string
|
|
|
|
:group 'tex)
|
2014-03-20 22:04:23 +01:00
|
|
|
|
2013-09-17 15:43:45 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; Functions
|
2016-10-14 14:03:30 +02:00
|
|
|
|
2013-07-04 10:37:18 +02:00
|
|
|
(defun tex-set-compiler ()
|
2014-03-13 13:50:56 +01:00
|
|
|
"Set `compile-command' for TeX-based document."
|
2014-04-02 11:31:22 +02:00
|
|
|
(interactive)
|
2013-09-17 15:43:45 +02:00
|
|
|
(hack-local-variables)
|
2014-03-20 22:04:23 +01:00
|
|
|
(let* (;; Master file.
|
2017-05-22 16:24:25 +02:00
|
|
|
(local-master (or tex-masterfile buffer-file-name (error "Buffer has no file name")))
|
2014-04-02 11:31:22 +02:00
|
|
|
(dirname (file-name-directory local-master))
|
|
|
|
(basename (file-name-sans-extension (file-name-nondirectory local-master)))
|
2014-03-20 22:04:23 +01:00
|
|
|
;; Note: makeindex fails with absolute file names, we need relative names.
|
2014-04-02 15:40:08 +02:00
|
|
|
(idxfile ))
|
2017-05-12 08:34:17 +02:00
|
|
|
(setq compile-command
|
|
|
|
(concat
|
|
|
|
"cd " (if dirname (shell-quote-argument dirname) ".") " && "
|
|
|
|
(when (executable-find tex-index-command)
|
|
|
|
(concat tex-index-command " " (shell-quote-argument (concat basename ".idx")) "; "))
|
|
|
|
(when (executable-find tex-bibtex-command)
|
|
|
|
(concat tex-bibtex-command " " (shell-quote-argument basename) "; "))
|
|
|
|
tex-command
|
|
|
|
" " tex-start-options
|
|
|
|
" " tex-start-commands
|
|
|
|
" " (shell-quote-argument basename)))))
|
2013-06-12 23:40:20 +02:00
|
|
|
|
|
|
|
(defun tex-clean ()
|
2017-05-22 16:24:25 +02:00
|
|
|
"Remove all TeX temporary files.
|
|
|
|
This command should be safe, but there is no warranty."
|
2013-06-12 23:40:20 +02:00
|
|
|
(interactive)
|
2013-09-17 15:43:45 +02:00
|
|
|
(hack-local-variables)
|
2017-05-22 16:24:25 +02:00
|
|
|
(let ((master (file-name-sans-extension (or tex-masterfile buffer-file-name))))
|
|
|
|
(dolist (file (mapcar
|
|
|
|
;; Concat file name with extensions.
|
|
|
|
(lambda (arg) (concat master "." arg))
|
|
|
|
tex-extension-list))
|
|
|
|
;; Delete file if it exists.
|
|
|
|
(when (and (file-exists-p file) (file-writable-p file))
|
|
|
|
(delete-file file)
|
|
|
|
(message "Deleted %S." file)))))
|
2013-06-12 23:40:20 +02:00
|
|
|
|
|
|
|
(defun tex-pdf-view ()
|
2017-07-02 20:07:19 +02:00
|
|
|
"Find PDF file associated to `tex-masterfile' if set or buffer-filename otherwise."
|
2013-06-12 23:40:20 +02:00
|
|
|
(interactive)
|
2013-09-17 15:43:45 +02:00
|
|
|
(hack-local-variables)
|
2017-07-02 20:07:19 +02:00
|
|
|
(find-file (concat
|
|
|
|
(file-name-sans-extension (or tex-masterfile buffer-file-name))
|
|
|
|
".pdf")))
|
2013-09-21 13:03:55 +02:00
|
|
|
|
2014-03-13 15:48:34 +01:00
|
|
|
(defun tex-toggle-escape-char ()
|
|
|
|
"Make backslash part of the word syntax or not.
|
|
|
|
This does not interfere with `subword-mode'."
|
|
|
|
(interactive)
|
|
|
|
(if (equal (char-syntax ?\\) ?\\)
|
|
|
|
(progn
|
|
|
|
(modify-syntax-entry ?\\ "w")
|
|
|
|
(message "\\ is a not an escape character"))
|
|
|
|
(modify-syntax-entry ?\\ "\\")
|
|
|
|
(message "\\ is a an escape character")))
|
|
|
|
|
2017-05-28 12:03:28 +02:00
|
|
|
(defun tex-compile ()
|
|
|
|
"Compile the TeX document."
|
|
|
|
(interactive)
|
|
|
|
(compile compile-command)
|
|
|
|
(sit-for tex-compilation-delay)
|
|
|
|
(delete-windows-on "*compilation*"))
|
|
|
|
|
2013-09-17 15:43:45 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; TeX setup
|
2013-09-26 12:07:33 +02:00
|
|
|
|
2017-06-16 16:29:52 +02:00
|
|
|
(setq-default
|
|
|
|
tex-run-command "pdftex"
|
|
|
|
tex-start-options "-file-line-error-style -interaction=nonstopmode -synctex=1"
|
|
|
|
;; Use the following variable to append file local commands without erasing
|
|
|
|
;; default options.
|
|
|
|
tex-start-commands nil)
|
2014-02-27 10:27:47 +01:00
|
|
|
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; `tex-mode' sets `indent-tabs-mode' to nil, invoking the following
|
|
|
|
;;; argument: "TABs in verbatim environments don't do what you think." Not
|
|
|
|
;;; sure how relevant this bad comment is. We revert it.
|
2017-07-03 23:43:37 +02:00
|
|
|
(dolist (fun '(turn-on-indent-tabs
|
|
|
|
turn-on-newline-paragraph
|
|
|
|
turn-on-newline-paragraph
|
|
|
|
prettify-symbols-mode
|
|
|
|
tex-set-compiler))
|
2017-06-16 16:29:52 +02:00
|
|
|
(add-hook 'tex-mode-hook fun))
|
2014-02-18 12:13:18 +01:00
|
|
|
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; Not sure how useful that is:
|
2017-05-28 14:15:51 +02:00
|
|
|
;; (set (make-local-variable 'use-hard-newlines) t)
|
|
|
|
|
2014-03-10 12:59:51 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; Skeletons
|
2014-03-10 12:59:51 +01:00
|
|
|
|
|
|
|
(define-skeleton tex-array
|
2017-06-04 12:47:10 +02:00
|
|
|
"Insert array."
|
2014-03-10 12:59:51 +01:00
|
|
|
"Format: "
|
|
|
|
"$$\\begin{array}{" @ str "}" \n
|
|
|
|
_ \n
|
|
|
|
"\\end{array}$$" > \n)
|
|
|
|
|
2017-06-04 12:47:10 +02:00
|
|
|
(define-skeleton tex-bf "Insert bold text." nil "{\\bf " @ _ "}" @)
|
|
|
|
(define-skeleton tex-binom "Insert binomial." nil "\\binom{" @ _ "}{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-coprod "Insert coproduct." nil "\\coprod_{" @ _ "}^{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-em "Insert emphasized text." nil "{\\em " @ _ "}" @)
|
|
|
|
(define-skeleton tex-footnote "Insert footnote." nil "\\footnote{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-href "Insert href." "Desc: " "\\href{" @ _ "}{" @ str "}" @)
|
|
|
|
(define-skeleton tex-it "Insert italic text." nil "{\\it " @ _ "}" @)
|
2014-03-10 12:59:51 +01:00
|
|
|
|
2017-06-04 12:47:10 +02:00
|
|
|
(define-skeleton tex-main "Insert document template." nil
|
2014-03-10 12:59:51 +01:00
|
|
|
"\\input eplain" \n
|
|
|
|
@ > _ \n
|
|
|
|
"\\bye" > @)
|
|
|
|
|
2017-06-04 12:47:10 +02:00
|
|
|
(define-skeleton tex-prod "Insert product." nil "\\prod_{" @ _ "}^{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-sum "Insert sum." nil "\\sum_{" @ _ "}^{" @ _ "}" @)
|
|
|
|
(define-skeleton tex-tt "Insert truetype text." nil "{\\tt " @ _ "}" @)
|
|
|
|
(define-skeleton tex-url "Insert URL." nil "\\url{" @ _ "}" @)
|
2014-03-10 12:59:51 +01:00
|
|
|
|
2017-06-18 18:50:31 +02:00
|
|
|
(provide 'init-tex)
|