Hello,
I'd like to define an emacs function which would:
- add a \newcommand to define a new macro in the preamble (just before
\begin{document})
- use the newly defined macro at point (using TeX-insert-macro)
I cannot just use (TeX-insert-macro "newcommand") followed by another
(TeX-insert-macro newmacro) because I don't know which macro was just
created by (TeX-insert-macro "newcommand") : it asks for the name
interactively.
This is what I do now.
(defun LaTeX-create-newcommand (symbol)
"Define a new macro with \\newcommand in the preamble, and use it at
point"
(interactive "sNew command name : \\")
(save-excursion
(goto-char (point-min))
(re-search-forward "\\\\begin{document}")
(beginning-of-line)
(insert TeX-esc "newcommand" TeX-grop TeX-esc symbol TeX-grcl)
(TeX-parse-arguments '(["Number of arguments"] ["Default value for
first argument"]))
(let
((TeX-arg-closing-brace TeX-grcl) (TeX-arg-opening-brace TeX-
grop))
(TeX-argument-insert (read-string "Definition of the macro (use #1,
#2, etc. for arguments): ") nil)
)
(TeX-normal-mode nil)
(newline)
)
(TeX-insert-macro symbol)
)
It somehow works, but I thought I would ask for comments and
suggestions. One thing I'd like to know : if I use this function then
change my mind, I wish saying "M-x undo" just once would make the
whole thing disappear, but that won't work. How should I do that ?
--
Nico.
_______________________________________________
auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex