Cleanup Latex

master
Jacopo De Simoi 7 years ago
parent ba2f2c8293
commit 1a6d97771a
  1. 223
      global.org

@ -980,6 +980,13 @@
(if arg (TeX-insert-macro "eqref")
(TeX-insert-macro "ref")))
#+END_SRC
This inserts a citation
#+BEGIN_SRC emacs-lisp
(defun wilder/TeX-insert-cite (arg)
(interactive "P")
(insert "~")
(TeX-insert-macro "cite"))
#+END_SRC
This inserts an ~align~ environment (or an ~align*~ with prefix arg)
#+BEGIN_SRC emacs-lisp
(defun wilder/TeX-insert-align (arg)
@ -988,6 +995,13 @@
(LaTeX-insert-environment "align")
(LaTeX-insert-environment "align*")))
#+END_SRC
This replaces horizontal space with a tilde
#+BEGIN_SRC emacs-lisp
(defun wilder/TeX-replace-tilde (arg)
(interactive "P")
(delete-horizontal-space)
(insert "~"))
#+END_SRC
Insert a todonote at point or wrap the region in a todonote.
#+BEGIN_SRC emacs-lisp
(defun wilder/TeX-insert-todonote (arg r-begin r-end)
@ -996,208 +1010,33 @@
(add-delimiter "\\todo[inline]{" "}{}" r-begin r-end)
(add-delimiter "\\todo{" "}{}" r-begin r-end)))
#+END_SRC
This re-implements LaTeX-insert-environment to my taste
TODO Figure out what are the differences with the original version
and explain!
#+BEGIN_SRC emacs-lisp
(defun LaTeX-insert-environment (environment &optional extra)
"Insert LaTeX ENVIRONMENT with optional argument EXTRA."
(let ((active-mark (and (TeX-active-mark) (not (eq (mark) (point)))))
prefix content-start env-start env-end)
(when (and active-mark (< (mark) (point))) (exchange-point-and-mark))
;; Compute the prefix.
(when (and LaTeX-insert-into-comments (TeX-in-commented-line))
(save-excursion
(beginning-of-line)
(looking-at
(concat "^\\([ \t]*" TeX-comment-start-regexp "+\\)+[ \t]*"))
(setq prefix (match-string 0))))
;; What to do with the line containing point.
(cond
;; if the line is made of blanks, erase them and start on the same line
((save-excursion (beginning-of-line)
(looking-at (concat prefix "[ \t]*$")))
(delete-region (match-beginning 0) (match-end 0)))
;; if after the point there are only blanks, erase them and dont add extra newline
((looking-at "[ \t]*$")
(delete-horizontal-space)
(newline))
((TeX-looking-at-backward (concat "^" prefix "[ \t]*")
(line-beginning-position))
(beginning-of-line)
(newline)
(beginning-of-line 0));; if we are at the beginning of the line (maybe with some spaces
((bolp)
(delete-horizontal-space)
(newline)
(beginning-of-line 0))
((eolp)
(delete-horizontal-space)
(newline)
)
(t
(delete-horizontal-space)
(newline 2)
(when prefix (insert prefix))
(beginning-of-line 0)))
;; What to do with the line containing mark.
(when active-mark
(save-excursion
(goto-char (mark))
(cond ((save-excursion (beginning-of-line)
(or (looking-at (concat prefix "[ \t]*$"))
(looking-at "[ \t]*$")))
(delete-region (match-beginning 0) (match-end 0)))
((TeX-looking-at-backward (concat "^" prefix "[ \t]*")
(line-beginning-position))
(beginning-of-line)
(newline)
(beginning-of-line 0))
(t
(delete-horizontal-space)
(insert-before-markers "\n")
(newline)
(when prefix (insert prefix))))))
;; Now insert the environment.
(when prefix (insert prefix))
(setq env-start (point))
(insert TeX-esc "begin" TeX-grop environment TeX-grcl)
(indent-according-to-mode)
(when extra (insert extra))
(setq content-start (line-beginning-position 2))
(unless active-mark
(newline)
(when prefix (insert prefix))
(newline))
(when active-mark (goto-char (mark)))
(when prefix (insert prefix))
(insert TeX-esc "end" TeX-grop environment TeX-grcl "%")
(end-of-line 0)
(if active-mark
(progn
(or (assoc environment LaTeX-indent-environment-list)
(LaTeX-fill-region content-start (line-beginning-position 2)))
(set-mark content-start))
(indent-according-to-mode))
(save-excursion (beginning-of-line 2) (indent-according-to-mode))
(TeX-math-input-method-off)
(setq env-end (save-excursion
(search-forward
(concat TeX-esc "end" TeX-grop
environment TeX-grcl))
(match-beginning 0)))
(fill-paragraph)
(run-hook-with-args 'LaTeX-after-insert-env-hooks
environment env-start env-end)))
#+END_SRC
*** TODO Leftovers
*** The hook
#+BEGIN_SRC emacs-lisp
(setq TeX-fold-ellipsis " …")
(add-hook 'LaTeX-mode-hook
(lambda ()
(turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(setq reftex-insert-label-flags '(t t))
(setq reftex-label-alist
'(("thm" ?t "thm:" "~\\ref{%s}" thm (regexp "theorems?"))
("lem" ?l "lem:" "~\\ref{%s}" lem (regexp "lemma{ta}?"))
("prop" ?p "prp:" "~\\ref{%s}" prp (regexp "propositions?"))
("cor" ?c "cor:" "~\\ref{%s}" cor (regexp "corollary"))
("def" ?d "def:" "~\\ref{%s}" cor (regexp "defintions?"))
))
(setq prettify-symbols-alist nil)
(add-to-list 'prettify-symbols-alist '(" ⊂ " . (? (Br . Bl) ? (Br . Bl) ?)))
(font-lock-add-keywords
'latex-mode `((,(rx "$") 0 'font-latex-sedate-face t)) t)
(turn-on-auto-fill)
(subword-mode)
(TeX-fold-mode 1)
(outline-minor-mode)
;; Move around commands in the Right Way™
(modify-syntax-entry ?\\ "w" LaTeX-mode-syntax-table)
(setq subword-forward-regexp "\\W*\\(\\([\\\\[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)")
(setq subword-backward-regexp "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([\\\\[:upper:]]+\\W*\\)\\|\\W\\w+\\)")
;; ;; FIXME: this breaks sourcepair for other modes.
;; (setq sourcepair-source-extensions '(".tex"))
;; (setq sourcepair-header-extensions '(".p.tex"))
(define-key LaTeX-mode-map (kbd "M-S-SPC") 'TeX-insert-braces)
(define-key LaTeX-mode-map (kbd "C-c C-v") 'wilder/TeX-insert-reference)
(define-key LaTeX-mode-map (kbd "C-c C-l") 'reftex-label)
(define-key LaTeX-mode-map (kbd "C-M-<return>") 'wilder/TeX-insert-align)
;; unbind return - NOTE it is important to unbind
;; <return> and not RET. If we unbind RET then C-m won't work
;; either.
(define-key LaTeX-mode-map (kbd "<return>")
(lambda() (interactive) (insert "\\")))
(define-key LaTeX-mode-map (kbd "S-<return>")
(lambda() (interactive) (insert "|")))
(define-key LaTeX-mode-map (kbd "C-c C-.") 'LaTeX-mark-environment)
#+END_SRC
Dealing with bad habits and sub|superscripts. Previous
bindings were ~M-_~ and ~M-^~ but they turned out to be too
typo-prone.
#+BEGIN_SRC emacs-lisp
(define-key LaTeX-mode-map (kbd "M-_")
(lambda() (interactive) (flash-hline) (message "Use C-c C-k")))
(define-key LaTeX-mode-map (kbd "M-^")
(lambda() (interactive) (flash-hline) (message "Use C-c C-i")))
(define-key LaTeX-mode-map (kbd "C-c C-k")
(lambda (r-begin r-end) (interactive "r") (add-delimiter "_{" "}" r-begin r-end)))
(define-key LaTeX-mode-map (kbd "C-c C-i")
(lambda (r-begin r-end) (interactive "r") (add-delimiter "^{" "}" r-begin r-end)))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(define-key LaTeX-mode-map (kbd "M-|") (lambda (r-begin r-end) (interactive "r") (add-delimiter "|" "|" r-begin r-end)))
(define-key LaTeX-mode-map (kbd "M-,") (lambda (r-begin r-end) (interactive "r") (add-delimiter ", " ", " r-begin r-end)))
(define-key LaTeX-mode-map (kbd "M-\"") (lambda (r-begin r-end) (interactive "r") (add-delimiter "“" "”" r-begin r-end)))
;; This is the rationale: C-M-SPC starts inline math C-M-RET starts display math
(turn-on-reftex)
(define-key LaTeX-mode-map (kbd "C-M-SPC") (lambda (r-begin r-end) (interactive "r") (add-delimiter "$" "$" r-begin r-end)))
(define-key LaTeX-mode-map (kbd "C-c C-d") 'wilder/TeX-insert-todonote)
(setq comment-column 0)
(setq prettify-symbols-alist nil)
(add-to-list 'prettify-symbols-alist '(" ⊂ " . (? (Br . Bl) ? (Br . Bl) ?)))
(define-key LaTeX-mode-map (kbd "C-M-d") 'kill-sexp)
(define-key LaTeX-mode-map (kbd "C-M-i") 'down-list) ;; -i stands for /in/
(define-key LaTeX-mode-map (kbd "C-M-o") 'up-list) ;; -o stands for /out/
(turn-on-auto-fill)
(subword-mode)
(TeX-fold-mode 1)
(outline-minor-mode)
(define-key LaTeX-mode-map (kbd "<f4>") (lambda() (interactive) (message "Use C-c C-c")))
(define-key LaTeX-mode-map (kbd "C-c C-c") (lambda() (interactive) (compile "/home/jacopods/scripts/latex-mk")) )
;; Move around commands in the Right Way™
(modify-syntax-entry ?\\ "w" LaTeX-mode-syntax-table)
(setq subword-forward-regexp "\\W*\\(\\([\\\\[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)")
(setq subword-backward-regexp "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([\\\\[:upper:]]+\\W*\\)\\|\\W\\w+\\)")
;; Turn this into a list
(define-key LaTeX-mode-map (kbd "=") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "≠") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd ">") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "<") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "≥") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "≤") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "⇒") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "∩") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "∪") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "∨") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "∧") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "×") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "⊂") 'insert-char-with-padding)
(define-key LaTeX-mode-map (kbd "⊃") 'insert-char-with-padding)
;; Force moves around to be more “semantic”
(define-key LaTeX-mode-map (kbd "C-v") 'forward-paragraph)
(define-key LaTeX-mode-map (kbd "M-v") 'backward-paragraph)
(define-key LaTeX-mode-map (kbd "C-S-v") 'backward-paragraph)
(define-key LaTeX-mode-map (kbd "<next>") (lambda() (interactive) (message "Command disabled")))
(define-key LaTeX-mode-map (kbd "<prior>") (lambda() (interactive) (message "Command disabled")))
))
#+END_SRC
*** TODO Leftovers
#+BEGIN_SRC emacs-lisp
(setq TeX-fold-ellipsis " …")
(load "latex-compile-filters.el")
#+END_SRC

Loading…
Cancel
Save