LaTeX
I typeset all of my notes and homework in LaTeX, using Vim as my text editor, with the VimTeX plugin for Vim+LaTeX incorporation, and the Ultisnips plugin for fast snippets while typesetting. All my diagrams are typeset with the TikZ and PGFPlots packages manually.
Inspiration to move over to Vim for LaTeX documents came from Gilles Castel's amazing blog post about his workflow. Most of my initial snippets were taken directly from this post, and I built up many others over time.
Tips
LaTeX can be hard to get used to, and has a decent learning curve. My largest tip is just to keep practicing—you'll only get better by continuously typesetting documents. I've only just gotten to the point where I can typeset live during lectures, and I've spent the past 2 years getting used to LaTeX and finding my own workflow.
Another huge tip is to Google everything you get stuck on as you typeset—eventually, you'll find yourself remembering more and more commands and environments, slowly getting over that learning curve.
Typesetting is very time consuming as you're starting out—be patient! You'll slowly build up speed and familiarity as you go, so don't immediately give up if you find that typesetting homeworks takes twice as long as writing everything by hand (or longer).
Custom Preamble
Here is a link to my current preamble.sty file,
and here is a link to a minimal version of the
physics package that I compiled from the package sources, containing only the \qty
command and the modified math commands.
My preamble is always evolving as I typeset more, and I will periodically update the version on this page.
The current version of the preamble should be compatible with TeX Live 2023
(there are likely some incompatibilities with TeX Live 2022, since many packages had breaking changes).
Note: it is not the best idea to use my preamble as-is, if you are looking for a long-term solution; you'll likely have no idea which packages are included and how to use any of the commands/environments I've defined.
I suggest using my preamble as inspiration for what to include in your preamble, or how to structure your custom preamble—this way, you'll know exactly what you're doing, and you'd have full control over what packages to add to suit your needs.
I provide my preamble and full documentation in hopes that I can help others in the process of learning LaTeX, and ease their transition into typesetting. The purpose of sharing my preamble is to give a supplement for learning, not as a drop-in default preamble. Thus, I highly suggest you read through the source code yourself and adapt it to your needs, referencing the below documentation if necessary to clarify any details.
Usage
You may include this preamble within your documents with \usepackage[flags]{preamble}.
To make the preamble.sty file available globally, put the file in
~/texmf/tex/latex/
(you may have to update your settings in your local TeX distribution);
I have it as ~/texmf/tex/latex/styles/preamble.sty.
Here are the possible options that you can use with my preamble; you can include multiple,
but flags specified later will override the previously specified flags.
You can include the flags as \usepackage[flag1,flag2]{preamble};
here, flag2 will override flag1.
Groups
-
homeworkEnables:
tikz,circuitsIncludes all packages for diagram creation (TikZ, PGFPlots, and CircuiTikZ).
If necessary, one can use the
noenumerateflag to revert the enumerate changes. -
lectureEnables:
tikz,circuits,tcbtheorems,fancysections,bibtexInitializes commands and theorem environments for typesetting lecture notes, and also includes all packages for diagram creation. Also configures the
biblatexpackage for references.The
\lecture[date]{title}command is added to start lectures, and theexample,definition,theorem,lemmaandcorollaryenvironments are added as well, using colored boxes. All of these environments have optional arguments\begin{environment}[title][label]. Labels can be referenced by prefixingex:,def:,thm:,lem:orcor:respectively to thelabelspecified in the environment.Lists of theorems, definitions, etc. can be typeset with
\listoflistname}. All list names are the environment names, with the prefixtcb; for example, to get a list of theorems, you would write\listoftcbtheorem.This is usually the group that includes the most packages and commands.
-
cheatsheetEnables:
tikz,circuits,narrowmargins,cheatsheetlengths,smallercomponentsInitializes page margins (narrower margins) and spacing for cheatsheet creation. Also includes all packages for diagram creation.
Best used with the
multicolsenvironment to include two columns in the cheatsheet. See the cheatsheets linked on the coursework page for reference. -
beamerEnables:
tikz,circuits -
examEnables:
tikz,circuits
Changes package settings to be compatible with the beamer document class.
I don't use beamer too much at all, so I may update the preamble at some point
breaking this flag.
To be used with the exam documentclass (i.e. \documentclass{exam}).
Adjusts various settings to ensure compatibility with the document class.
Options
-
tikz,notikzDefault: enabled
Includes or excludes the TikZ and PGFPlots packages, respectively.
If set, the CircuiTikZ package will automatically be loaded, and the
circuitsflag will do nothing.If unset, the CircuiTikZ package will never be loaded, even if the
circuitsflag is set. -
circuits,nocircuitsDefault: disabled
Includes or excludes the CircuiTikZ package, respectively.
The latter is most commonly used in
[tikz,nocircuits]to include TikZ but exclude CircuiTikZ. -
tcbtheorems,notcbtheoremsDefault: disabled
Initializes theorem environments with the
tcolorboxpackage, making them fancier than the default environments.Most commonly excluded if there is no need to define any theorems in lecture notes; in this case,
[lecture,notcbtheorems]would be used. -
narrowmarginsDefault: disabled
Makes the margins smaller (0.6 inches instead of the default 1 inch).
-
fancysections,nofancysectionsDefault: disabled
Defines the
\lecture[date]{title}command for fancier lecture headers. -
smallercomponentsDefault: disabled
Decreases the size of CircuiTikZ components to 80%.
-
mintedDefault: disabled
Includes the minted package.
Provides syntax highlighting for code listings. Requires the Pygments package to be installed in the system Python interpreter.
The Pygments style used is my custom port of the Atom One Light color scheme, and will fallback to the default Pygments style if not installed. Additionally, in homework answer environments, the background color of minted code blocks is changed to a light blue to differentiate between answer code blocks and problem statement code blocks.
This option also defines a new
tmintedenvironment, utilizing thetcolorboxpackage for fancier formatting of the code blocks. In particular, you can add titles to your code blocks, customize the background and borders, along with additional positioning options, allowing the code blocks to be placed side-by-side in a page, etc. Using atcolorboxalso tends allows for better page breaking within a code block, though it's not always perfect (much like the defaultmintedenvironment).The custom
tmintedenvironment takes in a new custom argument that is passed directly to the underlyingtcolorboxenvironment. Formally, the syntax is:\begin{tminted}[minted options]{language}[tcolorbox options]For side-by-side placement of code blocks, the
tcbrasterenvironment can be used (provided by thetcolorboxpackage). A customsidebysiderasterstyle is defined as well to make the configuration a little easier. -
tcbmintedDefault: disabled
Enables the minted package, with code blocks displayed using the
tcolorboxpackage.See the
mintedoption for more details.Completely replaces the original
mintedenvironment with the customtmintedenvironment. This may cause issues if there are already existingmintedenvironments in the document, created without this option enabled. -
pgfexternalDefault: disabled
Externalizes all TikZ figures.
TikZ ships with the
externallibrary, which saves all TikZ diagrams as their own separate files in an auxiliary directory, so that they can be loaded in a lot quicker in continuous compilation. This flag enables this package, while also setting some internal options to ensure that all auxiliary files are put in the correct directory.Internally, there is a hard-coded
\auxdirvalue, set toout; this should be the outer directory in which all external figures are stored. Figures are stored in an inner directory, named by the original.texfile. -
asymptoteDefault: disabled
Includes the
asymptotepackage. This is not included by default with any of the groups, and requires the external asymptote program to be installed.A fair warning that the Asymptote documentation is quite bad, and I've spent countless hours trying to make sense of the options. Since then, I've fully switched over to using TikZ for diagram creation.
-
minipagerestore,nominipagerestoreDefault: enabled
Restores the
\parskiplength inminipageenvironments.By default,
minipageenvironments resets the\parskiplength to zero, which can cause some uneven formatting. This setting restores the\parskipvalue insideminipageenvironments, and is enabled by default.There shouldn't really be a reason why you'd disable this, unless you prefer the modified
\parskipvalue. -
timesDefault: disabled
Overrides the font settings to use Times New Roman fonts.
The default font I use in my LaTeX documents is Utopia font from Adobe, through the Utopia package.
However, some people may prefer Times New Roman (which is the font I've used prior to switching over to Utopia), and this setting allows for a clean and seamless switch.
There are a few internal changes regarding certain symbols and commands that are present in one font and not the other; a fair warning that these differences are not all covered, as I don't typically use this setting anymore.
-
lecturenewpageDefault: disabled
Adds a
\newpageafter every call to\lecture.This option should only be used in conjunction with the
lectureoption group.Some people prefer to have each lecture start on a separate page, and this option modifies the lecture header commands to start on new pages. I personally prefer the lectures to flow continuously without starting a new page, as sometimes it can leave awkward mostly blank pages at the end of lectures.
-
bibtexDefault: disabled
Includes and configures the
biblatexpackage.The citation style that is configured uses the
alphabeticstyle that comes withbiblatex. Other options are also set; ex. line breaks within URLs, and disabling URLs in citations (as they tend to clutter the citation and cause line overflows; the DOI and other identification numbers are usually sufficient for locating the reference).To utilize citations with
biblatex, you need to define a.bibfile containing the citations in thebibtexformat. This file can be included in your source code through\addbibresource{filename.bib}, and the bibliography can be printed through\printbibliography.By default, if
fancysectionsis enabled, the bibliography header will match the lecture headers (i.e. displayed inside a fancy box). -
refsegmentsDefault: disabled
Adds reference sections after each lecture section.
By default, the
lectureoption group allows for a reference section to be added at the end of the document through\printbibliography. This option also adds automatic biliographies to be inserted after each lecture section, containing only references used in the section.This option is especially useful if you want the lectures to be distributed standalone (along with the
lecturenewpageoption), as all the necessary citations will be connected directly with each lecture. -
colorlinksDefault: disabled
Enables link colors throughout the document.
By default, all links in the document are not colored; the links use the original text color. Sometimes, (ex. in a document with many figures) you may want the links to be colored in blue, so that they are more easily identified. This option will enable these link colors.
However, note that the links in the table of contents will also be colored, which may not be the intention. To get around this, surround the table of contents commands (i.e.
\tableofcontents) with curly braces, and add\hypersetup{hidelinks}as the first line inside the braces.That is, it should look like
{\hypersetup{hidelinks}\tableofcontents}. The curly braces ensures that the\hypersetup{}command only applies locally, and does not apply to other parts of the document.