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

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

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

Loading…
Cancel
Save