Add helper to promote inline math to align

Introduce Tex-insert-align-dwim
master
Jacopo De Simoi 7 years ago
parent b6feff7660
commit 81f03808ea
  1. 28
      global.org

@ -809,7 +809,7 @@
; (define-key LaTeX-mode-map (kbd "C-c [") 'wilder/TeX-insert-cite)
(define-key LaTeX-mode-map (kbd "C-c C-w") 'wilder/TeX-insert-cite)
(define-key LaTeX-mode-map (kbd "C-M-<return>") 'wilder/TeX-insert-align)
(define-key LaTeX-mode-map (kbd "C-M-<return>") 'wilder/TeX-insert-align-dwim)
;; unbind return - NOTE it is important to unbind
;; <return> and not RET. If we unbind RET then C-m won't work
@ -1005,6 +1005,13 @@
(if arg
(LaTeX-insert-environment "align")
(LaTeX-insert-environment "align*")))
(defun wilder/TeX-insert-align-dwim (arg)
(interactive "P")
(if (texmathp) (wilder/TeX-promote-inline-math arg)
(if arg
(LaTeX-insert-environment "align")
(LaTeX-insert-environment "align*"))))
#+END_SRC
This replaces horizontal space with a tilde
#+BEGIN_SRC emacs-lisp
@ -1021,6 +1028,25 @@
(add-delimiter "\\todo[inline]{" "}{}" r-begin r-end)
(add-delimiter "\\todo{" "}{}" r-begin r-end)))
#+END_SRC
Promote inline math to an align
#+BEGIN_SRC emacs-lisp
(defun wilder/TeX-promote-inline-math (arg)
(interactive "P")
(when (and (texmathp) (string-equal "$" (car texmathp-why)))
(goto-char (cdr texmathp-why))
(push-mark)
(kill-sexp)
(if arg
(LaTeX-insert-environment "align")
(LaTeX-insert-environment "align*"))
(yank)
(delete-backward-char 1)
(exchange-point-and-mark)
(delete-char 1)
(exchange-point-and-mark)
(pop-mark)
(pop-mark)))
#+END_SRC
*** The hook
#+BEGIN_SRC emacs-lisp
(add-hook 'LaTeX-mode-hook

Loading…
Cancel
Save