Censorship banner.png

Guri:Latex book

From Wiki - Hipatia
Jump to: navigation, search
The help pages are provided by Hipatia volunteers to help wiki contributors.
Help index: Mediawiki Server configuration LaTeX Streaming Templates

Search for help:


Guri

Guri logo.png

Educazione e conoscenza libera

Risorse

Sito Ufficiale
Notizie ed eventi
Galleria Fotografica
Video
Mailing List
IRC
Ufficio

Attività correnti

Itis 2012
La Bottega dei Saperi
Cluster
Attività - Eventi passati

Offrici una birra
Contatti

Mailing List
IRC
Contattaci

Partecipanti attivi
Argon

Palby

Lio

Jucar

GlaxY
Stato: Attivo
Copyleft.svg Copyleft
All wrongs reversed

To configure our wiki for latex formula support, we have to follow this guide.

Introduction to Latex

LaTeX is a document markup language and document preparation system for the TeX typesetting program. The term LaTeX refers only to the language in which documents are written, not to the editor used to write those documents.

LaTeX is distributed under a free software license, the LaTeX Project Public License (LPPL). The LPPL is not compatible with the GNU General Public License, as it requires that modified files must be clearly differentiable from their originals (usually by changing the filename).The LPPL is DFSG compliant.

Getting Latex in Debian GNU/Linux

To install Latex in Debian Gnu/Linux you need the package texlive. So all you have to do is to:

apt-get install texlive

Then you can start making your .tex file and then compile it.

Why Latex?

Basic document preparation

The following sections of the page will cover the various commands, packages and styles that we chose to realize our book. This short reference does not expect to be a complete user's guide neither a how to. The aim of this quick reference is to coordinate ourselves in the writing of the document and also to explain how we did it, starting from the beginning.

To prepare your document open a text editor and write out a file such as

file.tex

then you can compile it in a dvi, pdf file. For complex structures such as our book, there are some tips you should know.

The Document

Environments

Sectioning

Sentences and paragraphs

Basically, to write sentences and paragraphs in Latex, you just have to type them. A word ends with a space and it does not matter how many spaces you use after the word, one is equivalent to 10 or more. The same is for a paragraph, but it ends with a blank line.

If you are using a period inside a sentence (e.g. for abbreviations) you have to tell Latex that the sentence is not ended. To do this just put a backslash \ after the period, followed by a blank space. For instance:

Please remember to take your books, notebooks, pens, etc.\ and remember the bag too.

NOTE: it is important not to leave any blank space between the period and the backslash.

If after the period you have to put a symbol (such as a parenthesis) you have to put the backslash after the symbol in this way:

Please remember to take your personal belongings (books, notebooks, etc.)\ before leaving the room.

This rule applies to all punctuation signs, such as "!" "?" and so on.

If you want to avoid Latex breaking a line in a particular point of a sentence (such as in a name), put a ~ in that point:

Mr.~H.G. ~Smith

will force Latex not to split the line between "Mr" and "H.G." and between "H.G." and "Smith"

Note: the ~ command is substitued by a blank space in the final document. If you want to prevent line breaking for certain words but you don't want a space to be inserted between them, use the \mbox command, passing the text as argument:

\mbox{Mr. H.G. Wells}

Special symbols

There are ten symbols that Latex use for it's syntax and so you cannot type them in your document directly if you want them in your text.

These signs are:

$ & % # _ { } ~ ˆ and \

However, you can easily reproduce them by typing:

\$ \% \& \# \_ \{ \}

the other three commands appear in DA AGGIUNGERE. Another useful command is \ldots which produces a blank space filled by three dots, with the correct spacing between them. If you simply type three periods you won't achieve the same spacing effect between the dots. For instance:

If \ldots, then \ldots, else \ldots

Emphasize text

Latex is designed to make you concentrate only on the content of the document, without being distracted by its formatting. Before writing the content you can define how your document will be, and decide its layout. When writing a document you should be focused only on the logical concept of emphasis. The syntax of the command is:

\emph{text to be emphasized}

of course this command can be nested:

Here is \emph{some text to be \emph{emphasized}}

To emphasize a longer part of text, such as a big quotation, it is better to use the \em command, which provides more readability to your latex source code and less chances of typos and mistakes (such as missed braces). This kind of command is called declaration. A declaration such as \em stops affecting the text when a } or an \end command are encountered. E.g: <syntaxhighlight lang="latex" enclosure="div">This is some text in my document. \begin{quote} People sometimes ask me if it is a sin in the Church of Emacs to use vi. \em Using a free version of vi is not a sin; it is a penance. So happy hacking. \end{quote}</syntaxhighlight> An equivalent way is to use <syntaxhighlight lang="latex" enclosure="div">\begin{em} text to emphasize \end{em}</syntaxhighlight>

Comment

The way to introduce a comment inside the Latex source file of the document is to use the % sign. The input following the % sign will be ignored in compilation time.

%this is a comment
The pen is on the table\footnote{this is not a comment.} %but this is a comment again

