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.

I am an avid fan of Oleg Alexandrov's method for customizing XEmacs to make it an efficient system for editing LaTeX files. One feature I find particularly useful is the ability to have XEmacs automagically expand abbreviations. (You may ask: why not just use macros? Answer: I like, for example, the ability to simply type \eq and, after pressing the spacebar, have my cursor be placed inside a syntactically-correct equation environment.)

One quirk of XEmacs seems to be that one cannot use capitalization in the abbreviations. For example, suppose one defines \s to be an abbreviation which is expanded into \mathsf{ (to use a sans-serif font in math mode). Then typing \S will be expanded into \Mathsf, which will not compile. This behavior is undesirable if one also wants to be able to use the ordinary \S command in LaTeX to typeset a "section" symbol. One workaround is to define \sec or something similar as an "abbreviation" to be expanded into \S, but this is sort of annoying.

(Another example: if -- for some reason -- one wants to avoid using macros, one can use abbreviations for the same functionality. But one cannot define \gl to be $\mathfrak{gl}$ and \GL to be \mathrm{GL} because of the same capitalization issue; the latter will be expanded to \Mathfrak{gl}, I believe.)

My question: is there a more satisfying workaround for this problem?

P.S. If this question is more appropriate for stackoverflow or a different stackexchange site, please let me know.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

The following is just a suggestion for a gross kludge, since it's been so long since I've written any elisp that it would take me too long to implement it, but for what it's worth: emacs and xemacs have a hook named pre-abbrev-expand-hook which is a list of functions to be called before abbrev expansion is done. You could use that hook to convert any abbrevs that have upper case letters into some other abbrev using all lower case letters that expands to what you want.

For example, you could choose a string that will never appear in any of your abbrevs, e.g., xxx, and write a function that looks at the word before point and replaces each upper case character with its lower case equivalent preceded by xxx. That is, if you type GL it would be replaced by xxxgxxxl. You could then add that function to pre-abbrev-expand-hook and define an abbrev that replaces xxxgxxxl with whatever you want to be the expansion of GL.

share|improve this answer
    
thanks, this is a good idea! –  Sam Lichtenstein Sep 4 '11 at 20:01
add comment

I think what you are looking for is the :case-fixed option to define-abbrev. In particular you won't be able to use define-mode-abbrev.

share|improve this answer
add comment

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.