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.

For those of you who are familiar with my questions, you would know that I'm a newbie.

If you don't, well you know now.

What is the problem with this piece of LaTeX? There aren't any major errors, it's just if there was a way to maybe optimize it a little.

\:\:\:\:\left(\sqrt{2}+\sqrt{3}\right)^2\\=\left(\sqrt{2}\right)^2+2\times\sqrt{2}
\times\sqrt{3}+\left(\sqrt{3}\right)^2\\=2+2\sqrt{6}+3\\=5+2\sqrt{6}
share|improve this question
    
To optimize the file size? –  Who is crazy first Oct 14 '12 at 16:32

3 Answers 3

up vote 10 down vote accepted

Keeping the documentation of amsmath package next to your monitor will go a long way for you, if you are using lot of equations.

BTW you can use align* and split the equation in to different lines.

\documentclass{article}
\usepackage{amsmath}   

\begin{document}
 \begin{align*}
 \left(\sqrt{2}+\sqrt{3}\right)^2 
            &=\left(\sqrt{2}\right)^2+2\times\sqrt{2}\times\sqrt{
                3}+\left(\sqrt{3}\right)^2\\
            &=2+2\sqrt{6}+3\\
            &=5+2\sqrt{6}
\end{align*}
\end{document}

enter image description here

Edit-1 As noted by Gonzalo in his comments, use of \left and \right gives slightly bigger delimiters. Instead, one can use \bigl and \bigr. But it is to be noted that these are not dynamic in nature (i.e., the size of parenthesis stays same).

\documentclass{article} 
\usepackage{amsmath} 
\begin{document} 
\begin{align*} 
\bigl(\sqrt{2}+\sqrt{3}\bigr)^2
            &=\bigl(\sqrt{2}\bigr)^2+2\times\sqrt{2}\times\sqrt{
                3}+\bigl(\sqrt{3}\bigr)^2\\
            &=2+2\sqrt{6}+3\\
            &=5+2\sqrt{6}
\end{align*} 
\end{document}

enter image description here

Edit-2 As per the comments of Peter Grill and Mico, You may opt to remove \times and add a thinspace \, after the sqrt, just before the closing parenthesis as in:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\bigl(\sqrt{2}+\sqrt{3}\,\bigr)^2
            &=\bigl(\sqrt{2}\,\bigr)^2+2\sqrt{2}\sqrt{
                3}+\bigl(\sqrt{3}\,\bigr)^2\\
            &=2+2\sqrt{6}+3\\
            &=5+2\sqrt{6}
\end{align*}
\end{document}

enter image description here

share|improve this answer
2  
I wouldn't use \left...\right here since they produce oversized parentheses; I'd rather use \bigl...\bigr: \documentclass{article} \usepackage{amsmath} \begin{document} \begin{align*} \bigl( \sqrt{2} + \sqrt{3}\,\,\bigr)^{2} &=\bigl( \sqrt{2} \,\,\bigr)^{2} + 2\times\sqrt{2}\times\sqrt{3} + \bigl(\sqrt{3}\,\,\bigr)^{2} \&=2 + 2\sqrt{6} + 3 \&=5 + 2\sqrt{6} \end{align*} \end{document} –  Gonzalo Medina Oct 14 '12 at 2:15
    
@think123: My personal preference would be to eliminate the use of the \times. It would be a lot clearer to read without that. Oh, and adding a \, space after the \sqrt (before the closing )) would also be nice. Then it would match the space at the opening of the (. –  Peter Grill Oct 14 '12 at 4:05
    
@think123 -- Like Peter Grill, I'd eliminate all uses of the \times symbol. I'd also use a "thinspace: -- \, -- to provide a tiny amount of visual separation between an expression containing a square root and the subsequent closing (large or ordinary) parenthesis. Finally, I don't think it's necessary (or even helpful) to place parentheses around the \sqrt{2} and \sqrt{3} expressions on the right-hand side of the first line. –  Mico Oct 14 '12 at 8:00
    
@PeterGrill: Thanks for the suggestions and edited accordingly. :) –  Harish Kumar Oct 14 '12 at 9:08
    
