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.

Most of the bloated preambles I see have dozens of lines like

\newcommand{\Acal}{\mathcal{A}}
\newcommand{\Bcal}{\mathcal{B}}
%...
\newcommand{\Gcal}{\mathcal{G}}

While I can easily code a macro to loop over a list and define the corresponding control sequences, it is not pretty. For instance,

\def\letterdef#1#2#3{\def\letterdef@##1{\expandafter\def\csname #1\endcsname{#2}}%
  \letterdef@@#3{?\@car{}}\@nil}
\def\letterdef@@#1{\@gobble#1\letterdef@{#1}\letterdef@@}

Used as \letterdef{#1cal}{\mathcal{#1}}{ABCDEFG}. Putting that in a preamble makes it look ugly. Is there already a package providing that kind of functionality?

share|improve this question
1  
I’m not convinced of the benefit of having such macros. They don’t define semantics, just questionable shorthands. So while I can’t answer your question, I actually advise against this practice. –  Konrad Rudolph Oct 3 '11 at 19:24
1  
@Konrad I agree that these macros are not semantic, but they are very useful, and I've seen them used a lot by coauthors (everyone has their own convention, though). They reduce the clutter in formulas compared to the full version. –  Bruno Le Floch Oct 3 '11 at 20:01

1 Answer 1

up vote 10 down vote accepted

The \docsvlist from etoolbox can make this much easier:

\def\do#1{\@namedef{#1cal}{\ensuremath{\mathcal{#1}}}

\docsvlist{A,B,C,D,E,F,G}

(Alternatively, there’s also \forcsvlist command which uses an inline handler instead of a pre-defined \do macro.)

But, as I’ve said in a comment above, I’m opposed to this kind of non-semantic shortcuts. While \Acal certainly is shorter than \mathcal{A}, it’s not necessarily cleaner. I prefer to always use semantic shortcuts, e.g. defining \bigO for \mathcal{O} (of the Landau symbols) or \laplace for \mathcal{L}.

share|improve this answer
    
I want to add that I am a big fan of what you call "semantic" shortcuts, and I would encourage their use. I often have a list of math commands that are not used to reduce length but to make my intent clearer. This is especially helpful for working across departments, each of which has its own idiomatic requirements for the same mathematical statements. –  Carl Morris Sep 25 '12 at 16:42
    
With etoolbox you can also use \csdef instead of \@namedef which would avoid the need for \makeatletter ... \makeatother –  cgnieder Jul 27 at 12:33

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.