My favorite LaTeX Tricks to save time

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
using latex to write beautiful math documents is incredibly powerful but it can be a little bit tedious behind the scenes and so in this video I want to show you my favorite tricks and tips to make writing in latex really efficient and how I just save myself a lot of time with some of these tricks I'm going to start by making a new project and I am using overleaf which is a really lovely cloud-based latex editor and the sponsor of today's video so my thank you to overleaf the first efficiency trick I want to show you is new commands if you write the same kind of cumbersome Expressions over and over again you can make a new command which is a shortcut for that longer expression it takes for example all of this code to make just this the partial derivative of Z with respect to X done in the display style I don't like doing that so what I'm going to do is in the Preamble before the begin document I'm going to make a new command so I go backslash new command and I'm going to call this backslash PD for partial derivative I like it to make take up the name that I like to use then in square brackets I'm going to give it a parameter and a partial derivative has a top and the bottom it's not always going to be Z and X it's going to be all sorts of things so we want one command that lets me do everything and so I need to have two parameters one the thing that I'm going to put up in the top and the other thing I put in the bottom and then in squiggly brackets I'm going to put in well whatever this is supposed to be so I'm going to come here and I copy everything that I've done before and I'm going to copy and paste it the only difference is I don't want Z and X because that would mean it would only ever be Z and X so I'm going to go and do number one which is the first of the two parameters and then for the X I'm going to go number two the second of the two parameters so how do I actually make this appear so I'm going to go back down into my main body I'm going to say versus and now let's do this command backslash PD that's the name that I was going to call it takes two parameters the top which is going to be Z and the bottom which is going to be X and if I compile it I hope it will look exactly the same thing and it does my next efficiency trick is about conditional formatting using an if else structure to allow you to quickly toggle on and off whether you want something displayed or don't want something displayed for example suppose this is question one something like that and then maybe I want to make some solutions but only sometimes do I want the solutions to actually be displayed maybe I want to hide them from students if it's their test for example so to do that I'm going to come up here and I'm going to make two new commands the First new command I'm going to call this how about con form for conditional formatting and what I'm going to do is I'm going to basically treat this as a variable and if it is given the name s then I'm going to do something and if it's given some other property other than S then I won't do something so let's try that I'm now going to do another new command this is the one I'm actually going to call so this is going to be called backslash solution and the solution is going to take a parameter because I'll have a big long solution that I'm going to write out so I'm going to put one parameter in the square brackets sort of like the two parameters I use for the partial derivatives and then for the thing I actually want to do I begin with an if statement the variable which was named conform is equal to S then I'm going to do something what should I do maybe I'll be like solution and then I should put whatever the solution is so I'll do number one that's the first parameter we'll just write out whatever my solution was I'm going to close my brackets and then I'm going to do also an else and this is going to happen if this conform is not an S if it's anything else how about I'll say uh there is no solution or it could just be left entirely blank then to close my conditional I started with if I'll just write it backwards back F I finally I'm going to close everything now I want to display it so I'm going to go backslash solution because that's the name of my command solution and what should I put in as the thing that goes how about like this uh is my solution whatever it's going to be if I click compile then what I'm going to get is this is question number one and then solution this is my solution now I want to toggle it on and off I'll go up to the S and I'm going to delete the S I'll just leave it blank here this if is going to fail and so now it should show the else instead let's see if it does we're going to format instead there is no solution and you can use conditional formatting for a ton of different things but I really like these little toggles that just make it way easier for me to show or not show precisely what I like to show the next trick is how to use style sheets to simplify your Preamble I've come up here and I've made a bunch of new commands and suppose I wanted to use those new commands over and over again in many different projects or maybe I just wanted it to look a little bit shorter so I'm going to control X these I'm going to click this little arrow button in overleaf to expand and I'm going to create a new file and I'm going to call my style sheet now a style sheet is not a tech file it is a DOT s t y file I'm going to create this and if I go to my style sheet I can copy and paste and those new commands that I like to say I wanted to use them over and over again now they're in the style sheet so how do I get them back in I'm going to come up here in just the same way I had you had the standard package I'm going to do another use package and this one I'm going to call it my style sheet if I hit recompile nothing should have changed and indeed it doesn't look like anything did all that it's doing now is when it sees the my style sheet package it's going over to the my style sheet and having all of that be included as part of my preamble down in the description I'll put a link to some more information about style sheet there's a lot you can do with them and a few caveats to be careful with I'll put all that link down below similar to how you could put stuff in a style sheet you can actually put chapters sections subsections anything you wish out of your main document into their own files when your projects get really large this is really convenient for just being able to focus on the specific thing that you need without tons of code everywhere as well as for compiling to not be compiling every element of a really big complicated project with lots of Graphics or whatever else it's going to be so the way I'm going to do this is I'm going to click a new file and I'm going to maybe call this a sub section one and I'll make another one of these because I need two to illustrate my point I'll call this subsection two if I go into these extra files well let's make some new sub sections I'll be like this is subsection one and it has some basic content which is just called test one I'll do the exact same thing for subsection two that'll be test two and then now if I go back to the main I want to actually have this included so I'm going to make a new section which is called multiple uh files I suppose I should also give my previous uh uh talking point of style sheets uh a section name either way section style sheet section multiple files and now what I'm going to do is backslash include and I'm going to include overly very nicely pops down all the possible files I could include I include subsection one and the same thing I'm going to do include and I'm going to do include subsection two if I compile this let's see what happens I get my sections one two three four down on the next page I get 4.1 as a subsection and down on the page after that I get subsection two it's gone and it's read in whatever is in those files now you might notice that it does these big page breaks and not like that if you don't like that instead of include you can put input if I do input a particular section then you're going to see that it happens directly after there's no new page break but include has a really powerful Advantage which is that if I go before the begin document and I write backslash include only I can list precisely the files I want to include so how about I do this I'll do SUB section two that's going to mean that only the subsection two files included so there's four there's no 4.1 but there is a 4.2 and notice that the numbering is kept track of so this is a great way for me to only include precisely the things that I want to on this iteration I'm not having to recompile section 4.1 so things are going to be really nice fast and snappy and it still keeps track of all the number and there's still a 4.2 even though 4.1 isn't for now appearing I could of course comment this out and subsection one would appear as well the next point I want to talk about is using overleaf to have multiple versions and track your changes for review I'm going to come up here to review and I'm going to take track changes and turn it to on now notice what happens if I start a new section I'm going to do a new section and I'm going to call this one tracking changes first of all I have this panel which I can toggle on and off but if I turn it off you'll notice that it's got the sort of green highlight this is the new stuff I'm doing since I started tracking my changes and when I do click review I now see this new segment that I just wrote here at 2 57 pm and I can choose whether I like it whether I don't I like it so I'm going to accept this particular thing now the tracking is off and I can hide it away I can also come up to history here and I can see all of the different versions of my project as I've gone along this just makes your whole life easier because whenever you're writing you're not thinking you have to remember every detail if you made a mistake write freely as you wish and then you can track and review and decide what things you want to keep and what things you don't this just lets me be sort of Freer and more efficient at the same time when I'm working in latex my next piece of advice I'm going to call this one be semantic semantic means I'm going to focus on meaning and not on formatting I don't want to be bogged down with how I'm going to display something I just want to write in mathematics let me give an example of how I would type set to be more semantic and less focused on formatting suppose I wanted something italicized I could compare writing text ID is the command for italics and I'll just write this but why do I want it italicized probably because I want to emphasize it in some way so instead of saying I wanted italicize thinking about the precise way I'm going to emphasize it let me instead do backslash M for emphasis and I'm going to write this if I go and compile it you're going to notice that actually there is no difference right now between these two things compare this and this they look the same but what if I'm in a different context like a theorem environment we've seen that in previous videos I'm going to make a new theorem I hit enter to autocomplete thank you overleaf and I'll write serum and Theorem one being the name first being the thing I used to call it and the second being the name and now I'm going to comment I'm going to make a new theorem by begin theorem and and Theorem in the middle of this I'm going to copy and paste that exact same code that I had before but now let's see what happens because theorems are special theorems are going to put all of their text in italics so for the first this the one I've told to be italicized compare this well it's in a sentence that is italicized italicizing it doesn't do anything but emphasis does in this sentence of italics emphasis has made it not italicized and so no now this word is emphasized so I talk about focus on the meaning and not the formatting if I wanted to change what emphasis did well there's ways to tweak that but the point is I don't have to think about how it's going to be formatted I don't have to be always thinking about what type of environment in I just know I want to emphasize a word so I use emphasis another example might be say I want another example might be let's say I want something large and bolded okay I'll do large and then backslash bold face and then like this is some big text okay that's totally great but why did I want it to be big large Tech what was the meaning was I for example starting a new segment of my document and it was like the title of kind of my new segment well if that was the reading if that was the meaning behind it then why not just use backslash subsection and write this is some big text here let's see what that's going to look like well formatting is exactly the same subsection enumerates the numbers appropriately and now the meaning of why I was trying to write big and large has been captured so there's many places when typesetting and leg tab where thinking about what you're trying to do the meaning behind it is better than focusing on the way you're going to eventually display it because maybe you want to change how you display it or maybe you just don't want to think about it at that particular moment next up I want to talk about one of my favorite packages which is the clever reference package so so I'm going to go up here I'm going to do use package and I'm going to write uh clever ref there's one R in this and I'm going to hit compile what cleverref does is help me focus on the internal labeling and reference of equations figures tables anything else in your document where you might want to refer to other parts of your document I previously used have used the standard ref commands for this now we're going to use clever reference instead I'm going to show you why it's just a lot more efficient let me imagine I have a new equation I'll start typing a few words I'll hit enter and overleaf will auto complete it and I don't know what we can do how about this I'll do the uh partial derivative of Z with respect to X I get both my equation and I get a equation number this is equation number one now suppose I want to refer to this equation somewhere else in my document I might want to give it a label so I'm going to go and go label and I like to be a bit semantic here I'm going to call this pd1 this is my first partial derivative equation some people like EQ one for like equation one but but I like to have my labels be specific to the types of equations that I'm talking about it helps me remember their meaning a little bit easier I'm actually going to take this equation and I'm going to copy and paste it a few times let me change the labels now I have four different equations they're all the same equation but they've got four different equation numbers and four different equation labels I can now refer to here's how it works I go backslash instead of ref I go C ref for ever reference and then well the simplest thing I could do is I could just write in how about pd1 for equation number one I'm going to compile it and let's see what it does the thing that clever ref focuses on is it picks out that this was in an equation environment I don't have to write the word equation it figures out that it's an equation and it writes a shorthand for equation EQ Dot and then it writes precisely the equation number one that's beside it so I had called the label partial derivative one pd1 and it spits out the number that's associated to it I can also do I'm going to do another C ref but now I'm going to list a whole bunch of ones maybe I'll do pd1 pd2 actually I'm going to go back and find that theorem that we had a little earlier here it is I'm going to give the theorem a label as well just to have something different how about I call this theorem one so then I'm going to refer to that this was theorem one th one and then maybe I'll also and then maybe actually you know what why not I'm going to throw a pd3 in there as well even though I've put it sort of out of order and look how cool it is I can do equations one to three it figures out that there's one two and then eventually three and that it should be all cleverly put together as one to three and then theorem one you might also notice that the equations which have equation are formatted the way equations are and for theorems which are formatted this way theorem one it's formatted exactly consistent so clever breath is just a really nice Lifesaver to do all of your formatting really easily you don't have to think about it you just list all of your labels my final piece of advice is to make a bunch of templates I've done videos for example on using the tixie package I've done videos on pgf plots I've done videos on tables and oddly enough I go back to those same template files over and over and over again whenever I'm doing something new so that I can copy and paste the basic sets of commands that I've already figured out from these more complicated packages and so I love having a bunch of templates that I know well and anytime I want to make a new graphic or something like this I can go back to a similar one for my template file if I make a new one I add it to my template file choose one that's closer to what I want and use that to adapt this just saves me so much time so you don't have to go and watch a new YouTube video every single time you want to make a new taxi plot now I want to thank again overleaf who is the sponsor for this latex series they have been so supportive of me I really appreciate them and I really believe in their product with overleaf you can start completely for free and get a ton of features it's actually kind of unreasonable that are still in the entirely free category and actually their upgrades are totally worth it as well some of these cool things like the tracking changes I think it can be a huge Lifesaver everyone needs a latex editor if you're writing in latex but you may as well use one that is easy it has all those quality of life features you don't need to install anything weird it just lives on the cloud you can share you can collaborate I really do like overlay so check out overleaf and with that is said and done if you have any questions or thoughts leave them down in the comments below and we're gonna do some more math in the next video
Info
Channel: Dr. Trefor Bazett
Views: 60,532
Rating: undefined out of 5
Keywords: Example, math, latex, new command, conditional latex, latex tutorial, latex tutorial for beginners, overleaf latex tutorial, how to use latex, tracking changes, overleaf history, write your own package
Id: UzMRZowz1xI
Channel Id: undefined
Length: 17min 3sec (1023 seconds)
Published: Tue Jan 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.