[LaTeχ] Cleanup the promote-inline-math function

master
Jacopo De Simoi 7 years ago
parent 6851f3f67e
commit 7caf188575
  1. 37
      global.org

@ -1112,9 +1112,7 @@
(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*"))))
(wilder/TeX-insert-align arg)))
#+END_SRC
This replaces horizontal space with a tilde
#+BEGIN_SRC emacs-lisp
@ -1133,22 +1131,27 @@
#+END_SRC
Promote inline math to an align
#+BEGIN_SRC emacs-lisp
(defun wilder/char-punctuation-p (ch)
"returns t if the char is a punctuation"
(interactive)
(string-match (string ch) ".,:;"))
(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)))
(when (and (texmathp) (string-prefix-p "$" (car texmathp-why)))
(let* ((delim (car texmathp-why))
(pos (cdr texmathp-why))
(n (length delim)))
(goto-char pos)
(push-mark)
(delete-char n)
(search-forward delim)
(delete-backward-char n)
;; include punctuations in the align
(when (wilder/char-punctuation-p (char-after)) (forward-char))
(activate-mark)
(wilder/TeX-insert-align arg)
(pop-mark)
(pop-mark))))
#+END_SRC
*** The hook
#+BEGIN_SRC emacs-lisp

Loading…
Cancel
Save