AUCTeX alterna los modos matemáticos

AUCTeX alterna los modos matemáticos

Lo uso $ ... $para matemáticas en línea y \[ ... \]para matemáticas de visualización. Me gustaría poder alternar entre los dos seleccionando el texto y llamando TeX-insert-dollar.

Sin embargo, según tengo entendido, esta función sólo permite los ciclos

$ ... $ <-> $$ ... $$ <-> ...

y

\( ... \) <-> \[ ... \] <-> ...

(este comportamiento se controla estableciendo la variable TeX-electric-math).

¿Hay alguna forma de personalizar este comportamiento según mis necesidades (también sería útil extenderlo a otros entornos de ecuaciones como ,,, equationetc. )?aligngather

Respuesta1

Finalmente logré hacer esto así.

(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")))

(veraquí)

información relacionada