Docsity

La Te X, Manuais, Projetos, Pesquisas de Física

Pré-visualização parcial do texto

Baixe La Te X e outras Manuais, Projetos, Pesquisas em PDF para Física, somente na Docsity!

LaTeX

by Wikibooks contributors

Created on Wikibooks,

the open content textbooks collection.

Copyright ©c 2005–2008 Wikibooks contributors.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.

  • 1 Introduction
  • 2 Absolute Beginners
    • The LaTeX source
    • Our first document
  • 3 Basics
  • 4 Document Structure
    • The document environment
  • 5 Errors and Warnings
    • Error messages
    • Warnings
    • Examples
  • 6 Title Creation
    • Create the title
    • A practical example
    • Insert it in your document
  • 7 Bibliography Management
    • Embed system
    • Citations
    • BibTeX
    • Natbib
  • 8 Tables
    • The tabular environment
    • The table environment — captioning etc
    • The tabular* environment — controlling table width
    • The tabularx package — simple column stretching
    • Vertically centered images
    • Professional tables
    • Need more complicated features?
    • Summary
  • 9 Importing Graphics
    • The graphicx package
    • Xfig
  • 10 Floats, Figures and Captions
    • Floats
    • Captions
  • 11 Formatting
    • Text formatting
    • Paragraph Formatting
    • Special Paragraphs
    • List Structures
    • Footnotes
    • Margin Notes
    • Summary
  • 12 Page Layout
    • Page Dimensions
    • Page Orientation
    • Page Styles
    • Multi-column Pages
    • Manual Page Formatting
    • Summary
  • 13 Mathematics
    • Basic Mathematics: plain LaTeX
    • Advanced Mathematics: AMS Math package
    • List of Mathematical Symbols
    • Notes
    • Further reading
    • External links
  • 14 Theorems
    • Basic theorems
    • Theorem counters
    • Proofs
    • Theorem styles
    • External links
  • 15 Labels and Cross-referencing
    • Examples
    • The varioref package
    • The hyperref package and \autoref{}
    • The hyperref package and \phantomsection
  • 16 Indexing
    • Abbreviation list
    • Multiple indexes
  • 17 Algorithms and Pseudocode
    • Typesetting using the algorithmic package
    • The algorithm environment
    • An example from the manual
    • Code formating using the Listings package
  • 18 Letters
    • The letter class
    • Envelopes
    • Sources
  • 19 Packages
    • Using an existing package
    • Package documentation
    • Packages list
  • 20 Installing Extra Packages
  • 21 Color package
  • 22 Hyperref package
    • Usage
    • Customization
    • Problems with Links
    • Problems with Bookmarks
    • Problems with tables and figures
  • 23 Listings package
  • 24 Rotating package
  • 25 Beamer package: make your presentations in LaTeX
  • 26 Xy-Pic package: create diagrams
    • A simple diagram
    • References
  • 27 Producing Mathematical Graphics
    • Overview
    • The picture Environment
    • XY-pic
    • Alternatives
  • 28 Advanced Topics
    • Using \includeonly
    • Boxes
    • Rules and Struts
  • 29 Fonts
    • Useful example
    • XeTeX
    • Some useful websites
  • 30 Customizing LaTeX
    • New commands
    • New Environments
    • Extra space
    • Command-line LaTeX
    • Creating your own style
    • Spacing
  • 31 Collaborative Writing of LaTeX Documents
    • Abstract
    • Introduction
    • Interchanging Documents
    • The Version Control System Subversion
    • Hosting LaTeX files in Subversion
    • Subversion really makes the diff erence
    • Managing collaborative bibliographies
    • Conclusion
    • Acknowledgements
    • References
    • Other Methods
  • 32 Tips and Tricks
    • Add the Bibliography to the Table of Contents
    • id est & exempli gratia (i.e. & e.g.)
    • Referencing Figures or Equations
    • Grouping Figure/Equation Numbering by Section
    • New Square Root
    • A new oiint command
    • Generic header
    • Using graphs from gnuplot
  • 33 General Guidelines
    • Project structure
    • The file mystyle.sty
    • The main document document.tex
    • Writing your document
  • 34 Export To Other Formats
    • Convert to PDF
    • Convert to PostScript
    • Convert to RTF
    • Conversion to HTML
    • Conversion to image formats
  • 35 Internationalization
    • Arabic script
    • Cyrillic script
    • Czech
    • French
    • German
    • Greek
    • Hungarian
    • Italian
    • Korean
    • Polish
    • Portuguese
    • Spanish
  • 36 Links
  • 37 Authors
    • Included books
    • Wiki users
  • A Installation
    • TeX and LaTeX
    • Editors
    • Bibliography management
    • Graphics tools
    • See also
  • B Useful Measurement Macros
    • Units
    • Length ’macros’
    • Length manipulation macros
    • Samples
  • C Useful Size Commands
  • D Sample LaTeX documents
    • General examples
    • Semantics of Programming Languages
  • E Glossary
  • F Document Information
    • History
    • PDF Information & History
    • Authors
  • G GNU Free Documentation License

