On Sun, May 21, 2023 at 4:41 PM Hongyi Zhao <hongyi.z...@gmail.com> wrote:
>
> Hi here,
>
> I want to convert `bla` to `$bla$` automatically when be highlighted
> and typeset a `$'.
>
> Currently, my observed result is `bla$$`, which is not consistent with
> the LaTeX math environment.

I tried the following, but failed to do the trick:

(defun my-insert-dollar ()
  "Insert pair of dollar signs around region or at point."
  (interactive)
  (if (use-region-p)
      (let ((beg (region-beginning))
            (end (region-end)))
        (goto-char end)
        (insert "$")
        (goto-char beg)
        (insert "$"))
    (insert "$")))

;; Add to your Emacs configuration file (~/.emacs or ~/.emacs.d/init.el)
(define-key LaTeX-mode-map "$" 'my-insert-dollar)

Regards,
Zhao

Reply via email to