|  | 


Basics of LATEX

A useful guide I created for my sister on how to use the math coding language 

Wanted to post it online, in case it would help others as well. Please check it out and ignore all of the jokes I found funny in my 3 AM drowsiness.

Try using LATEX in Word, or an online Latex editor, like this one.
Start/End every statement with:
(  … ) or $…$
Text + Numbers – Just enter regularly
(Bhagirath), (2)
There are fancier ways to write these, but for now, using the method above, we get
I will ignore the (  … ) for pretty much everything else after this.
You can practice your skills on ://www.codecogs.com/latex/eqneditor.php. You don’t need  (  … ) to start your commands, as this editor expects LaTeX to be used, not a mixture of normal text and LaTeX.
+,-, *,/ works the same way for addition, subtraction, multiplication and division, respectively
Notice that the division symbol is a forward slash. This is important, as a back slash will be interpreted as an end slash mark, or the beginning of a command/function. If the LaTeX editor does not recognize the command/function, it will be ignored.
Use a carat sign for powers:
We use _ to get the ‘bottom’ parts of summations, products, and limits, as well as the subscripts of logarithms. We use ^ to get the ‘top’ parts of sums and products. (Integration symbols work the same way, as you’ll see in the calculus section.) Click here for a few other commands which take ‘bottom’ parts. Don’t click.
frac is an abbreviation for fraction; sqrt for square root
sum is sigma – this is the function that adds up all the numbers
DID YOU KNOW? there is a similar function that multiplies all the numbers i.e instead of adding all the numbers from n =1 to 10, the function will multiply them.
Instead of sigma, it uses the uppercase letter pi.
It looks like this:  =10!
prod is uppercase pi.
A function (READ: NOT TEXT) needs a slash mark before it:
frac or sqrt or LaTeX
sqrt = 
sum = 
prod = 
LaTeX basically just makes LaTeX look fancy, like this . Putting a slash mark before normal words does not usually make them look fancy. Just words like LaTeX and TeX
This is a good time to notice that ALL commands are case-sensitive. 🙂
To put the numbers you want to fit in the function, you must use curly brackets
sqrt{x^2} is 
[BTW, read the text that comes up when hovering over the LaTeX images.
I hope you are starting to get a sense of what LaTeX images looks like. It is a formatting and mathematical equation creating code, somewhat like HTML, although HTML is used to create entire webpages. An entire webpage is not usually created using LaTeX. I am not sure if it is possible to create a webpage using LaTeX, or its harder-to-use parent, TeX.
The following webpage, for example, uses HTML to be displayed. An HTML editor “reads” the code and changes everything to whatever needs to be displayed. Then, one can ask the HTML editor to temporarily “read” LaTeX, or insert things created from a LaTeX editor and saved as images. http://mathmaine.wordpress.com/2010/04/01/sigma-and-pi-notation/ We return to our regularly scheduled program.]
A fraction has two parts, right? So you need two curly bracket pairs for the numerator and denominator. Just put them next to each other. The first curly bracket is the numerator, the second is the denominator.
frac{1}{2} is
What if you want a fraction in a fraction? Well, first of all, you will have a lot of slash marks and curly brackets within one another, so you need to keep track of everything. This goes for mixing other commands together, too, like a sqrt in a sqrt or a sqrt in a fraction.
Work on it from the outside-in. This requires you to be smart about it.
[If you are trying this in the editor, you will notice that the editor will automatically insert a end bracket when you have a beginning bracket. frac will give you two pairs of brackets automatically.This is not true for all editors.]
Try it yourself.
frac{1}{2+frac{1}{2+frac{1}{2+frac{1}{2+frac{1}{2}}}}} looks like this:
This is good, but small. For continued fractions, use cfrac:
cfrac{1}{2+cfrac{1}{2+cfrac{1}{2+cfrac{1}{2+frac{1}{2}}}}} looks like this:
Ordering can be confusing in things like fractions. For example, if you have frac{pi}{1} and you want to multiply the pi by 2, or something, it may be easier to put the 2 along with anything else in the numerator, before the pi, so the editor does not confuse pi and pi2. If you have a fraction in a fraction, put the embedded fraction at the end of the curly braces just to keep things simple and easy.
If things are too close for comfort, maybe like pi+, where the pi and plus sign are too close together, 
pi +
pi              +
won’t make a difference. The spacing will stay the same, as the LaTeX editor ignores spaces, so try:
pi +
The end slash mark makes the difference.
Don’t make it pi+, because the editor thinks that +  should be a command. It doesn’t recognize it, so the + will be ignored.
Superscript/exponent, as we said before, uses a carat (^).
Subscript uses an underscore.
For place where you want a subscript and superscript/exponent, use the following:
H^2+_2 or H_2^2+
Woah there, horsey.  We get
 or .
We want this:
The LaTeX editor thinks that the 2 and + are separate, so it treats them as such. They are one term and we want the command to do the same thing to both. We must put 2+ in curly brackets, so it is treated as one term. Once you do that, it doesn’t matter what order the subscript and superscript are in.
H^{2+}_2 or H_2^{2+} is  .
Note that the curly brackets rule applies to two-digit numbers as well.
H^20 and H^{20} are not the same thing. They look like this, respectively:
 and . You probably wanted the second one.
If you want something next to the  with no spaces, like the letter O, just put the O next to H_2^{2+}, outside of any curly brackets. It makes sense that the curly brackets are necessary. The computer doesn’t know if x should be part of the superscript/subscript, or should be next to the original term. Since by default, things will be placed next to the original term, you need curly brackets if you want to tell the computer that x is part of the superscript/subscript. Things are placed next to the original term by default, because you would need a lot more symbols if the opposite was the case. If you think about, in H^2+_2, the computer wouldn’t know if _2 applies to the original term, or to the 2+. In H^2p, the computer doesn’t know if p is part of the exponent or is next to H^2, so it assumes the latter by default. If you use this logic throughout LaTeX and other programming languages, you don’t need to memorize the syntax rules. You just need to understand why they exist and this will help you think of new rules that may not be mentioned, but exist. Then, you can avoid making mistakes or avoid cases where mistakes may happen, altogether. You can also use logic to find simpler way to write things. 
Moral of the Story: If you want things to be together, put them in curly brackets. Otherwise, the computer will treat everything separately.
The same applies to sums, products, logs and everything that needs something on top and/or bottom.
sum_{n=1}^{10}k or sum_{n=1}^{10}{k} is
prod{n=1}^{10}k or prod{n=1}^{10}{k} is
log_216 = log_{2}16 = log_2{16} = log_{2}{16}
If you have base 10 and don’t want to write it, you can, of course, just write:
You can guess that 
int is an integral.
int = 
int_{x=0}^{1}{x^2dx} is
Derivatives can be shown using fractions, but find out if there is a special function/related command for derivatives. 
BTW, parentheses will show up in the final image. Find out and tell me if it is possible for backslashes and/or curly braces to show up in the final image.
Make a list of commands for homework, like this.
frac        fraction
int          integral
sqrt        square root
Or you could use Daum Equation Editor. 🙂
Next Time: Formatting with LaTeX (Like HTML putting things into paragraphs, headings, changing fonts, etc.)

No Comment

  1. Haripriya Mehta

    Thanks! Finally referring to the guide you made for me for 6.006 psets.

Leave a Reply


%d bloggers like this: