Function: LaTeX-modify-math

LaTeX-modify-math is an interactive and byte-compiled function defined in latex.el.

Signature

(LaTeX-modify-math NEW-TYPE)

Documentation

Modify the current math construct to NEW-TYPE.

Interactively, prompt for NEW-TYPE from a list of inline math delimiters ("$", "\\("), display math delimiters ("$$",
"\\=\\[") and valid LaTeX environments ("equation", ...).

Non-interactively, NEW-TYPE must be either
- a string specifying the target delimiter or environment name, or
- a cons cell ((OPEN . CLOSE) . INLINE), where OPEN and CLOSE are
  delimiters and INLINE is non-nil if the math construct is to be
  understood as inline.

The function converts the math construct at point (inline, display, or environment) to the specified NEW-TYPE, preserving the content. If point is not in a math construct, signal an error. Clears any active previews at point before modification.

Does not support modifying macro-based constructs such as \ensuremath.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-modify-math (new-type)
  "Modify the current math construct to NEW-TYPE.

Interactively, prompt for NEW-TYPE from a list of inline math
delimiters (\"$\", \"\\(\"), display math delimiters (\"$$\",
\"\\=\\[\") and valid LaTeX environments (\"equation\", ...).

Non-interactively, NEW-TYPE must be either
- a string specifying the target delimiter or environment name, or
- a cons cell ((OPEN . CLOSE) . INLINE), where OPEN and CLOSE are
  delimiters and INLINE is non-nil if the math construct is to be
  understood as inline.

The function converts the math construct at point (inline, display, or
environment) to the specified NEW-TYPE, preserving the content.  If
point is not in a math construct, signal an error.  Clears any active
previews at point before modification.

Does not support modifying macro-based constructs such as \\ensuremath."
  ;; FIXME: this function may not work correctly in docTeX
  (declare (modes LaTeX-mode))
  (interactive
   (let ((type (progn (texmathp) (car texmathp-why)))
         (tbl (append '("$" "\\(" "$$" "\\[")
                      (LaTeX--math-environment-list))))
     (barf-if-buffer-read-only)
     (unless type (user-error "Not inside math"))
     (LaTeX--closing type) ;; Check for errors.
     (list (completing-read
            (format "Convert %s → " type) tbl nil t nil nil
            type))))
  (let ((new-open (if (stringp new-type)
                      new-type
                    (caar new-type)))
        (new-close (if (stringp new-type)
                       (LaTeX--closing new-type)
                     (cdar new-type)))
        (new-inline (if (stringp new-type)
                        (member new-type '("$" "\\("))
                      (cdr new-type))))
    (when (fboundp 'preview-clearout-at-point)
      (preview-clearout-at-point))
    (unless (called-interactively-p 'any)
      (unless (texmathp) (error "Not inside math")))
    (let ((type (car texmathp-why))
          (math-start (cdr texmathp-why))
          (pos (point-marker)))
      (set-marker-insertion-type pos
                                 (not
                                  (and
                                   (< (point) (point-max))
                                   (save-excursion
                                     (forward-char)
                                     (not (texmathp))))))
      (goto-char math-start)
      (let ((open (if (member type '("\\(" "$" "\\[" "$$"))
                      type
                    (concat TeX-esc "begin" TeX-grop type TeX-grcl)))
            (close (LaTeX--closing type)))
        (if (or (not (stringp new-type))
                (member new-open '("$" "\\(" "\\[" "$$")))
            ;; Conversion to inline or non-environment display.
            (let ((inline (member type '("$" "\\("))))
              (LaTeX--modify-math-1 open close inline new-open new-close new-inline pos))
          ;; Conversion to an environment.
          (delete-char (length open))
          (push-mark (save-excursion
                       (search-forward close)
                       (delete-region (match-beginning 0) (match-end 0))
                       (when (= (point) pos)
                         (set-marker pos nil)
                         (setq pos nil))
                       (when (member type '("$" "\\("))
                         (skip-chars-forward ".,;:!?"))
                       (point)))
          (activate-mark)
          (LaTeX-insert-environment new-type)))
      (when pos
        (goto-char pos)
        (set-marker pos nil)))))