Quotations

Latex has two different environments to show quotations.

  • the quote environment is used for a short quotation or a sequence of short quotations, separated by blank lines.
\begin{quote}
 Quotation one
 Quotation two
 Quotation three
\end{quote}
  • the quotation environment is used to show quotations composed by more than one paragraph, separated by blank lines.
\begin{quotation}
This is a quotation which contains one or more paragraphs.
\end{quotation}

Lists

Latex provides three main ways to display a list of content.

  • to make an unordered list start the itemize environment. Inside it each item in the list is described with the command \item, followed by its content.
\begin{itemize}
\item This is the first item of the list
\item This is the second one
\end{itemize}
  • for a ordered list we have the enumerate environment:
\begin{enumerate}
\item This is the first element
\item This is the second element
\item And so on\ldots
\end{enumerate}
  • then there is the description environment, which produces a dictionary-like list of content:
\begin{description}
\item[item] An item is a element of this list
\item[another item] Another element of the same list
\end{description}

Note that if you avoid putting the brackets in the description environment your label will not be displayed correctly.

Writing in languages other than english

To write our first version of the book, we decided to produce it in Italian, since in our language there is a big lack of material regarding free software and free knowledge. A language such Italian use a lot of accents and if you type them directly in your document, Latex will have problems to renderize them correctly. Latex provides a special syntax to insert accented symbols, but it's easier to write them directly (if your keyboard is mapped to do so).

To accomplish such a task we had to use two packages:

  • the package Babel provides spacing and section names translated in the language specified as option (in our case italian). For example it will produce "Teorema" instead of "Theorem" and "Capitolo" instead of "Chapter".
  • using then the command
\frenchspacing

at the beginning of our document will force Latex to use the latin character spacing instead of the English one.

\usepackage[utf8x]{inputenc} % In GNU/Linux environment it is necessary to substitute [latin] with [utf8x]

provides the possibility to input accented characters directly from the keyboard without the necessity of writing '\' before the characters.

Figures

Tables

Foot notes

To introduce a footnote use the \footnote{} with the text of the note as argument. E.g:

As stated by the FSF\footnote{aka the Free Software Foundation} in the newsletter...

Marginal notes

It is possible to make a marginal note with the \marginpar command.

This is some text \marginpar{This is a note}
you want to put a marginal note besides.

This command puts the note in the right margin of the produced page by default. If the twoside option is passed to the document class the note will appear on the outside margin. You can pass an optional argument to \marginpar in this way:

\marginpar[optional argument]{argument}

By using this you are telling to latex to use the text of argument inf the note will be put on the right side and to use the optional argument if the note is put on the left side instead. This is useful when the content of the note depends on its left or right position.

A marginal note is never broken in two pages.

The command \reversemarginpar forces the marginal notes to be placed in the opposite margin from the default one. To return to the default side use the command \normalmarginpar

Table of Contents

The information that are needed to Latex to make a table of content are sparse for all the document (such as sections, equations, etc.). So the program as to read the document twice when producing such a list in order to collect all the information and references and them making the table. Instead of doing this, Latex stores the information collected in a file, using the extension .toc. If you add new sections of the document, the information stored in the toc file will be outdated and you need to make latex process the document again, updating the tableofcontent file.

The

\tableofcontents

command insert in the page a table of content. It makes latex write a new toc file and then it reads the information from the toc file to produce a table of contents (including heading).

The commands

\listoffigures

and

\listoftables

intuitively produce an index of all the tables and of all the figures. The information are stored in a file .lof for the first command and .lot for the tables one.

Cross references

To make a reference to previous or following sections (or figures, tables, ...) in your document, cross references are used. You can assign a name to each of the elements you want to refer to in the future and refer to it later. The \label command provides a way to assign such a name:

\label{figure:lines}

will assign to the figure a name called figure:lines

You can then refer to this with the command

\ref{figure:lines}

with the argument of the \label command passed as option.

Remember that Latex commands are case sensitive: the label named Lines will be different from lines and from LiNes and so on.

Refer to a page number

To refer to the page number in which the specified label appear, just type:

\pageref{label_name}

passing the name of the label you want to refer to as argument.

Bibliography

To make a citation to another document or publication we use the \cite command. Later, using BibTeX, a reference management software for formatting lists of references, it is possible to produce a bibliography, starting from an apposite database (.bbl).

The syntax of the \cite command is simply:

\cite{label}

or, to cite multiple sources, you can use a comma separated list of arguments:

\cite{label1,label2}

It is also possible to pass the number or pages as optional argoment to \cite:

 \cite[pages 11-17]{label}

Remember again that Latex is case sensitive.

Bibtex

To use Bibtex you have to include in your Latex source file the command \bibliography. Then Bibtex creates a source file with all the citation labels specified by the \cite commands. The bibliographic database must have an entry for everyone of these labels. Add a quick guide to bibtex

Index

When an index is made in Latex, the program will write all the necessary data on a idx file, if the preamble of the document contains a \makeindex command. To index an instance the command \index is used in this way:

