My LaTeX notes

Since I am not a heavy user of the LaTeX typesetting system, I decided to write down tips for myself, because I use it only once in a while. I frequently forget important things about that and, although I have a set of bookmarks related to LaTeX, they are spread so I cannot find them when I want. To avoid using Google for every feature of LaTeX I need, here comes these notes.

Using abnTeX

abnTeX adds support to ABNT standards to LaTeX. You can install it by downloading it from its site, but it is present in package managers, like Debian's apt-get or NetBSD pkgsrc (via pkgsrc-wip, in the tex-abntex package).

After you just installed it, create a document with the following structure:

\documentclass[pnumplain,normaltoc]{abnt}
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[alf]{abntcite}
\autor{Authors name}
\titulo{Title}
\comentario{Comment (a subtitle, for instance)}
\instituicao{Institution name}
\data{2012}
\begin{document}
\begin{resumo}
Abstract comes here.
\end{resumo}
\end{document}


This is the basic structure you will need for an academic work in abnTeX. Pay attention to some details:

• \documentclass is abnt, that defines page sizes and margins accordingly. The optional parameters we used here are:

• pnumplain: use normal page numbering.
• We are using the package abntcite, for citations of bibliography in the ABNT form. The optional parameter is alf, which tells abntex to cite like "(AUTHOR, YEAR)", not "(1)". The later is activated by using num in that field.

• Important commands got their portuguese version, like \autor, \titulo, \comentario, \instituicao and \data. The command to draw the title, author's name, etc., is \folhaderosto.

• There is an environment \begin{resumo} .. \end{resumo}, ABNT's abstract.

Figures

Using the figure environment

In order to use figures, first by including the graphicx package:

\includegraphics


Them by using the figure environment:

\begin{figure}[h]
\begin{center}
\includegraphics[width=.5\paperwidth]{path_to_picture.png}
\caption{Caption comes here}
\label{fig:labelhere}
\end{center}
\end{figure}


It is interesting to point out the [width.5\paperwidth] parameter, that sets the picture width to half of page width.

Figures in different chapters have the same number

In the default class of LaTeX, pictures are numbered 1.1, 1.2 for chapter 1; 2.1, 2.2 for chapter 2 and so on. ABNT uses just one number (the second one), so you may have figure 1 in chapter 1 and figure 1 in another chapter! This is confusing, but easily fixable, with the chngcntr package. Include it first:

\usepackage{chngcntr}


Then, tell it to count figures outside of chapter division (I use to include this line just after \begin{document}:

\counterwithout{figure}{chapter}


General tips

Remove a number of a page

To remove a number from a page, just use the \thispagestyle{empty} command.

Cross-references

Cross-references are one of the most powerful features of LaTeX in my opinion. See this figure example:

Here some sh code at figure \ref{fig:sh-code}:

\begin{figure}
\caption{sh code}
\label{fig:sh-code}
\begin{verbatim}
echo "bla";
\end{verbatim}
\end{figure}


Important commands here are:

• \ref, that references a label.
• \label, that fixes a label on somewhere (a figure, a section, a chapter, etc.
• \caption, that relates a caption to the figure. \label should always come after or inside it, to avoid confusion with the outer environment (see this link and this link for details).

"Small" verbatims

\begin{verbatim} .. \end{verbatim} is used for text blocks. If you want to put a small verbatim text inside a paragraph, just use:

\verb|my verbatim text|


See that, any character can be a \verb delimiter, like pipe in the last example. Another example using plus:

\verb+my verbatim text+


The listings package

I recently discovered that there is the listings package that would allow you to list program's source code and color them according to their syntax. To use the package, just:

\usepackage{listings}


Use the \lstset{} command to configure listing options and just use it that way:

\lstinputlisting[
language=VHDL,
caption={Description of a VHDL code},
label={lst:my_vhdl_code}
]{path_to_file.vhd}
\vspace*{0.4cm}


\newcommand{\xline}[0]{\noindent\underline{\makebox[0.5cm][l]{}}}