122 lines
4.4 KiB
EmacsLisp
122 lines
4.4 KiB
EmacsLisp
;;==============================================================================
|
|
;; 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.
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; CUSTOM
|
|
|
|
(defcustom masterfile nil
|
|
"The file that should be compiled. Useful for modular documents."
|
|
:safe 'stringp)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; VARIABLES
|
|
|
|
(defvar tex-extension-list nil
|
|
"List of known TeX exentsions. This list is used by `tex-clean'
|
|
to purge all matching files.")
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; FUNCTIONS
|
|
(defun tex-set-compiler ()
|
|
"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
|
|
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)
|
|
(hack-local-variables)
|
|
(let (;; Master file.
|
|
(local-master
|
|
(if masterfile masterfile buffer-file-name))
|
|
|
|
;; Support of prefix argument to toggle -shell-escape.
|
|
(local-shell-escape
|
|
(if (equal current-prefix-arg '(4)) "-shell-escape" "")))
|
|
|
|
(set (make-local-variable 'compile-command)
|
|
(concat tex-command
|
|
" " tex-start-options
|
|
" " local-shell-escape
|
|
" " tex-start-commands
|
|
" " (shell-quote-argument local-master)))))
|
|
|
|
(defun tex-clean ()
|
|
"Remove all TeX temporary files. This command should be safe,
|
|
but there is no warranty."
|
|
(interactive)
|
|
(hack-local-variables)
|
|
(let* ((local-master (if (not masterfile) buffer-file-name masterfile)))
|
|
;; Concatate file name to list.
|
|
(mapcar
|
|
;; Delete file if exist
|
|
(lambda (argfile) (interactive)
|
|
(if (not (and (file-exists-p argfile) (file-writable-p argfile)))
|
|
(message "[%s] not found." argfile)
|
|
(delete-file argfile)
|
|
(message "[%s] deleted." argfile)))
|
|
(mapcar
|
|
;; Concat file name with extensions.
|
|
(lambda (arg) (interactive) (concat file arg))
|
|
tex-extension-list))))
|
|
|
|
(defun tex-pdf-compress ()
|
|
"Use `masterfile' variable as default value for `pdf-compress'."
|
|
(interactive)
|
|
(require 'tool-pdf)
|
|
(hack-local-variables)
|
|
(let ((local-master (if (not masterfile) buffer-file-name masterfile)))
|
|
(pdf-compress local-master)))
|
|
|
|
(defun tex-pdf-view ()
|
|
"Use `masterfile' variable as default value for `pdf-view'."
|
|
(interactive)
|
|
(require 'tool-pdf)
|
|
(hack-local-variables)
|
|
(let ((local-master (if (not masterfile) buffer-file-name masterfile)))
|
|
(pdf-view local-master)))
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; TeX setup
|
|
|
|
(setq tex-start-options "-file-line-error-style -interaction=nonstopmode -synctex=1")
|
|
(setq tex-start-commands nil)
|
|
|
|
(add-hook-and-eval
|
|
'tex-mode-hook
|
|
(lambda ()
|
|
(dolist (key '("\C-c\C-f" "\C-c\C-b"))
|
|
(local-unset-key key))
|
|
(set-face-attribute 'tex-verbatim nil :family "freemono")
|
|
(set (make-local-variable 'compilation-scroll-output) t)
|
|
(set (make-local-variable 'compilation-hide-window) t)
|
|
(set (make-local-variable 'paragraph-start) "
|
|
")
|
|
;; (set (make-local-variable 'use-hard-newlines) t)
|
|
(local-set-key (kbd "<f9>") 'tex-pdf-view)
|
|
(setq tex-command "pdftex")
|
|
(tex-set-compiler)))
|
|
|
|
(provide 'mode-tex)
|