2
votes

I am typing a math document in Russian using Emacs 24.3.1 and AUCTeX 11.87. I am using the russian-computer input method to type Russian. It would be very convenient to disable this input method inside math delimiters such as \( \) so that inside formulas I automatically switch to typing English without pressing Ctrl-\. For example, I could type "Рассмотрим формулу \(\)" ("Consider the formula \(\)"), put the point between the parentheses and start typing \forall. Currently, I would be typing \ащкфдд, but I would like Emacs to recognize that I am inside a formula and switch off the Russian input method.

I suspect that this can be done using post-self-insert-hook and texmathp from AUCTeX, but I am not sure if this is the most elegant method.

1
You might get better answers at tex.stackexchange.comHigh Performance Mark

1 Answers

0
votes

I found solution to the problem at http://lists.gnu.org/archive/html/help-gnu-emacs/2009-08/msg00200.html The code works almost as expected. But drawback is that one can't switch to English from e.g. Russian outside of math delimiters.

This function does the job: switch between english and your current input method.

(defun LaTeX-dynamic-input-method-toggle-maybe ()
  (when (or (and current-input-method
             (texmathp))
        (and (not current-input-method)
             (not (texmathp))))
    (toggle-input-method)))

"Define a minor-mode, so this behaviour can be conviniently enabled/disabled. The minor-mode puts the above function on the `post-command-hook', so that the above function gets called everytime you do something (e.g. move point)."

(define-minor-mode LaTeX-dynamic-input-method
  "Dynamically disable input-method in math-mode."
   nil nil nil
  (if LaTeX-dynamic-input-method
      (add-hook 'post-command-hook 'LaTeX-dynamic-input-method-toggle-maybe nil t)
    (remove-hook 'post-command-hook 'LaTeX-dynamic-input-method-toggle-maybe t)))

Enable the mode in LaTeX-mode.

(add-hook 'LaTeX-mode-hook 'LaTeX-dynamic-input-method)