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.

This expression is just an example, of course.

My question is: should one always specify the quantity being exponentiated by surrounding it with braces, or is it acceptable to drop those braces? (Cases in which \left(...\right) are used lie outside the scope of my question.)

It seems to me that one should write {(x+y)}^2 but I do see (x+y)^2 a lot...

enter image description here

\documentclass{article}
\begin{document}
${(x+y)}^2$ or $(x+y)^2$?
\end{document}
share|improve this question
    
I think there's no need for the first expression, as the second is readable, and if you are between lines (inline math), the second expression won't change interline spacing. –  Manuel Mar 23 '13 at 23:53
13  
Definitely (x+y)^2. –  egreg Mar 23 '13 at 23:53
5  
There is a clear visual difference between the two renderings, in the position of the exponent. –  Kaz Mar 24 '13 at 5:40
add comment

5 Answers

up vote 66 down vote accepted

There is an argument that logically the squaring operation applies to the whole subterm so the {} are correct. However it makes the {} into a mathord which can affect spacing to adjacent terms and if the subterm is large (but \left \right are not used so the brackets are not stretched) then the superscript could float up and become visually detached. So on balance, I think it's better to use the )^2 form.

enter image description here

\documentclass{article}

\begin{document}

${(x+y)}^2 + \sin{(x+y)}^2+{(x+\frac{\frac{A}{B}}{C}+y)}^2$

$(x+y)^2 + \sin(x+y)^2+(x+\frac{\frac{A}{B}}{C}+y)^2$

\end{document}
share|improve this answer
6  
The parentheses themselves apply to the whole subterm. So you square the subterm, by setting the exponent to the closed parenthesis. –  egreg Mar 24 '13 at 0:00
1  
@egreg, mathematically yes, but that's not the way TeX views it (as you know:-) –  David Carlisle Mar 24 '13 at 0:02
    
As both a typophile (type that word and ask Google for spelling suggestions :) ) and an amateur mathematician (if meta) I prefer the second line to the first as I have a preference for closely attaching functions and parenthesis. Just sayin... –  hsmyers Mar 24 '13 at 1:55
    
@David: See my answer for another reason why {} shouldn't be used. –  Hendrik Vogt Mar 24 '13 at 20:51
    
@HendrikVogt Yes I should have mentioned the spacing (and lack of line breaking) within the subterm. egreg also mentioned that in a comment to one of the other answers. –  David Carlisle Mar 24 '13 at 20:55
add comment

There's one major reason against using {} that isn't mentioned in the other answers: like \left(...\right), it makes the spacing inside loose its flexibility. Look at this example:

output

In the first case, the space around the - is shrunk to make everything fit into the line, but the {} around the parentheses has the effect that the space around the + isn't shrunk. In the second case you get even spacing: the shrinking around the - is the same as around the +.

\documentclass{article}
\setlength{\textwidth}{4.9cm}
\begin{document}
$a+{(x+y)}^2$ versus $a+(x+y)^2$
\end{document}

Also if you want to prevent a line break, don't use {} around the expression, use \nobreak instead at appropriate places, like in (x+\nobreak y)^2.

share|improve this answer
    
${...}$ is the correct notation for preventing a line break of an inline formula –  Herbert Mar 24 '13 at 20:55
    
+1 yes I should have mentioned this (and line breaking) –  David Carlisle Mar 24 '13 at 20:57
    
@Herbert: It would be correct if it wouldn't affect the spacing! –  Hendrik Vogt Mar 24 '13 at 20:57
2  
@Herbert if you use {} to prevent linebreaking then you have to accept it also freezes horizontal glue. An alternative (but perhaps less convenient way) is to set binoppenalty and relpenalty to 10000 –  David Carlisle Mar 24 '13 at 20:59
    
@DavidCarlisle: sure ... –  Herbert Mar 24 '13 at 21:00
show 6 more comments

Months later...

A relevant passage of the TeXbook (Chapter 16, p129) is the following, which is in agreement with David's answer; I thought I should add it here, for completeness.

A superscript or subscript following a character applies to that character only; but when following a subformula it applies to that whole subformula, and it will be raised or lowered accordingly. For example,

$((x^2)^3)^4$ enter image description here

${({(x^2)}^3)}^4$ enter image description here

In the first formula the ^3 and ^4 are superscripts on the right parentheses, i.e., on the ) characters that immediately precede them, but in the second formula they are superscripts on the subformulas that are enclosed in braces. The first alternative is preferable, because it is much easier to type and it is just as easy to read.

(my emphasis)

share|improve this answer
    
Isn’t this ultimately the same as David’s {(x+\frac{\frac{A}{B}}{C}+y)}^2 example (the last one)? However, the source is a good one. :) –  Qrrbrbirlbel Nov 21 '13 at 19:50
    
The example is similar, yes. Perhaps I should just delete this answer and edit David's to add the reference... –  Jubobs Nov 21 '13 at 19:55
add comment

I (edit just corrected my belief to) always use $\left( x + y \right)^2$, or rather I have a command for the parenthesis and doing $\paren{ x + y }^2$. That's semantically a valid thing to do, and I let the TeX engine authors sort out what how they want to render it.

share|improve this answer
6  
I wouldn't recommend this. To be honest, I consider this wrong input. –  egreg Mar 24 '13 at 11:17
2  
The unnecessary usage of \left and \right and the braces; the \left-\right pair "freezes" the spacing around +, not allowing it to stretch or shrink for helping justification in in-line math; the braces usually put the exponent too high. –  egreg Mar 24 '13 at 11:24
2  
Your wording suggests that the result of that input could change depending on TeX developments, but it is input to a fixed system so the first form will produce the output it produces (which is usually not the output you want) The second form of course is OK so long as you define \paren in a suitable way. –  David Carlisle Mar 24 '13 at 11:57
    
@einpoklum "suitable". that and not adding {} around the outside which as discussed in several answers here affects spacing in several ways. Actualy if you don't add {} you don't need to check for the following superscript as it will work automatically. –  David Carlisle Mar 24 '13 at 14:05
1  
einpoklum: In this particular case, I find some of the comments here hard to follow without being able to see the whole conversation--including the comments you deleted. That having been said, I don't want to suggest that deleting your own earlier comments that you now consider erroneous is in any way wrong. [Or even that I have any authority whatsoever to say whether it is wrong.] –  Charles Staats Mar 24 '13 at 22:46
show 6 more comments

Unlike MathML, TeX's math mode makes no attempt to encode the semantics of the typeset math. Math mode is susceptible to linebreaks, but you can use braces to prevent that: the formula${(x+y)^2}$ will not break across lines, while $(x+y)^2$ may.

share|improve this answer
add comment

protected by Jubobs Feb 23 at 22:06

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.