Improve frac TeX fold

This commit is contained in:
tecosaur 2020-04-14 23:23:36 +08:00
parent 6a1ff4d9e1
commit e85d8c0d8e
1 changed files with 8 additions and 2 deletions

View File

@ -2334,7 +2334,9 @@ Let's enhance ~TeX-fold-math~ a bit
("𝑑" ("dd"))
;; known commands
("" ("phantom"))
("❪{1}{2}❫" ("frac"))
(,(lambda (num den) (if (and (TeX-string-single-token-p num) (TeX-string-single-token-p den))
(concat num "" den)
(concat "❪" num "" den "❫"))) ("frac"))
(,(lambda (arg) (concat "√" (TeX-fold-parenthesize-as-neccesary arg))) ("sqrt"))
(,(lambda (arg) (concat "⭡" (TeX-fold-parenthesize-as-neccesary arg))) ("vec"))
("{1}" ("text"))
@ -2390,10 +2392,14 @@ Let's enhance ~TeX-fold-math~ a bit
(defun TeX-fold-parenthesize-as-neccesary (tokens &optional suppress-left suppress-right)
"Add ❪ ❫ parenthesis as if multiple LaTeX tokens appear to be present"
(if (string-match-p "^\\\\?\\w+$" tokens) tokens
(if (TeX-string-single-token-p tokens) tokens
(concat (if suppress-left "" "❪")
tokens
(if suppress-right "" "❫"))))
(defun TeX-string-single-token-p (teststring)
"Return t if TESTSTRING appears to be a single token, nil otherwise"
(if (string-match-p "^\\\\?\\w+$" teststring) t nil))
#+END_SRC
Some local keybindings to make life a bit easier