Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

1 Answer 1

up vote 6 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

$\tau$

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

(add-hook
 'LaTeX-mode-hook
 (lambda ()
   (let ((math (reverse (append LaTeX-math-list LaTeX-math-default))))
     (while math
       (let ((entry (car math))
         value)
     (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
1  
@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

 
discard

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.