Introduzione a LaTex Fabrizio Messina messina@dmi.unict.it www.dmi.unict.it/~fmessina
Tex and LaTex TEX is a formatting program created by Donald E. Knuth from 1977. Typesetting text and mathematical formulae. LaTex is based on the Tex formatting system, and allows typesetters to print their work at the highest typographical quality, using a predefined, professional layout. LaTex was originally written by Leslie Lamport, and is nowadays maintained by Frank Mittelbach.
LaTex vs WYSIWYG Authors usually send their own manuscripts to book designers. As a human book designer will decide chapter headings, citations, examples, formulae, basing on his professional knowledge and from the contents of the manuscript. LaTex takes the role of the book designer and uses TEX as its typesetter. Therefore, the author has to write only LaTex commands.
WYSIWYG vs LaTex In the WYSIWYG (What You See Is What You Get) approach, e.g. MS Word or LibreOffice, authors specify the document layout interactively while typing text: *They can see on the screen the final work as it will be printed *With LaTex it is not normally possible to see the final output while typing the text, which can be previewed on the screen after processing the source files with LaTex
LaTex advantages Professional layouts are available for everyone. Typesetting mathematical formulae is conveniently supported. Users learn a few easy-to-understand commands that specify the logical structure of a document, without having to deal with the actual layout of the document. Complex structures such as footnotes, references, table of contents, and bibliographies can be generated easily. Many packages exist for many typographical tasks not directly supported by basic LaTex, e.g. typeset bibliographies conforming to well known standards.
LaTex documentation Preliminary information: * https://www.tug.org/texlive/ * https://www.tug.org/texlive/acquire-netinstall.html (installation) LaTex distributions * Standard texlive installation: - http://mirror.ctan.org/systems/texlive/tlnet/install-tl-windows.exe * MIKTEX: http://miktex.org/download : up-to-date implementation of TeX/LaTeX and related programs for Windows.
Editors for LaTex Syntax highlighting, built-in commands * Texstudio: http://www.texstudio.org/ (Linux, Windows & Mac OS X) * Texmaker: http://www.xm1math.net/texmaker/ (Linux, Windows & Mac OS X) * TeXnicCenter http://www.texniccenter.org/ * More information at: https://en.wikipedia.org/wiki/comparison_of_tex_editors
LaTex document structure, special chars Input files must be plain text files with extension.tex. Spaces do not matter, i.e. multiple spaces are not included in the final document. Character "~" will introduce real spaces in the document. Special characters: # $ % ^ & _ { } ~ \ as they assume a special meaning, they have to be included by a backslash: \# \$ \% \^{} \& \_ \{ \} \~{} while the backslash itself will be printed by the command \textbackslash.
LaTex commands LaTex commands start with a backslash "\", and a name without numbers LaTex ignores white spaces after command. Use a ~ or "{} " after the command. Commands may require a mandatory parameter, given between "{ }". Some commands may take optional parameters, given between "[]". \command[optional parameter]{parameter} \textbf{bold} \newline A comments start with a character "%", thus the rest of the present line will be ignored.
Typical structure of a LaTex document \documentclass{...} %packages to load \usepackage{...} %start content \begin{document} % CONTENT START HERE % commands here \end{document} % END CONTENT
LaTex document structure: minimal example \documentclass{article} \begin{document} Small is beautiful. \end{document}
Producing final document. Create document.tex in plain text format. ------------- $ latex document.tex #will produce document.dvi $ xdvi document.dvi # to view the results $ dvips document.dvi #will produce a postscript $ dvipdf document.dvi #will produce a PDF from the dvi ------------- DVI is the output file format of the TeX typesetting program: not human-readable binary data describing the visual layout of a document in a format hardware or printer independent.
Classes of documents \documentclass[options]{class} standard classes: article: scientific journal, presentations, short reports report: thesis and small books book: for real books slides: for slides, but very basic. May use the package "Beamer" instead. minimal: very small, with page size and base font, used for debugging.
Class Options \documentclass[options]{class} Options: - "10pt", "11pt", "12pt" - "a4paper", "a5paper", etc - "titlepage": a new page will start after the document title - "notitlepage:" a new page does not start after the title. - "onecolumn" or "twocolumn", "twoside" "oneside" - "landscape"
Page style \pagestyle{style} "plain": page numbers at the bottom center of each page "headings": chapter heading + page number in the header of each page "empty": set header and footer to be empty
Splitting document \include{filename} must be placed in the body of the document. The content of filename will be included in the document and a new page will start \includeonly{filename1, filename2,...} % if placed in the preamble, only the specified filenames can be included in the document by \include directive \input{filename} As \include{}, but it will not start a new page
Example \documentclass[a4paper,12pt,oneside,twocolumn]{article} % mainly used for hyphenation patterns \usepackage[english]{babel} % to generate random content \usepackage{blindtext} \author{latex student} \title{test} \begin{document} \maketitle
Example (continue) \tableofcontents \section{a first section} \blindtext %generate random text \section{another section} \blindtext %generate random text \end{document}
Paragraph The paragraph is the most important unit of a text. Paragraph break: leave blank lines This is a paragraph with one sentence. %end of paragraph This is another paragraph. A paragraph is made by sentences. Line breaks can be forced by the command "\\", while new pages can be forced by \newpage. This is a sentence in a paragraph, \\ %line breaks This is another paragraph. \newpage %new page
Hypenation (sillabazione) LaTex will do the work automatically by loading the appropriate language: \usepackage[italian]{babel} Nevertheless, if the hyphenation algorithm does not find the correct hyphenation points: \hyphenation{fortran Hy-phen-a-tion} Keeping a word in one line: \mbox{phone number: 095.738.3333}
Special characters Quotation marks. Don't use the character " for quotaton marks, use ` (grave accent) and ' (vertical quote) instead, in a double or single form: ``Please pres any key to continue, or `x' for '' Dashes, hyphens and symbols X-files % 1 dash (hyphen) pages 10--20 % 2 dashes (en-dash) yes---or no? % 3 dashes (em-dashes) $-10.2$ % 1 dash (minus sign)
Special characters (continue) Tilde \textasciitilde \texttildelow $\sim$ % produce a small tilde (high) % produce a small tilde (low) % centered tilde (web addresses) http://www.dmi.unict.it/$\sim$fmessina %
Special characters (continue) Euro currency symbol. \usapackage{eurosym} \euro % produce euro symbol Ellipses Usually indicates an intentional omission of a word, sentence, or whole section from a text without altering its original meaning. Es: New York, Rome, Budapest,... New York, Rome, Budapest, \ldots % produce a series of three dots \`o % produce ò (grave) \'o % produce ó (acuto)
Sections, subsections, paragraphs. \section{...} \subsection{...} \subsubsection{...} \paragraph{...} \subparagraph{...} \part{} % will not influence the numbering
Chapters, Appendix Chapter \chapter{...} % do not use this command with class article Appendix \appendix % From here, the numbering will be changed to A, B,... \chapter{...} % First appendix \chapter{...} % Second appendix
Title, date and ``starred parts \chapters*{...} % not included in toc, no numbering \title{...} % Set title \author{...} % Set author \date{...} % optional. To have no date, just use \date{}
Cross references \chapter{first chapter}\label{chap:1} In chapter~\ref{chap:pre} we discussed the... We discussed the state of the art at page~\ref{chap:pre} Footnotes In this context we discuss only the first issue\footnote{the remaining issue will be addressed in the next document}
Emphasized words In the \emph{first area} we have given \textbf{two} contributions: the \underline{first} is... Itemize \begin{itemize} \item first item \item second item \end{itemize}
Enumerate, description \begin{enumerate} \item first item... \end{enumerate} %description \begin{description} \item[one] first item \item[two] second item \end{enumerate}
Left, right, center alignment \begin{flushleft} % left Left-aligned text \end{flushleft} \begin{flushright} % right Right-aligned text \end{flushright} \begin{center} % center This text is centered. \end{center}