Defining new accents in LaTeX

The documents that I type include lots of references to complex numbers and their complex conjugates, such as $j, \overline{j}$.

I would find it lots easier to be able to type something as \*j to denote \overline{j}. Then \* would work very much like an accent, applying only to the next symbol if no curly braces are present.

However, using \renewcommand{\*}[1]{\overline{#1}} doesn’t yield satisfactory results at all: (x^\*j) yields .

Ideas?

Solutions Collecting From Web of "Defining new accents in LaTeX"

In the specific application that you mention, you can simply double the braces in the definition of \*. Namely,

\documentclass{article}
\renewcommand{\*}[1]{{\overline{#1}}}
\begin{document}
\[
(x^\*j)
\]
\end{document}

The default behaviour of ^ is that it expands what follows until it cannot anymore. Once that happens, ^ will grab whatever is the next “token”, and put it as an exponent. With your definition of \*, the expansion transforms (x^\*j) into (x^\overline{j}). Then TeX cannot expand \overline more, so it puts \overline as the exponent of x. But that’s not going to work, because \overline takes an argument.

With the extra set of braces, the same expression expands to (x^{\overline{j}}), and the whole expression is in braces.

I would advise against that solution though, and instead type $(x^{\*j})$, keeping your previous definition. You should not rely on the fact that ^ expands its argument before grabbing it: some packages change that behaviour.