Emacs: Replace homebrewed config with AUCTeX
parent
d323e8ea69
commit
274327ae1f
|
@ -334,12 +334,11 @@
|
|||
(setq term-buffer-maximum-size 0))
|
||||
|
||||
;;; TeX / LaTeX / Texinfo
|
||||
(with-eval-after-load 'tex-mode (require 'init-tex))
|
||||
(with-eval-after-load 'texinfo (require 'init-texinfo))
|
||||
;;; LaTeX is defined in the same file as TeX. To separate the loading, we add it
|
||||
;;; to the hook.
|
||||
(nconc package-selected-packages '(auctex latex-math-preview))
|
||||
(with-eval-after-load 'tex (require 'init-tex))
|
||||
;; LaTeX is defined in the same file as TeX. To separate the loading, we add it
|
||||
;; to the hook.
|
||||
(add-hook 'latex-mode-hook (lambda () (require 'init-latex)))
|
||||
(nconc package-selected-packages '(latex-math-preview))
|
||||
|
||||
;;; Torrent
|
||||
(nconc package-selected-packages '(transmission))
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
;;; TODO: `beginning-of-defun'/`end-of-defun' should go to next section.
|
||||
|
||||
;;; TODO: Replace init-tex, init-texinfo and init-latex with AucTeX.
|
||||
;;; Only keep some skeletons.
|
||||
|
||||
;;; We use the TeX setup.
|
||||
(require 'init-tex)
|
||||
(require 'latex-pretty-symbols nil t)
|
||||
|
@ -13,17 +10,16 @@
|
|||
;;; Since current buffer is a LaTeX one, we can use `local-set-key'.
|
||||
(local-set-keys
|
||||
"C-c m" 'latex-article
|
||||
"C-c C-a" 'latex-insert-table
|
||||
"C-c C-c" 'latex-smallcaps
|
||||
"C-c C-e" 'latex-emph
|
||||
"C-c C-l" 'latex-slanted
|
||||
"C-c C-s" 'latex-insert-section
|
||||
"C-c C-u" 'latex-superscript
|
||||
"C-c l" 'latex-lstinline
|
||||
"C-c o" 'latex-orgtbl
|
||||
"C-c u" 'latex-package
|
||||
"M-<return>" 'latex-itemize)
|
||||
"C-c o" 'latex-orgtbl)
|
||||
|
||||
(dolist (fun '(turn-on-orgtbl turn-on-skeleton-markers))
|
||||
;; Since this file is loaded from `latex-mode-hook', these functions will not
|
||||
;; be applied to the current buffer. We do it manually.
|
||||
(funcall fun)
|
||||
(add-hook 'latex-mode-hook fun))
|
||||
|
||||
;;; latex-math-preview
|
||||
;;; Needs dvipng.
|
||||
;;; With TeXlive, the following packages are needed: psnfss, symbol, zapfding
|
||||
(when (and (executable-find "dvipng") (require 'latex-math-preview nil t))
|
||||
|
@ -35,120 +31,28 @@
|
|||
;; Any color package should be filtered out as they will have unexpected impact on coloring.
|
||||
(add-to-list 'latex-math-preview-usepackage-filter-alist '("color")))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Functions
|
||||
|
||||
(defun latex-itemize ()
|
||||
"Itemize current line or lines in region.
|
||||
Prepend \\item to the beginning of the lines if not already
|
||||
there, otherwise insert it on next line. If region, surround it
|
||||
by an {itemize} environment."
|
||||
(interactive)
|
||||
(let (min max)
|
||||
(if (not (use-region-p))
|
||||
(if (string-match "\\item" (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
|
||||
(progn
|
||||
(goto-char (line-end-position))
|
||||
(newline)
|
||||
(insert "\\item "))
|
||||
(goto-char (line-beginning-position))
|
||||
(insert "\\item")
|
||||
(just-one-space))
|
||||
;; On region:
|
||||
(let ((end-marker (set-marker (make-marker) (region-end))))
|
||||
(goto-char (region-beginning))
|
||||
(goto-char (line-beginning-position))
|
||||
(insert "\\begin{itemize}")
|
||||
(newline-and-indent)
|
||||
(while (and (< (line-beginning-position) end-marker) (not (eobp)))
|
||||
(insert "\\item")
|
||||
(just-one-space)
|
||||
(indent-according-to-mode)
|
||||
(forward-line))
|
||||
(insert "\\end{itemize}")
|
||||
(newline-and-indent)))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; LaTeX setup
|
||||
|
||||
(setq latex-block-default "itemize")
|
||||
(setq latex-block-names '("listing" "align" "align*" "Bmatrix" "Vmatrix" "bmatrix" "matrix" "pmatrix" "smallmatrix" "vmatrix"))
|
||||
|
||||
(dolist (block '("listing" "verbatim" "verbatim*"))
|
||||
(add-to-list 'latex-block-body-alist `(,block nil '(delete-horizontal-space t) _)))
|
||||
|
||||
(defun latex-set-compiler ()
|
||||
(set (make-local-variable 'tex-extension-list)
|
||||
'("aux" "bbl" "blg" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "maf" "mt" "mtc" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy"))
|
||||
(set (make-local-variable 'tex-command) "pdflatex")
|
||||
;; Need to reset the compiler because we changed tex-command, order matters.
|
||||
(tex-set-compiler))
|
||||
|
||||
;;; For some unknown reasons, `skeleton-end-hook' is set to nil in tex-mode.
|
||||
(dolist (fun '(latex-set-compiler turn-on-orgtbl turn-on-skeleton-markers))
|
||||
;; Since this file is loaded from `latex-mode-hook', these functions will not
|
||||
;; be applied to the current buffer. We do it manually.
|
||||
(funcall fun)
|
||||
(add-hook 'latex-mode-hook fun))
|
||||
;; (dolist (fun '(latex-set-compiler turn-on-orgtbl turn-on-skeleton-markers))
|
||||
;; ;; Since this file is loaded from `latex-mode-hook', these functions will not
|
||||
;; ;; be applied to the current buffer. We do it manually.
|
||||
;; (funcall fun)
|
||||
;; (add-hook 'latex-mode-hook fun))
|
||||
|
||||
(with-eval-after-load 'latex ; AUCTeX
|
||||
(advice-add 'LaTeX-insert-item :before (lambda () (end-of-line)))
|
||||
|
||||
(with-eval-after-load 'font-latex
|
||||
(set-face-foreground 'font-latex-sectioning-5-face "white"))
|
||||
|
||||
;; TODO: Add "tabu" and "longtabu" to environment list.
|
||||
|
||||
(require 'tex-fold)
|
||||
(add-hook 'LaTeX-mode-hook 'TeX-fold-mode)
|
||||
(add-hook 'find-file-hook 'TeX-fold-buffer t)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Skeletons
|
||||
|
||||
(define-skeleton latex-emph "Insert emph." nil "\\emph{" @ _ "}" @)
|
||||
(define-skeleton latex-slanted "Insert slanted text." nil "\\textsl{" @ _ "}" @)
|
||||
(define-skeleton latex-smallcaps "Insert smallcaps text." nil "\\textsc{" @ _ "}" @)
|
||||
(define-skeleton latex-superscript "Insert supercript text." nil "\\textsuperscript{" @ _ "}" @)
|
||||
(define-skeleton latex-package "Use package." "Package: " \n "\\usepackage[" @ "]{" @ _ "}" \n @)
|
||||
|
||||
(defvar latex-section-default "section")
|
||||
(defvar latex-section-names
|
||||
'("part" "part*" "chapter" "chapter*" "section*" "subsection" "subsection*"
|
||||
"subsubsection" "subsubsection*" "paragraph" "paragraph*" "subparagraph" "subparagraph*")
|
||||
"Standard LaTeX section names.")
|
||||
|
||||
(define-skeleton latex-insert-section
|
||||
"Insert section at point.
|
||||
Puts point to section title. Section are auto-completed from
|
||||
`latex-section-names'."
|
||||
(let ((choice (completing-read (format "LaTeX section name [%s]: "
|
||||
latex-section-default)
|
||||
latex-section-names
|
||||
nil nil nil nil latex-section-default)))
|
||||
(setq latex-section-default choice)
|
||||
(unless (member choice latex-section-names)
|
||||
;; Remember new block names for later completion.
|
||||
(push choice latex-section-names))
|
||||
choice)
|
||||
\n "\\" str "{" @ _ "}" @)
|
||||
|
||||
(defvar latex-table-default "tabular")
|
||||
(defvar latex-table-names
|
||||
'("tabular" "tabu" "tabular*" "tabularx" "tabulary" "longtabu")
|
||||
"Standard LaTeX table names.")
|
||||
|
||||
(define-skeleton latex-insert-table
|
||||
"Create a table at point.
|
||||
The table type is any value found in `latex-table-names'."
|
||||
(let ((choice (completing-read (format "LaTeX table type [%s]: "
|
||||
latex-table-default)
|
||||
latex-table-names
|
||||
nil nil nil nil latex-table-default)))
|
||||
(setq latex-table-default choice)
|
||||
(unless (member choice latex-table-names)
|
||||
;; Remember new block names for later completion.
|
||||
(push choice latex-table-names))
|
||||
choice)
|
||||
'(require 'functions)
|
||||
\n "\\begin{center}" > \n
|
||||
"\\begin{" str "}{"
|
||||
'(setq v1 (skeleton-read "Format: " "ll"))
|
||||
v1 "}" > \n
|
||||
'(setq v2 (count-occurences "[a-z]" v1))
|
||||
@ (mapconcat 'identity (split-string (make-string v2 ?&) "" t) " ") " \\\\" \n
|
||||
@ _ "\\\\" \n
|
||||
"\\end{" str "}" > \n
|
||||
"\\end{center}" > \n @)
|
||||
|
||||
;;; TODO: implement orgtbl directly with latex tables and remove this skel.
|
||||
(define-skeleton latex-orgtbl
|
||||
"Insert orgtbl skel."
|
||||
|
|
|
@ -1,96 +1,9 @@
|
|||
;;; 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.
|
||||
|
||||
(define-keys tex-mode-map
|
||||
"C-c C-f" nil
|
||||
"C-c C-b" nil
|
||||
"<f5>" 'tex-pdf-view
|
||||
"C-<f6>" 'compile
|
||||
"<f6>" 'tex-compile)
|
||||
|
||||
(defvar-local tex-masterfile nil
|
||||
"The file that should be compiled. Useful for modular documents.")
|
||||
|
||||
(defcustom tex-compilation-delay 2
|
||||
"Seconds before hiding the compilation window."
|
||||
:type 'number
|
||||
:group 'tex)
|
||||
|
||||
(defcustom tex-extension-list nil
|
||||
"List of known TeX exentsions. This list is used by `tex-clean'
|
||||
to purge all matching files."
|
||||
:type '(repeat list)
|
||||
:group 'tex)
|
||||
|
||||
(defcustom tex-index-command "makeindex"
|
||||
"The TeX index file generator."
|
||||
:type 'string
|
||||
:group 'tex)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Functions
|
||||
|
||||
(defun tex-set-compiler ()
|
||||
"Set `compile-command' for TeX-based document."
|
||||
(interactive)
|
||||
(hack-local-variables)
|
||||
(let* (;; Master file.
|
||||
(local-master (or tex-masterfile buffer-file-name (error "Buffer has no file name")))
|
||||
(dirname (file-name-directory local-master))
|
||||
(basename (file-name-sans-extension (file-name-nondirectory local-master)))
|
||||
;; Note: makeindex fails with absolute file names, we need relative names.
|
||||
(idxfile ))
|
||||
(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)))))
|
||||
|
||||
(defun tex-clean ()
|
||||
"Remove all TeX temporary files.
|
||||
This command should be safe, but there is no warranty."
|
||||
(interactive)
|
||||
(hack-local-variables)
|
||||
(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)))))
|
||||
|
||||
(defun tex-pdf-view ()
|
||||
"Find PDF file associated to `tex-masterfile' if set or buffer-filename otherwise."
|
||||
(interactive)
|
||||
(hack-local-variables)
|
||||
(find-file (concat
|
||||
(file-name-sans-extension (or tex-masterfile buffer-file-name))
|
||||
".pdf")))
|
||||
(dolist (fun '(turn-on-indent-tabs
|
||||
;; turn-on-newline-paragraph
|
||||
prettify-symbols-mode))
|
||||
(add-hook 'tex-mode-hook fun))
|
||||
|
||||
(defun tex-toggle-escape-char ()
|
||||
"Make backslash part of the word syntax or not.
|
||||
|
@ -103,62 +16,26 @@ This does not interfere with `subword-mode'."
|
|||
(modify-syntax-entry ?\\ "\\")
|
||||
(message "\\ is a an escape character")))
|
||||
|
||||
(defun tex-compile ()
|
||||
"Compile the TeX document."
|
||||
(interactive)
|
||||
(compile compile-command)
|
||||
(sit-for tex-compilation-delay)
|
||||
(delete-windows-on "*compilation*"))
|
||||
(with-eval-after-load 'tex ; AUCTeX
|
||||
(setq TeX-auto-save t
|
||||
TeX-parse-self t
|
||||
;; Use pdf-tools to open PDF files
|
||||
TeX-view-program-selection '((output-pdf "PDF Tools"))
|
||||
TeX-source-correlate-start-server t
|
||||
;; TeX-fold-auto t
|
||||
TeX-electric-escape t
|
||||
;; TeX-electric-math t
|
||||
TeX-electric-sub-and-superscript t)
|
||||
(setq-default TeX-master nil)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; TeX setup
|
||||
(when (require 'helm-config nil t)
|
||||
(define-key TeX-mode-map (kbd "M-s f") 'helm-semantic-or-imenu))
|
||||
|
||||
(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)
|
||||
|
||||
;;; `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.
|
||||
(dolist (fun '(turn-on-indent-tabs
|
||||
turn-on-newline-paragraph
|
||||
turn-on-newline-paragraph
|
||||
prettify-symbols-mode
|
||||
tex-set-compiler))
|
||||
(add-hook 'tex-mode-hook fun))
|
||||
;; Update PDF buffers after successful LaTeX runs
|
||||
(add-hook 'TeX-after-compilation-finished-functions
|
||||
#'TeX-revert-document-buffer))
|
||||
|
||||
;;; Not sure how useful that is:
|
||||
;; (set (make-local-variable 'use-hard-newlines) t)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Skeletons
|
||||
|
||||
(define-skeleton tex-array
|
||||
"Insert array."
|
||||
"Format: "
|
||||
"$$\\begin{array}{" @ str "}" \n
|
||||
_ \n
|
||||
"\\end{array}$$" > \n)
|
||||
|
||||
(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 " @ _ "}" @)
|
||||
|
||||
(define-skeleton tex-main "Insert document template." nil
|
||||
"\\input eplain" \n
|
||||
@ > _ \n
|
||||
"\\bye" > @)
|
||||
|
||||
(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{" @ _ "}" @)
|
||||
|
||||
(provide 'init-tex)
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
;;; Texinfo
|
||||
|
||||
;;; We use the TeX setup.
|
||||
(require 'tex-mode)
|
||||
(require 'init-tex)
|
||||
|
||||
(local-set-key (kbd "C-c C-b") 'texinfo-menu-update)
|
||||
|
||||
(defun texinfo-menu-update ()
|
||||
"Update texinfo node menu automatically."
|
||||
(interactive)
|
||||
(hack-local-variables)
|
||||
(texinfo-multiple-files-update (or tex-master-file buffer-file-name) t 8))
|
||||
|
||||
(defun texinfo-set-compiler ()
|
||||
(set (make-local-variable 'tex-extension-list)
|
||||
'("aux" "cp" "cps" "fn" "ky" "log" "pg" "toc" "tp" "vr" "vrs"))
|
||||
(set (make-local-variable 'tex-start-options) nil)
|
||||
(set (make-local-variable 'tex-command) "texi2pdf -b")
|
||||
(tex-set-compiler))
|
||||
|
||||
;;; For some reason, Texinfo-mode forces the fill-column to 70...
|
||||
(dolist (fun '(texinfo-set-compiler reset-fill-column))
|
||||
(add-hook 'texinfo-mode-hook fun))
|
||||
|
||||
(provide 'init-texinfo)
|
Loading…
Reference in New Issue