Intro to LaTeX **Full Tutorial** Part II (Equations, Tables, Figures, Theorems, Macros and more)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
If you want to write beautiful mathematics if  you want to make documents that are full of math   equations the standard and best way to do this is  using LaTeX. LaTeX is a markup language and what   that means is that there's a whole bunch of code  that you write down it looks messy but don't worry   it's not so bad I'm going to show you exactly how  to do it and what it does is it converts that into   beautiful documents like this one that nicely  display complicated mathematical expressions   and allow you to just really tightly control  exactly how you want to display mathematics.   This is actually my second LaTeX video, my  first video was the very introduction for   absolute beginners and in this video I'm going  to show you a bunch of tips and tricks that build   on that previous video and basically tell you  everything you need to know to be able to write   your homeworks or your projects or whatever else  using LaTeX. Now before you can actually write any   LaTeX you have to have some software that allows  you to convert from the code to the mathematics   and the one that I think overwhelmingly is  the best is Overleaf. Overleaf is a web-based   editor you just go to overleaf.com you make an  account and you can just start working in LaTeX   everything just sort of exists in the cloud. Now  I've used Overleaf for years I've recommended it   to my students and to you on youtube for years so  that's why I'm very proud for the first time I'm   actually being officially sponsored by Overleaf  to create this video and the idea is that we're   going to create this little mini series together  so that any of you can go from a complete novice   at LaTeX to a master at LaTeX over the course  of this video series. Where I'm going to start   is where I left off on the previous video that  is I have this little bit of code and basically   all I showed you previously was how to make these  different equations so if this seems completely   foreign go and check out the previous video to  that the link is down in the description. So the   first thing I'm going to do is perhaps the easiest  is the low-hanging fruit is I want to show you how   to do basic formatting. So as you might notice I  have these three definitions of e. I have a limit,   I have a sum, and a continued fraction. Perhaps I  want to put different types of emphases on those   okay so let's imagine first that I want to  take this limit that I have and I want to   make that bold face. First thing I can just do is  double-click on that limit and Overleaf is really   nice it takes the cursor on the left-hand side  to precisely that location so here I have it in   the code as a limit now what I'm going to type is  a very common structure in LaTeX I'm going to go   backslash and then I'm going to do \textbf so text  boldface left curly brace and finally right curly   brace. We do this all the time in LaTeX as in  backslash some command and then we put the object   inside of curly braces. If I click recompile then  what happens well that limit is now bolded. It   won't always be this command you might have other  commands beyond just text boldface we're going to   see many in this video but this is the type of  thing you wrap the object that you're interested   in converting in some way in curly braces with  some sort of command on the front in this case   \textbf. Now there's actually another way to have  done this so maybe I'm going to try to go for the   sum but this time I'm going to try to make italics  I could instead have gone up here to rich text.   Rich text is adding extra menus this is all  Overleaf not LaTeX itself this is one of the   reasons why it's so convenient to use Overleaf  because I can just come here and I can select the   sum and I can use the i button the italics button  and if I go back to the source what's happening   here it's put in \textit which is the code for  italics. If I recompile it I'm going to have my   sum now be italicized so it's up to you whether  you want to memorize the commands like \textbf or   \textit or if instead you prefer the contextual  menu this rich text menu that was created by   Overleaf it's a little bit up to you. I'll do  one more this one is not on the menu this is   \underline again there's a left brace and  a right brace and the continued fraction is   inside of there and as you can imagine \underline  is just going to underline the continued fraction   so that's how you do some very simple formatting.  What I want to do next is play around with   equations I want to make better equations I want  to make fancier equations because the three that   I have right now are relatively simple. I'm  going to just observe that the way I made   the three right now was that I put an equation  when it's in its own environment what we call   a display math environment so it's sort of own  line and basically all of this code is in between   two different \[ and \]. Instead of the square  brackets I can do the following I'm going to go   \begin{equation} and same at the end I'm going  to go \end{equation} very similar idea nothing   about the actual equation in the middle e is equal  to a limit of blah blah blah I showed you how to   do all of that formatting in the previous video  but when I recompile it one thing does change   the thing that changes is that on the right  hand side now there is this 1 and basically   what's happening as soon as you go and begin  equation it now starts to number the equations.   If I did this for each one it would become 2 and 3  and so forth. So if you have a long document with   many different equations you want to refer back  to an equation well the \begin{equation} allows   you to have a numbering system but there's even  better way to refer to it maybe I want to say that   equation one was really cool something like that  now I could do that but because I manually typed 1   here if I didn't make some changes to my documents  like I would add a new equation then the number is   not going to be pointing to the right thing so  I'm going to go to my \begin{equation} and I'm   going to do something called \label{} here and  maybe I'll call this limit because this equation   is a limit. Now if I execute at this point if I  recompile at this point nothing changes because   all I was doing was creating this label that was  internal to LaTeX it's not displayed in any way   but now what I can do is in place of writing  equation 1 where I manually type 1 I'm going to go   \ref{} as in I'm going to reference my label  and I'm going to put in the name of it which was   limit all right so nothing's going to change when  I do it I'll go and do this exact thing and what   do I have is equation 1. What's relevant here is  that this equation 1 wasn't me literally typing   the number 1 it's that because I referred to the  limit and right now that limit equation was the   first equation in my document it spits out the  number one. Now I want to do a little bit more   so let me suppose that uh I have e which is  this one limit I'm going to do another limit   so I'm going to do \lim for another limit sign  underneath the limit so I'm going to do underscore   and I'm going to put a left and right brace to  put something down beneath it I'm going to do t   \to which makes a little bit of an arrow and zero  and then I'm going to put in bracket one plus t and then this is all to the power of an exponent  so I'll put the exponent sign and then another set   of braces and then I'm going to put a fraction in  here to do fractions that I do \frac and then I'm   going to do 1 on the top and t on the bottom and  if I compile that then what I get is the limit as   t goes to 0 of 1 plus t all the power of 1 over t  this is just another limit that is also equal to   e. However, I sort of don't like it you'll notice  that even though my equation in my LaTeX code here   I have it on one line and the other the LaTeX code  doesn't understand returns as something meaningful   in this context inside of an equation environment  it sort of ignores this white space that is so   what I can do instead is not use an equation  environment but use something called a line   and a line allows us to well align multiple  equations so I'm going to go a line up here   and I'm going to end my align so instead of  calling an equation it's now called an align   and I have to do one other thing to make this  work at the end of the first line to indicate   that that line has indeed ended I'm going to do  \\ and that lets LaTeX know that that's the end   of the line and the final thing I'm going to do  is just delete this label because I've got two   different equations going on here I don't need  to have that label any longer I hit recompile   and let's see what happens all right now I have  two different equations 1 and 2 here and they   occur on top of each other vertically. I don't  really like that the equal sign here and the equal   sign there are sort of offset I want them to be  nicely aligned so you can do one further trick in   this first equation where it says e equal to I'm  going to put an & and then down here in front of   this equals I'm going to put another & and notice  how right now the equal signs are away from each   other as soon as I put that ampersand in the same  spot right before the equal signs it lines them up   it's kind of like having two different columns in  a table and that ampersand says well where are you   going to split what are you going to put in the  first column what are you going to put in the   second column so basically saying we're splitting  this equation at the place where this ampersand is   we'll line up all the ampersands and stuff to  the left and stuff to the right is going to be   separated accordingly so for example there is  no left hand side of the equation on the bottom   one but maybe I'll write in some text by the way  to make text you go backslash text otherwise in   the middle of an equation it's going to look  a little bit weird uh how about this uh like   and subscribe just need something which is long  it could be anything I'll just choose that one   and notice what happens again the equal signs are  aligned and the stuff to the left of it is sort of   spread on either side of that alignment of either  side of those two equal signs and I get these two   equations 1 and 2. Now you might be thinking okay  that's great but I actually don't want this to be   thought of as two different equations 1 and 2  I really would have preferred it to be thought   of just one equation and I could give it that  single reference like I was doing before okay   how do we do that well very similar to \align I'm  actually to go right back to equation where I was   at before \begin{equation} and \end{equation}  so I'll have the same sort of structure   but now what I do is use something called split  I'm going to go \begin{split} and I'm going to go   and \end{split} as well so everything else is  exactly the same the &s are the same the end   of the lines are the same it's just instead of  being wrapped by begin and end align it's being   wrapped by \begin{equation} \begin{split} and  finally \end{split} \end{equation} look what   we get visually the exact same thing but there  is now one reference here they're sort of this   is thought of as basically one equation iI could  give it a label I could reference that label in   exactly the same way. Okay I'm going to do one  final thing for funky equations I'm going to   go down to the second point where this is as a sum  here and I'm going to try a new different equation   I'm going to do begin and by the way this is  something very cool about how Overleaf works   is you'll notice i haven't yet typed all of begin  equation but it's popping out what the different   possibilities are and as soon as i hit the first  one begin equation it automatically actually   fills out the other half of it the end equation  and so it's kind of convenient because it allows   you to just just save when you're typing you don't  have to write as much you just do begin and then   you think about the different options if you get  the first queue up just hit enter and it fills out   all the structures this is a real nice time-saving  way to do it and this is again all something sort   of overly adds on top of LaTeX just to make it  easier for you now I'm going to put in i've copied   and pasted it a big long messy expression here  and if i compile it let's just see what we get   well do you see how annoying that is this is  just the expansion for e to the x here the   first 13 terms but it's like it's going too long  that reference equation 2 is like overlapping   there's just not quite enough space so if you have  that scenario your equation is too long you can   fix that by instead of doing \begin{equation} you  do instead \begin{multline} this is for multiple   lines and similarly \end{multline} and then to  do this to figure out there's a split somewhere   in the middle you have to do that same trick  that we've done before the \\ which indicates   tells LaTeX this is the end of a line okay so  if iI recompile this notice how it just sort of   nicely splits down into two different lines it  takes up the total width but it sort of jiggers   it over top of each other and just automatically  deals with how to display it really nicely   maybe you're starting to get a bit of a sense of  the kind of precise control that LaTeX allows you   to do and why mathematicians go to it yes you have  to learn this little bit of code but then your   control afterwards is fantastic. All right next  topic I wanted to go to let's in fact start an   entire new section the fact that we had definition  of e is one section that was our first section I'm   going to do a new section and I'm going to call  it more tricks pop it out and then I've got that   more tricks and what I'm going to begin with is  by making a table. I wanna show you how to make   tables so I begin as I so often do with \begin{  and let's just see what happens if I start typing   table ah there we have this nice table environment  and we're gonna get table but I'm actually gonna   begin with the second on the list which is  tabular double click on this and it puts out   a whole bunch of very standard formatting so so  what's going on with the standard formatting well   begin tabular and tabular that makes and  closes the environment as you can expect   this thing at the top and times of braces that it  goes c | c this basically says have it be centered   and then create a vertical line down the middle of  the table and then be centered again and likewise   in the middle here you see those placeovers like  blank and blank end the line blank and blank   exactly like we were seeing before when we're  doing these sort of arrays is that the & separates   the different columns of the table and that the \\  ends it so maybe iI could say how about this one   two three and four it makes this little table  one two three and four with this vertical bar   right here because it went c | c. If I  wanted more bars then I could for example put   a vertical bar to the left and the right of  the c and that would say that you have these   columns that are centered and then you want  something to the left and the right as well   and then if I also wanted things on the top we  can make horizontal bars by going \hline so I'm   going to do a initial \hline at the very top  before there's anything then I'm going to do   another \hline in the middle and then final \hline  after everything now here there's a syntax error   and this is good to have this happen because you  see how Overleaf tells us this little red error   and it says exactly what you can't do with the  sort of \hline business and it and you can see it   sort of screwed up on the right hand side I needed  to go and end that line before I typed in \hline   I can fix that nicely and I have this nice little  table that's sort of all surrounded final thing   I'm going to do is okay let's make one that's  sort of ridiculously long I'll put a bunch of   zeros here and instead of center I could go left  or right maybe in this case I'm going to go right   just so you can sort of see what's going to happen  if I do it so basically the left column here the   first one that appears had with the c here well  that looks perfectly fine but it's right justified   in the second column now I want to improve this  table in several different ways the first thing   is I don't like that it's sort of stuck here on  the left and so I'm going to do a little trick   I'm going to go \begin and now I'm going to do  center I'm canadian I always have to remember to   spell it the american way and center as you can  imagine if you wrap something and begin{centre}   and \end{centrre} it's going to put it right there  in the center but I'd like to do more I'd like to   do the same type of thing that I've done before  with equations like I want to give it a reference   so I can refer to this table I also would like  to kind of give it a caption like I want to be   like this is table one and it tells me you know  whatever the subject of the table is so I can   do that by taking this entire thing between  \begin{center} and \end{center} that has this   \begin{tabular} and \end{tabular} in the middle  and wrap all of that in \begin the other thing   that started with t begin table and \end{table}  but now iIcan do something like \caption   and say a nifty table or something like this and  if I compile this let's see what's going to happen   it's going to be right there and it says table 1  a nifty table and it displays my table likewise iI   could come here and give it a label like uh \label  I don't know what should we call it nifty table   how about that then I can refer to that particular  label like I like table and then whatever it is   referencing and by the way it's kind of nice if  soon as you do the reference it pops up all the   things you could refer to so here I've got this  nifty table I can just go and immediately do it   let's recompile this and what we see here is I  like table one which is indeed named table one   by the way you can control these things but right  now LaTeX is just finding a nice convenient spot   within the page to display this it doesn't fit  within the remaining room on the first page   and there's nothing on the second page you're just  putting it nice in the center and the second page   if there was more text in the second page it  would move around to a logical spot which is   all quite nice to put this on the same page I'm  actually going to go and put backsplash new page   here right beneath the section more tricks and  if I do that let's take a moment to compile it   what you'll notice here is that on the new  page you get the table nice at the top then   you get your section and then your reference I  like this table one that's been put up there so   sometimes you can use things like new page just  sort of manually force things onto another page if   things aren't quite lining up exactly all right  next up I want to do something kind of similar to   tables this is adding graphics and I did show this  actually in the previous video but i want to show   more elements to it in particular I'm going  to begin with figure and again I'll hit enter   and you can see all the stuff that Overleaf is  going to pop up here a bunch of different things   now the main thing is I have to put something in  between these braces here for \includegraphics{}   so I'm going to pull myself over here and give  myself a little bit of space and what I'm going   to do is I'm going to upload a file so I'll click  upload and I'm going to select one for my computer   so the one I chose was called 100k.png and so  to reference that I'm going to go 100k now if   I try to compile it right now it actually turns  out there's a bit of a problem you can see that   there's this error here and the problem is  that this thing requires one extra thing to   work if I scroll all the way at the top I have  various packages that can be included and I need   to add one more package so it has used package  something that knows how to deal with graphics   there's several but I'm going to use graphicx as  you can see it sort of automatically pops up again   now if I click recompile it actually knows what's  going on and okay let's see what happens here okay   it's no longer red this is now going to be a says  over full which means it's too big of an image   so this has an overfull horizontal box as  the idea so it doesn't know how to display it   so what I can do here is add a little parameter to  it and parameters I put inside of square brackets   and I'm going to set the width so I'm going to say  the width is equal to backslash the text width and   this is basically saying that I'm going to make  the width of the image equal to the same width of   which there's space on the page so there you can  see I've got my graphic for when I passed my 100   000 subscribers and it's exactly the width  of that page because I've set the width   equal to text click you can make it half  the width of the page or whatever you like   I can also come here and change the caption like  I did it I can change the stock label that's put   into here to maybe 100k something like this and  if I do do that I can say I am so proud of figure   reference and now you can see there's nifty table  like we had before but there's also the 100k   one okay let's compile this and see what happens I  get my images but it says I am so proud of figure   one just like I previously had I like table one so  basically the figure environment works a lot like   the table environment they're just sort of these  larger environments that include images but the   actual calling of it is the include graphics just  like how the actual calling of the specific table   was that begin tabular and then you could add the  captions you can add the labels so you can refer   to things and put titles on all that good stuff.  All right things are moving right along what i   want to do next is talk about theorems definitions  proofs limits all of that good stuff that we use   all the time in mathematics what i need to do is  a few things to get this going basically i want to   create these custom environments to allow me to  do theorems and definitions and all those types   of things so I'm going to use another package  I'll show you a different way to actually add   packages this one is called amsthm and while we're  at it I'm going to do amsfonts as well because   I always like to have those three big standard  ams ones but right now we're going to use amsthm   and what I can do again in the preamble so the  preamble of your LaTeX document is everything that   occurs prior to the \begin{document} so I'll just  do it up here somewhere I'm going to define a new   theorem so here's how I do it I do \newtheorem and  as you can see already there's a couple different   options that appear here from Overleaf giving the  standard ones I'm going to do the second of these   the ones that takes two different parameters the  first set of braces is how I'm going to call this   environment so I'll call it theorem so if I type  theorem in anywhere like \begin{theorem} then   that's going to use this type of environment  and then the second is what it's going to be   labeled at what it's going to look like and here  I'm going to do capital theorem I care about the   capitalization because now people will actually  be able to see it this is going to do many things   it's going to create this new environment  and it's also going to deal with things like   numbering so for example begin the theorem so I'm  going to go down here into the body and I'm going   to \begin{theorem} so the same code that I put in  here and I'm going to say uh you should like and   subscribe I want an excellent theorem and then  \end{theorem} and let's see what happens so I   compile this and what you get is this whole lovely  environment this is our first theorem so it knows   that it's theorem one and this theorem environment  is going to bold face that title it puts the   number in and then it puts down in italics the  body of my theorem and this is really nice because   I can write as many theorems as I want they're  all going to be stylistically consistent without   me having to think about the styles like bolding  and italicizing things in different spaces like   I was doing before I just do this every time  it will look exactly the same and it's going   to keep track of the numbering I can go if I want  to add a title to this I can come here and i put   my title into square bracket so maybe I'll call  it uh the youtube theorem is how you should like   and subscribe and if I do this it says theorem one  and it puts it right there in brackets so you can   always get a sense of what the titles are again a  standard formatting that will always occur I can   do the same basic idea so maybe I'll come here and  do another theorem this one I won't have a title   you should like subscribe how about this ring the  notification bell we'll be quite silly about it   and and what I really want to illustrate here is  that the theorem will now be called theorem two.   Now there's one further option though  that you might want to consider   I am currently in section two so if you remember  there is section one here on definitions of e   and section two and more tricks and I've got  theorem one and two but i might want that   numbering to be associated with the fact that  I'm in section two so how would I change that   well if I go back to the top to where I define  this new theorem I can add one more property and   I'm gonna add it inside of square brackets  and this particular parameter is all about   at what level are you going to do the numbering so  if I go and write at the section level it's going   to number at the section level I could have  done subsection number or many other options   but I'm going to write section number for now  and now you see if I'm in section 2 I have   theorem 2.1 and theorem 2.2 it starts that  first number with whatever section you're in.   I can then do something similar perhaps I  should have a corollary here so I will go   corollary that's the name by which I call it  uh maybe I'll do capitalize that's not how   you spell corollary there we go and I could  have corollaries indicated by the section   however normally if you have a theorem it has  possible many corollaries that come from it   so instead of having the numbering based on  section I'm going to have the numbering based on   the theorem okay I actually have to go down here  and make a corollary so let's go\begin{corollary}   and \end{corollary} and in the beginning  I'll say and check out Overleaf as well! If I compile that notice what's going to happen  first of all the name has changed like it's a   different type of theorem it's not a theorem it's  a corollary but second look at the numbering it's   Corollary 2.2.1 and basically the idea is theorem  2.2 occurs the corollary is associated theorem 2.2   and I can have many of them they'd be 2.2.1 2.2.2  and so forth. Final thing about these theorems is   you might be like hold on Trefor you can't just  state theorems you have to prove them as well okay   I will begin my proof and here  I'll say left to the interested   subscriber to figure out the proof of that but  let's just take a look at what it looks like   and I have theorem 2.1 the YouTube theorem it  has a proof which is italicized I have the body   of the proof and then on the right hand side the  qed symbol so again this proof environment always   looks like this is standardized every single time  and it's just associated underneath the theorems   and you can make all sorts of these different  environments for other things like for example we   didn't do lemmas but you could add one for lemmas  or definitions or anything else you so chose.   All right we are getting near to the end but I  want to show you my final trick one of my favorite   things to do this is all about making entirely new  commands isn't not using the standard commands of   LaTeX or things that are added by these packages  if you want to make your own command what you do   and I actually do this quite often it's just  sort of to save myself a little bit of time so   for example the real numbers I'll do an  inline equation so in between two different uh   dollar signs and the normal way is \mathbb{R} this  by the way required amsfonts that we used earlier   okay if I compile that let's  take a look at what it looks like   and we have the real numbers and that fancy symbol  that we associate to the real numbers but I hate   having to type \mathbb{R} every single time I  want to use a symbol because I use it all the time   so one of the things I can do is I can make  a little macro that'll that just sort of   shorthands this so I'll show you how to do it I  go right back up here to where i had those new   theorems and I'm going to make now a new command  backslash new command it shows you some of the   options and I'm going to use this one here the  middle one with two different parameters in the   first set of braces I'm going to put what I'm  going to call this command I'm going to call this   \R because \R is way shorter than \mathbb{R} but  I do have to do this for the final time \mathbb{R}   I'll put those all in there and now I have  this new shorthand just type in \R and I get   that full thing. I'll show you how it works  instead of putting this all in I'll just do   \R which previously LaTeX didn't know anything  about and how to deal with it but well it looks   exactly the same because I made it look exactly  the same I'm going to show you one more slightly   more complicated type of new command you can make  imagine I want to make a column vector something i   do in linear routes for all the time so I could  do the following I could make a \begin{bmarix}.   bmatrix stands for a bracket matrix I could  then put an a and then a b and then I could   \end{bmatrix} and close my environment and  let's see what happens if I do all of that   well that's what I want that looks great that's  this nice little column vector with the square   brackets that's exactly what I want but I don't  want to type that every time but can't just do   exactly what I did previously because anytime I  make a column vector the actual a and the b here   those are going to change so really what I want to  make is a new command that has sort of inputs that   I can put two inputs in and it will spit it out to  look like this so let's go back up to where I was   doing my new commands and I'm going to do a new  command but this time I'm going to use the first   of these okay so I need to say what I'm going to  call it how about call it \cv for column vector   and then I have inside of these square brackets  I've got to put a parameter and put the parameter   2 and that's going to indicate that it takes  two different inputs and then I'm going to   go and copy and paste all of this stuff that  I had before so I'm going to take the whole   \begin{bmatrix} to \end{bmatrix} thing and I'm  going to put the whole thing in there it's just   I don't want a generic a I want whatever my first  input is so I do #1 that indicates my first input   and then for b that's going to be my second input  #2 and then I'm gonna come down here and say   I could do \cv my new name how about one and  two and let's compile that and what is I have   exactly what I want a column vector with the one  and two inside of it but I have this nice little   shorthand you can get these macros to do just  sort of all kinds of things they're very powerful   and they're going to allow you to actually make  your life easier whenever you're doing something   complicated over and over and over again just  take the time to make a little macro for it it's   gonna save it in the long run. So this video was  part two what's going to be at least four videos   in this series on LaTeX there are several more  tips and tricks that are coming down the road   for how to do more complicated LaTeX definitely  check out all the links in the description both   to Overleaf this wonderful software that allows  us to so easily write in LaTeX and work so   wonderfully in the cloud but also to some of the  documentation guides that I put down there as well   so i hope you enjoyed this video if you  did please give it a like for the youtube   algorithm you have any questions about LaTeX  or want to see something specific in the next   video leave those down in the comments and  we'll do some more math in the next video!
Info
Channel: Dr. Trefor Bazett
Views: 18,505
Rating: undefined out of 5
Keywords: Solution, Example, math, LaTeX, Intro to LaTeX, LaTeX tutorial, overleaf, bold, italics, underline, equations, align, split, multline, references, captions, labels, figures, tables, tabular, theorem, \newtheorem, \newcommand, macros, LaTeX macro, Learn LaTeX, write math
Id: -HvRvBjBAvg
Channel Id: undefined
Length: 30min 35sec (1835 seconds)
Published: Tue Aug 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.