2

How do I declare custom completions for command arguments to AUCTeX?

I have a LaTeX package that defines a number of macros. I'm writing the Elisp style support manually as some of the TeX code is rather hairy. One of the macros is \ref-like, so in the style support file, I have

(TeX-add-symbols '("myref" TeX-arg-ref))

If I insert \ref or \myref with TeX-insert-macro, I get prompted for a label with completion. If I type \ref{ and press M-TAB (TeX-complete-symbol), I get completions of labels. But if I type \myref{ and press M-TAB, I only get the fallback to dictionary words.

How do I tell AUCTeX that the first argument of \myref should be completed as a label?

2

Add entries to TeX-complete-list. This isn't documented in the manual, but there are examples in the support files distributed with AUCTeX.

  (setq TeX-complete-list
        (append '(
                  ("\\\\myref{\\([^{}\n
\\%,]*\\)" 1 LaTeX-label-list "}")
                  ) TeX-complete-list))

Each element of TeX-complete-list is a list consisting of a regexp to complete after, e.g. the command name followed by an opening brace and the already-existing element content in a group, followed by either:

  1. The number of the group that contains the text to be completed.
  2. A function that is called with no arguments and returns a completion alist.
  3. A string to add after a completion.

or:

  1. A function of no arguments that is called to perform the completion.
  • In general TeX-complete-symbol doesn't receive as much love as TeX-insert-macro, it's good to see you gave this useful answer! – giordano May 11 '16 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.