AUCTeX 토글 수학 모드

AUCTeX 토글 수학 모드

나는 $ ... $인라인 수학과 \[ ... \]디스플레이 수학에 사용합니다. 텍스트를 선택하고 를 호출하여 둘 사이를 전환할 수 있기를 바랍니다 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")))

(보다여기)

관련 정보