A collection of LaTeX code I find useful. Code in this page is licenced under CC0 1.0.
The Not So Short Introduction to LaTeX is a great introduction to LaTeX. This text has translations to many languages.
There is also a lot of tutorials at Overleaf (which is also a full-blown TeX editor).
For graphics, the TikZ manual is good. An unofficial .html
version of the TikZ manual can be found here.
For slides, I recommend beamer.
When writing conference papers, it is convenient to have an automated warning if the paper is too long. I put the following code on the end of the text (before or after bibliography, depending on the page restrictions):
\ifnum \thepage>10
Paper is too long!
Currently {\thepage} pages.
\PackageWarning{}{Paper is too long!}
\fi
Remember to put the right page limit in the place of 10. This may not be the prettiest way of doing it, but it works.
.png
I have a handy figure_generator.tex
file to produce standalone TikZ pictures. I just need to put the figure code in the file and run it once to get it as a .pdf
file.
As an example, to produce the figure
I use the code below:
\documentclass[border=1mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{tikz}
\begin{document}
\tikzstyle{world}=[circle,draw,minimum size=7mm,inner sep=0pt]
\begin{tikzpicture}
\node[world] (z) at (0,0) {$w_0$};
\node[world] (a) at (1,0) {$w_1$};
\node[world] (b) at (2,0) {$w_2$};
\node[world] (c) at (3,0) {$w_3$};
\node (d) at (4,0) {$\cdots$};
\node[world] (e) at (5,0) {$w_{n}$};
\draw[->] (z) -- (a);
\draw[->] (a) -- (b);
\draw[->] (b) -- (c);
\draw[->] (c) -- (d);
\draw[->] (d) -- (e);
\node (el) at (5.5,-0.2) {$P$};
\end{tikzpicture}
\end{document}
The standalone
class makes .pdf
file have the same size as the figure. The border
option adds some padding to the figure (sometimes some parts stay hidden). Other than TikZ, the loaded packages are for convenience. Substitute contents of tikzpicture
and the TikZ style by your own code.
I use ImageMagick to convert and edit the resulting .pdf
file.
To transform the .pdf
into a .png
, I run:
magick -density 300 figure_generator.pdf a.png
Since my blog is always in dark mode, I want the figure to be white with transparent background. To do so, I run:
magick a.png -channel RGB -negate negate_a.png
An empty .tex
template if available here.
I use the following style for my beamer
slides:
\useoutertheme[subsection=false,shadow]{miniframes}
\useinnertheme{default}
\usefonttheme{serif}
\beamertemplatenavigationsymbolsempty
\usepackage{palatino}
\setbeamerfont{title like}{shape=\scshape}
\setbeamerfont{frametitle}{shape=\scshape}
\renewcommand\refname{\scshape References}
\definecolor{TohokuPurple}{RGB}{65,59,156}
\definecolor{UFGBlue}{RGB}{0,103,172}
\definecolor{UFGBlueLight}{RGB}{161,184,214}
\setbeamercolor*{lower separation line head}{bg=TohokuPurple}
\setbeamercolor*{normal text}{fg=black,bg=black!10}
\setbeamercolor*{alerted text}{fg=red}
\setbeamercolor*{example text}{fg=black}
\setbeamercolor*{structure}{fg=black}
\setbeamercolor*{block title}{fg=black,bg=black!20}
\setbeamercolor*{block body}{fg=black,bg=black!15}
\setbeamercolor*{palette tertiary}{fg=black,bg=black!20}
\setbeamercolor*{palette quaternary}{fg=black,bg=black!20}
For most of the details, I recomment looking at the beamer
user guide. I define the colors for the universities where I did my undergrad and PhD.
The command \beamertemplatenavigationsymbolsempty
hides the the navigation icons from the slides. I've heard of only one person who uses these symbols, and their beamer
setup is very unusual.
I'd also recommend loading the packageappendixnumberbeamer
to omit the slides in the appendices from the slide count; and to load beamer
with the option compress
to make all navigation bars on the slide as small as possible. Less cruft is better.
It's better when a proof fits one slide, but sometimes it's not possible. I use the following code to for proofs which do not fit one slide:
\makeatletter
\newenvironment<>{proofs}[1][\proofname]{
\par
\def\insertproofname{#1\@addpunct{.}}
\usebeamertemplate{proof begin}#2}
{\usebeamertemplate{proof end}}
\makeatother
If a proof needs n slides, use proofs
environments on the n-1 first slides, and a proof
environment on the last.
I use \input{file_name}
to divide a .tex
file into many files. file_name
is not compilable by itself, but the main file compiles smoothly.
Download a minimal working example here (.zip
, 94KB).
I write my CV in LaTeX using a template by Dario Taraborelli.