Perfect Emacs Org Mode Exports to LaTeX – Straightforward Emacs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to another straightforward emacs video today we'll discuss exporting emacs org mode files to beautifully set the tech pdfs anyway we'll be going from this simple org file to this super nice latex pdf an impressive result in my opinion if you liked the video please consider leaving a like and subscribing it helps a lot and also if you have any questions leave a comment i try and reply to all of them first a few prerequisites you should have both basic org mode and latex knowledge to follow along effectively you'll also need a locally installed latex compiler i've provided a link to install one if you haven't already with that out of the way let's make our first export in the header of your file you're going to want to place the three lines i have on the right here which i'll go over briefly first hash plus latex underscore class article this defines the class we'd like to use article is the most common and probably the one you want next the options letter paper defines obviously the paper size that we'd like to use and goes along with the class finally hash plus options toc colon t now this enables the table of contents which by default is on but i'm just putting it here so you can disable it if you'd like and to do that you change t to nil so i'll paste in these three lines with that done to export let's run org export dispatch after this i'll be using my custom key binding to call a command once in press l for latex and o for pdf and open and you see our pdf was both compiled and opened after this i'll be using just the p option to generate a pdf but not open it and we'll view the pdf together in the firefox window on the right but in any case the pdf file will export to the same directory as the org file you generated it from so feel free to view it however you'd like now this pdf is nice but there are a few things that could be improved for example the ugly link highlighting and the ugly source code blocks down here and we definitely want a way to include custom latex options and headers so let's see how to do that before we continue i'd like to briefly explain the idea behind what we're about to do now when you export an org mode file to latex by default a bunch of headers and different packages are added in and not everyone likes that personally i would rather include the packages i need from scratch and make sure everything i need is included and what i don't need isn't included so to do that we create our own class which i've called org plain latex and all it includes is the bare minimum after that we build our own file called a setup file and linked to it in the file we'd like to export now in that setup file are a bunch of lines prefixed with latex header and after that are simply latex used packages and different configurations that will be included directly in the exported file here's what it'll look like right here and everywhere where you see latex underscore header will be eliminated and only what comes after the line will be included in the file this way everything you see right here which my file is actually over 40 lines long instead of manually adding that to each file you can simply add a single line adding your setup file that will link it directly another benefit of this is you have no reliance on local files or packages so after you've exported the text file it can be shared sent around compiled somewhere else without needing to send along any extra files with that out of the way let's put in our org plane latex class open your init.el or wherever you put your configurations.spaceemax or maybe your doom configuration file whichever it is paste in the chunk i've highlighted right here and restart emacs after that you'll have access to the org plain latex class also note you'll want to have some basic latex prepared for your setup file feel free to dig around on the internet for a template or use mine which i provided in the resources next let's create the setup file which will hold all of your latex code make a new file with a.org extension and start it off with the following headers most importantly hash plus latex underscore class or plain latex this ensures we'll use the class that we just went through all the trouble to create an install then just like before we'll make sure we're using letter paper and a few more latex header use package l modern ensures we have the right font and use package auto input enc make sure we have the right encoding now from here it's all up to you what you put in just note that everything must be prefixed with a hash plus latex underscore header colon in the resources file i have a few used packages that you'll definitely want to install to make everything work properly when exporting from org mode like tables links math graphics and stuff like that just to show you briefly on the right side is a dot sty file which contains all of the headers that i would have included in a normal latex file if i were writing it manually now i've taken the majority of these lines and brought them over into the separate org file that we just created together for my export the setup file and i've prefixed each of them with the hash plus latex header so for example when we use geometry over here on the right side we use geometry over here on the left side and it'll include it in exactly the same way as if you were writing this latex code yourself except it's automatically generated by org mode now that we've finished our setup file let's link to it and export in the document we're working on earlier i'll start off by deleting the three latex lines i put in first then i'll add in the following line hash plus setup file colon then simply list out the full direct path to your setup file i have it right here so i'll just paste it in and there we go that's all everything in the setup file that we wrote earlier will magically be included in this org file when it's exported so let's give that a go i'm going to run org export dispatch and open the pdf file as you can see there are some notable differences between this file and the one we created earlier it has different margins different spacing the link colors look much better and the math looks a bit better as well now we still need to go over code and that's a bit out of the scope of this video though i will include some resources to make your code formatting look correct when you export to latex to finish let's do a quick recap of what we went over in the video first we did a basic latex export with minimal options then we created the org plain latex class and made a setup file that included all of our latex code lines an easier more effective and usable way of including custom packages and configurations in your automatically generated text file finally we included that file with the hash plus setup file option and generated a great looking pdf from that file i hope i made the steps as clear as possible but please feel free to leave a comment and i'll do my best to clarify i'd like to note that while this is not the only way to configure latex exports i believe it is far more effective than other options as you only need a single file if you're so inclined you could even make a library of setup files one for each document type that you'd like to export anyway i hope this video helped you create some beautiful pdfs if you liked it please consider leaving a like and subscribing and if you didn't like it or have a question please let me know down in the comments i try and reply to all of them
Info
Channel: Jake B
Views: 29,115
Rating: undefined out of 5
Keywords: emacs, orgmode, org mode, org, mode, export orgmode, latex, tex, LaTeX
Id: 0qHloGTT8XE
Channel Id: undefined
Length: 8min 6sec (486 seconds)
Published: Sun Mar 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.