
Я использую $ ... $
для встроенной математики и \[ ... \]
для отображения математики. Я хотел бы иметь возможность переключаться между ними, выбирая текст и вызывая TeX-insert-dollar
.
Однако, насколько я понимаю, эта функция допускает только циклы
$ ... $ <-> $$ ... $$ <-> ...
и
\( ... \) <-> \[ ... \] <-> ...
(это поведение контролируется установкой переменной TeX-electric-math
).
Есть ли способ настроить это поведение под мои нужды (было бы также полезно распространить его на другие среды уравнений, такие как equation
, align
, gather
и т. д.)?
решение1
Мне наконец удалось сделать это вот так
(defun begin-end-regexps (env)
(list env
(replace-regexp-in-string "{\\([a-zA-Z]+\\)\\*}" "{\\1\\\\*}" (concat "\\\\begin{" env "}\\([^\0]*?\\)\\\\end{" env "}"))
(concat "\\\\begin{" env "}\\1\\\\end{" env "}")))
(defun loop-math-modes (step)
(if (texmathp)
(let
((math-modes (list '("$" "\\$\\([^$\0]+?\\)\\$" "$\\1$")
'("\\[" "\\\\\\[\\([^\0]*?\\)\\\\\\]" "\\\\[\\1\\\\]")
(begin-end-regexps "equation")
(begin-end-regexps "equation*")
(begin-end-regexps "align")
(begin-end-regexps "align*")
(begin-end-regexps "gather")
(begin-end-regexps "gather*")))
commands)
(dolist (element math-modes) ;; get list of cars
(setq commands
(append commands (list (car element)))))
(let
((math-mode-index (cl-position (car texmathp-why) commands :test 'equal))
(current-pos (point)))
(goto-char (cdr texmathp-why)) ;; for some reason save-excursion is not working
(re-search-forward (nth 1 (nth math-mode-index math-modes)))
(replace-match (nth 2 (nth (mod (+ math-mode-index step) (length math-modes)) math-modes)))
(goto-char current-pos)))
(message "Not inside math environment")))
(видетьздесь)