LaTeX syntax quick references

[ Home ] [ Back ]

Comments

% this is a comment

Basic document structure

\documentclass[options]{class type}
...
...


\begin{document}
...
...
\end{document}

How to obtain a well organized source code

It is possible to recall external parts of code in order to obtain a simpler and more clear structure of your main source code by using of the \input{} command.

% Preamble:
\documentclass[options]{class type}
\usepackage{...}
...

% body of your document
\begin{document}

\input{section_01.tex} 
\input{section_02.tex}
\input{section_03.tex}
...
\input{section_n.tex}

\end{document}

:!: Please note that in each .tex document (section_01.tex, section_02.tex etc.) you have not to put any line just like \begin{document} or \end{document}, or packages' declarations: these are just pieces of code recalled in your text!!!

Preamble

The portion of code within \documentclass and \begin{document} statements.

Available document classes:

  • article (chapters are not supported)
  • report
  • book (two-side document by default)
  • letter

Basic class options:

\documentclass[a4paper,11pt]{class type}

The default font sizing is 10pt, but you can also specify 11pt or 12pt.

Core document

The code within \begin{document} and \end{document}.

Extensions (packages)

\usepackage[options]{package name}

Basic formatting syntax

LaTex supports bold, italic etc.

LaTex supports \textbf{bold}, \textit{italic} etc. 

You can also combine all these,

You can also \textit{\textbf{combine} all these}

Note that \textit{} and \emph{} produce the same italic output.

Other formats:

\textsl{slanted text}
\texttt{typewriter text}
\textsc{small caps}

Sectioning

A document can be divided using chapters, sections, subsections, sub-subsections and paragraphs.

\part{name}
\section{name}
\subsection{name}
\subsubsection{name}
\paragraph{name}

New paragraphs are automatically created by leaving an empty line.

If you are using the book document class you can also use:

\chapter{name}

Breaks

\newline
\newpage
\clearpage

The \clearpage command is similar to \newpage, but forces LaTex to print all folating tables and pictures before the page break.

Spacing

Vertical spacing:

\vspace{5mm}

Horizontal spacing:

\hspace{8cm}

Usually you will specify spaces in cm or mm, but other typographic units exist.

\vfill

The \vfill fill command produces a rubber length which can stretch or shrink vertically. It is equivalent to a blank line followed by \vspace\fill.

Alignment

\begin{center}
...
\end{center}
\begin{flushright}
...
\end{flushright}
\begin{flushleft}
...
\end{flushleft}

Pictures

First you need to declare the package in your preamble:

\usepackage{graphicx}

Then you could use this code in order to insert an image in the same path of your file .tex (otherwise you have to specificate the whole path and not only the name of your picture):

\begin{figure}[options]
 \centering
 \includegraphics[angle=-90,scale=0.80,keepaspectratio=true]{pipe.jpg}
 \caption{Ceci n'est pas une pipe - This is not a pipe (Magritte).}
 \label{fig: pipe}
\end{figure}

Environment figure options:

  • h - here
  • t - top of the page
  • b - bottom of the page
  • p - extra page
  • ! - force positioning

includegraphics main options:

  • angle=[+/- degree values]
  • scale=[value] (i.e. 0.80 means that you are resizing your picture at the 80%)
  • keepaspectratio=[true/false]

You can refer to a picture in your text by using the \ref{labelcontents}, i.e.:

\ref{fig: pipe}

See also:

Tables

Simple tables:

\begin{tabular}{|l|c|r|} % 'l' is for 'left', 'c' is for 'center', 'r' is for 'right'
\hline
 first & second & third \\
\hline
 1 & 2 & 3 \\
\hline
\end{tabular}

See also:

Math formulas

If you want to obtain some mathematical text without using some special packages directly in your text:

$ e^{i\pi}+1=0 $ 
\begin{math} \vec{F} = m \vec{a}\end{math}
\S = \int{L \: dt} \)
$ \lim_{x \rightarrow \infty} \frac{\sin{x}}{x} = 1 $

… or in a different text block:

