LATEX

Vicente González Ruiz

March 4, 2015

Contents

1 Introduction
 1.1 What is TEX?
 1.2 What is LATEX?
 1.3 LATEXalternatives
 1.4 Installation
 1.5 A very basic test of TEX
 1.6 An editor: Emacs + AUCTeX
 1.7 Basic data flow
 1.8 Basic syntax
2 Structures
 2.1 Minimal
 2.2 Letter
 2.3 Article
 2.4 Report/Book
 2.5 Slides
3 Encodings (Internationalization)
 3.1 (Input) Source Encoding
 3.2 (Output) Document Encoding
 3.3 Hyphenation and Specific Language Rules
4 Commenting the Source Code
5 Tables
6 List of Items
 6.1 The itemize environment
 6.2 The enumerate environment
 6.3 The description environment
7 Formating
 7.1 Sizing
 7.2 Moving Horizontally
 7.3 The verbatim Environment
8 Fonts
 8.1 Series
 8.2 Shape
 8.3 Changing the Font for the Entire Document
 8.4 Changing the Font for a Part of the Document
9 Mathematics
10 Creating Macros
 10.1 (Re)Defining a new command
 10.2 (Re)Defining a new environment
11 Drawing
 11.1 The picture environment
 11.2 Inserting (vectorial) drawings
12 Arithmetic
13 Producing HTML5 Documents

Chapter 1
Introduction

1.1 What is TEX?

1.2 What is LATEX?

1.3 LATEXalternatives

  1. XeTeX/XeLaTeX: a TEX/LATEXbranch specifically designed to support non-English languages.
  2. LuaTeX/LuaLaTeX: adds Lua support to the TEX/LATEXengines, with the objective of incrementing the posibilities of the typesetting system. For example, in LuaTeX we can write:
    $\pi = \directlua{tex.print(math.pi)}$  
                      <--------------->  
                            LUA code

    to get the value of π.

1.4 Installation

  1. On BSD and GNU/Linux, install Tex Live:
    # Debian and derivatives:  
    sudo apt-get install texlive  
     
    # Arch Linux:  
    sudo pacman -S textlive-most

  2. On Mac OS X, install:
    1. MacTex: Download and install the package.
    2. Tex Live using MacPorts or Fink:
      # MacPorts:  
      sudo port install texlive  
       
      # Fink:  
      fink install texlive

  3. In Microsoft Windows, install:
    1. MiKTeX: Download and install the package.
    2. Tex Live: Download and install the package.

1.5 A very basic test of TEX

  # Run:  
  tex ’\empty Hello World!\bye’  
  # To get a file: "texput.dvi" that can be displayed with "xdvi".

1.6 An editor: Emacs + AUCTeX

# Debians:  
sudo apt-get install auctex  
 
# Arch:  
sudo pacman -S auctex

1.7 Basic data flow

  .tex + .eps  
       |  
+------+  
|      v  
|  +-------+  
|  | latex |  
|  +-------+  
|      |.aux  
| +----+  
| |    | |.bib  
| |    v v  
| | +--------+  
| | | bibtex |  
| | +--------+  
| +---+ |  
+---+ | |.bbl  
    | | +---------+  
    | +-|-------+ |  
    +-|-|-----+ | |  
    | | |     | | |  
    v v v     v v v  
 +---------+ +-------+  
 | htlatex | | latex |  
 +---------+ +-------+  
      |.html     |.dvi  
      v    +-----+-----+  
           |           |  
           v           v  
       +--------+  +-------+  
       | dvipdf |  | dvips |  
       +--------+  +-------+  
           |.pdf       |.ps  
           v           v

1.8 Basic syntax

 
% Commands: 
\command[optional argument]{argument} 
 
% Environments: 
\begin{environment} 
  argument 
\end{environment}

Chapter 2
Structures

2.1 Minimal

 
% Simple minimal template 
 
\documentclass{minimal} 
\listfiles % For debugging purposes 
\begin{document} 
Hello World! 
\end{document}

2.2 Letter

 
% Simple letter template 
 
%                    <- Class -> 
\documentclass[12pt]{letter} 
%      <- Options -> 
 
\listfiles % For debugging purposes 
 
\signature{Vicente Gonz\’alez Ruiz} 
\address{University of Almer\’ia} 
 