@Mico: Thanks :) –  Harish Kumar Oct 14 '12 at 9:08

There is no need for larger parentheses in such expressions. Only a few strategically placed \, will give room and make the expression perfectly readable.

The places to look out for are the ends of radicals. If they are next to another "ordinary" object (not a relation or operation symbol), it's usually correct to insert the thin space \,. For instance, notice the difference in

\sqrt{2}\,x \quad x\sqrt{2}

enter image description here

What about parentheses? Larger ones are not needed, in general; compare

(\sqrt{2}\,)^{2} \quad \bigl(\sqrt{2}\,\bigr)^{2}

enter image description here

The left one is perfectly readable, while the one on the right has the exponent too high and the vinculum clashes with the parenthesis even with the thin space. Here is the version with \left and \right, which is clearly wrong:

\left(\sqrt{2}\,\right)^{2}

gives

enter image description here

and this should be enough to discard it. Use \left and \right only when really needed.

Your mathematical reasoning can be typeset with the help of the align* environment:

\begin{align*}
(\sqrt{2}+\sqrt{3}\,)^{2}
&=(\sqrt{2}\,)^{2}+2\sqrt{2}\,\sqrt{3}+(\sqrt{3}\,)^{2}\\
&=2+2\sqrt{6}+3\\
&=5+2\sqrt{6}
\end{align*}

Notice that there's no \, after \sqrt{6} in the second line, because it precedes a binary operation.

enter image description here

share|improve this answer
    
Nice explanation +1. –  Harish Kumar Oct 14 '12 at 9:51

We can reduce the number of keystrokes more as follows. Save the storage space, save the earth from Carbon emission.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\def\l{\bigl(}
\def\r{\,\bigr)}
\def\s#1{\sqrt#1}

\begin{document}
\begin{align*}
\l\s2+\s3\r^2
            &=\l\s2\r^2+2\s2\s3+\l\s3\r^2\\
            &=2+2\s6+3\\
            &=5+2\s6
\end{align*}
\end{document}

Notes from egreg's comment:

\l is the LaTeX Internal Character Representation (LICR) for "ł", while \r is the LICR for the "ring accent", for instance \r{u} gives "ů". When using UTF-8 in (pdf)LaTeX, each ł is translated into \l, so those definition would break all Polish documents. The redefinition of \r would break the Czech ones. Sorry, but \L is for "Ł"

So if these restrictions matter, then please use the other vacant characters, \F (leFt) or \G (riGht) may be candidate replacements for them.

Fortunately, \def is not harmful--it will never make your machine explode--even though it may silently redefine the existing macro without your awareness.

share|improve this answer
    
Hmm, the codes seem to be more readable, right? –  Who is crazy first Oct 14 '12 at 9:32
4  
No, it's cryptic. By the way, \l and \r are commands in the LaTeX kernel and they should never be redefined. –  egreg Oct 14 '12 at 9:53
4  
\l is the LaTeX Internal Character Representation (LICR) for "ł", while \r is the LICR for the "ring accent", for instance \r{u} gives "ů". When using UTF-8 in (pdf)LaTeX, each ł is translated into \l, so those definition would break all Polish documents. The redefinition of \r would break the Czech ones. –  egreg Oct 14 '12 at 10:02
3  
Last comment here: never use \def in LaTeX documents, unless you're a skilled LaTeX programmer; and, if you are, think twice before using \def. –  egreg Oct 14 '12 at 10:16
1  
following up on @egreg's comment about \l and \r, these are also redefined by hyperref, so if you're expecting to have live links in your output, you'll get instead either error messages or confusion. –  barbara beeton Oct 14 '12 at 11:56

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.