# An Introduction To LaTeX

You may be trying to display physics equations, biology genes, or chemical formulas. Whichever it is, you realize you have to be super creative to even approach the accuracy that you want. At this point you will probably start asking around or researching the best way to do this. Well let me tell you folks, there is a better way.  This is when most people find out about the wonderful Latex typesetting environment. Read on and I will explain as simply as I can about Latex.

### Chapter 1 - Introduction

Latex is a tool that many people will need eventually. It is great for creating a document exactly the way you want it. It does have a learning curve, however, once you get past that it is quicker to create an advanced document than a word processor.

If you write about math then this is your go to solution. Scientists and mathematicians use this every day.

### Getting Latex Free

Latex is easy to get. It is free. You can not beat that. You just download it to your computer and start working with it. For Linux users try here. If you are a Mac user then you go to this site.  If you are using Windows then go here.

That is all there is to it. Follow the directions from there that you are given. This article by the way is a quick Latex tutorial for Windows who need more functionality than Microsoft Word or Google Docs gives them.

You can use any editor. The document you create just needs the appropriate extension. There are also TEX environments available like [TexWorks] and [TexMaker]. I use them both.

### Installing Latex

You first need to install a distribution. This can be something like MikTex, TexLive, or ProText. They are all good and it does not matter which one. It did not to me when I looked at their differences.

Then you either work from the console, use an editor, or an IDE. Again it does not matter which you do as long as you are comfortable with it. most people prefer IDE's from what I have seen. Here is a picture of TexMaker below.

There are two ways to create your first document. First of all, use the text editor of your choice and write a sentence. Save the file as a [.tex] file. Now open a terminal and navigate to the directory of the document to run it.

The second choice, if it is available, is to use your TEX environment to run the file you just created.

### Latex Uses Backslashes

The first thing you might notice about Latex is that is uses backslashes to start every command. I felt it was important to mention.

Every time I have a document that will not compile it was because of a missing backslash. A little reinforcement will only help you in future debugging I am hoping.

### Latex Environments

There are many kinds of environments in Latex. An environment is a section devoted to a specific kind of formatting task. It can be a block of text or an [equation]. There are commands that to start them.