\begin{document} 
 
\begin{letter}{Peter Pan\\Neverland} % Addressee 
 
\opening{Dear Peter:} 
 
To keep flying all night long is a good idea ... bla, bla, bla. 
 
Thank you for your time and consideration. 
 
Looking forward to hearing from you. 
 
\closing{Yours Faithfully,} 
 
\ps 
 
% PostScript 
P.S. Please, remember that ... 
 
% Enclosure 
\encl{A map of Neverland.\\ 
The list of known pirates in Neverland.\\ 
\vdots} 
 
\end{letter} 
\end{document}

2.3 Article

 
% Simple article template. 
 
%              <----- Options ---->  <Class> 
\documentclass[11pt,twoside,a4paper]{article} 
 
%%%%%%%%%%%%%%%%% BEGIN PREAMBLE %%%%%%%%%%%%%%%%% 
 
%           <-Options->  <Package> 
\usepackage[ margin=2cm]{ geometry} % Comment it if you want to use the default margins! 
\usepackage{graphicx} % Provides \includegraphics 
\usepackage{color} 
 
%%%%%%%%%%%%%%%%%% END PREAMBLE %%%%%%%%%%%%%%%%%% 
 
\listfiles % For debugging purposes 
 
\begin{document} 
\title{An Article Template Written in {\color{red}\LaTeX}} 
\author{Vicente Gonz\’alez Ruiz} 
\maketitle 
 
\begin{abstract} 
A synthesis of the paper. 
\end{abstract} 
 
\section{Introduction} 
Motivation, background, questions, etc. 
 
\section{Related work} 
Similar papers: In~\cite{greenwade93} bla, bla, bla. 
 
\section{Proposal} 
Your work: Figure~\ref{fig:sin} shows ... and bla, bla, bla. 
 
\begin{figure} 
  \begin{center} 
    \includegraphics[width=0.5\textwidth]{sin} 
  \end{center} 
  \caption{This is a pure sin function.\label{fig:sin}} 
\end{figure} 
 
\section{Results} 
An evaluation of your proposal: Bla, bla, bla. 
 
\section{Conclusions} 
Answers to the Introductions questions: Bla, bla, bla. 
 
\bibliographystyle{plain} 
\bibliography{example} 
 
\end{document}
 
# sin.gpt (run "gnuplot sin.gpt" to built "sin.pdf") 
set terminal pdfcairo 
set output "sin.pdf" 
plot sin(x)

2.4 Report/Book

 
% Simple report template 
 
\documentclass{report} 
 
\listfiles % For debugging purposes 
 
\begin{document} 
 
\title{This is a large document} 
\author{Vicente Gonz\’alez Ruiz} 
\date{\today} 
 
\maketitle 
 
\part{A Part} 
\chapter{A Chapter} 
\section{A Section} 
\subsection{A Subsection} 
\subsubsection{A Subsubsection} 
\paragraph{A Paragraph} 
\subparagraph{A Subparagraph} 
 
\end{document}

2.5 Slides

 
% Simple slides template 
 
\documentclass[landscape,12pt]{slides} 
\usepackage[landscape]{geometry} 
%\usepackage{amsfonts} 
%\usepackage{bm} 
 
\begin{document} 
 
\begin{slide} 
  \begin{center} 
    \Huge 
    Using the \texttt{slides} Document Class of the Standard {\LaTeX} System 
  \end{center} 
\end{slide} 
 
\begin{slide} 
  (\ref{eq:emc}) is one of the most famous equations ever found! 
  \begin{equation} 
    E=mc^2 
    \label{eq:emc} 
  \end{equation} 
\end{slide} 
 
\end{document}

Chapter 3
Encodings (Internationalization)

3.1 (Input) Source Encoding

\usepackage[utf8]{inputenc} % Enought for most latin languages.

3.2 (Output) Document Encoding

\usepackage[T1]{fontenc} % Necessary, for example, for creating Spanish documents.

3.3 Hyphenation and Specific Language Rules

% We specify on Spanish in this example!  
\usepackage[spanish]{babel} % Extra info at: "http://www.ctan.org/pkg/babel".

Chapter 4
Commenting the Source Code

 
\documentclass{minimal} 
 
\usepackage{comment} 
 
\begin{document} 
% There is nothing in this line, except a comment. 
 