Beware
\index{Jabberwock}%
the Jabberwock, my son!

It is convenient to put the \index command next to the word we are referring to (without blank spaces), because this will prevent Latex to put a wrong page reference if the word ends or begins a page.

Glossary

To make a glossary the command \makeglossary is used and the \glossary one will be used instead of the \index one. The \makeglossary command will produce a file .glo instead of a .idx one.

The makeindex command

To enable the \makeindex command you have to use the package makeidx and call it in the preamble by doing:

\usepackage{makeidx}

Then you should put the \makeindex command in the preamble.

To print the index in a page put:

\printindex

when you want the index to appear, usually just before the \end{document} command.

To generate the index you should:

  • run latex on your root document file.tex
latex file

this will produce file.idx. Remember to call latex on the file without the ".tex" extension

  • run makeindex on your file
makeindex file

latex will read the .idx file and produce a .ind file

  • run again latex on your file
latex file

now latex will produce a index inside the document using the data in the .ind file

Index subentries

To make an index sub entry the command is:

\index{cars!production}

which will make production as index sub entry for cars. You can make subindexes but the max level of depth admitted by Latex is 3 (so you won't have sub-sub-sub-indexes)

Books

Dividing the input in multiple files

To write our book we decided to split it in one file for each chapter, making it easier to correct bug and work cooperatively. To achieve this we just made one tex file for each chapter of the book. This section quickly explains how to put all the chapters together at the end of the work. In this way you will have a root file, which you will run the latex command on. Another convenient reason to split the input file in multiple pieces is that a single content can be use several times in the same file (e.g. by using multiple \input commands). This is often used for definitions of commands and environments.

The \input command makes latex substitute the \input command itself with the content of the specified file.

\input{file_to_include}

The file must be a .tex file, passed as option without the .tex extension.

The \include command shares the same functions (and syntax) of the \input one. \include has some more functions that are not covered here, but one important point to stress is that the \include command will make the included text start a new page.

Our template

To realize the book pages we used the following template, making a different file for each chapter and the including them all in a final input file. The template may change from time to time, according to our current needs. The latest version of the file can be found in our subversion repository.

<syntaxhighlight lang="latex" enclose="div">
% The content of this file are released under GNU FDL license. For reference, please visit http://www.gnu.org/copyleft/fdl.html
% This document is provided and maintained by Guri - Hipatia:
% http://guri.hipatia.net
% USAGE: This template is meant to be used as input file for every chapter of the book.
% Please save the file as capitolo{numero}_guri.tex substituting numero with the current chapter number.

\documentclass[a4paper|twoside|10pt|openright]{book} % declaring the class book: page format: A4, using front/back pages, font size: 10pt, chapters will always start in a odd page.
\usepackage[italian]{babel} % the automatically generated content (index, chapters...) will be localized in Italian
\usepackage[T1]{fontenc} % allows keyboard input with ISO-8859 encoding
\usepackage[latin1]{inputenc} % lets users type directly accents, umlauts, etc.
\usepackage{textcomp} % tex symbols like the "copyleft" one
\usepackage{url} % manages urls
\usepackage{hyperref} % to implement cross references 
\usepackage{graphics} % allows graphics to be embedded in the document
\usepackage{makeidx} % enables the makeindex command, which automatically generates the index from given entries
\usepackage{svn-multi} % loads the package svn-multi
\svnidlong % stores revision information in the variables below
{$LastChangedBy$} % author of the change
{$LastChangedRevision$} % revision number for the change
{$LastChangedDate$} % date of the change
{$HeadURL$} % url of the changed file
\begin{document}
\frenchspacing % switch to european spacing


\footnote{Author: \svnauthor; Revision: \svnrev; Last changed on: \svndate; URL: \url{\svnurl}}

\end{document}

</syntaxhighlight>

Title page and abstract

To make the book title page you have to define the author(s), title and date of composition. The title is defined by the command

\title

passing the title as argument. For the author:

\author

for which more than one author are passed with the command \and in this way:

\author{A. Uthor \and B. Uthor \and C. Uthor}

Finally for the date we use the command:

\date

giving the date as argument, e.g:

\date{17 November 2010}

It is also possible to add a footnote to the title. This is useful to add the author's email address, or similar information, such as thanks or acknowledgments. The command \thanks provides such a feature:

\thanks{text of the footnote}

This command can be nested inside the \author command.

To generate the title page, use the command

\maketitle

after the \begin{document} command. Note that when using the \maketitle the commands \author and \title are required.

Finally, an abstract can be added to the document with the abstract environment:

\begin{abstract}
Text of the abstract.
\end{abstract}

The abstract will be placed in a separate page.

Numbering

Spacing

Further readings

For a guide on how to integrate Latex and Subversion please read here.

This is a 2 pages reference with the most frequently used LaTeX commands: PNG: page 1page 2 LATEX: page 1 and 2. Please rename the Latexsheet.txt file to Latexsheet.tex to compile it properly.