10 CHAPTER 1. INTRODUCTION

TeX typesetting, especially for documents containing mathematical formulae. It is currently maintained by the LaTeX3 project. Many later authors have contributed extensions, called packages or styles, to LaTeX. Some of these are bundled with most TeX/LaTeX software distributions; more can be found in the Comprehensive TeX Archive Network (CTAN). Since LaTeX comprises a group of TeX commands, LaTeX document processing is essentially programming. You create a text file in LaTeX markup. The LaTeX macro reads this to produce the final document. Clearly this has disadvantages in comparison with a WYSIWYG (What You See Is What You Get) program such as Openoffice.org Writer or Microsoft Word:

  • You can’t see the final result straight away.
  • You need to know the necessary commands for LaTeX markup.
  • It can sometimes be difficult to obtain a certain ’look’.

On the other hand, there are certain advantages to the markup language approach:

  • The layout, fonts, tables and so on are consistent throughout.
  • Mathematical formulae can be easily typeset.
  • Indices, footnotes and references are generated easily.
  • Your documents will be correctly structured.

The LaTeX-like approach can be called WYSIWYM, i.e. What You See Is What You Mean: you can’t see how the final version will look like while typing. Instead you see the logical structure of the document. LaTeX takes care of the formatting for you. The LaTeX document is a plain text file containing the content of the document, with additional markup. When the source file is processed by the macro package, it can produce documents in several formats. LaTeX supports natively DVI and PDF, but using other software you can easily create PostScript, PNG, JPG, etc.

Skills needed

LaTeX is a very easy system to learn, and requires no specialist knowledge, although literacy and some familiarity with the publishing process is useful. It is, however, assumed that you are completely fluent and familiar with using your computer before you start. Specifically, effective use of this document requires that you already know and understand the following very thoroughly:

  • how to use a good plain-text editor (not a wordprocessor like OpenOffice, Word- Perfect, or Microsoft Word).
  • where to find all 95 of the printable ASCII characters on your keyboard and what they mean, and how to type accents and symbols, if you use them.
  • how to create, open, save, close, rename, move, and delete files and folders (directories).
  • how to use a Web browser and/or File Transfer Protocol (FTP) program to download and save files from the Internet.
  • how to uncompress and unwrap (unzip or detar) downloaded files.

If you don’t know how to do these things yet, it’s important to go and learn them first. Trying to become familiar with the fundamentals of using a computer at the same time as learning LaTeX is not likely to be as effective as doing them in order. These are not specialist skills, they are all included in the European Computer Driving Licence (ECDL) and the relevant sections of the ECDL syllabus are noted in the square brackets above, so they are well within the capability of anyone who uses a computer.

Prerequisites