I mentioned above that each environment is started and ended with a backslash. It looks like this: [\begin{document] and [\end{document}]. It is not hard to use. The hard part is keeping up with the brackets and backslashes.

Examples of beginning latex environments are equation, center, figure, picture, and verse.

This example is simple but it shows the basics of an environment. An environment can grow and be as complicated as you are familiar with the language. It is easy to start though as you can see.

So no fearing how complicated it can get. You just do what you need and learn more if you need to.

Note how the commands start with a backslash. They all start like that. Also notice that for every [$$] there is a [$$] with it.

### The Parts Of An Article Are Easy To Word With

The document area must be defined. Commands begin with a backslash. Environment declarations have a begin and ending tag. This pretty much describes everything. There are many kinds of environments and commands.

The most basic document would be defining the class, starting and then stopping the document. Every document pretty much needs that information in order to compile.

Every document must have [\documentclass{article}]. The [article] option is optional. There are other classes you can use with [\documentclass]. Hope this is not confusing. Since this is a beginner Latex tutorial

### Latex Subsections

You can also add subsections easily when writing paragraphs. This is super useful. It is through the [\subsection] command. This works just like the [\section] command. This makes it easy to format your text.

Do not make the mistake of writing paragraphs without formatting your text. High school and college students are both very bad at this.

This is why the command [\subsection] exists so please use it. Here is an example of beginning latex subsections what it looks like.

### Doing More With Documents

In the above section I showed a quick example of what could be done to organize a document. Now I want to go into how to do that. Take a look at this piece of code.

The \documentclass line is always be there. For now assume it does not change. You will also have a \begin{document} and an \end{document}.

Everything that makes your document what it is will go between the \begin and \end statements. The above code looks like this once it is run.

Choosing the font size of your document is quite easy. Use \documentclass[15pt]{article} in the beginning of your code.

Let me show you how to make sections and subsections in your thesis or proposal.

As you can see I used \section for my main topic. Then \subsection is used to narrow down for more organization. We can do even more though because often it is needed.

I want to add more sections to each of the planets. How would you do that you might ask? Its done like this.

You will see the statement \subsubsection. Yes it is kind of weird but that is how you make sections within sections. This is the output.

### Formatting Text

This is done often by everyone. Fortunately it is easy to do. Just type: \textbf{Planets of our Solar System}

This will make the text bold and stand out.

To emphasize text use: \emph{Mercury}

### Latex Packages

You can add functionality to your installation by downloading morepackages. To use different packages you use the [\usepackage] command. You do this in the preamble of the document.

There are many packages to use. You just download them to use. It is nice and simple. To search for different packages to download you go to CTAN. In the future I will write the most useful packages and how to use them.

### Using Equations

This beginning Latex tutorial for math is designed to show equations and formulas. If you have ever used a word processor you know how hard this can be. In addition to using a math environment, you can also just include an equation in the middle of a sentence.

You do this by putting [$] symbols around your math. This is really just when you want to put a formula into the middle of your text. This is not for doing expressions. You do it like this: [$x^2+ 6x -3]. The exponents will be in the proper position then. ### Aligning Equations Makes A Huge Difference It is easy to align equations in Latex. You do so by using the command [\begin{align}]. You will end it by using [\end{align}] when you are done with that section. This makes all your equations look beautiful. It is for your math environments that have expressions. When you want equations to look nice, that is what you do. It also helps in making comparisons because the equations or formulas are seen more clearly. ### Typesetting Latex Matrices Latex can even do matrices. This is very useful. It is done by [\begin{matrix}] and ended by typing [\end{matrix}]. This is very practical for math students. There are other ways of doing them too. So you have options if the regular way of [\begin{matrix}] does not fit your needs. As you can see it is easy to get a matrix going. Here is the simple code for that. Two things to watch out for: First, just make sure you space everything out correctly. I added spaces so I would be less prone to mistakes. Second, you need to watch for those backslashes. Missing one will mess up the code when it compiles. ### Using Powers Latex can easily handle equations with powers or exponents. It even does subscripts well too. Here are a couple quick examples. This shows the versatility of Latex code. Here I just made up some arbitrary numbers for equations. So don’t go trying to factor them. I have a feeling it will end badly. Anyway, a couple things I want to point out is that the equations are right justified and they are automatically numbered. You can adjust the left or right justification if you need to at some point. It is also very handy to have the equations numbered when you are going through steps in an equation. The code to generate this is short but powerful. Here it is. It is just the basics in order to show you the equations above. Notice after the first equation that there are two backslashes. You do not want to forget those. I will again mention to not forget your other backslashes. Also you see every regular command has a [\begin] and [\end] section. So when you are writing your code pay attention to that. ### Typesetting Fractions Fractions are also handled nicely. It is done by the [\frac] command. The first example is just a plain old fraction. See, that really is easy. It is numbered and that is about it. Now the second expression is adding two fractions together. You can see how things are spaced and aligned with each other. The third expression starts showing some of the real potential here. You will notice it is a complex fraction. It looks very good. Note the code below. It still does not take very much code to accomplish the fractions above. Nor is the code complex. It is actually very simple. Latex can do so much more just so you know. I just typed some random expression in my head and added some spacing. That is it. That is how you do fraction and should cover most of your needs. ### Using Square Roots Is Not Complicated You can do square roots in beginning latex as well. While not terribly exciting they are still important to know. In the first expression I just do a simple root. The second expression I show how you can be a bit more complicated and add a fraction under the root. For the third expression I show how to do a whole expression under the root. All these forms are useful. In the code below I demonstrate how to do square roots. Note the simple syntax. Just remember to keep everything spaced so you can see potential errors. If everything goes well you will be shooting out roots in no time. ### Typesetting Derivatives Making derivatives look nice is something you want to do too. It is quite easy also. You are just putting a fraction over a fraction. In beginning Latex you will use derivative notation heavily. This is how you can do derivatives. There are a myriad of ways to do them. There are different styles and display modes for everything mathematical. So this is just one way to accomplish it. The equations are again numbered. They are spaced out as well nicely. This is evident in the code. You can see at any time how to adjust your vertical spacing. In the code itself I am still using [amsmath] package. There are several more math packages. One day I will get to them all. I am just concentrating on the basics for this quick latex tutorial. ### Using Integrals Integrals are one of the most used equation forms out there. Look how much you can do. Here are example integrals. They are the opposite of derivatives in a way. The typesetting here in this beginning latex tutorial looks really good. Integrals are done flawlessly. Notice at bottom and top of the integral symbol you have the area where the calculation takes place. In the code window below you have the integration examples. This is just standard. It is meant to be combined with the other examples above or whatever your math needs are. This does not take complex code as you can see. For each type of math we do the code is always pretty simple. There is a lot to learn about Latex. You do not have to know everything though. The purpose of this beginning latex tutorial was to get you started. I also did things in such a way that you will learn quite a bit. The key to this is if you type out the code and get everything to work. I highly encourage you to do this if you need to learn latex. I placed many resources to learn from throughout the article. So if you have questions or want to learn something I did not cover then check one of those sites out. They are all good. Just read until you find what you are looking for. I will also be making a Latex tutorial PDF in the future for download. If you want to ask me any particular question then please use the comments section below. I will do my best. If you have found this article useful I would appreciate you subscribing to my email list and sharing it within your friends. ### Chapter 2 - Introduction Learning LaTeX typesetting does not have to be hard. While it can be very involved, there are really just a few basics. Today I will strive to help you with the fundamentals. If you need additional options after that they are easy to find. LaTeX can be very useful so lets get started. You may wonder why I am using Latex over something like Microsoft Word. The problem with Word is that it hides what is really going on in the background and it has far less capability than Latex. I use it when I want to display math or caluclus and it also helps me learn those topics better. The reason why is that you have to completely understand how the math works before you can properly display it in a document or a web site. That is my logic and I hope it is obvious to others. Besides, if you are in a computer, math, or physics discipline then you will need to learn this anyway. So today I want to talk about how to use LaTeX typesetting in your documents. ### Defining LaTeX Typesetting LaTeX is a tool for creating very refined looking documents. It is quite different than Microsoft Word. Fundamentally, you have a page of source code that is compiled by an editor. That sounds all fancy and complicated but it is not. Editors and online tools make this quite easy. ### Reasons To Learn It LaTeX is used everywhere in the world. It is mostly used by scientists and engineers. This is because it is the easiest way to portray their math and diagrams into a document. You can also extend its usage quite a bit by the use of packages. There types of packages for anything conceivable to write about. Others use LaTeX typesetting for writing documents. It gives ultimate control over spacing, fonts, and organization. Making document templates is a very popular way to use this typesetting tool. ### Your First Document If you are creating a document from scratch you will need to give it a [.tex] file extension through whatever editor you are using. A pure LaTeX editor and online sites will do this in the background for you. That is how you start a document and write a little text. I will show you how to do more with this in later sections. First, make sure you save it with the [.tex] extension. Then use your editor to compile this source. There should be an obvious button that says compile or build. The first line declares what kind of document you are using. An {article} is the most basic class. There are several other document classes as well. Everything else goes between the {document} tags. ### Modifying The Preamble In Latex Typesetting The preamble is the part of a document above the \begin{document} line. You can do a variety of things here. This is where you can specify font size and any special encoding. The font size can be set to whatever you prefer. The [utf8] encoding is pretty universal as well. There are many other packages and options you can use here. Titles, authors, and dates can easily be added to your document. This information goes in the preamble of your document. Use these commands in your preamble. Now you will also need to add another line in the body of your document. Add this right below \begin{document}. This line will enable the information you just added to your preamble to show up. These are very popular options to add with LaTeX typesetting. ### Commenting Your Code This is quite easy to do when using LaTeX typesetting. Add a % to any line will tell the compiler to not do anything with it. If you are following along in your own editor you will see that my commented line with a [%] does not show up in the document. It is for you. Use it to remind you of things and to tell yourself at a later date what your logic was. I know I have to do this or I will not remember why I did things. ### Formatting Your Text Well this is about LaTeX typesetting so talking about formatting had to come eventually. This is actually a huge topic on its own. For now I am just going to mention the basics to get you started. Later we can go more in depth together. • To make words bold you use the \textbf{ } command. • Italicizing is done with \textit{ }. • Underlining is done with \underline{ }. Let me show you some examples. ### Making Text Bold The preamble is the same as before. Just ignore the title for now as I did not update it. I used \textbf{fdisk-l} to make that bold. ### Using Italics Now to italicize you do something very similar. Try that in your editor. You will see that --create and --verbose are now italicized. ### Underlining Text To underline portions of your text you do the same thing. Notice how everything I underlined is enclosed with this bracket. This will have [@virtualization] underlined. ### Lists in LaTeX Typesetting Lists are easy and a good way to break up your content. They also get across a message well too. We will use a different environment for lists. We invoke it by using [\begin{itemize}. That sets up our environment. For each individual item or bulletpoint you will use [\item]. lets look at an example. This is an unordered list. It is just bulletpoints. You can see how easy that is. Note the beginning and ending of the [itemize] environment. We can do the same thing with to make an ordered list. These are sometimes helpful so we should know how to do them. We use a different environment for this too. It is the [enumerate] environment. You can see how the [enumerate] environment lets us order our list. ### Displaying Math In Latex Typesetting Here comes the really fun part of this! A lot of us have had to write about an algebra or calculus concept at one time or another. Do you remember the first time you opened up Word and tried to figure that out? So how long did it take you to get frustrated? Well LaTeX type setting has been around a lot longer than Word and other similar types of software. I am going to be writing about the display mode capabilities today just in case you are wondering. Lets start off in simple terms. Get it, terms, in math? Oh never mind. So here is basic Algebra. $y + 8 = 30$ This is some Calculus. $$E=mc^2$$ $$f(x)=3x^2+2x-5$$ These small equations are displayed by by enclosing them with $$before and after the equation. This is called the display mode in LaTex typesetting. ### Math Expressions Expressions are a fundamental part of equations. They are what make up equations to be precise. Something like:$$f'=3x^3+4x^2+9x-3$$. The code to display that is f'=3x^3+4x^2+9x-3. You can do most of algebra with that little bit of code. It will take care of simple expressions, logarithms and exponents. There are some nuances and other details that I will get into later. ### Parentheses In Latex These are every day items when doing math of any kind. In Latex typesetting you can control almost every aspect of how they look. So if I want to make an equation behave a certain way with parentheses it is easily done. Lets take this one for example and then I will break it down into smaller pieces.$$y=\left \{3x+6 \right \} + \left \{4x-2 \right \}$$To do this you will enclose your whole line in$$ ... $$You will use the \left and \right commands. After either \left or \right you add a space. So your whole will look like this:$$ \left \{ .......... \right \} $$The dots are where your expressions go. The size can also be controlled. You can do \big{ , \Big{ , \bigg{ , \Bigg{ instead of using \left and \right . The reason is that \left and \right use automatic sizing. Sometimes you may want your parentheses a different size and have to manually size them.$$y= \bigg \{4x-9 \bigg \}$$You can recreate this simple line by using y= \bigg \{4x-9 \bigg \} in your editor or file. ### Fraction In Latex Typesetting Simple fractions are used continually in math and calculus. Elementary school and collegiate courses both use them constantly. They take the form of \frac {}{}. The top number or letter goes in the first pair of parentheses. The bottom number or letter goes in the second pair. So lets do a simple problem. What is:$$ \frac{2}{3} + \frac{3}{4} = ? $$Of course the answer is to this problem is:$$ \frac{2}{3} + \frac{3}{4} \rightarrow \frac{17}{12} $$This is achieved with \frac{2}{3} + \frac{3}{4} \rightarrow \frac{17}{12}. Not too hard at all. ### Trigonometric Operators In Latex Once you get to Pre-Calculus in your schooling, trigonometry will be very common. Therefore, it is important to know how to display these operators properly when you are learning about them. The basic forms are \sin, \cos, \tan, \csc, \sec, and \cot. We can have problems like:$$ \cos \frac{5\pi}{6} = ? $$which is given by \cos \frac{5\pi}{6}.$$ \sin \frac{4\pi}{3} = ? $$which is done by \sin \frac{4\pi}{3}.$$ \tan \frac{3\pi}{4} = ? $$is displayed with \sin \frac{4\pi}{3}.$$ \sec \frac{2\pi}{4} = ? $$is given with this, \sec \frac{2\pi}{4}.$$ \csc \frac{3}{2\pi} = ? $$is done with the code \csc \frac{3}{2\pi}.$$ \cot \frac{11}{4\pi} = ? $$will be shown by the code cot \frac{11}{4\pi} . There are a lot more trigonometric functions but this should get you started for now. These are examples for all the basic types of functions. ### Integrals Using Typesetting Basic integrals will pop up in your first year of calculus. Therefore, it is vital you know how to handle them. This is where calculus starts getting fun. I will just put the code below the problem as usual. The basic integral form is this:$$ \int_{A}^{B} x^2 dx $$\int_{A}^{B} x^2 dx Another form of the integral looks like this:$$ \int 5x^2 +3x +9 dx $$\int 5x^2 +3x +9 dx Here is a slightly different form but basically the same.$$ \int 6x^3 - 4x^2 +7x -5 dx $$\int 6x^3 - 4x^2 +7x -5 dx This is a more complicated form of an integral.$$ \int (8x-12) (4x^2-4x)^4 dx\$

\int (8x-12) (4x^2-4x)^4 dx

Integrals can get really complicated. There is a lot more I could list here and talk about here. However, these are the basic forms and will be enough for first and maybe second year calculus.

Typesetting in Latex is like many other disciplines. It is fairly easy to get started but can take a very long time to master. Fortunately, it is rare that anyone really needs to master it. most of us, myself included, pick up what we need as we go.

It started with computer science and physics classes in school. That got me really interested in this and other topics. That is why it is so fun though. I was already interested in what I was doing and Latex was just an extension of those interests.

If you find similar interests and if any of them include typesetting documents for one reason or another then I hope this guide will be useful. I will be adding subsections continually as I am making this my official guide and reference to myself. Hope it helps!