LaTeX/Introduction : Différence entre versions
(→Formats created by tex -ini (was named initex)) |
m (→What is TeX? : some links added) |
||
| Ligne 13 : | Ligne 13 : | ||
TeX is the work of a single man, is free, have had a fixed number of bugs. See [[Wikipedia:en:Knuth_reward_check]] to understand how D. Knuth improved the quality of TeX by rewarding 256 cents at start (1 hexadecimal US dollar) and doubling every year for each new bug, until it reached 32768 cents. It is interesting to note that the current version number of TeX is 3.1415926 . Guess the next one if any. | TeX is the work of a single man, is free, have had a fixed number of bugs. See [[Wikipedia:en:Knuth_reward_check]] to understand how D. Knuth improved the quality of TeX by rewarding 256 cents at start (1 hexadecimal US dollar) and doubling every year for each new bug, until it reached 32768 cents. It is interesting to note that the current version number of TeX is 3.1415926 . Guess the next one if any. | ||
| − | To understand the humour of Donald Knuth but also to realize how the world has changed since the late 70's in relation to computer sciences, publishing, collaborative work, pricing, you are invited to listen to the presentation of his new iTeX product at the [http://river-valley.tv/media/conferences/tug-2010/Don-Knuth | + | To understand the humour of Donald Knuth but also to realize how the world has changed since the late 70's in relation to computer sciences, publishing, collaborative work, pricing, you are invited to listen to the presentation of his new iTeX product at the ''32nd TeX User Group in 2010 at Stanford University'' [http://river-valley.tv/media/conferences/tug-2010/Don-Knuth], where Steve Jobs was also invited in 2005 for a ''commencement talk'' [http://news.stanford.edu/news/2005/june15/jobs-061505.html] or even in 2001 in a interview [http://www.cbi.umn.edu/oh/pdf.phtml?id=293]. The comparison is done because Knuth himself compares his iTeX' talk (using acetate overhead transparencies) with the recent high quality of Steve Jobs presentations [http://videosift.com/video/The-Presentation-Secrets-of-Steve-Jobs-7-01 (presentations secrets)]. You will see that even within the audience of TeX users, many people aren't understanding the jokes. |
You can also read an interview in 2002 at the [http://www.ams.org/notices/200203/fea-knuth.pdf Technische Universität München] . He agreed on the fact that scientists would recognize computer science as a mature discipline only when it had 1,000 deep algorithms, but he think that the discipline is halfway there. | You can also read an interview in 2002 at the [http://www.ams.org/notices/200203/fea-knuth.pdf Technische Universität München] . He agreed on the fact that scientists would recognize computer science as a mature discipline only when it had 1,000 deep algorithms, but he think that the discipline is halfway there. | ||
Version du 27 avril 2011 à 07:21
Sommaire
- 1 What is TeX?
- 2 TeX engines
- 3 Which TeX engine should I choose?
- 4 Which "format" should I used for my preferred TeX engine?: LaTeX
- 5 Which packages or classes should I use?
- 6 What is LaTeX?
- 7 Installing a distribution
- 8 Getting a text editor
What is TeX?
TeX (Tau Epsilon Chi) is a low-level markup and programming language created by Donald Knuth to typeset documents attractively and consistently.
Knuth started writing the TeX typesetting engine in 1977 for the second edition of his main book "The art of computer programming". He wanted to explore the potential of the digital printing equipment that was beginning to infiltrate the publishing industry at that time, especially in the hope that he could reverse the trend of deteriorating typographical quality.
TeX is a programming language, in the sense that it supports the if-else construct, you can make calculations with it (that are performed while compiling the document), etc., but you would find it very hard to make anything else but typesetting with it. The fine control TeX offers makes it very powerful, but also difficult and time-consuming to use. TeX is renowned for being extremely stable, for running on many different kinds of computers, and for being virtually bug free.
Nowadays when producing documents in the TeX language, only old documents are using plain TeX. Instead, different TeX distributions such as LaTeX are used to help author structuring their text while saving time, automating certain tasks and reducing user introduced errors.
TeX is the work of a single man, is free, have had a fixed number of bugs. See Wikipedia:en:Knuth_reward_check to understand how D. Knuth improved the quality of TeX by rewarding 256 cents at start (1 hexadecimal US dollar) and doubling every year for each new bug, until it reached 32768 cents. It is interesting to note that the current version number of TeX is 3.1415926 . Guess the next one if any.
To understand the humour of Donald Knuth but also to realize how the world has changed since the late 70's in relation to computer sciences, publishing, collaborative work, pricing, you are invited to listen to the presentation of his new iTeX product at the 32nd TeX User Group in 2010 at Stanford University [1], where Steve Jobs was also invited in 2005 for a commencement talk [2] or even in 2001 in a interview [3]. The comparison is done because Knuth himself compares his iTeX' talk (using acetate overhead transparencies) with the recent high quality of Steve Jobs presentations (presentations secrets). You will see that even within the audience of TeX users, many people aren't understanding the jokes.
You can also read an interview in 2002 at the Technische Universität München . He agreed on the fact that scientists would recognize computer science as a mature discipline only when it had 1,000 deep algorithms, but he think that the discipline is halfway there.
In order to typeset characters, D. Knuth also created METAFONT (1979, revised in 1984) which was the first attempt to draw characters with a computer but with the same art that linotype font designers, like Hermann Zapf, used. The characteristics of Metafont is that all of the shapes of the glyphs are defined with geometrical equations, e.g., one can define a given point to be the intersection of a line segment and a Bézier cubic.
Also, D. Knuth pioneered the idea of literate programming where your algorithm and its documentation are written within the same document. Two compilers tangle and weave will compile the same document and produce a Pascal program (yet a C program with web2c) and a documentation (in TeX of course).
The web source of TeX can be accessed at http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web . Applying the weave program by the command:
$ weave tex.webtex.tex
$ pdftex tex.texYou can have a look at the weaved and texed source of TeX at http://ctan.binkerton.com/systems/unix/tex-gpc/tex.pdf A particular attention may be paid to the quality but also the complexity of the index.
Literate programming hasn't been adopted by the entire world and most of programs do not mix documentation and code: code must be clear enough to let you understand the algorithm.
Some people (http://rw4.cs.uni-sb.de/~heckmann/papers/neuform.ps.gz) tried to understand the functional description of TeX'formula layout described in Knuth's web document, but they are still not sure that what they describe in their article is what TeX is doing...
The Literate Programming concept is not over and Sweave is a nice way to incorporate some R (the ancestor of R was named S) code within your LaTeX document.
TeX engines
TeX82 or tex
TeX82, the first TeX engine, was only able to read ASCII characters and did run only on mainframes like thePDP-10 (36 bits) at Stanford or IBM (32 bits) at the Faculty of Orsay, and then on Vax machines. TeX evolved and has been ported to PC (16 bits) with a commercial very efficient product PCTeX and, in 1990, the first Public Domain distribution of TeX and LaTeX has been built by the French Gutenberg association (see http://www.tug.org/TUGboat/tb11-1/tb27brouard.pdf). Despite efforts to make TeX able to read accented characters, the standard TeX engine produce a DVI (device independent) format which is based only on single byte (ASCII) characters even if the fonts used can display any character. A standard DVI file even transformed to PDF (with dvipdf) is therefore unsearchable for accented characters. For example, you can search for Jacques Vallin in the previous PDF document but you can't search (neither copy and paste correctly) for his sentence
- Éberluée, décontenancée, hébétée, défaite de toute sérénité devant cet abécédaire décapité, étêté, évidé, émasculé, désagrégé, débilité, dégénéré, parce que privé de lettres accentuées et correctement orthographiées, Thérèse-Éléonore a décrété avec sincérité et opiniâtreté l'immortalité des çàçâcécècêcëcïçôçöçùçûçü
which emphasized the importance of typing accented characters like "é" directly on French keyboards instead of typing using the TeX way "\'e" (see also http://cahiers.gutenberg.eu.org/cg-bin/article/CG_1989___3_48_0.pdf)
pdfTeX
pdfTeX is currently the default TeX engine. It suffers the same weaknesses concerning the accented characters, but is able to output a PDF format instead of the old DVI. For inclusion of PostScript figures, using PSTricks, you can't use pdfTeX but standard TeX engine and then converts your dvi to pdf using dvips and pstodf. If you want to make graphics made by TeX (or LaTeX) itself, your are invited to use PGF/TikZ. Most people are using external softwares which will export to PDF file (or eps files to be converted with epstopdf) to be incorporated in the TeX source, but a major issue is how to incorporate mathematics within your graphics. That is the reason why many more softwares can export (like Geogebra and next Gnuplot release) to Tikz tex source. Other graphics softwares offers direct visualization of mathematics by compiling (in the background) the LaTeX source included in legends or labels, like Inkscape or the recent IPE.
Another advantage of pdfTeX is that you can incorporate hypertext links using packages such as hyperref for your presentation (Beamer) and bibliography at least.
XeTeX
With the XeTeX engine project which started in 2004, TeX is now able to manage any Unicode character and not only western accented characters and to process right to left characters. If the final output format is PDF, the intermediate format, .xdv, is an extended DVI format which can be transformed to PDF whith xdvipdfxm.
LuaTeX
More recently a TeX engine, named LuaTeX lets you use any font and not only TeX fonts and simplify the use of any language with a single fontenc package (see a recent document of December 2010 http://ctan.mines-albi.fr/info/luatex/lualatex-doc/lualatex-doc.pdf which promotes LuaTeX). A stable version of LuaTeX will be announced for late 2012.
Which TeX engine should I choose?
Most of TeX distributions on any of the main three OS (Windows, MaC OS/X and Linux) as offering the 4 four main TeX engines. Most of the editors let you choose the TeX engine of your choice. If you are writing in English only, your choice will probably be pdfTeX until XeTeX or LuaTeX offer the same functionality and stability.
Which "format" should I used for my preferred TeX engine?: LaTeX
AMSTeX as well as LaTeX and ConTeXt are formats.
Formats created by tex -ini usually correspond to different TeX dialects
A format is the result of a set of macros which are dumped into a compact file with the extension .fmt like latex.fmt, amstex.fmt etc. They are output by a TeX engine command using a special option -ini and a \dump tex order. For example, in order to create the format amstex.fmt the command is:
$ tex -ini
\input plain
\input amstex
\dumpIt is easy to understand that the TeX engine tex will: (a) read the file plain.tex which contains the basic TeX macros from the TeXBook, (b) read the specific amstex.tex macros from the American Mathematical Society which improved TeX with many more macros and (c) will finally dump all the macros into a binary and compact file which will be renamed amstex.fmt .
Next time, in order to use AMSTeX, the TeX engine command will use the ampersand ('&') character to directly load the format file amstex.fmt, and thus
$ amstex my_amslatexfile.texis similar to:
$ tex &amstex my_amslatexfile.tex
It is exactly the same thing for LaTeX and you will find a file named latex.fmt on your TeX distribution tree as well as many other formats for other TeX dialects.
pdfLaTeX is not another engine but correspond to the LaTeX format using the pdftex engine:
pdftex &latex my_latex_text.tex
For other TeX engines, like LuaTeX, you can find other formats like lualatex.fmt and its associated name LuaLaTeX: again it is not another TeX engine but a LaTeX format for the LuaTeX engine.
If you can build different LaTeX formats corresponding, for example, for different hyphenation patterns, usually different formats corresponds to different family of macros or different TeX dialects. How different are these dialects and how can I know which dialect use a particular file.
Let us see an simple example starting with a Plain TeX document which use \input commands and stops with a \bye .
%% Plain TeX file \input tikz.tex \baselineskip=12pt \hsize=6.3truein \vsize=8.7truein We are working on \tikzpicture \draw (-1.5,0) -- (1.5,0); \draw (0,-1.5) -- (0,1.5); \endtikzpicture. \bye
The same output can be generated in LaTeX with the following file:
%% LaTeX file \documentclass{article} % say \usepackage{tikz} \begin{document} We are working on \begin{tikzpicture} \draw (-1.5,0) -- (1.5,0); \draw (0,-1.5) -- (0,1.5); \end{tikzpicture}. \end{document}
If you want to start using Context (a serious competitor to LaTeX for the future), you will use the following code:
%% ConTeXt file \usemodule[tikz] \starttext We are working on \starttikzpicture \draw (-1.5,0) -- (1.5,0); \draw (0,-1.5) -- (0,1.5); \stoptikzpicture. \stoptext
Which packages or classes should I use?
Once you choose LaTeX (and a TeX engine of your choice to compile your source text), you have to make a choice within the classes offered by LaTeX, depending on the class of your text: a book, a report, an article, a presentation, you will alter the first line of your document with a command such as \documentclass{article} for an article. If you use a figure using PGF/Tikz TeX code, you need a second command \usepackage{pgf,tikz} .
A class, is simply another set of macros. Most of times a class can have options, like \documentclass[12pt]{report} which means that the document will be printed in12pt instead of the default 10pt.
A package is also a set of macros. Even if computers are 10,000 more powerful than when running on DOS in the mid 80's, they are still very limited in speed and memory management and you can't load all the macros of the CTAN TeX public Library. That the main reason of using packages.
Sometimes, even when loading a package like xy (for drawing diagrams) you will get memory limitations of LaTeX with certain TeX engine and you will need other package like the etex package which will modify how LaTeX allocates registers to use e-TeX (the command-line switch -enable-etex (which is on by default anyway) only makes the extensions available: it does not change how LaTeX actually works).
It can be even worse: sometimes some packages have to be loaded before other packages. For example:
\usepackage{etex} \usepackage[all]{xy}
and sometimes some packages are conflicting and you will have to find a solution on yourself or on googling.
If it is normal to be confused with all these notions which are the heritage of a 30 years history of TeX and LaTeX. A newer product, ConTeXt is very promising but hasn't reached a stable situation and can't compete with LaTeX yet.
But if you read until here, now you need to use your own laptop, choose a distribution (see below), an editor (see below) and once you are ready, you can write you first document in LaTeX.
If this is the first time you are trying out LaTeX, you don't even need to install anything. Just go to:
and continue this tutorial in the next chapter. ScribTeX is a web based online editor for LaTeX documents with collaboration capabilities allowing you to experiment with LaTeX syntax without having to bother with installing and configuring a distribution and an editor. When you later feel that you would benefit from having a standalone LaTeX installation, you can return to this chapter and follow the instructions below.
What is LaTeX?
LaTeX (pronounced either "Lah-tech" or "Lay-tech") is a macro package based on TeX created by Leslie Lamport in 1985. Its purpose is to write scientific documents like presentation (beamer class), article (article class), report or entire book or thesis. It can also typeset music scores even more appropriate tools exist today.
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.
This approach has some disadvantages in comparison with a WYSIWYG (What You See Is What You Get) program such as Openoffice Writer or Microsoft Word.
In LaTeX:
- The compiled (final) version of the document is on a different window that the editor window .
- You generally need to remember the necessary commands for LaTeX markup.
- It can sometimes be difficult to obtain a certain look for the document.
On the other hand, there are certain advantages to the LaTeX approach:
- Document sources can be read with any text editor and understood, unlike the complex binary and XML formats used with WYSIWYG programs.
- You can concentrate purely on the structure and contents of the document, not get caught up with superficial layout issues.
- You don't need to manually adjust fonts, text sizes, line heights nor text flow for readability, as LaTeX takes care of them automatically.
- In LaTeX the document stucture is visible to the user, and can be easily copied to another document. In WYSIWYG applications it is often not obvious how a certain formatting was produced, and it might be impossible to copy it directly for use in another document.
- The layout, fonts, tables and so on are consistent throughout the document.
- Mathematical formulae can be easily typeset.
- Indexes, footnotes, citations and references are generated easily.
- You are forced to structure your documents correctly.
The LaTeX-like approach can be called WYSIWYM, i.e. What You See Is What You Mean: you can't see what 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 natively supports DVI and PDF, but by using other software you can easily create PostScript, PNG, JPG, etc.
Installing a distribution
If you want to use LaTeX locally on your computer, you generally need to install a TeX distribution. TeX distributions are packaged collections of packages and programs that enable you to typeset without having to manually fetch files and configure things. The recommended distributions for each of the major operating systems are:
- TeX Live is a major TeX distribution for Unix/Linux, Mac OS and Windows.
- MiKTeX is a Windows-specific distribution.
- MacTeX is a Mac OS-specific distribution based on TeX Live.
Windows
TeX live and MikTeX have easy installers that take care of setting up the environment and downloading packages.
Mac OS
- Download MacTeX.mpkg.zip on the MacTeX page, unzip it and follow the instructions.
Linux
TeX and LaTeX being used by the Linux OS for documentations and info files, at least a minimum installation of TeX and LaTeX is implemented by default on Linux distribution.
If your distribution does not have the TeX Live packages, you will need to download TeX Live yourself and run the installer by hand. From the TuG site you can get access to latest version of any software or package or macro.
Getting a text editor
You will also need a text editor to write LaTeX code. You should use a text editor (i.e. Notepad or wordpad), not a word processor (Word, Openoffice). Dedicated LaTeX editors are more useful than a plain text editors, because they usually have autocompletion of commands, spell and error checking and handy macros.
Editors that you can find on any of the three OS
TeXworks
TeXworks is a dedicated TeX editor that is included TeX Live and MikTeX. It was developed with the idea that a simple interface is better than a cluttered one, and thus to make it easier for people in their early days with LaTeX to get to what they want to do: write their documents. TeXworks originally came about precisely because a math professor wanted his students to have a better initial experience with LaTeX.
You can install TeXworks with the package manager of your Linux distribution or choose it as an install option in the Windows or Mac installer.
Emacs
Emacs is a general purpose text processing system. When used in combination with Auctex and Reftex (extensions that may be installed into the Emacs program), Emacs provides a complete LaTeX editing environment complete with table of contents view, document preview and many other features. Emacs is a very mature editing system with a unique set of keyboard commands. SyncTeX lets you synchronize your pointer from the PDF file to the source LaTeX file. On MaC OS/X, Aquamacs is probably the unique Emacs editor for French keyboards and the pdf previewer, Skim, lets you synchronize automatically.
One of many satirical expansions of the acronym EMACS is "Escape Meta Alt Control Shift" meaning that you can do everything with your fingers on a keyboard without using the mouse. It was and is still true but now you can do everything with a mouse and icons.
The advantage of a general purpose editor is that you can simultaneously have your LaTeX source in one buffer, your R source code in another, your SAS code in a third while gnuplot source is in a fourth window.
LyX, almost a WYSIWYG
LyX is a popular LaTeX editor for Windows, Linux and Mac OS. It contains formula and table editors and shows visual clues of the final document on the screen enabling users to write LaTeX documents without worrying about the actual syntax.
Other TeX editors
TeXnicCenter
TeXnicCenter is a popular free and open source LaTeX editor for Windows. It also has a similar user interface to TeXmaker and Kile.
BaKoMa TeX
BaKoMa TeX is a editor for Windows with WYSIWYG-like features. It takes care of compiling the LaTeX source and updating it constantly to view changes to document almost in real time.
TeXShop
TeXShop is a TeXworks-like editor for Mac OS.
gedit-latex-plugin
Gedit with gedit-latex-plugin is also worth trying out for users of GNOME. GEdit is a cross-platform application for Windows, Mac, and Linux
Gummi
Gummi is a LaTeX editor for Linux, which compiles the output of pdflatex in realtime and shows it on the right half of the screen.
Kile
Kile is a LaTeX editor for KDE (cross platform), providing a powerful GUI for editing multiple documents and compiling them with many different TeX compilers. Kile is based on Kate editor, has a quick access toolbar for symbols, document structure viewer, a console and customizable build options. Kile can be run in all operating systems that can run KDE.
TeXmaker
TeXmaker is a cross-platform editor very similar to Kile in features and user interface. In addition it has its own PDF viewer.
LaTeXila
LaTeXila is another text editor for Linux (Gnome).
Viewers
Finally, you will need a viewer for the files LaTeX outputs. Normally LaTeX saves the final document as a .dvi (Device independent file format), but you will rarely want it to. DVI files do not contain embedded fonts and many document viewers are unable to open them.
Usually you will use a LaTeX compiler like pdflatex to produce a PDF file directly, or a tool like dvi2pdf to convert the DVI file to PDF format. Then you can view the result with your preferred PDF viewer (Adobe Reader, Okular, Evince, Sumatra, Foxit).
Practically all LaTeX distributions have a DVI viewer for viewing the default output of latex, and also tools such as dvi2pdf for converting the result automatically to PDF and PS formats.
Applications within a distribution
Here are the main programs you expect to find in any LaTeX distribution:
- latex compiler reads a LaTeX .tex file and creates a .dvi
- pdflatex compiler reads a LaTeX .tex file and creates a .pdf
- dvi2ps converts the .dvi file to .ps (postscript).
- dvi2pdf converts the .dvi file to .pdf (dvi2pdfm is an improved version).
Also tex and pdftex compilers are included, but you shouldn't use them, because they support only plain TeX. Note that since LaTeX is just a collection of macros for TeX if you compile a plain TeX document with a LaTeX compiler (such as pdflatex) it will work while the opposite is not true: if you try to compile a LaTeX source with a TeX compiler you will get many errors.
When LaTeX was created, the only format it could create was DVI; later PDF support was added by pdflatex. PDF files can be created with both pdflatex and dvipdfm. The output of pdflatex takes direct advantage of modern features of PDF such as hyperlinks and embedded fonts, which are not part of DVI. Passing through DVI imposes limitations of its older format. On the other hand, some packages, such as PSTricks, exploit the process of conversion to DVI, and therefore will not work with pdflatex. Some of those packages embed information in the DVI that doesn't appear when the DVI is viewed, but reemerges when the DVI is converted to another, newer format.
You would write your document slightly differently depending on the compiler you are using (latex or pdflatex). But as we will see later it is possible to add a sort of abstraction layer to hide the details of which compiler you're using, while the compiler can handle the translation itself.
The following diagram shows the relationships between the LaTeX source code and the formats you can create from it:
The boxed red text represents the file formats, the blue text on the arrows represents the commands you have to use, the small dark green text under the boxes represents the image formats that are supported. Any time you pass through an arrow you lose some information, which might decrease the quality of your document. Therefore, in order to achieve the highest quality in your output file, you should choose the 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 Wikipedia:en:Ghostscript, which is a free and multi-platform software as well.
Chapter Wikibooks:en:LaTeX/Export_To_Other_Formats discusses more about exporting LaTeX source to other file formats.