From 7caf1885754487437bf144a427f820881cab1427 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Thu, 21 Mar 2019 22:41:55 -0400 Subject: [PATCH] =?UTF-8?q?[LaTe=CF=87]=20Cleanup=20the=20promote-inline-m?= =?UTF-8?q?ath=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global.org | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/global.org b/global.org index 4daa02d..3ec132c 100644 --- a/global.org +++ b/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