# 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}

Having worked at an academic publisher for years, I want to remark that in my opinion, such macros are a terrible nuisance. Your input may be consistent with itself, but it will not be consistent with anyone else's.

But if you absolutely have to define syntactical macros for some (to me) unfathomable reason, then by far the best ones are those that actually describe their content. These are not generally the shortest ones, but at least then when another person has to edit your text, the input syntax gives clues to the produced output. For example:

A \in \Q


is somewhat reasonable if \Q is \mathbb{Q}, but

\theta \neq \Q


I consider bad whatever the definition of \Q is.

Macros that use active characters instead of backlash are absolutely horrible, and for much these same reason: imagine editing someone else's file where stuff like a simple @ sign suddenly is a macro.

Secondary argument: in some workflows, your actual TeX input can become part of the result (for example as alternate text for a bitmap in a html/epub view). none of the macro definitions will survive, so the reader (even one that understands LaTeX well) would have to make a guess at the intended meaning.

-
This is certainly a valid opinion, but it is not an answer to the question; I have therefore flagged this post for moderator attention. Comments do not get lost if people upvote them; highly upvoted comments will be easily visible. –  Jukka Suomela May 29 '11 at 10:32
@Jukka: I think Taco's point here is that if you load this page, only the first few comments show up but you see all of the answers. There is a point to saying 'sometimes, the correct answer to a question is "do not do this because ..."'. –  Joseph Wright May 29 '11 at 10:35
@Joseph: Actually, it is not the first few comments that show up, but the highly-voted comments. The system falls back to displaying the first comments only if there are no highly-voted comments. –  Jukka Suomela May 29 '11 at 10:52
@jukka which means that if there already are a few upvoted comments (as in this case) your comment is likely to get overlooked. –  Taco Hoekwater May 29 '11 at 11:30
@Taco: I agree that comments that were added later have a disadvantage, as fewer people will notice and upvote them, but I don't think that is a good excuse to post comments as answers. But in this particular case, there is a simple solution: edit your answer so that it actually tries to answer the question. For example, you could tell what kind of short macro names would be best from the perspective of a publisher. I don't think short macro names as such are inherently bad; I would guess that macros that don't look like macros are bad. –  Jukka Suomela May 29 '11 at 13:40

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...

-
The macros \0, \1, ..., \9 are generally regarded as userspace scratch csnames: you can repurpose them as short macro names in the way that you want.
You can define a macro that \lets all these macro names be equal to the long csname you used in their definitions, and if you are worried that some badly behaved package is repurposing them, then you can have another macro that tests that equality with the long csname, using \ifx`, has not been violated.