[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] Inserting math environment
From: |
Ivan Andrus |
Subject: |
Re: [AUCTeX] Inserting math environment |
Date: |
Mon, 16 Apr 2012 18:05:45 +0200 |
On Apr 15, 2012, at 1:59 PM, Uday S. Reddy wrote:
> This is probably a basic question, but I can't find the answer.
>
> How can I insert a matching \[ ... \] brackets for a math display? I thought
> LaTeX-environment would do it, but I can't see how.
>
> Cheers,
> Uday
I thought someone might have a better way, but here is what I use:
(defun gvol-LaTeX-insert-equation (&optional arg)
"Enclose following ARG sexps in dollar signs.
Leave point after initial dollar sign.
No argument is equivalent to zero: just insert `\$\$' and leave point between.
If region is active, insert enclosing characters at region boundaries.
If point is in between dollar signs, then they are deleted and \\[\\] is
inserted.
See `insert-parentheses'."
(interactive "P")
(if (and (or (not arg) (= arg 1))
(> (point-max) (point))
(< (point-min) (point))
(string-equal "$$"
(buffer-substring-no-properties (- (point) 1) (+
(point) 1))))
(progn (delete-char 1)
(delete-char -1)
(insert "\\[\\]")
(backward-char 2))
(insert-pair arg ?\$ ?\$)))
You could bind this to whatever key you like (perhaps $), and the first time it
will insert $$. If you do it again, the dollar signs will be deleted and \[\]
will be inserted.
-Ivan