[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] Insertion of braces in math mode for certain macros
From: |
Nicolas Richard |
Subject: |
Re: [AUCTeX] Insertion of braces in math mode for certain macros |
Date: |
Tue, 06 Nov 2012 15:30:14 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Lionel Henry <address@hidden> writes:
> Is there a way to specify a list of macros that should always be
> inserted with braces, even in math mode? For example, when inserting
> the macro "text" in math mode, it makes sense that braces should be
> automatically inserted.
as a side note on the same subject, I use the following modified version
of TeX-parse-macro. The change is so that, when the region is active and
TeX-insert-macro is called, a pair of braces is inserted around the
region, even in math mode : it's a slight abuse of the brace insertion
mechanism (which, I assume, existed to avoid space gobbling by TeX in
non-math mode), but that abuse already existed in non-math mode too.
Nico.
(defun TeX-parse-macro (symbol args)
"(CHANGED!)How to parse TeX macros which takes one or more arguments.
First argument SYMBOL is the name of the macro.
If called with no additional arguments, insert macro with point
inside braces. Otherwise, each argument of this function should
match an argument to the TeX macro. What is done depend on the
type of ARGS:
string: Use the string as a prompt to prompt for the argument.
number: Insert that many braces, leave point inside the first.
nil: Insert empty braces.
t: Insert empty braces, leave point between the braces.
other symbols: Call the symbol as a function. You can define
your own hook, or use one of the predefined argument hooks. If
you add new hooks, you can assume that point is placed directly
after the previous argument, or after the macro name if this is
the first argument. Please leave point located after the
argument you are inserting. If you want point to be located
somewhere else after all hooks have been processed, set the value
of `exit-mark'. It will point nowhere, until the argument hook
set it. By convention, these hooks all start with `TeX-arg-'.
list: If the car is a string, insert it as a prompt and the next
element as initial input. Otherwise, call the car of the list
with the remaining elements as arguments.
vector: Optional argument. If it has more than one element,
parse it as a list, otherwise parse the only element as above.
Use square brackets instead of curly braces, and is not inserted
on empty user input."
(if (and (TeX-active-mark)
(> (point) (mark)))
(exchange-point-and-mark))
(insert TeX-esc symbol)
(let ((exit-mark (make-marker))
(position (point)))
(TeX-parse-arguments args)
(cond ((marker-position exit-mark)
(goto-char (marker-position exit-mark))
(set-marker exit-mark nil))
((and TeX-insert-braces
;; Do not add braces if the argument is 0 or -1.
(not (and (= (safe-length args) 1)
(numberp (car args))
(<= (car args) 0)))
(equal position (point))
(string-match "[a-zA-Z]+" symbol)
(or (not (texmathp)) (TeX-active-mark))) ;; CHANGED HERE.
(insert TeX-grop)
(if (TeX-active-mark)
(progn
(exchange-point-and-mark)
(insert TeX-grcl))
(insert TeX-grcl)
(backward-char))))))