scripts:latex

# LaTeX

This is a compilation in progress of handy LaTeX shortcuts and packages.

# Including stuff

Use lstlisting

\usepackage{listings}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=tblr,
language=C,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\tiny\ttfamily},
numbers=left,
numberstyle=\tiny\color{gray},
identifierstyle=\color{black},
keywordstyle=\color{blue},
stringstyle=\color{red},
breaklines=true,
breakatwhitespace=true,
tabsize=4,
breaklines=true,
basicstyle=\ttfamily,
escapeinside={(*@}{@*)}
}

\begin{lstlisting}
#include<stdio.h>
#include<unistd.h>

/* Print hello world or something */

int main(void) {
printf("foobar\n");
return 0'
}
\end{lstlisting}


Sometimes you need to inline PDF files in a TeX document. Previously, I did this by just compiling and running pdfunite (from the Linux Tips page), or converting to PNG and adding a figure. There is a better way to include PDF files in a tex file.

Use the pdfpages packages to be able to include PDF files like you do images. In your header, add

\usepackage[final]{pdfpages}

Where you want to include the PDF file, you can use the following snipped

\includepdf[pages=-,pagecommand={},width=1.0\textwidth]{file.pdf}

You may need to experiment with the width. With my file, I had to use width=1.3\textwidth, since my PDF file included it's own margin as well, which was being added to the margins of the LaTex file. You can also include a single page by giving a page number such as with pages=1 instead of pages=- which includes all pages. Finally, file.pdf is the filename.

This is super useful to get the names of math icons where you know the shape but not the name. Draw the symbol on this site and it will tell you that the command is: http://detexify.kirelabs.org/classify.html

# Formatting

LaTeX indents paragraphs by default. Sometimes this is annoying. You can avoid indenting a given paragraph by starting it with

\noindent

If you wish to disable indents on the whole documents, you can make a macro defined in the heading as follows:

\setlength{\parindent}{0pt}

Alternatively, one can use

\renewcommand{\headrulewidth}{0pt}

You can easily set and change between line spacing using the setspacing package.

\usepackage{setspace}

Then, at any point, you can change the spacing using

\doublespacing
\onehalfspacing

etc to change between the different options.

Alternatively, you can use \linespread{2.0} but changing between double/single spacing with the setspace stuff is more convenient.

\usepackage{hyperref}
\hypersetup{
}