# AUCTeX prompting for optional arguments

My general question: is there a way to get AUCTeX to prompt me automatically for an optional argument of a command when I invoke it with `TeX-insert-macro` (i.e. C-cRET)? (like it does when you invoke, for instance, `\newcommand`)

My specific question: is there a way to get AUCTeX to prompt me automatically for an optional overlay specification when I invoke the `\alert` command with `TeX-insert-macro` (i.e. C-cRETalertRET)?

I asked the AUCTeX mailing list, and Mosè Giordano kindly provided the following answer:

You have to manually patch the file style/beamer.el in your AUCTeX installation. Replace the line

``````'("alert" 1)
``````

with

``````'("alert" TeX-arg-beamer-overlay-spec 1)
``````

Remember to byte-recompile the file with M-x byte-recompile-file RET RET.

• I wonder if there is a more robust way to do this, one that would not require me to recompile /style/beamer.el everytime I update AUCTeX Sep 24 '18 at 1:58

1. `(setq TeX-insert-macro-default-style 'show-optional-args)`
2. `(setq TeX-insert-macro-default-style 'show-all-optional-args)`

the difference between the two is as described in Auctex documentation:

User Option: TeX-insert-macro-default-style Specifies whether 'TeX-insert-macro' will ask for all optional arguments. If set to the symbol 'show-optional-args', 'TeX-insert-macro' asks for optional arguments of TeX marcos, unless the previous optional argument has been rejected. If set to 'show-all-optional-args', 'TeX-insert-macro' asks for all optional arguments. 'mandatory-args-only', 'TeX-insert-macro' asks only for mandatory arguments.

Although this suggestion may not be applicable to beamer macros as noted by @ArashEsbati however it may answer the first part of the question that is:

Is there a way to get AUCTeX to prompt me automatically for an optional argument of a command when I invoke it with TeX-insert-macro (i.e. C-c RET)? (like it does when you invoke, for instance, \newcommand)

• Thanks Hafid. Unfortunately, this did not work for me. Sep 24 '18 at 1:56
• With your code, Emacs will throw an error at startup since it looks for a variable `show-optional-args` which is not defined. As described in the manual, you need symbols. Hence, you need `(setq TeX-insert-macro-default-style 'show-optional-args)` (note the `'`). Even quoted, I'm afraid that your suggestion will not work since the function`TeX-arg-beamer-overlay-spec` is defined in a way that it doesn't respect the settings in your answer. Sep 28 '18 at 16:16
• Thank's to @ArashEsbati for his relevant remarks especially about quoting the symbols `show-optional-args` and `show-all-optional-args`. So I reedit my answer accordingly. Sep 29 '18 at 21:18