LaTeX code snippets
LearnLaTeX has some high quality tutorials, resources, and more interestingly, a nice online compiler!
βΉοΈ Also see my leaf.sty package for useful configurations.
Generalπ
LaTeX via Imagesπ
This is the last thing one should use since images arenβt accessible, and terrible to manipulate. Many platforms, however, do not leave a choice (e.g. Github Markdown). As a stop-gap, use CodeCogs Equation Editor 1 to generate SVGs of equations. Hereβs the Bayesβ rule,
generated through the URL,
https://latex.codecogs.com/svg.latex?p(x&space;\mid&space;y)&space;=&space;\frac{p(y\mid&space;x)p(x)}{p(y)}
Package Conflictsπ
Often, packages may be loaded transitively and conflict with a previous declaration. To avoid such scenarios, pre-emptively send in package options.
% {<options>}{<package_name>}
\PassOptionsToPackage{pdftex}{graphicx}
A good place is in the preamble right before any other package imports. In this
case, any subsequent import of the graphicx
package can be done as
\usepackage{graphicx}
which will implicitly also pass the desired option. This is helpful when another
package wants to load graphicx
with different options. Effectively, this
command will append to the options list. This may not always be the best solution
but should work for most cases.
Localize Settingsπ
Just wrap everything inside
\begingroup
...
\endgroup
or
\bgroup
...
\egroup
Wrapping Figure Around Textπ
% "r" for right, "l" for left
\begin{wrapfigure}{r}{0.5\textwidth}
...
\end{wrapfigure}
Clean up Referencesπ
Use rebiber. An example command:
rebiber -i references.bib -r pages,editor,volume,month,url,biburl,address,publisher,bibsource,timestamp,doi
Equationsπ
Avoid Inline Splittingπ
This is often helpful in two-column formats where the inline math can split over
multiple lines. To the reader, that looks ugly and distracting. The solution is
to simply wrap the equation with curly braces {}
.
This inline equation ${a^2 + b^2 = c^2}$ will not split over multiple lines.
Split Long Equationsπ
Inside align
environments, use split
. {}&
for alignment and the usual new line \\
for split points.
\begin{align}
a = b + c \\
\begin{split}
z^2 = {}&x^2 + \\{}&y^2
\end{split} \\
...
\end{align}
Tablesπ
Fit Oversized Tableπ
To make a table fit automatically across the width, use
\begin{adjustbox}{width=\linewidth}
\begin{tabular}
\end{tabular}
\end{adjustbox}
In fact, this may just work for anything.
Wrap Textπ
\begin{tabular}{l|l}
Cell & \parbox{.5\linewidth}{This is a very long text that will wrap}
\end{tabular}
Column Spacingπ
\setlength{\tabcolsep}{1pt}
Table Merge Columnsπ
% <column size> (2), <type> (c), <content>
\multicolumn{2}{c}{...content...}
Footnotesπ
-
The range of LaTeX math grammar this supports is unclear. β©