How to use LaTeX and why all textbooks look the same

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
these are my textbooks they're the four textbooks that i have amassed over the last almost three years as an astrophysics student they are haldi resnick and walker's principles of physics bundle and blundell's concepts in thermophysics robinette's quantum mechanics and schneider's extragalactic astronomy and cosmology and they all have something in common let's have a look inside so looking at the inside of all four of these books the formatting looks all very similar doesn't it like they've but they've all got a pretty similar structure most of them are either one or two columns they use a pretty similar font all all of their section headings follow a pretty similar pattern like this with like 7.3.1 and if you ignore the content of them the fact that extragalactic astronomy is very different from quantum mechanics if you ignore the differences in content they look extremely similar so this begs the question have i just got the four most similar looking textbooks in all of physics and astronomy or is this more widespread is this something that extends through all of physics or perhaps even all of science let's go and have a look it's much the same in scientific papers as well i've pulled four papers off the archive those are pre-published place that uh people put up papers that haven't been peer reviewed yet but they hope will be peer-reviewed correct like as as accurate and put into a journal and it's much the same let's have a look we've got one here talking about the hubble uv legacy library of young stars like that looks pretty similar in format to the ones i was looking at before in my textbooks or what about this one on information theoretic measure for task complexity in deep reinforcement learning i appreciate this is a like a computer science paper um this looks pretty similar as well this is strange and what about this one this is group theory this is mathematics again it's pretty similar we don't have two column layout but you can see from the headings in the font that they're using and just how it's laid out this is very similar as well what's going on what's going on is something called latex this is something that's used by scientists all over the world and over the rest of this video i'm going to be explaining what is latex why is latex and the how is latex and yes that is a very out of order avengers reference yeah i'm thomas rintual i'm a third year astrophysics student this is my channel where i talk about science and university life and in this video i'm going to be doing a tutorial explaining a bit about latex from a beginner's perspective so no prior knowledge required and don't worry if you don't really know what latex is if you do there's timestamps in the video description below that will take you straight to the tutorial and if not then sit tight and i will explain a bit about latex and why i'm even bothering to make this video so what is latex latex is when you boil it down to a software for word processing now you might be sitting there thinking well we've already got microsoft word google docs libreoffice apple pages why do we need another one well for one thing this predates all of them and for another they all fall short in a few key areas especially if you're dealing with science that being said latex is more complicated than word pages libreoffice google docs it is a more complicated piece of software because it is not what we call a wysiwyg if what you see is what you get that's what all those other softwares are what you see on the screen is what is printed out when you press control p or whatever the shortcut is on a mac latex is different in latex we type in something called plain text there's not a control b and suddenly whatever you've highlighted is bold you've got to enclose things in curly brackets and do backslash bf it's more like coding than it is word and this is actually really useful the other key difference is that you don't print from the latex file or the tech file the dot tex what you do is you pass that into a compiler that then makes something like a pdf something that anyone can open even google chrome can open a pdf file so that's what latex is but now why why do we bother with this more cumbersome software that is harder to use is less intuitive than something like word well there's a few key advantages first one it's free the second one equations now this is the this is the big one latex was created to be good at equations being able to write them out if you've seen in any textbook or any scientific paper equations that actually look decent rather than a sort of odd string of normal characters that are trying to pretend to be math symbols if you've got that sort of weird string of characters then that's because they're not using latex the one that looks good is latex now some of you might be sitting there thinking doesn't microsoft word have an equation editor and yes it does it's actually the best of its kind and it's terrible like it is just really really bad there's also a certain advantage with bibliographies something that a lot of other software's aren't quite as good at but i'm not going to cover that in this video i'm going to make a follow-up video to this where i go into more the formatting side and also bibliographies and integration with something called mendeley which i mentioned in my video about what apps i use in my physics degree but that's not the topic for this video but it is another good advantage to latex it's just a little bit more beyond beginner level so that's the why but the bulk of this video is going to be left to the how how do we use latex i've hinted that it's not as simple as just firing up word for one thing you can't write it in word i suppose you probably could but it would be horrific and i don't even know word count tech files i'm getting off topic let's talk about editing latex now there are a few different ways to write latex now you don't do it by downloading a software called latex and you fire up and it runs you write latex in really anything technically you could write it in something like notepad so i would not recommend that a lot of people write latex in an online editor a common one is called overleaf it looks kind of like this when you open up the main project window where you can select your projects now you can create projects by going to new project blank project and calling this a latex beginner's tutorial when that loads up it gives you the base stuff you need to get started and it compiles the right hand site now compiling is the process of turning your tech file into a pdf so that's done that here now it's given as obviously the title that i gave the the project to begin with it's given you it's given us my name and march 2021. now this is what's been populated over on this side but this isn't the only way to create a latex file the other way you can do it is to use a normal editor that can edit anything overleaf is really designed for latex but i use something called atom this is a program that can edit any language so i use it currently for latex python and fortran 90. but i know other people who have used it for things like html editing and it's not the only one of its kind atom is the one i prefer because i know how it works and i quite like the interface i know other people that swear by vs code and some people who swear by sublime which is a bit older these are a bit different for example atom you open up it looks like this this is something you install on your computer and it's a bit more effort to get it running you have to actually download something called tech live or something similar to it that installs latex on your computer i'll put a link to that in the video description but it's not just quite that easy um let me open up a dot tech file and i'll show you what i mean so i've opened a new text file in atom this is a little different like at the minute this is just called untitled if i start typing then yeah you get some letters but they don't really mean anything and if i type something like oh i'm not doing this in latex but if i typed print hello world in any on any other editor you'd expect that to appear with some highlighting for example if that was in python for example then there you go lit up blue and a sort of teal color it starts telling you what these things are now we're not doing python we are we are doing latex now there's a way you can tell it to do this in atom and in vs code and spline you have to do this in overleaf you won't so if you're going to use overleaf just ignore this but i know that some people will be familiar with editors just not latex i type in latex beginners tutorial i'm going to put on hyphens here just to make it a little easier for calling things later probably not important but it's the sort of thing that can trip you up later and it makes things easier if they're just all one string of text now to make this a latex file a text file you do dot tex save and then because i manually chose python i'll have to change this to latex but it would have done it automatically had i not specified python so make that latex and then if i type in for example the first command that you need to use in latex backslash document class there you go let up in green this has started linting the file now these are all packages you have to download for atom i'll put a list with links in the video description with the ones that i use there are probably other ones that do similar if not better jobs but these are just the ones that i use anyway let's have a look at creating this our aim is that we want to go and create a pdf file that can be looked at in anything else latex is a little different from something like word in that you can't just start typing you need to tell it a few things to get going the first thing you need to be able to tell it is what sort of paper are you using for example are you using a4 a5 a3 or letter paper what are you actually typing onto so the way you do this is using this document class command the first thing you want to do to specify that is to put in some square brackets after document class but before the curly brackets so the first thing we need is we're using a4 paper so you type in that and you can also set your sort of default text size so i'm going to go with 11 points because that seems like roughly the right size for something you would print it's what i would tend to use then in the curly brackets you need to tell it what type of documents you're using this will affect things later on now most of what we're going to be writing in later will be articles so let me go with the article class this is what i tend to be writing if i'm writing a lab report or an article for a module i'm going to be writing it in document class article so let's stick with that there's then a couple of other packages that we're going to need the first one if we want to have a title that works properly is we're going to need to use the use package command so backslash use package and then the package name is auth blk another command that you should definitely put in just now is the input enc package this you want to specify uft8 i can't quite remember what that does but if i've remembered to look it up it will appear about here but it's something that i always have in mind and it's very useful to have i can't quite remember what it's for i think it's something to do with some symbols and that sort of thing everything in latex starts with a backslash at least every command backslash square brackets uft utf-8 and then input enc so that's really all we need to get going just now now we need to talk about formatting the page so where is your text going to appear this means defining margins now there we default margin sizes set in and we're going to stick to them mostly the first one is the top margin which we want to set to be zero centimeters so it's exactly where it is by default we don't want to look at even side margin that's good how far was it in spaces space is really not going to help here um now we i tend to like these to be a little take a little bit more space than the default so i'm going to set this to minus one centimeters but you can play about with it once you've got your files working because this is stuff you can change you can you just change the value and recompile it so i'm just gonna be setting up some basic ones the even side would be for even number of pages and then this one odd side margin is for odd side pages and because we don't want them looking any different uh let's go with one centimeter there as well next up is text height and text width these are how much of the space on your page it takes up so i found that a good size for text height is 23 centimeters for a4 paper so let's go with that again this is something that you can change whatever you like realistically what i'm putting in you don't need to stick with you can change it if you want again text width i'm going to go with 18 centimeters because i think that works quite well the next important thing you need to be able to do is make your title information at the minute this is going to print nothing basically title author maybe the date you put it in if you're affiliated to somewhere such as a university or a university school then you want to put that in as well so i'm going to do it for my channel at the minute i'm not going to do it for what i would do with the university because that's different so let's first have a look so the way you do titles is to do backslash title and then you type in your title which for this one is latex beginners tutorial and that would print something but it's not going to print where i want it to it's going to print something like this it's a bit too far down the page for me i want it a bit higher up so for that i'm going to use the v space command the v space command kind of does what it says on the on the tin it gives you a space in the vertical now if you make it positive you'll get things moving down the page and if you make it negative it'll move up the page so i'm going to go with minus 3.5 centimeters because that is roughly speaking how high i want it to move up the page this will all become a bit clearer once we've got enough to make the title on the page and i can show you them moving around similarly we can look at author now that for me is obviously my name for you it would be your name so author automaton tool and i'm going to go with again a v space but this one's only going to be minus three millimeters you can see where i'm going with this i've done this a few times so i know what i need for formatting i also got it over on another screen so i can double check my values again let's have a look at the next line down which is affiliation this is not necessarily one that you will use i'm going to use it here because i look it's something i've used before and i think it's important to show it but don't feel you have to use it if you don't have anything to sort of affiliate yourself with so again i'm going to use another vspace because i like i figured out what formatting i like and then this is where we're going to bring in sizes and italics so the affiliation is less important than the title of the article or your name so we're going to make it a little smaller for that we do backslash small and then open up more curly brackets let's say we want to put it in italics well here we do backslash it and then type it out so the affiliation for me at the minute is thomas runtool youtube channel make sure to like and subscribe and then finally the last thing that we need in this section is the date so when did you write it so the date is done by again i'm going to use a v space because i know my formatting that i like so it's minus one centimeter and then march 2021 now i will come on to how you can do that a little differently later on because there are different things but we're nearly there we're nearly at the point that we can have a document to show on this right hand side of the screen so let's let's do this last bit we need to do oh the next bit we need to do is to tell latex what bit it wants to actually be printing to the screen this is what's going to be contained in the begin and end documents command so what we do is we do backslash begin and then document and then the way that my editor works is added it in for me yours might not do this automatically so make sure that you've written backslash end and then document or whatever type of thing you're doing so you could be doing begin end equation for example so here we're doing begin end document and nothing that we put outside of this is going to be printed to the pdf so all this information we've just put in here in this the title author affiliation date section that's all going to be wrapped up in one command backslash make title i've done control s which is actually going to compile it for me but it's not going to show it here i can drag in my pdf that i've created i've got it over in the folder that i put the latex file in and this is what we've got here now actually my formatting is a little bit off so what i'm going to do is i'm going to change the formatting here to minus four millimeters and hit ctrl s that didn't work i'm going to change this to be minus 0.5 centimeters and there we can see that it's moved the date down and it's no longer interfering so obviously i can move things around a little maybe i want to make it 0.75 centimeters and every time i hit ctrl s it recompiles the document and shows me what's going on so here we can see we've got latex beginners tutorial my name thomas intel youtube channel and march 2021 this has been a very long walk for a rather short drink of water so what else can we do here now i mentioned that there is this section here the march 2021 now i've specified what it is but maybe you just wanted to print today's date to do that we need to use a different package specifically a package called date time it's rather intuitive so we go backslash use package date time which will give us time and date formatting this is the the percent symbol is the comment uh symbol for a latex so anything that you put behind a percent sign is not going to show up this is something i'll come to later because this could cause you problems this will then let us change this to be backslash today and then if i recompile this document it will replace march 2021 with wednesday 24th of march 2021 the date that i'm recording this video so i'm going to change this back to march 2021 but that is something you can do i want the time that was not particularly useful unless you really need it for like say date of publication of an article you've written for a newspaper or a magazine that sort of thing the other thing you might be realizing is that the bit that says latex beginners tutorial it's not particularly it's not standing out is it so i'm going to do another size thing and do backslash huge and contain my latex tutorial section and that and then recompile it and it's much bigger now it's more it's a bit clearer that being said it's not the best font and i know it's not the best font especially if you're for example dyslexic you might be having trouble reading this so i'm going to change this to be a different font that should hopefully be a little better for that we need to use a command called renew command so renew command and then in curly brackets backslash family default and then in another set of curly brackets we put in the code for the font we want so i'm going to go with phb which is i believe helvetica so this should hopefully be a little easier to read there's another fun thing we can do with latex though if i do backslash latex and recompile we can change this to that gives you the latex logo but in helvetica font so we've got as far as writing a title an author the affiliation and the date that's only the start of a document we need the rest of it writing is probably the simplest thing like writing a sentence so hello my name is thomas i can write that and it will just print it if i do ctrl s it will just recompile this to give me hello my name is thomas now that is pretty simple chances are that that's not everything you're going to want to write perhaps you're writing something financial so uk vat is 20 so this is where we might hit some problems yeah here we go uk v80 that's value-added tax or sales tax is 20. 24. i've written 20 you can see it here there's a percentage symbol but it's not appeared now that's because the percentage symbol is the comment symbol for latex to get that to show up we need to do backslash percent now if i recompile this we'll get uk that is 20 this is something that happens with a lot of symbols for example if i want to write um say say i want to write the the u.s government stimulus check is two thousand dollars or whatever it actually is and then i try and compile that then suddenly everything kind of breaks and nothing happens and that's because the dollar sign is used for math mode it's an american program that's why i'm saying math it should be maths but we need to specify that we're not going into maths mode again backslash dollar sign and we get the us government stimulus check is two thousand dollars this happens with a lot of things and it's one of the quirks of latex that can make it a little bit harder to write in for example it's easier to write the us government stimulus check is dollar sign two thousand rather than backslash dollar sign 2000 and everything like that but it's something that we just deal with because equations are so much easier so let's make a new section so i'm going to get rid of this stuff that i've written here and just say um this is a tutorial on backslash latex for beginners which has two ends not two eyes we're go so over the rest of this video we're going we're going to look at sections and subsections equations and figures subscribe and hit the bell icon to make sure that you don't miss the next part on bibliographies and more formatting so a little plug out of the way if i do control s it will print what i've said but this isn't particularly useful maybe we want to use some sections so i've i've said we're going to look at sections and subsections so maybe you want to give this the heading introduction for that we use backslash section introduction compile that and here we get section 1 introduction but maybe you don't want section one to be introduction maybe you want section zero to be an introduction well this is where we will use a command called backslash set counter now for that we want to set the counter for sections so put in section and then how much you want to change it by so maybe you want it to start from two so you put in section one and that should give us introduction being section two this could be useful if you're writing like say a chapter of a book so you're starting on chapter 12. you don't want it to say zero you want it to say 12. but that's not what we're going for here maybe we wanted to count from one like from zero like a computer does in a lot of cases well if we do set counter section minus one we'll then get counting from zero but maybe we don't want the introduction to have a section number at all so we can ignore this so we'll comment that out with a percentage sign and then use section star recompile again and we lose v0 this means that introduction doesn't have a number and then when we make the new section which since we're moving on to the next section will be equations then that should start with number one as it does here so equations are something that realistically is why a lot of us use latex it makes it a lot easier to write equations let's say we want to have a look at some different equations that are used commonly in maths and physics let's have a look at for example the area of a circle so to talk about that let's make a subsection of subsections are really useful they're in their sections inside sections and they're denoted differently so we've got subsection and we'll do area of a circle if i compile this you don't have to compile after you write every line i'm doing that to illustrate this so we've got 1.1 so it's section 1 subsection 1 area of a circle so to calculate the area of a circle we use this equation and this is where we have to do a begin and end inside a begin end so we already have our begin document to end document here we're going to do a begin equation oh and because i hit tab by accident it's how we screwed things up but that's okay we've got begin equation and end equation so what we're doing here now you don't need this much space i've just done it to make it a little bit easier so what we want to appear in our equation is the area is equal to pi times the radius squared so how we're going to do pi well it's a lot simpler than you might be thinking all we have to do is type backslash pi and then r to the power of 2. if i recompile this it will then give us so it's done things a little strangely and the formatting has kind of gone out the window so what's gone wrong well let's first ditch all this spacing and do ctrl s there we go so we've got begin equation end equation and with our equation in the middle a equals a backslash pi so that gives you the pi symbol times r the radius to the power of 2. now that gives us this over on the right-hand side now you'll notice that over the right-hand side is something i've not typed i haven't typed bracket one bracket this is something very useful in latex that allows us to refer to different things to do that we need to tell it what it should call it so here the reference is going to be found by backslash label so we're labeling this equation as circle area the reason i've said circle area is because we could quite easily do something similar with a different shape so if i do another subsection area of a cube then we've got begin equation backslash label cube area and our area is 6 times the length of a side squared we've got the area of the cube is 6 times l squared l being the length of the side so square that you get one side and there's six sides to a cube now what we've got here is equation two this is useful because we want to be able to reference our equations for example if i say the area of a circle is given by equation 1 then that's great up until the point that i do this and move the cube above it so that's not particularly helpful for us what i want to be able to do is have that number change so if i say instead of equation one i see equation tilde to keep it all in the same line in case there was a line break and then backslash ref and then i look at this now atom brings this up makes it nice and easy to see it in other softwares that might not be quite as easy but we've got backslash reference or backslash ref open curly brackets and then circle area wherever else i've misspelled circle there but that's fine the area of a cube is given by equation and again ref cube area and then if i compile this this is where it gets really clever we've got area of a circle is given by equation one area of a cube is given by equation two but what if i swap them i move my area of a cube up above my area of a circle and recompile this is where things get interesting now the area of a circle is given by equation two which is what it's reflecting here and the area of a cube is given by equation one this is really useful if you're writing long documents because you might shift things about and if you've had to manually say oh the equation for the area of a circle is given by equation one and now it's equation two but you've referenced this in like 17 other places you've now to go and manually change them this way latex does it for you it's really helpful let's have a look at a more complex one let's have a look let's make another subsection and how about we look at luminosity i'm using the i'm using the luminosity equation which is the brightness of a star because it includes some greek letters let's do a backslash begin equation and again it's being a little bit screwy with uh how it's done that just this is mostly user error on my end but it's fine as long as we've got begin equation and end equation then in the middle we can do our l is equal to now the equation for luminosity is four pi r squared the radius of the object giving off the light times sigma times t to the power of four so we'll do four backslash pi r squared times sigma t to the power of 4. and we want to call this one we'll label it as luminosity then pop that in there and we get our new subsection hopefully yep our new subsection luminosity l equals four pi r squared sigma t to the four that's exactly what we're looking for and it's really helpful so this is the sort of thing that latex is good for it's good for equation editing and shoving things in the right order but it's good for more things i'm sure you've had to put pictures figures that sort of thing in your articles before this is something of course latex can do so let's move on and do a new section which we will call figures so figures are a little bit more annoying we want this to take up half of the space on the line so let's have a look at this the first thing we're going to want to do is actually bring in a couple of new commands i've used use package and now we're going to bring in graphic x we're also going to use the package called wrap fig just to make sure everything sort of fits around it properly and we're also going to use another package called set space i think that's actually for something else but we probably do need to bring it in because it'll make formatting also nicer later on as well as geometry this is good for centering which something we want to be able to do so the first thing we're going to do is begin and then wrap fig we're then going to put it in section area one i can't exactly remember what that is and then uh 0.5 line width this means that it will take up half of the line width that's as much as it will take out before it just won't show it so for us our line width is 18 centimeters so this means that it will take up nine at most next we'll look at a little bit of formatting which is something that i've done through trial and error before i'm going to move things back 0.5 centimeters and then we're going to start centering this now we want to include graphics now this is where that file that i mentioned before comes in this one the the image file this is the picture of me it's a it's an uncropped version of what i use as my channel photo so we want to be able to bring this into the document for that we use the command include graphics but that's not particularly helpful yet it doesn't know where to look so the first thing we want to do is set its width so we've said that it won't take up any more than nine centimeters so let's let's let it use all the space it can now we need to tell it the file name now it'll look for graphic files such as jpeg or maybe png this is a jpeg so we just need to type in the file name so everything before the dot so in this case that is sta underscore 3707 now you could recall anything i've just left it as the file name that it had then if i do ctrl s and it should bring it in it now brings it in and we've got this now this isn't particularly helpful we've got a thing 10.05 what is that actually what is that ah sorry i've made a minor mistake here so actually this what we're dealing with here is me having to debug things a little but we've got this thing and it's got this 10.5 because it's not dealing with things properly what this should be is rap figure not wrap fake my mistake so we recompile it now it gives us the image but the image on its own is not particularly useful let's install a package called capped off so we'll use backslash use package capped and i need to double check if it's got a dash in it it does it's capped off with a dash this will let us do captioning so we want to put a caption of what this picture is a picture of caption of and then put in curly brackets and we'll make this small because it is a caption and we'll see this is thomas rintoul me standing outside the school of physics and astronomy in saint andrews he is wearing a navy jumper and blue jeans okay after a little bit of troubleshooting we've got it working um i wasn't really sure what was working here um but now we've done we added in this section it says label thomas now this will let us refer to it so if i say um a picture of thomas rin2 can be seen in figure and here again we're going to go with ref command thomas and then recompile this and we get like we had before picture of television tool can be seen in figure one and it's been moved on to the next page because there's not quite enough space here we can get it on the same page by doing backslash new page recompile and then we have this so it's formatting can be a little bit of a mess and because there's not enough text here it's not really clear how it's formatting things latex will just sort of put things where there's space for them and you kind of deal with it but this is not too bad you would realistically have a lot more typing here maybe a description of who i am and that sort of thing that would fill up this space so that's where i'm going to finish today hopefully this has been interesting to you it's covered a few of key things in latex i will make sure that i've posted the packages that i've used in the video description both for latex and for atom i'll give you links to overleaf and to atom to download it because i think it's really helpful as well as to tech live which will get the whole thing working there is also a lot of help files on the internet that can be really useful for getting things working when they do go wrong if you've enjoyed this video please do like and comment it's a lot longer than most videos that i've made but i feel like it's a useful thing to exist on the internet and there's not that many that are as informative for somebody writing for science in the meantime though make sure that you are subscribed and if you've hit the bell icon so you don't miss the follow-up to this where i'm going to talk about bibliographies formatting using mendeley and bib tech and in the meantime i hope you have a very good rest of your day i've been taught until and i will see you in my next video see ya [Music] you
Info
Channel: Thomas Rintoul
Views: 2,793
Rating: undefined out of 5
Keywords: LaTeX, LaTeX Editor, Science Writing, Nature, Scientific Journal, Science, University, Physics, Scientific Paper, How to use LaTeX, How to write LaTeX, How to write in LaTeX, Beginners Guide to LaTeX, LaTeX Tutorial
Id: nzXX2gc327M
Channel Id: undefined
Length: 40min 43sec (2443 seconds)
Published: Thu Apr 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.