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.

By "bind more tightly" I refer to the order in which operations are carried out by default.

Experimenting shows that if \ab is ab and \cd is cd then \ab^\cd is ab^cd. I would like it to be {ab}^{cd}. Of course, I can do this by defining \ab to {ab} and \cd to {cd} but that's not always an acceptable solution; for example, if \cd is actually c^d then \cd_2 is c^d_2 but if \cd is {c^d} then \cd_2 is {c^d}_2. Indeed, if \cd is c^d then with the current precedence, \ab^\cd produces a complaint about double superscripts but changing the precedence would make it {ab}^{c^d} which is fine.

(NB I've tried to present the simplest case that I can; the actual macros that I'm using are considerably more complicated and introducing braces into these macros is much more problematic than in the simplistic case above. In particular, they are recursively defined and so introducing new braces at the outside actually introduces new braces at several inconvenient spots inside as well.)

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You can't change this behaviour directly, no. However, the breqn package makes ^ and _ active characters that behave as macros that take arguments ‘like normal’, which then has the effect you're looking for. So if you're happy to load breqn, that should fix your problem:

\documentclass{article}
\usepackage{amsmath,breqn}
\begin{document}
\def\ab{ab}\def\cd{cd}
$\ab^\cd$
\end{document}
share|improve this answer
    
Perfect! I notice that the actual bit that I want is handled by the mathstyle package; but the whole mh package looks like one that I'd consider loading by default. (Bizarrely, on Ubuntu I had to install a package called "texlive-latex3" to get this lot.) –  Loop Space Jul 28 '10 at 11:37

Another option is to add an extra group in the definition of the macros. For example

\newcommand\ab{{ab}}
\newcommand\cd{{cd}}

However, depending on the actual usage, an additional group may not be desirable.

share|improve this answer

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.