Hello % Hola 
World % Mundo 
 
% Use "\usepackage{comment}". 
% More info at: "http://www.ctan.org/tex-archive/macros/latex/contrib/comment". 
\begin{comment} 
  This text if not compiled. 
\end{comment} 
 
\end{document}

Chapter 5
Tables

 
\documentclass{article} 
 
\begin{document} 
 
\newcommand{\mytable}{\begin{tabular}{l*{6}{c}r} 
  Team              & P & W & D & L & F  & A & Pts \\ 
  \hline 
  Manchester United & 6 & 4 & 0 & 2 & 10 & 5 & 12  \\ 
  Celtic            & 6 & 3 & 0 & 3 &  8 & 9 &  9  \\ 
  Benfica           & 6 & 2 & 1 & 3 &  7 & 8 &  7  \\ 
  FC Copenhagen     & 6 & 2 & 1 & 3 &  5 & 8 &  7  \\ 
\end{tabular}} 
 
\mytable 
 
\begin{table} 
  \begin{center} 
    \mytable 
  \end{center} 
  \caption{This is a table inside of the articles ‘‘table’’ environment.\label{tab:table_x}} 
\end{table} 
 
Be careful! The format of the table can change with the document class! 
 
Please, see Table~\ref{tab:table_x}. 
 
\end{document}

Chapter 6
List of Items

6.1 The itemize environment

 
\documentclass{article} 
 
\begin{document} 
 
\begin{itemize} 
\item [One:] item 1. 
\item Two. 
\item Three. 
\end{itemize} 
 
\end{document}

6.2 The enumerate environment

 
\documentclass{article} 
 
\begin{document} 
 
\begin{enumerate} 
\item [One:] item 1. 
\item Two. 
\item Three. 
\end{enumerate} 
 
\end{document}

6.3 The description environment

 
\documentclass{article} 
 
\begin{document} 
 
\begin{description} 
\item [One:] item 1. 
\item Two. 
\item Three. 
\end{description} 
 
\end{document}

Chapter 7
Formating

7.1 Sizing

 
\documentclass{article} 
 
\begin{document} 
 
{\noindent\tiny We \scriptsize start \footnotesize \small small, 
\normalsize get \large big \Large and \LARGE bigger, \huge huge and 
\Huge gigantic!} 
 
\end{document}

 
\documentclass[10pt]{article} 
% Usually 10, 11 and 12 pt fonts are available, 10pt is the default. 
 
\begin{document} 
 
Hello world! 
 
\end{document}

 
\documentclass[12pt]{article} 
% Usually 10, 11 and 12 pt fonts are available, 10pt is the default. 
 
\begin{document} 
 
Hello world! 
 
\end{document}

 
\documentclass{article} 
 
\usepackage{anyfontsize} 
 
\begin{document} 
 
\newcommand{\myfontsize}{10} 
\fontsize{\myfontsize}{1.2\myfontsize}\selectfont 
%         <-  size ->  <-line space-> 
Hello world! 
 
\renewcommand{\myfontsize}{20} 
\fontsize{\myfontsize}{1.2\myfontsize}\selectfont 
 
Hello world! 
 
\renewcommand{\myfontsize}{30} 
\fontsize{\myfontsize}{1.2\myfontsize}\selectfont 
 
Hello world! 
 
\renewcommand{\myfontsize}{40} 
\fontsize{\myfontsize}{1.2\myfontsize}\selectfont 
 
Hello world! 
 
\renewcommand{\myfontsize}{50} 
\fontsize{\myfontsize}{1.2\myfontsize}\selectfont 
 
Hello world! 
 
\renewcommand{\myfontsize}{60} 
\fontsize{\myfontsize}{1.2\myfontsize}\selectfont 
 
Hello world! 
 
\end{document}

7.2 Moving Horizontally

 
\documentclass{article} 
 
\begin{document} 
 
\begin{center} 
  Centered text. 
\end{center} 
 
\begin{flushright} 
  Flushed text. 
\end{flushright} 
 
\end{document}

7.3 The verbatim Environment

 
\documentclass{article} 
 
\begin{document} 
 
\begin{verbatim} 
Testing the verbatim environment!! 
 
!’’$%&/()=?-_<> 
\end{verbatim} 
 
\end{document}

