Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable underscore (_) subscripting in Emacs, TeX input method

On Emacs, while editing a text document of notes for myself (a .txt document, not a .tex document), I am using M-x set-input-method Ret TeX, in order to get easy access to various Unicode characters. So for example, typing \tospace causes a "→" to be inserted into the text, and typing x^2 causes "x2" to be inserted, because the font I am using has support for Unicode codepoints 0x2192 and 0x00B2, respectively.

One of the specially handled characters in the method is for the underscore key, _. However, the font I am using for Emacs does not appear to have support for the codepoints for the various subscript characters, such as subscript zero (codepoint 0x2080), and so when I type _0, I get something rendered as a thin blank in my output. I would prefer to just have the two characters _0 in this case.

I can get _0 by the awkward keystroke sequence _spacedel0, since the space keystroke in the middle of the sequence causes Emacs to abort the TeX input method. But this is awkward.

So, my question: How can I locally customize my Emacs to not remap the _ key at all when I am in the TeX input method? Or how can I create a modified clone (or extension, etc) of the TeX input method that leaves out underscore from its magic?

Things I have tried so far:

  • I have already done M-xdescribe-key on _; but it is just bound to self-insert-command, like many other text characters. I did see a post-self-insert-hook there, but I have not explored trying to use that to subvert the TeX input method.

Things I have not tried so far:

  • I have not tried learning anything about the input method architecture or its source code. From my quick purview of the code and methods. it did not seem like something I could quickly jump into.
like image 513
pnkfelix Avatar asked Mar 02 '13 22:03

pnkfelix


2 Answers

So here is the solution I just found: Make a personalized copy of the TeX input method, with all of the undesirable entries removed. Then when using M-x set-input-method, select the personalized version instead of TeX.

I would have tried this earlier, but the built-in documentation for set-input-mode and its ilk does not provide sufficient guidance to the actual source for the input-methods for me to find it. It was only after doing another search on SO and finding this: Emacs: Can't activate input method that I was able to get enough information to do this on my own.

Details:

  1. In Emacs, open /usr/share/emacs/22.1/leim/leim-list.el and find the entry for the input method you want to customize. The entry will be something like the following form:

    (register-input-method
     "TeX" "UTF-8" 'quail-use-package
     "\\" "LaTeX-like input method for many characters."
     "quail/latin-ltx")
    
  2. Note the file name prefix referenced in the last element in the form above. Find the corresponding Elisp source file; in this case, it is a relative path to the file quail/latin-ltx.el[.gz]. Open that file in Emacs, and check it out; it should have the entries for the method remappings, both desired and undesired.

  3. Make a user-local copy of that Elisp source file amongst your other Emacs customizations. Open that local copy in Emacs.

  4. In your local copy, find the (quail-define-package ...) form in the file, and change the name of the package; I used FSK-TeX as my new name, like so:

    (quail-define-package
     "FSK-TeX" "UTF-8" "\\" t   ;; <-- The first argument here is the important bit to change.
     "LaTeX-like input method for many characters but not as many as you might think.
     ...)
    
  5. Go through your local copy, and delete all the S-expressions for mappings that you don't want.

  6. In your .emacs configuration file, register your customized input method, using a form analogous to the one you saw when you looked at leim-list.el in step 1:

    (register-input-method
     "FSK-TeX" "UTF-8" 'quail-use-package
     "\\" "FSK-customized LaTeX-like input method for many characters."
     "~/ConfigFiles/Elisp/leim/latin-ltx")
    
  7. Restart Emacs and test your new input-method; in my case, by doing M-x set-input-method FSK-TeX, typing a_0, and confirming that a_0 shows up in the buffer.


So, there's at least one answer that is less awkward once you have it installed than some of the workarounds listed in the question (and as it turns out, are also officially documented in the Emacs 22 manual as a way to cut off input method processing).

However, I am not really happy with this solution, since I would prefer to inherit future changes to TeX mode, and just have my .emacs remove the undesirable entries on startup.

So I will wait to see if anyone else comes up with a better answer than this.

like image 140
pnkfelix Avatar answered Nov 14 '22 16:11

pnkfelix


I did not test this myself, but this seems to be the exact thing you are looking for:

"How to disable underscore subscript in TeX mode in emacs" - source

Two solutions are given in this blogpot:

  1. By the author of the blogpost: (setq font-lock-maximum-decoration nil) (from maximum)

  2. Mentioned as comment:

    (eval-after-load "tex-mode" '(fset 'tex-font-lock-subscript 'ignore))

like image 1
PascalVKooten Avatar answered Nov 14 '22 16:11

PascalVKooten