1

I'm new to this kind of Q&A site. Now I'm writing some article using Sphinx (reStructured text). Writing an equation (like E = mc^{2}) in Sphinx is a little bit demanding, because you have to decorate it as follows.

:math:`E=mc^{2}`

So I wrote a function like the following.

(add-hook 'rst-mode-hook
          '(lambda ()
            (local-set-key (kbd "C-m") '(lambda (eq)
                                         (interactive "sEnter LaTeX Equation.")
                                         (insert (concat " :math:`" eq "` "))))))

It works

  1. C-m
  2. You are prompted to enter an equation like E = mc^{2}
  3. Then :math:`E=mc^{2}` is automatically inserted.

However, very strangely, when I feed Enter key, I am again prompted to Enter LaTeX Equation, which is not a desired (just entering Enter key!!!). How can I avoid this?

1

My psychic debugging skills tell me that you're using Emacs inside of a terminal emulator. Because of how computers evolved from teletype machines, the enter key in a terminal emulator sends exactly the same character as C-m; Emacs literally cannot distinguish between them. C-i is the same as the tab key, C-l is the form-feed character, etc.

Personally, I recommend that you use Emacs as a GUI program (even though it mostly only renders text). GUI programs have much more direct access to the precise details of how keyboards work, and a much better selection of fonts and colors.

1

Use C-c m as key sequence instead of C-m.

The key bindings C-c letter just work and are reserved for users.

They are not (should not be) used in any official libraries.

See the Key Binding Conventions Section in the Emacs Manual.

Db48x already described the possible reason for your specific problems in his answer.

  • Thank you, Tobias and db48x! it worked fine well! Actually, it was the first time to write my own lisp code. – sovereign Mar 21 at 9:31

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.