In AUCTeX, you can enable a minor mode called LaTeX-math-mode that instructs the prefix character ` to insert various common macros. For example, ` t inserts \tau@ when you are in a math environment (where @ is where point is left).

This is wonderful when you are in a math environment already. However, I often refer to these symbols in the running text, and just doing the same ` t inserts just \tau{}@ in text mode.

How can I instruct AUCTeX to, when in text mode, enter math mode like so: ` t yields $\tau$@?


Of course AUCTeX is already able to do this out of the box! From the description of LaTeX-math-mode (C-h f LaTeX-math-mode RET):

Easy insertion of LaTeX math symbols. If you give a prefix argument, the symbols will be surrounded by dollar signs.

Thus, C-u ` t inserts


If you want to automatically wrap dollars around the symbol when in text mode without the prefix argument, add this to your .emacs:

 (lambda ()
   (let ((math (reverse (append LaTeX-math-list LaTeX-math-default))))
     (while math
       (let ((entry (car math))
     (setq math (cdr math))
     (if (listp (cdr entry))
         (setq value (nth 1 entry))
       (setq value (cdr entry)))
     (if (stringp value)
         (fset (intern (concat "LaTeX-math-" value))
           (list 'lambda (list 'arg) (list 'interactive "*P")
             (list 'LaTeX-math-insert value
                   '(null (texmathp)))))))))))

This redefines all LaTeX-math-* functions defined inside LaTeX-math-initialize, in latex.el.

  • This... this is cool. I can survive without it, but is there any way to add this prefix argument automatically depending on whether or not we are in math mode? – Sean Allred Dec 6 '13 at 6:12
  • 1
    @SeanAllred see the updated answer :-). – giordano Dec 6 '13 at 13:51

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.