TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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$@?

share|improve this question
up vote 9 down vote accepted

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.

share|improve this answer
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
@SeanAllred see the updated answer :-). – giordano Dec 6 '13 at 13:51
This is absolutely fantastic. Thank you!! – Sean Allred Dec 7 '13 at 21:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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