scripts:latex

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
scripts:latex [2022-04-12 19:09] Tonyscripts:latex [2022-04-26 07:53] (current) Tony
Line 1: Line 1:
 +====== LaTeX ======
 +
 +
 +This is a compilation in progress of handy LaTeX shortcuts and packages.
 +
 +
 +====== Including stuff ======
 +
 +===== Inline code =====
 +
 +Use lstlisting
 +
 +<code>
 +\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},
 + commentstyle=\color{dkgreen},
 + 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}
 +
 +</code>
 +
 +
 +
 +
 +===== Inline PDF File =====
 +
 +
 +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
 +
 +<code>\usepackage[final]{pdfpages}
 +</code>
 +Where you want to include the PDF file, you can use the following snipped
 +
 +<code>\includepdf[pages=-,pagecommand={},width=1.0\textwidth]{file.pdf}
 +</code>
 +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.
 +
 +
 +===== Get symbol names =====
 +
 +
 +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 ======
 +
 +
 +
 +===== Remove indents =====
 +
 +
 +LaTeX indents paragraphs by default. Sometimes this is annoying. You can avoid indenting a given paragraph by starting it with 
 +
 +<code>\noindent
 +</code>
 +If you wish to disable indents on the whole documents, you can make a macro defined in the heading as follows:
 +
 +<code>\setlength{\parindent}{0pt}
 +</code>
 +
 +
 +Alternatively, one can use 
 +
 +  \renewcommand{\headrulewidth}{0pt}
 +
 +===== Line spacing =====
 +
 +
 +You can easily set and change between line spacing using the setspacing package.
 +
 +<code>\usepackage{setspace}
 +</code>
 +Then, at any point, you can change the spacing using 
 +
 +<code>\doublespacing
 +\onehalfspacing
 +</code>
 +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.
 +
 +
 +===== Proper URL colouring =====
 +
 +<code>\usepackage{hyperref}
 +\hypersetup{
 + colorlinks=true,
 + linkcolor=blue,
 + filecolor=magenta,      
 + urlcolor=cyan,
 +}</code>
 +