At a minimum, you’ll need the following programs to edit LaTeX:

  • An editor (You can use a basic text editor like notepad, but a dedicated LaTeX editor will be more useful). - On Windows, TeXnicCenter(http://www.texniccenter.org/) is a popu- lar free and open source LaTeX editor. - On Unix-like (including Mac OS X) systems, Emacsen and gvim provide powerful TeX enviroments for the tech-savvy, while Texmaker http://www. xm1math.net/texmaker/index.html and Kile http://kile.sf.net pro- vide more user-friendly development environments.
  • The LaTeX binaries and style sheets — e.g. MiKTeX http://www.miktex.org/ for Windows, teTeX http://www.tug.org/teTeX/ for Unix/Linux and teTeX for Mac OS X http://www.rna.nl/tex.html.
  • A DVI viewer to view and print the final result. Usually, a DVI viewer is included in the editor or is available with the binary distribution.

A distribution of LaTeX, with many packages, add-ins, editors and viewers for Unix, Linux, Mac and Windows can be obtained from the TeX users group at http://www.tug.org/texlive/.

Applications within a distribution

Here are the main programs you expect to find in any (La)TeX distribution:

  • tex: the simplest compiler: generates DVI from TeX source
  • pdftex: generates PDF from TeX source
  • latex: generates DVI from LaTeX source (the most used one)
  • pdflatex: generates PDF from LaTeX source

shortest route to reach your target format. This is probably the most convenient way to obtain an output in your desired format anyway. Starting from a LaTeX source, the best way is to use only latex for a DVI output or pdflatex for a PDF output, converting to PostScript only when it is necessary to print the document. Most of the programs should be already within your LaTeX distribution; the others come with Ghostscript, which is a free and multi-platform software as well.

14 CHAPTER 1. INTRODUCTION

16 CHAPTER 2. ABSOLUTE BEGINNERS

“whitespace.” An empty line between two lines of text defines the end of a paragraph. Several empty lines are treated the same as one empty line. The text below is an example. On the left hand side is the text from the input file, and on the right hand side is the formatted output.

It does not matter whether you enter one or several spaces after a word.

An empty line starts a new paragraph.

It does not matter whether you enter one or several spaces after a word. An empty line starts a new para- graph.

Special Characters

The following symbols are reserved characters that either have a special meaning under LaTeX or are unavailable in all the fonts. If you enter them directly in your text, they will normally not print, but rather make LaTeX do things you did not intend.

$ % ^ & _ { } ~ \

As you will see, these characters can be used in your documents all the same by adding a prefix backslash:

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

The other symbols and many more can be printed with special commands in math- ematical formulae or as accents. The backslash character \ can not be entered by adding another backslash in front of it (\); this sequence is used for line breaking. For introducing a backslash in math mode, you can use \backslash instead. If you want to insert text that might contain several particular symbols (such as URIs), you can consider using the \verb command, that will be discussed later in this book.

LaTeX Commands

LaTeX commands are case sensitive, and take one of the following two formats:

  • They start with a backslash \ and then have a name consisting of letters only. Command names are terminated by a space, a number or any other “non-letter”.
  • They consist of a backslash \ and exactly one non-letter. Some commands need a parameter, which has to be given between curly braces { } after the command name. Some commands support optional parameters, which are added after the command name in square brackets [ ]. The general syntax is: \commandname[option1,option2,...]{argument1}{argument2}...

THE LATEX SOURCE 17

LaTeX environments

Environments in LaTeX have a role that is quite similar to commands, but they usually have effect on a wider part of the document. Their syntax is:

\begin{environmentname} text to be influenced \end{environmentname}

between the \begin and the \end you can put other commands and nested environ- ments. In general, environments can accept arguments as well, but this feature is not commonly used and so it will be discussed in more advanced parts of the document. Anything in LaTeX can be expressed in terms of commands and environments.

Comments

When LaTeX encounters a % character while processing an input file, it ignores the rest of the present line, the line break, and all whitespace at the beginning of the next line. This can be used to write notes into the input file, which will not show up in the printed version.

This is an % stupid % Better: instructive <---- example: Supercal% ifragilist% icexpialidocious

This is an example: Supercalifragilisticexpialidocious

The % character can also be used to split long input lines where no whitespace or line breaks are allowed.

Input File Structure

When LaTeX processes an input file, it expects it to follow a certain structure. Thus every input file must start with the command \documentclass{...} This specifies what sort of document you intend to write. After that, you can include commands that influence the style of the whole document, or you can load packages that add new features to the LaTeX system. To load such a package you use the command \usepackage{...} When all the setup work is done, you start the body of the text with the command \begin{document} Now you enter the text mixed with some useful LaTeX commands. At the end of the document you add the

OUR FIRST DOCUMENT 19

% hello.tex - Our first LaTeX example! \documentclass{article} \begin{document} Hello World! \end{document}

  • Save your file as hello.tex.

What does it all mean?

% hello.tex - Our first LaTeX example! The first line is a comment. This is because it begins with the percent symbol (%); when LaTeX sees this, it simply ignores the rest of the line. Comments are useful for humans to annotate parts of the source file. For example, you could put information about the author and the date, or whatever you wish. \documentclass{article} This line is a command and tells LaTeX to use the article document class. A document class file defines the formatting, which in this case is a generic article format. The handy thing is that if you want to change the ap- pearance of your document, substitute article for another class file that exists. \begin{document} This line is the beginning of the environment called document; it alerts LaTeX that content of the document is about to commence. Any- thing above this command is known generally to belong in the preamble. Hello World! This was the only actual line containing real content — the text that we wanted displayed on the page. \end{document} The document environment ends here. It tells LaTeX that the document source is complete, anything after this line will be ignored.

As we have said before, each of the LaTeX commands begin with a backslash (). This is LaTeX’s way of knowing that whenever it sees a backslash, to expect some commands. Comments are not classed as a command, since all they tell LaTeX is to ignore the line. Comments never affect the output of the document.

Generating the document

It is clearly not going to be the most exciting document you have ever seen, but we want to see it nonetheless. I am assuming that you are at a command prompt, already in the directory where hello.tex is stored.

20 CHAPTER 2. ABSOLUTE BEGINNERS

  1. Type the command: latex hello (the .tex extension is not required, although you can include it if you wish)
  2. Various bits of info about LaTeX and its progress will be displayed. If all went well, the last two lines displayed in the console will be:

Output written on hello.dvi (1 page, 232 bytes). Transcript written on hello.log.

This means that your source file has been processed and the resulting document is called hello.dvi, which takes up 1 page and 232 bytes of space. This way you created the DVI file, but with the same source file you can create a PDF document. The steps are exactly the same as before, but you have to replace the command latex with pdflatex:

  1. Type the command: pdflatex hello (as before, the .tex extension is not re- quired)
  2. Various bits of info about LaTeX and its progress will be displayed. If all went well, the last two lines displayed in the console will be:

Output written on hello.pdf (1 page, 5548 bytes). Transcript written on hello.log.

you can notice that the PDF document is bigger than the DVI, even if it contains exactly the same information. The main differences between the DVI and PDF formats are:

  • DVI needs less disk space and it is faster to create. It does not include the fonts within the document, so if you want the document to be viewed properly on another computer, there must be all the necessary fonts installed. It does not support any interactivity such as hyperlinks or animated images. DVI viewers are not very common, so you can consider using it for previewing your document while typesetting.
  • PDF needs more disk space and it is slower to create, but it includes all the necessary fonts within the document, so you will not have any problem of porta- bility. It supports internal and external hyperlinks. Nowadays it is the de facto standard for sharing and publishing documents, so you can consider using it for the final version of your document.

About now, you saw you can create both DVI and PDF document from the same source. This is true, but it gets a bit more complicated if you want to introduce images or links. This will be explained in detail in the next chapters, about now assume you can compile in both DVI and PDF without any problem. Note, in this instance, due to the simplicity of the file, you only need to run the LaTeX command once. However, if you begin to create complex documents, including bibliographies and cross-references, etc, LaTeX needs to be executed multiple times to resolve the references. But this will be discussed in the future when it comes up.