Chapter 8
Fonts

 
\documentclass{article} 
 
\begin{document} 
 
\textnormal{textnormal}, \textsf{textsf}, \texttt{texttt}. 
 
\end{document}

8.1 Series

 
\documentclass{report} 
 
\begin{document} 
 
\Huge 
{\par\fontseries{l}\selectfont AaBbCc using the light series.} 
{\par\fontseries{m}\selectfont AaBbCc using the medium series.} 
{\par\fontseries{b}\selectfont AaBbCc using the bold series.} 
{\par\fontseries{bx}\selectfont AaBbCc using the very bold series.} 
 
Notice, however, that some series can not be available depending on 
the font :-( Revise the \LaTeX console output). 
 
\end{document}

8.2 Shape

 
\documentclass[12pt]{report} 
 
\begin{document} 
 
\begin{center} 
  \Huge 
  \begin{tabular}{r|l} 
    Example & Shape \\ 
    \hline 
    \hline 
    \textrm{AaBbCc} & Roman (default) \\ 
    \textup{AaBbCc} & \textup{Upright} \\ 
    \textsf{AaBbCc} & \textsf{Sans serif } \\ 
    \texttt{AaBbCc} & \texttt{Teletype} \\ 
    \textit{AaBbCc} & \textit{Italic} \\ 
    \textsl{AaBbCc} & \textsl{Slanted} \\ 
    \hline 
    \textsc{AaBbCc} & \textsc{Small Capitals} \\ 
    \uppercase{AaBbCc} & \uppercase{Uppercase} \\ 
    \lowercase{AaBbCc} & \lowercase{Lowercase} \\ 
    \hline 
    \textbf{AaBbCc} & \textbf{Bold} \\ 
    \textmd{AaBbCc} & \textmd{Medium bold} \\ 
    \hline 
    \textnormal{AaBbCc} & \textnormal{Roman by default} \\ 
    \emph{AaBbCc}       & \emph{Emphasized (Italic)} 
  \end{tabular} 
\end{center} 
 
Notice, that some shapes can be unavailable depending on the font 
:-( Revise the LaTeX console output). 
 
\end{document}

8.3 Changing the Font for the Entire Document

 
\documentclass[12pt]{report} 
 
\usepackage{blindtext}      % http://www.ctan.org/tex-archive/macros/latex/contrib/blindtext 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% Selects the "Computer Modern Bright" font for the entire document. 
\usepackage{cmbright}       % http://www.tug.dk/FontCatalogue/cmbright/ 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
\begin{document} 
\large 
\blindtext 
\end{document}

8.4 Changing the Font for a Part of the Document

 
\documentclass[12pt]{report} 
 
\usepackage{blindtext}      % http://www.ctan.org/tex-archive/macros/latex/contrib/blindtext 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% Selects the "Computer Modern Bright" font for the entire document. 
\usepackage{cmbright}       % http://www.tug.dk/FontCatalogue/cmbright/ 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
\begin{document} 
 
\large 
 
{\fontfamily{cmr}\selectfont Font in Computer Modern Bright:} 
\texttt{<- Computer Modern Roman} 
\par\blindtext \texttt{<- Computer Modern Bright} 
 
{\fontfamily{cmr}\selectfont Font in the Computer Modern Times:} 
\texttt{<- Computer Modern Roman, again} 
{\fontfamily{ptm}\selectfont\par\blindtext} \texttt{<- Computer Modern 
  Times} 
 
\end{document}

Chapter 9
Mathematics

 
\documentclass{article} 
 
\usepackage{amsmath} 
 
\begin{document} 
 
The equivalence of energy $E$ and mass $m$ is reliant on the speed of 
light $c$ and is described by 
\begin{equation} 
  E=mc^2. 
  \label{eq:emc} 
\end{equation} 
Equation~\ref{eq:emc} was found by Albert Einstin in 1905. 
 
Also equations without equation numbers such as: 
\begin{equation*} 
  \sin(x)^2 + \cos(x)^2 = 1 
\end{equation*} 
are also possible. 
 
In-line math $y=\sqrt{x}$ is also possible. 
 
\end{document}

Chapter 10
Creating Macros

10.1 (Re)Defining a new command

 
\documentclass{article} 
 
