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.

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?

share|improve this question
    
How would you like $x^\*j$ to render? –  Caramdir Mar 17 '11 at 21:10
1  
@CFP: Shouldn't it be $(x^{\*j})$ ?; otherwise, using $x^\*j$ will produce an error. –  Gonzalo Medina Mar 17 '11 at 21:15
1  
@CFP: You're writing "(x^\*j) renders as $(x^{\overline{j})}$." Do you actually mean "I would like (x^\*j) to render as $(x^{\overline{j})}$"? (And probably better "yield" instead of "render as"?) If yes, then it would be great if you can edit your question accordingly; at the moment it's somewhat confusing. Thanks a lot in advance! –  Hendrik Vogt Mar 18 '11 at 8:10
2  
@CFP: I think now I got why we didn't understand you at first. When you used $...$, then you didn't mean TeX code but the output you got, correct? I replaced your second $...$ with the corresponding image; I think this way your question is much clearer. OK? When we read "$(x^{\overline{j})}$" here, we always think of the TeX code and not of the output. (Moreover, I didn't even realize that the ) was inside the outer {}.) –  Hendrik Vogt Mar 18 '11 at 21:10
1  
@Hendrik, @CFP: what happens is that TeX inserts { before \overline, trying to recover from ^\overline, and then inserts } before the closing dollar, hence the weird output. –  Bruno Le Floch Mar 18 '11 at 22:13

1 Answer 1

up vote 11 down vote accepted

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.

share|improve this answer
    
Thanks for your thorough explanations. I'll follow your advice, and write it cleanly =) Thanks! –  CFP Mar 18 '11 at 19:47

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.