Cours LATEX EDITE De Paris
Total Page:16
File Type:pdf, Size:1020Kb
Cours LATEX EDITE de Paris First steps with LATEX 20/01/2011 Page 1 / 62 Pierre Senellart Licence de droits d’usage Outline LATEX: a typesetting system General Description LATEX Compilation Resources LATEX Documents Writing Text with LATEX Application 20/01/2011 Page 2 / 62 Pierre Senellart Licence de droits d’usage Outline LATEX: a typesetting system General Description LATEX Compilation Resources LATEX Documents Writing Text with LATEX Application 20/01/2011 Page 3 / 62 Pierre Senellart Licence de droits d’usage General principles Pronounce “latek”: the last letter is a chi (휒) Typesetting system Not WYSIWYG (what you see is what you get) like classical word processing software (Microsoft Word, OpenOffice Writer, etc.) ALATEX document: a text file (or several), usually with the .tex extension, structured with tags (sometimes called macros or commands) with arguments (e.g., \section{Section title} ) Special case: environments \begin{center} This text is centered \end{center} 20/01/2011 Page 4 / 62 Pierre Senellart Licence de droits d’usage Advantages / a WYSIWYG system (More or less) semantic structuring of a document into chapters, sections, theorems, etc. Possible to describe (relatively) easily complex mathematical equations Better algorithms for justification, hyphenation, etc., since they do not need to run in real time Better typographic quality (e.g., kerning, ligatures) cf. http://nitens.org/taraborelli/latex Advantage of dealing with text files: arbitrary text editor, version control, regular expressions, production from scripts, etc. De facto standard in academia in mathematics, computer science, theoretical physics, etc. 20/01/2011 Page 5 / 62 Pierre Senellart Licence de droits d’usage History End of the 1970s Donald E. Knuth creates the typesetting systemTEX to write his book The Art of Computer Programming Beginning of the 1980s Leslie Lamport writes the macro systemLATEX on top of TEX 1985 Release ofLATEX 2.09 1994 Release of the current version of LATEX,LATEX 2휀 In progress Development of version3 ofL ATEX 20/01/2011 Page 6 / 62 Pierre Senellart Licence de droits d’usage First LATEX document \documentclass{minimal} \usepackage{cmap} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[francais]{babel} Bonjour à tous ! \begin{document} +∞ Bonjour à \emph{tous}! 1 π2 = n2 n 6 % Et une équation X=1 \[ \sum_{n=1}^{+\infty} \frac 1{n^2}=\frac{\pi^2}{6} \] \end{document} 20/01/2011 Page 7 / 62 Pierre Senellart Licence de droits d’usage Equivalent in Plain TEX \documentclass{minimal} \usepackage{cmap} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} Bonjour \‘a {\it tous\/}~! \usepackage{lmodern} \usepackage[francais]{babel} % Et une équation \begin{document} $$ Bonjour à \emph{tous}! \sum_{n=1}^{+\infty} {1\over n^2}={\pi^2\over 6} % Et une équation $$ \[ \sum_{n=1}^{+\infty} \end \frac 1{n^2}=\frac{\pi^2}{6} \] \end{document} 20/01/2011 Page 8 / 62 Pierre Senellart Licence de droits d’usage Outline LATEX: a typesetting system General Description LATEX Compilation Resources LATEX Documents Writing Text with LATEX Application 20/01/2011 Page 9 / 62 Pierre Senellart Licence de droits d’usage Output formats DVI (device-independent file format) historical output format of TEX. Readable with YAP (Windows), Evince (Gnome), Okular (KDE), Skim (Mac OS X), etc. PS (PostScript) page description language, understood by many printers. Readable with GhostView (Windows), Evince (Gnome), Okular (KDE), Skim (Max OS X), etc. PDF (Portable Document Format) page description language. Numerous readers, in particular Adobe Reader. The most convenient to distribute documents. HTMLAL ATEX document can also be turned into a Web page or Web site, but the process is imperfect. ODT It is possible to obtain an OpenDocument output, readable with Openoffice (e.g., to convert then into a Word document), but this does not work very well. 20/01/2011 Page 10 / 62 Pierre Senellart Licence de droits d’usage Compilation of a LATEX document pdflatex PDF dvipdfm ps2pdf latex dvips LATEX DVI PostScript mk4ht oolatex ODT hevea, latex2html, tth, mk4ht htlatex HTML 20/01/2011 Page 11 / 62 Pierre Senellart Licence de droits d’usage Recommended compilation methods pdflatex to prefer; simple, fast, produces an output format directly readable by all. latex + dvips + ps2pdf if used packages require a PostScript output (e.g., pstricks) hevea or latex2html or tth or mk4ht htlatex for an HTML output. None of them is ideal. Sometimes produce formulas as images, sometimes as MathML, sometimes as enriched text. mk4ht oolatex for an ODT output, convertible then in Word format with OpenOffice. Manual corrections to plan. 20/01/2011 Page 12 / 62 Pierre Senellart Licence de droits d’usage Outline LATEX: a typesetting system General Description LATEX Compilation Resources LATEX Documents Writing Text with LATEX Application 20/01/2011 Page 13 / 62 Pierre Senellart Licence de droits d’usage LATEX Distributions ALATEX distribution is a bundle of programs (pdflatex, dvips, etc.), fonts, LATEX packages, etc., with everything required to compile. Depending on the distributions, some slight differences of behavior are to be expected. Most often used distributions: TeX Live under Unix/Linux MikTeX under Windows; see also proTeXt, that adds some supplementary tools (TeXnicCenter, GhostView) MacTeX under Mac OS X 20/01/2011 Page 14 / 62 Pierre Senellart Licence de droits d’usage How to edit a LATEX document? With any text editor With a text editor that has syntax highlighting: emacs, vim, gedit, kate, etc. With an integrated environment for editing, compilation, complementary tasks: TeXnicCenter, TeXworks, AucTeX (emacs), etc. With a graphical interface that “hides” LATEX commands: LyX, Scientific Word (commercial) 20/01/2011 Page 15 / 62 Pierre Senellart Licence de droits d’usage Common issues Overfull hboxesT EX does not manage to find a decomposition of the text into lines that fits in the margins. Identify on a case by case basis if the problem is really apparent, and if so solve it by hand. Underfull vboxesT EX does not manage to put enough content on a page, which may look underfull. Identify on a case by case basis if the problem is really apparent, and if so solve it by hand. Not understandable error message Error messages are (sometimes) not really understandable. No other solutions than to look attentively at the code in question, to try and reproduce the problem on a minimal example, etc. Deleting generated files (e.g., .aux) sometimes helps. 20/01/2011 Page 16 / 62 Pierre Senellart Licence de droits d’usage When there is a compilation error TEX display the error message: ! Undefined control sequence. l.5 the \foo is The problem is (often) at the end of the first highlighted line; sometimes the problem is a consequence of another problem, difficult to identify. Press <Enter> to resume, ignoring the incriminated portion, (seldom useful) or x<Enter> to stop the compilation. TEX sometimes simply displays “*” and waits for an input. Most of the time, it means that an environment has not been closed. Press CTRL+C, then x<Enter>, to stop the compilation. 20/01/2011 Page 17 / 62 Pierre Senellart Licence de droits d’usage Where to find help? In the documentation of each package, accessible with “texdoc nom_du_package” if the package is properly installed, can be found on the CTAN package archive otherwise: http://www.ctan.org/ In the TeX FAQ UK, very comprehensive: http://www.tex.ac.uk/cgi-bin/texfaq2html On the newsgroups comp.text.tex or fr.comp.text.tex The Comprehensive LATEX Symbol List, accessible with “texdoc symbols-a4” Find a LATEX symbol by drawing it: http://detexify.kirelabs.org/classify.html 20/01/2011 Page 18 / 62 Pierre Senellart Licence de droits d’usage Books to go further LATEX par la pratique, Ch. Rolland, O’Reilly France (in French, sold out, very good introduction) The LATEX Companion, F. Mittelbach et al., Addison-Wesley (reference book listing a large number of LATEX packages and describing their use) The TEXbook, D. E. Knuth, Addison-Wesley (very technical on the functioning of the TEX engine, but very interesting) 20/01/2011 Page 19 / 62 Pierre Senellart Licence de droits d’usage Outline LATEX: a typesetting system LATEX Documents Structure Classes and Packages LATEX commands Writing Text with LATEX Application 20/01/2011 Page 20 / 62 Pierre Senellart Licence de droits d’usage Outline LATEX: a typesetting system LATEX Documents Structure Classes and Packages LATEX commands Writing Text with LATEX Application 20/01/2011 Page 21 / 62 Pierre Senellart Licence de droits d’usage General structure: 1/2 A class declaration \documentclass{minimal} Reference to packages, possibly with other declarations \usepackage{cmap} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[francais]{babel} The beginning of the document \begin{document} 20/01/2011 Page 22 / 62 Pierre Senellart Licence de droits d’usage General structure: 2/2 The body of the document Bonjour à \emph{tous}! % Et une équation \[ \sum_{n=1}^{+\infty} \frac 1{n^2}=\frac{\pi^2}{6} \] The end of the document \end{document} Everything after a % is a comment and is ignored. 20/01/2011 Page 23 / 62 Pierre Senellart Licence de droits d’usage One document, several files For a large document, useful to split it into several files (e.g., one per chapter, or even one per section) The file content is included with \input{file_name} No need to specify the .tex extension \begin{document} \input{abstract} \input{introduction} \input{algorithm} \input{experiments}