summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tex-conf.el130
1 files changed, 129 insertions, 1 deletions
diff --git a/tex-conf.el b/tex-conf.el
index 4c5211d..be0ad34 100644
--- a/tex-conf.el
+++ b/tex-conf.el
@@ -35,7 +35,7 @@
(output-pdf "PDF Tools")
(output-html "open")))
-;; I don't want to split the screen.
+;;; I don't want to split the screen.
;;;###autoload
(defun durand-TeX-pdf-tools-sync-view-a ()
@@ -56,9 +56,27 @@
(switch-to-buffer (or (find-buffer-visiting pdf)
(find-file-noselect pdf))))))
+(add-hook 'TeX-after-compilation-finished-functions
+ #'TeX-revert-document-buffer)
+
+(setq pdf-sync-forward-display-action
+ (list (list 'display-buffer-same-window)))
+
+(setq pdf-sync-backward-display-action
+ (list (list 'display-buffer-same-window)))
+
(advice-add #'TeX-pdf-tools-sync-view :override
#'durand-TeX-pdf-tools-sync-view-a)
+;;; Correlate
+
+(setq TeX-source-correlate-start-server t)
+(TeX-source-correlate-mode 1)
+
+;;; Section display
+
+(setq font-latex-fontify-sectioning 1.3)
+
;;; Dollars
(setq TeX-electric-math (cons "\\(" "\\)"))
@@ -71,6 +89,116 @@
(interactive)
(insert "\\"))
+;;; Parens don't require space
+
+(add-hook 'LaTeX-mode-hook #'durand-prepare-latex)
+
+;;; Brackets handling
+
+(mapc
+ (function
+ (lambda (cell)
+ (define-key LaTeX-mode-map (vector (car cell)) (cdr cell))))
+ (list
+ (cons ?\( #'open-paren)
+ (cons ?{ #'open-curly)
+ (cons ?\[ #'open-bracket)
+ (cons 'backspace #'durand-delete-pair)
+ (cons ?\) #'end-exit-paren)
+ (cons ?à #'open-back-paren)))
+
+;;;###autoload
+(defun open-paren ()
+ "open parenthesis inserts a matching pair"
+ (interactive)
+ (progn
+ (insert "()")
+ (backward-char)))
+
+;;;###autoload
+(defun open-curly ()
+ "open curly inserts a matching pair"
+ (interactive)
+ (progn
+ (insert "{}")
+ (backward-char)))
+
+;;;###autoload
+(defun open-bracket ()
+ "open bracket inserts a matching pair"
+ (interactive)
+ (progn
+ (insert "[]")
+ (backward-char)))
+
+;;;###autoload
+(defun durand-delete-pair ()
+ "Delete the matching pair"
+ (interactive)
+ (cond ((region-active-p) ; if the region is active, then do the original thing
+ (delete-backward-char 1))
+ ((looking-back "\\(\\\\(\\|\\\\\\[\\)" (- (point) 2))
+ (save-excursion
+ (backward-char 1)
+ (ignore-errors
+ (forward-sexp 1)
+ (delete-char -2)))
+ (delete-char -2))
+ ((memq (char-before) '(?\( ?\[ ?\{))
+ (save-excursion
+ (backward-char 1)
+ (ignore-errors
+ (forward-sexp 1)
+ (delete-char -1)))
+ (delete-char -1))
+ (t
+ (backward-delete-char-untabify 1))))
+
+;;;###autoload
+(defun end-exit-paren ()
+ "Use closing pasenthesis to exit the parenthesis"
+ (interactive)
+ (let ((ch (char-after nil))
+ (ch-list '(?\) ?\} ?\] ?\$)))
+ (cond ((memq ch ch-list) (forward-char))
+ ((looking-at-p "\\(\\\\)\\|\\\\]\\|\\\\}\\)")
+ (forward-char 2))
+ (t (self-insert-command 1)))))
+
+;;;###autoload
+(defun open-back-paren ()
+ "Use \"à\" to go back to the parenthesis."
+ (interactive)
+ (let ((ch (char-before nil))
+ (ch-list '(?\) ?\} ?\] ?\$)))
+ (cond ((looking-back "\\(\\\\)\\|\\\\]\\|\\\\}\\)" (- (point) 2))
+ (forward-char -2))
+ ((memq ch ch-list) (backward-char))
+ (t (self-insert-command 1)))))
+
+(make-variable-buffer-local 'parens-require-spaces)
+
+;;;###autoload
+(defun durand-prepare-latex ()
+ "Prepare some settings in LateX mode."
+ (modify-syntax-entry ?\\ "_")
+ (turn-on-auto-fill)
+ (setq parens-require-spaces nil))
+
+;;; Don't insert a new line between the section and the label.
+
+;;;###autoload
+(defun durand-latex-delete-newline ()
+ "If the character before point is a newline, then delete it."
+ (cond
+ ((= (char-before) ?\n)
+ (delete-char -1))))
+
+(setq LaTeX-section-hook
+ '(LaTeX-section-heading LaTeX-section-title
+ LaTeX-section-section durand-latex-delete-newline
+ LaTeX-section-label))
+
;;; Expansions
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)