# Short names for macros

Often it happens that I would like to define macros that I would use very frequently throughout the document – for example, a special symbol that I use repeatedly in many equations.

Ideally, in such situations, I would like to keep the name of the macro as short as possible. However, most of the one-letter names seem to be already defined, either in one of the standard Latex classes or in commonly-used packages. For example, \b, \c, \d, \i, \j, \l, \o, \t, \u, and \v are already defined. Usually I just give up and use something like \myX instead of \X to avoid conflicts, but it gets a bit verbose.

Two questions:

1. Is there a list of very short names that are available and that I could (reasonably safely) use for my own purposes?

2. Are there some clever tricks and hacks that I could use to define short names for macros? For example, the babel package makes the " character special so that you can use sequences such as "= and "a to enter symbols. Could I use a similar trick for my own purposes, using another character instead of " – or was it the only character that was not yet allocated?

I would like to stick to plain 7-bit ASCII characters.

-
Possibly do something similar to what Christian Linding is doing here? –  pmav99 May 26 '11 at 12:06
@Seamus: I am fairly certain that these 2 answers are not an exhaustive list of all possible tricks that you can use in TeX to construct short, non-conflicting macro names... So I encourage all other TeX hackers to give it a try! Besides, while the current answers are a great starting point, they could be improved: @Martin's answer does not cover commonly-used packages, just core Latex. @Niel's answer shows how to use ", but I already know that " conflicts with Babel. So there is +250 points available for the best answer to question 1, question 2, or both. –  Jukka Suomela May 28 '11 at 17:27
@Jukka: Niel's answer will work with any character—just replace " with whatever you want. (Except @, which will break at \makeatother.) You might want to do something like \newcommand\quote{"} first, though, if you use a character you need to type sometimes. –  Antal S-Z May 28 '11 at 17:44
Does the saving of a few characters of typing really buy that much? Are you that slow a typist that this saves even a few seconds? Consider this tiny savings against the huge, inevitable loss of understandability that results from one character commands. You should go with two character commands, which are so much more meaningful! (BTW, how can I insert a smiley to go along with that sarcastic remark?) –  David Hammen May 28 '11 at 19:24
It is not really that relevant how long it takes to type something – what matters is how easy it is to read (and edit) the source code. Anyway, this is not really an answer to the question; I hope the moderators could convert it into a comment. –  Jukka Suomela May 28 '11 at 23:51

You can display the definitions of this single-letter macros using:

\def#$1{\csname @mymacro$1\endcsname}

Again this is not really an answer to the question, but if you really want to save on keystrokes, then perhaps a better option to catcode-fu is to use a smart text editor. For example emacs has a funky LaTeX-math-abbrev-prefix which is  by default.

This gives you access to a bunch of mathmode symbols in two keystrokes. For example, you can get \subset by typing  {

By customising LaTeX-math-list you can get whatever you like out of this prefix command.

Vim with some snippet add-on can almost certainly achieve the same thing. I don't know what other editors will allow you this sort of prefix key control, but I'm sure there are others. If you're interested in efficiency to the level of worrying about a handful of keystrokes, then I think this is a better option than fiddling with making other characters active...

Postscript: The weird paragraphing was needed to allow  to display properly. I really hit the limits of markdown typing this...

-

There's the at package by Mark Wooding. It makes possible to say

\newatcommand X{Whatever you like}
\newatcommand Y[2]{Whatever you like with #1 and #2}


and then use @X or @Y{a}{b}. However this is likely to conflict with hyperref (the package is quite old and not developed any more), so it's best not to use the newly defined @-commands in moving arguments. But one can at least try.

-
Conflicts with hyperref is a good point; some other approaches seem to have problems with hyperref as well, if we happen to overload a character that may occur in a URL. It also looks like \verb`, etc., might produce surprising results... –  Jukka Suomela May 28 '11 at 23:44