I’m writing this blog as I’m learning latex and setting up emacs to use it. Previously I mainly use LyX for writing research papers but the lack of text leads to lesser customization options sometimes, which is why I’ll be shifting to plain text LaTeX henceforth.

# Latex protips

## Structure of documents

Docs consist of preamble and main document. The preamble contains commands for telling latex which packages you will use and what kind of document you want to setup.

A sample preamble looks like so:

% Preamble
% ---
\documentclass{article}

% Packages
% ---
\usepackage[utf8]{inputenc} % Unicode support (Umlauts etc.)
\usepackage{listings} % Source code formatting and highlighting


Only the documentclass command is mandatory. The rest are optional. usepackage cannot be used inside the main document. When using the article documentclass, latex will add the page numbers automatically to the bottom of each document.

The main document is contained inside the document environment like this:

\begin{document}
% ...
% ... Text goes here
% ...
\end{document}


## Environments

Latex comes with many pre-defined environments which you can use for setting up your documents with minimal work. They come with some useful defaults too. For example, to write a new Design Thinking assignment, I wrote the following preamble:

\documentclass{article}
\title{Assignment 2: One hour observation}
\date{2018-4-22}
\author{Sameer Deshmukh}


Then using the \maketitle command inside the document body will directly create the title page for us.

## Sections and paragraphs

Add sections using \section{Section-name} and sub-sections using \subsection{sub-sec-name}. You can add as many sub’s to the subsection in order to specify multiple subsections. Using the \paragraph{Name goes here} command will add a paragraph to the section.

You need the graphicx package to use images in your documents. Then use the \graphicspath{ {folder-name/} } command to tell latex the directory in which the images are stored w.r.t the current directory. These should be declared in the preamble.

You can then use the \includegraphics{graphic-name} command to show images in your document wherever you want.

You can specify various parameters to includegraphics for working with the image like height, width and scaling inside square brackets. For example:”

\includegraphics[width=3cm, height=4cm]{image}


Just seeting width to \textwidth and leaving out height will keep the default height and set the width to the width of the text in the document. Like this:

\includegraphics[width=\textwidth]{image}


See the reference guide for a more detailed description of the lengths and units that can be specified.

## Useful commands

• New page - \newpage.
• Make a title page - \maketitle.

### Text formatting

Use \textbf{text} for bold text, \underline{text} for underlined text and \textit{text} for italics.

### Symbols

• Empty set: \emptyset is a 0 with a back slash through it.
• Uptack or falsum: \bot looks like Japanese 上 but without the upper dash.
• Is a member of: \in, for denoting that something is a part of a set.
• Not equal to: \neq.
• Set union: \cup

## Writing algorithms

### Setup of environment

I’m using the algorithmicx package for writing algorithms. This package will be installed with the texlive-full package on the Ubuntu repos. Put the following lines in the preamble to use:

\usepackage{algorithm}
\usepackage{algpseudocode}


This is because algorithmicx pacakage is just a bundle of style files with macros that build on top of algorithm and algorithmic. It does not define a package of itself.

The algorithms should lie inside the algorithm environment. You can use \caption and \label to define those properties respectively. For example:

\begin{algorithm}
\end{algorithm}


### Writing algorithms

The actual algorithm should be written inside the algorithmic block. An optional numerical argument can specify in how many lines do you want the lines to be numbered. Example:

\begin{algorithmic}[1]
\State \textbf{when} {START} \textbf{is received do}
\end{algorithmic}


\algdef{SN}[when]{When}{EndWhen}
[3][\null]{
\ifthenelse{\equal{#1}{\null}}{
\ifthenelse{\equal{#3}{}}{
{\bf when} \Call{#2}{\null} {\bf is received do}
}{
{\bf when} \Call{#2}{#3} {\bf is received do}
}
}{
\ifthenelse{\equal{#3}{}}{
{\bf when} \Call{#2}{\null} {\bf is received from #1 do}
}{
{\bf when} \Call{#2}{#3} {\bf is received from #1 do}
}
}
}
\renewcommand{\thealgorithm}{}


# Emacs latex setup

I mainly followed other blog posts to setup this one. First install texlive and auctex packages from your package manager.

;; setup auctex
(require tex-site)
(require tex-style)
(add-hook LaTeX-mode-hook turn-on-reftex)

;; spellcheck in LaTex mode
(add-hook latex-mode-hook flyspell-mode)
(add-hook tex-mode-hook flyspell-mode)
(add-hook bibtex-mode-hook flyspell-mode)

;; Math mode for LaTex


## Auctex protips

Using auctex for your document editing provides some powerful features for editing and previewing documents. Here’s a list of what can be done:

• Preview a section right inside the buffer: C-c C-p C-d.
• Preview the entire buffer: C-c C-p C-b.
• Compile into a PDF: C-c C-c.

## View formatted PDF

The docview-mode can be used for previewing a PDF file from within emacs. This mode is bundled with emacs 24. Put the line (setq doc-view-continuous 1) in your init file so that you can scroll through PDFs seamlessly.

## Writing posters using a0poster

a0poster is a package for writing scientific posters.