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
  • homework

    Enables: tikz, circuits

    Includes all packages for diagram creation (TikZ, PGFPlots, and CircuiTikZ).

    If necessary, one can use the noenumerate flag to revert the enumerate changes.

  • lecture

    Enables: tikz, circuits, tcbtheorems, fancysections, bibtex

    Initializes commands and theorem environments for typesetting lecture notes, and also includes all packages for diagram creation. Also configures the biblatex package for references.

    The \lecture[date]{title} command is added to start lectures, and the example, definition, theorem, lemma and corollary environments are added as well, using colored boxes. All of these environments have optional arguments \begin{environment}[title][label]. Labels can be referenced by prefixing ex:, def:, thm:, lem: or cor: respectively to the label specified in the environment.

    Lists of theorems, definitions, etc. can be typeset with \listoflistname}. All list names are the environment names, with the prefix tcb; for example, to get a list of theorems, you would write \listoftcbtheorem.

    This is usually the group that includes the most packages and commands.

  • cheatsheet

    Enables: tikz, circuits, narrowmargins, cheatsheetlengths, smallercomponents

    Initializes page margins (narrower margins) and spacing for cheatsheet creation. Also includes all packages for diagram creation.

    Best used with the multicols environment to include two columns in the cheatsheet. See the cheatsheets linked on the coursework page for reference.

  • beamer

    Enables: 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.

  • exam

    Enables: tikz, circuits

  • To be used with the exam documentclass (i.e. \documentclass{exam}). Adjusts various settings to ensure compatibility with the document class.

Options
  • tikz, notikz

    Default: enabled

    Includes or excludes the TikZ and PGFPlots packages, respectively.

    If set, the CircuiTikZ package will automatically be loaded, and the circuits flag will do nothing.

    If unset, the CircuiTikZ package will never be loaded, even if the circuits flag is set.

  • circuits, nocircuits

    Default: disabled

    Includes or excludes the CircuiTikZ package, respectively.

    The latter is most commonly used in [tikz,nocircuits] to include TikZ but exclude CircuiTikZ.

  • tcbtheorems, notcbtheorems

    Default: disabled

    Initializes theorem environments with the tcolorbox package, 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.

  • narrowmargins

    Default: disabled

    Makes the margins smaller (0.6 inches instead of the default 1 inch).

  • fancysections, nofancysections

    Default: disabled

    Defines the \lecture[date]{title} command for fancier lecture headers.

  • smallercomponents

    Default: disabled

    Decreases the size of CircuiTikZ components to 80%.

  • minted

    Default: 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 tminted environment, utilizing the tcolorbox package 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 a tcolorbox also tends allows for better page breaking within a code block, though it's not always perfect (much like the default minted environment).

    The custom tminted environment takes in a new custom argument that is passed directly to the underlying tcolorbox environment. Formally, the syntax is: \begin{tminted}[minted options]{language}[tcolorbox options]

    For side-by-side placement of code blocks, the tcbraster environment can be used (provided by the tcolorbox package). A custom sidebysideraster style is defined as well to make the configuration a little easier.

  • tcbminted

    Default: disabled

    Enables the minted package, with code blocks displayed using the tcolorbox package.

    See the minted option for more details.

    Completely replaces the original minted environment with the custom tminted environment. This may cause issues if there are already existing minted environments in the document, created without this option enabled.

  • pgfexternal

    Default: disabled

    Externalizes all TikZ figures.

    TikZ ships with the external library, 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 \auxdir value, set to out; this should be the outer directory in which all external figures are stored. Figures are stored in an inner directory, named by the original .tex file.

  • asymptote

    Default: disabled

    Includes the asymptote package. 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, nominipagerestore

    Default: enabled

    Restores the \parskip length in minipage environments.

    By default, minipage environments resets the \parskip length to zero, which can cause some uneven formatting. This setting restores the \parskip value inside minipage environments, and is enabled by default.

    There shouldn't really be a reason why you'd disable this, unless you prefer the modified \parskip value.

  • times

    Default: 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.

  • lecturenewpage

    Default: disabled

    Adds a \newpage after every call to \lecture.

    This option should only be used in conjunction with the lecture option 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.

  • bibtex

    Default: disabled

    Includes and configures the biblatex package.

    The citation style that is configured uses the alphabetic style that comes with biblatex. 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 .bib file containing the citations in the bibtex format. This file can be included in your source code through \addbibresource{filename.bib}, and the bibliography can be printed through \printbibliography.

    By default, if fancysections is enabled, the bibliography header will match the lecture headers (i.e. displayed inside a fancy box).

  • refsegments

    Default: disabled

    Adds reference sections after each lecture section.

    By default, the lecture option 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 lecturenewpage option), as all the necessary citations will be connected directly with each lecture.

  • colorlinks

    Default: 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.