




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































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”.
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:
On the other hand, there are certain advantages to the markup language approach:
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.
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:
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.
At a minimum, you’ll need the following programs to edit LaTeX:
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/.
Here are the main programs you expect to find in any (La)TeX distribution:
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.
“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.
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 are case sensitive, and take one of the following two formats:
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.
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.
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
% hello.tex - Our first LaTeX example! \documentclass{article} \begin{document} Hello World! \end{document}
% 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.
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.
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:
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:
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.