\usepackage{url}     % http://www.ctan.org/tex-archive/macros/latex/contrib/url 
\usepackage{xparse}  % http://www.ctan.org/pkg/xparse 
 
\begin{document} 
 
1. \url{http://www.tug.org}\par 
2. \url{www.tug.org} 
 
%                        Command definition 
%                           <-----------> 
\newcommand{\site}[2][http]{\url{#1://#2}} 
%             ^    ^   ^         ^    ^ 
%             |    |   |         |    Second argument. 
%             |    |   |         First argument. 
%             |    |   Default value for the fist argument. 
%             |    Number of arguments. 
%             Command name. 
 
3. \site{www.tug.org}\par % Only the second argument has been provided 
4. \site[ftp]{ctan.org}   % Both arguments have been provided 
 
\renewcommand{\site}[2][http]{[\url{#1://#2}]} % Includes "[" ... "]" 
 
5. \site{www.tug.org}\par 
6. \site[ftp]{ctan.org} 
 
% Using \newcommand (or \renewcommand) only the first argument can be optional. 
% To overcome this drawback, use: 
\DeclareDocumentCommand{\site}{O{http://}O{www.ual.es}}{\{\url{#1#2}\}} 
 
7. \site[][www.tug.org]\par     % We specify the second argument 
8. \site[ftp://][ctan.org]\par  % We specify both arguments 
9. \site                        % We dont specify arguments 
 
% Definitions are easier than if you dont touch the arguments. 
\renewcommand{\site}{\url} 
10. \site{http://www.ual.es} 
 
% Delete definition. 
\let\site\relax 
 
\end{document}

10.2 (Re)Defining a new environment

 
\documentclass{article} 
 
\usepackage{forloop} 
 
\begin{document} 
 
\newcounter{problem_counter} 
\setcounter{problem_counter}{0} 
\newcounter{i} 
\newenvironment{problem} 
{ % Start commands: 
  \refstepcounter{problem_counter} 
  \noindent\textbf{Begin of problem number \arabic{problem_counter}.} 
  \begin{quote} 
} 
{ % End commands: 
  \end{quote} 
  \textbf{End of problem number \arabic{problem_counter}.} 
} 
 
\begin{problem} 
Solve \forloop{i}{1}{\value{i} < 200}{ bla,} 
 
\end{problem} 
 
Text in between ... 
 
\begin{problem} 
Now solve \forloop{i}{1}{\value{i} < 200}{ bla,} 
\end{problem} 
 
\end{document}

Chapter 11
Drawing

11.1 The picture environment

 
\documentclass{minimal} 
 
\begin{document} 
 
\begin{picture}(50,50) 
  \thicklines 
  \qbezier(0,0)(0,50)(50,50) 
  \qbezier[20](0,0)(50,0)(50,50) 
  \thinlines 
  \put(0,0){\line(1,1){50}} 
\end{picture} 
 
\end{document}

11.2 Inserting (vectorial) drawings

Chapter 12
Arithmetic

 
\documentclass{article} 
 
\usepackage[nomessages]{fp} % More info at "http://ctan.org/pkg/fp" 
 
\begin{document} 
 
\FPeval{\result}{clip(1+1)} $1+1=\result$ 
 
\end{document}

Chapter 13
Producing HTML5 Documents

  1. Write your document in LATEX using any standard document class package (for example, article works great).
  2. Create your raster images in PNG or JPEG format and your vectorial figures in SVG. In order to have both the .pdf and the .html version of your document, include them in the text with:
     
    \ifx \HCode\Undfef 
    \begin{center} 
      \includegraphics[width=1.0\textwidth]{your-figure} % PDF 
    \end{center} 
    \else 
    \HCode{ 
      <div style="text-align:center;"> 
      <img height="600" src="your-figure.extension" />   % SVG 
      </div> 
    } 
    \fi

    where your-figure is the filename of your figure without the extension, and extension is .png, .jpg or .svg, accordingly. All these figures must be in the same directory that the LATEX source.

  3. Create the .pdf version of your document by running:
     
    pdflatex your-document 
    bibtex your-document   # If neccesary 
    pdflatex your-document # If neccesary
  4. Create the .html version of your document by running:
     
    htlatex your-document.tex

An example is available at https://github.com/vicente-gonzalez-ruiz/LaTeX-to-HTML5-example.