Skip to main content

LaTeX

Setup

I used to write with the excellent Texifier but have switched to VSCode and the LaTeX Workshop plugin. You will need TinyTeX installed.

# Install TinyTeX. Note that this may require Superuser privs since the
# binary ends up in /usr/local/bin
curl -sL "https://yihui.org/tinytex/install-bin-unix.sh" | sh

# Optional: Restart shell or open a new session. Now install some packages.
# Errors on a few ones. Fix later.
tlmgr install amsmath adjustbox algorithm algpseudocode amsfonts amsthm changepage csquotes empheq fontawesome fullpage graphicx,booktabs,array graphicx,subcaption,titlesec hyperref longtable multicol multirow tabularx tikz

Fire up VSCode and create a new .tex document. Adapt the document template below, pick "SyncTeX from Cursor" in the command palette1 to see live-previews! 🤩

You can now configure your environment as much as you'd like based on this excellent article.

Formatting

Makes your TeX files more readable (especially tables and lists!). On macOS, install LaTeX Indent via brew install latexindent2. Then go to your VSCode Settings and add this:

{
"latex-workshop.formatting.latex": "latexindent"
}

References and Resources

My Document Template

\documentclass[twoside,11pt]{article}

% Set some margins, set the typeface, do not indent paragraphs,
% adjust paragraph line heights.
\usepackage[margin=0.75in]{geometry}
\renewcommand{\familydefault}{\sfdefault}
\setlength{\parindent}{0em}
\setlength{\parskip}{0.75em}

\usepackage{amsmath, amsfonts, amsthm}
\begin{document}

% =============================================================

\begin{center}
{\LARGE \textbf{Homework I}}\\[0.5em]
{\large Nikhil Anand (\texttt{XY1122})}\\[0.5em]
\textit{Submitted \today}
\end{center}

\noindent\rule{\textwidth}{0.5pt}

% =============================================================

% Here be content...

% ======================= REFERENCES ==========================

% Equation. Entire block numbered.
\begin{equation}
\begin{aligned}
E & = mc^2 \\
\implies E & = \sum_{x=2}^{\infty}\frac{y^x}{x!} \\
F & = ma \\
F & = ma \\
F & = ma \\
\end{aligned}
\end{equation}

% Equation. Selective labeling.
\begin{align}
E & = mc^2 \label{eq:einstein} \\
F & = ma \nonumber \\
pV & = nRT \label{eq:ideal_gas}
\end{align}

% Tables
\begin{table}[h!]
\centering
\begin{tabular}{|l c |r|}
\hline
Constant & Symbol & Value \\
\hline
Speed of light & $c$ & $3.00 \times 10^8 \,\text{m/s}$ \\
Gravitational constant & $G$ & $6.67 \times 10^{-11} \,\text{N m}^2/\text{kg}^2$ \\
Planck constant & $h$ & $6.63 \times 10^{-34} \,\text{J s}$ \\
\hline
\end{tabular}
% Label should go right after Caption
\caption{Physical constants used in the experiments}
\label{tab:constants}
\end{table}

% Refer to Equations with \eqref{} and Tables with \ref{}

% =============================================================

\end{document}

Footnotes

  1. Cmd+Shift+p on macOS and Ctrl+Shift+p on poorer platforms.

  2. There's [tex-fmt](https://github.com/WGUNDERWOOD/tex-fmt) that's written in Rust but it doesn't do tables well.