\begin{displaymath}e^{i\pi}+1=0 \end{displaymath}
\[\vec{F} = m \vec{a}\]
$$S = \int{L \: dt} $$

… or in a different block of text with the number of the equation flagged:

\begin{equation}\lim_{x \rightarrow \infty} \frac{\sin{x}}{x} = 1 \end{equation}

Some utilities:

See also:

Coding

If you want to add some code listings into your text you can use the listings package putting

\usepackage{listings}

in your preamble. Then you can define some setting for your code; for instance:

\lstset{
language=VHDL,
numbers=left,
numberstyle=\tiny,
stepnumber=1,
basicstyle=\small\ttfamily,
keywordstyle=\color{red}\bfseries,
commentstyle=\color{blue},
stringstyle=\color{green},
showstringspaces=false}

The listings package supports highlighting of all the most common languages and it is highly customizable.

\begin{lstlisting}[frame=lines]
entity eqcomp is
  port (a, b: in bit_vector (3 downto 0);
  eq, neq : out bit);
  end eqcomp;
 
architecture dataflow of eqcomp is
  signal aux1 : bit;
  begin
  neq <= not aux1; -- low active
  aux1 <= ‘1’ when (a = b) else ‘0’;
  eq <= aux1;
 end dataflow;
\end{lstlisting}

You can find here the complete list of the supported languages.

See also:

Non-formatted text

Verbatim environment permits to insert large sections of preformated text in a LaTeX file (for example, also symbols like '%', '&', '#' and much more):

\begin{verbatim}
Roses are #FF0000 & violets are #0101DF
sugar is sweet and so are you. 
\end{verbatim}

Graphs

Feynman diagrams

Table of contents

A table of contents (TOC) is automatically created using the command

\tableofcontents

Note that two consecutive compilation are required to update the table of contents

Other similar commands are \listoftables and \listoffigures which produce a list of tables (LOT) and a list of figures (LOF) respectively.

Supported Languages

\usepackage[languages]{babel}
\selectlanguage{choosenlanguage}

i.e.

\usepackage[italian, english]{babel}
\selectlanguage{english}

Numerical references

To create references inside your text, use the \cite{refLabel} command wherever you want an external reference to something (books, papers, Web sites, etc.). It is a good practice to use the surname of the first author followed by the last two digits of the year of publication. Each reference will be numbered and each citation will correspond to the number.

Then you can build a bibliography with the LaTex built-in environment thebibliography,

\begin{thebibliography}{n}
   \bibitem[label]{refKey} Author(s), \emph{Work title}, detailed reference coordinates
   ...
   ...
\end{thebibliography}

Here {n} is the maximum number of expected references in the list, usually {100} works fine. This parameter is mandatory (compile error otherwise).

By default the name of the page will be Bibliography. If you want to change it in References use

\renewcommand{\bibname}{References}  %  print "References" instead of "Bibliography"
\begin{thebibliography}{n}
   ...
   ...
\end{thebibliography}

Furthermore, by default the bibliography is not automatically added to the table of contents.

\clearpage
\addcontentslin{toc}{chapter}{References}
\renewcommand{\bibname}{References}
\begin{thebibliography}{100}
   ...
   ...
\end{thebibliography}

Each item of the bibliography is referenced with a number within square brackets. You can assign custom labels to your reference indeed, simply add the [label] option in \bibitem, e.g.

   \bibitem[Krummenacher, 1991]{Krummenacher1991} 
   F. Krummenacher, 
   \emph{Pixel detectors with local intelligence}, 
   NIM A305, 1991, 527-532

As an alternative you can use a BibTex database. See http://www.bibtex.org/.

Harvard referencing

Use the natbib package. Add

\usepackage[option(s)]{natbib}

in your preamble.

To create references you can use different versions of the basic \cite{} command to display the type of citation you want.

Common options:

  • round round parenthesis ()
  • square square parentheses []



Last update: Serena Panati Nov 6th, 2013

  • vlsi/resources/latex/syntax.txt
  • Ultima modifica: 06/11/2013 23:44
  • da panati