1 LaTeX |
1 LaTeX |
2 ===== |
2 ===== |
3 |
3 |
4 Introduction |
4 Introduction |
5 ------------ |
5 ------------ |
6 LaTeX is a typesetting program used to produce excellently typeset documents. It is extensively used for producing high quality scientific and mathematical documents. It may also be used for producing other kinds of documents, ranging from simple one page articles or letters |
6 |
7 |
7 LaTeX is a typesetting program that produces excellently typeset |
8 |
8 documents. Typesetting is placing text onto a page with all the style |
9 TeX & LaTeX |
9 formatting defined, so that content looks as intended. It is |
10 ~~~~~~~~~~~ |
10 extensively used for producing high quality scientific and |
11 |
11 mathematical documents. It is also used for producing other kinds of |
12 TeX |
12 documents, ranging from simple one page articles or letters to |
13 +++ |
13 books. LaTeX is based on the TeX typesetting language. |
14 |
|
15 TeX is a typesetting system designed by Donald Knuth, the renowned Computer Scientist and Emeritus professor at Stanford University. Typesetting is placing text onto a page with all the style formatting defined, so that content looks as intended. |
|
16 |
|
17 It was designed with two goals in mind- |
|
18 |
|
19 1. To allow anybody to produce high-quality books using a reasonable amount of effort. |
|
20 2. To provide a system that would give the exact same results on all computers, now and in the future |
|
21 |
|
22 TeX is well known for it's stability and portability. |
|
23 |
|
24 TeX is pronounced as "tech". |
|
25 |
|
26 The current version of TeX is 3.1415926 and is converging to π. |
|
27 |
|
28 LaTeX |
|
29 +++++ |
|
30 |
|
31 LaTeX was originally written by Leslie Lamport in the early 1980s. It is an extension of TeX, consisting of TeX macros and a program to parse the LaTeX files. It is easier to use than TeX itself, at the same time producing the same quality of output. |
|
32 |
14 |
33 LaTeX is pronounced either as "Lah-tech" or "Lay-tech" |
15 LaTeX is pronounced either as "Lah-tech" or "Lay-tech" |
34 |
16 |
35 WYSIWG vs. WYSIWM |
17 In this course, we shall use the sample document, ``sample.pdf``, as a |
36 ~~~~~~~~~~~~~~~~~ |
18 tool to learn various commands of LaTeX. By the end of the sessions on |
37 |
19 LaTeX, we will have produced a copy of that document, starting from |
38 WYSIWG is an acronym for "What You See Is What You Get". Word processors, are typically WYSIWG tools. LaTeX, TeX or other TeX based tools are not. They are typesetting or text formatting or document description programs. They can be called WYSIWM or "What You See Is What you Mean" systems, since you give a description of how things look, and LaTeX typesets the document for you. |
20 scratch. |
39 |
21 |
40 Here are a few reasons, why you should use LaTeX - |
22 A Look at the Sample Document |
41 |
23 ----------------------------- |
42 * LaTeX produces documents with excellent visual quality, especially mathematical and scientific documents. |
24 |
43 * It does the typesetting to you. Typically, when one works with a word-processor, the user is doing the text formatting or typesetting along with typing out the content. LaTeX allows the user to concentrate on the content leaving aside the typesetting to LaTeX. |
25 Let's first look at the basic structure of the sample document. |
44 * It is light on your resources as compared to most of the word processors available today. |
26 |
45 * It is well known for it's stability and for it's virtually bug free code base. |
27 Slides with screen shots of |
46 * It encourages users to structure documents by meaning rather than appearance, thereby helping produce well structured documents. |
28 |
47 * It uses plain text files as input, which have a lot of well known advantages over binary files. To state a few, they can be opened with any editor on any operating system, they are smaller in size compared to the binaries, can be version controlled and can be processed using widely used text processing utilities. |
29 * Title, Author, Date |
48 * The output can be generated in more than one formats. |
30 * Abstract |
|
31 * Sections |
|
32 * Subsections |
|
33 * Appendix |
|
34 * References/Bibliography |
|
35 * Tables |
|
36 * Figures |
|
37 * Math |
|
38 |
|
39 Writing the source & compiling it |
|
40 --------------------------------- |
|
41 |
|
42 Let's begin with a simple hello world, to see how to write a LaTeX |
|
43 document and compile it. Write the following code into the file |
|
44 ``draft.tex``. :: |
|
45 |
|
46 \documentclass{article} |
|
47 \begin{document} |
|
48 SciPy is open-source software for mathematics, science, and engineering. |
|
49 \end{document} |
|
50 |
|
51 To compile the document, do the following in your terminal:: |
|
52 |
|
53 $ pdfLaTeX draft.tex |
|
54 |
|
55 This produces the output file ``draft.pdf`` |
|
56 |
|
57 Note: The ``LaTeX`` command is often used, instead of ``pdfLaTeX`` to |
|
58 get the ``dvi`` output. But, throughout this course, we shall use |
|
59 pdfLaTeX to compile our documents. |
|
60 |
|
61 ``\documentclass`` |
|
62 ------------------ |
|
63 |
|
64 The documentclass command, defines the structure and formatting of our |
|
65 document. LaTeX typsets the document, based on the documentclass. |
|
66 |
|
67 LaTeX is a document based markup language. |
|
68 |
|
69 First of all, a markup language is a system of annotating text or |
|
70 adding in extra information to the text that specifies it's structure |
|
71 or presentation. |
|
72 |
|
73 LaTeX is a document based markup and not an element based one. You |
|
74 generally don't have to worry about typesetting each of the elements |
|
75 of your document. Choosing an appropriate documentclass, gives you a |
|
76 suitable typesetting. You as an author can worry about the content of |
|
77 the document, rather than the appearance or presentation of the |
|
78 document. |
|
79 |
|
80 Why should you use it? |
|
81 ~~~~~~~~~~~~~~~~~~~~~~ |
|
82 |
|
83 A few reasons for using LaTeX - |
|
84 |
|
85 * It produces documents with excellent visual quality. |
|
86 * It does the typesetting for you, leaving you - the author - to |
|
87 focus on writing the content. |
|
88 * It makes writing math just as easy as writing simple text. |
|
89 * It's renowned for it's stability and a virtually bug free code |
|
90 base. |
|
91 * It is light on your resources as compared to most of the word |
|
92 processors available today. |
|
93 * It uses plain text files as input and can give output in a variety |
|
94 of formats including PDFs and html making it platform independent. |
49 * It is free software (free as in freedom) and gratis too. |
95 * It is free software (free as in freedom) and gratis too. |
50 * It is widely used. |
96 * It is widely used and has a large user community. |
51 |
97 |
52 Hello World |
98 |
53 ~~~~~~~~~~~ |
99 ``\begin`` and ``\end`` commands define environments. In our document, |
54 |
100 we have the document environment, which defines the beginning and end |
55 OK, let's get started with our first LaTeX document. Open up your favorite editor and type in the following code. |
101 of the content of the document. We place all the content of the |
|
102 document within this environment. |
|
103 |
|
104 Also, as you may have noticed, all the commands in LaTeX begin with a |
|
105 ``\``. Note that they are case sensitive. Command names in LaTeX |
|
106 usually have only alpha characters. Any characters other than alpha |
|
107 characters, terminate the command name. Parameters to commands are |
|
108 passed in ``{ }``. |
|
109 |
|
110 |
|
111 Top Matter |
|
112 ---------- |
|
113 |
|
114 Let us begin with adding the Title, Author's name and the date to the |
|
115 document. |
56 |
116 |
57 :: |
117 :: |
58 |
118 |
59 %hello.tex - First LaTeX document |
|
60 \documentclass{article} |
119 \documentclass{article} |
61 |
120 \title{A Glimpse at Scipy} |
|
121 \author{FOSSEE} |
|
122 \date{June 2010} |
62 \begin{document} |
123 \begin{document} |
63 Hello, World! |
124 \maketitle |
|
125 SciPy is open-source software for mathematics, science, and engineering. |
64 \end{document} |
126 \end{document} |
65 |
127 |
66 Save the file as ``hello.tex`` and open up a terminal to compile your ``tex`` file to get the output in a ``pdf`` format. |
128 We add the title, the author and the date to the document before the |
67 |
129 ``\begin{document}`` directive. We compile the document to see if the |
68 Compiling & Output |
130 details appear in the document, but they donot. These details do not |
69 ++++++++++++++++++ |
131 appear in the document until we use the ``\maketitle`` command with |
|
132 the document environment to instruct LaTeX to place the top matter |
|
133 information into the document. Now the document has these details, on |
|
134 compiling again. |
|
135 |
|
136 If no date is specified, LaTeX automatically inserts the current date. |
|
137 |
|
138 Abstract |
|
139 -------- |
|
140 |
|
141 Next we shall add an abstract to our document. LaTeX provides an |
|
142 environment, for adding an abstract to the document. :: |
|
143 |
|
144 \documentclass{article} |
|
145 |
|
146 \title{A Glimpse at Scipy} |
|
147 \author{FOSSEE} |
|
148 \date{June 2010} |
|
149 |
|
150 \begin{document} |
|
151 |
|
152 \maketitle |
|
153 |
|
154 \begin{abstract} |
|
155 This document shows a glimpse of the features of Scipy that will be explored during this course. |
|
156 \end{abstract} |
|
157 |
|
158 SciPy is open-source software for mathematics, science, and engineering. |
|
159 \end{document} |
|
160 |
|
161 The abstract environment is placed at the location where we wish it to |
|
162 appear in the document. |
|
163 |
|
164 Sections |
|
165 -------- |
|
166 |
|
167 Now let's look at how to add (chapters,) sections and sub-sections to |
|
168 our document. Let's add the section headings and sub headings present |
|
169 in our sample document to the working copy of our document. |
|
170 |
|
171 ``\section``, ``\subsection``, ``\subsubsection`` |
|
172 |
|
173 On compiling, we can see that the headings of the sections and the |
|
174 sub-sections appear in the document. |
|
175 |
|
176 You may have noticed that LaTeX automatically numbers the sections. To |
|
177 prevent a section from getting numbered, an asterix is appended to the |
|
178 corresponding sectioning command. |
|
179 |
|
180 If the document was a longer document, we could have used a report or |
|
181 a book class. (Note: Books donot have the abstract environment.) Let's |
|
182 look at what happens to the document, when we change it to the report |
|
183 class. |
|
184 |
|
185 The numbering strangely begins from zero, now. This is because, |
|
186 chapters have an additional sectioning command called |
|
187 ``\chapter``. The chapter is one level above a section and since, our |
|
188 document does not have a ``\chapter`` command, the sections are |
|
189 numbered from 0. To change this, we add a chapter command before the |
|
190 first section. We say:: |
|
191 |
|
192 \chapter{One} |
|
193 |
|
194 Now, observe that we now have a chapter title appearing and the |
|
195 numbering starting from 1. |
|
196 |
|
197 Also, note that the subsubsections donot get a numbering now. This is |
|
198 controlled by a variable called the secnumdepth. By default it is set |
|
199 to 2. We can now, change it to 3 and get numbering for subsubsections |
|
200 also. :: |
|
201 |
|
202 \setcounter{secnumdepth}{3} |
|
203 |
|
204 What do you expect to happen if we changed the secnumdepth to 1? What |
|
205 if it is 0? -1? {Lab excercise} |
|
206 |
|
207 |
|
208 Appendix |
|
209 -------- |
|
210 |
|
211 Notice that our document also has an appendix. Let's add an appendix |
|
212 to our document. |
70 |
213 |
71 :: |
214 :: |
72 |
215 |
73 $pdflatex hello.tex |
216 \appendix |
74 |
217 \section{Plotting using Pylab} |
75 Output written on hello.pdf (1 page, 5733 bytes). |
218 |
76 Transcript written on hello.log. |
219 Table of Contents |
77 |
220 ----------------- |
78 Open the ``hello.pdf`` to see the output as shown. |
221 |
79 |
222 Our sample document is not long enough to warrant a table of contents, |
80 .. image:: examples/hello.jpg |
223 but let us learn to add a table of contents to a LaTeX document. If |
81 |
224 you ever tried adding a table of contents, to a document in a |
82 Note: The command ``latex`` is often used to get the ``dvi`` output. But, throughout this course, we shall use pdflatex to compile our documents. |
225 wordprocessor, you would know how much of a trouble it is. In LaTeX, |
83 |
226 it is a matter of just one command and placing the command at the |
84 A peek at the source |
227 location where you would want to have the table of contents. Let's now |
85 ++++++++++++++++++++ |
228 add a table of contents to our draft. Now, compile the document and |
86 |
229 look at the output document. It does not have the table of contents! |
87 ``%hello.tex - First LaTeX document`` |
230 |
88 |
231 On the first compilation only the "Contents" heading appears in the |
89 This line is a comment. LaTeX ignores this line and it is meant only for the human readers. LaTeX ignores anything after a ``%`` symbol to the end of the line. |
232 document, but the actual table does not appear. You will need to |
90 |
233 compile your document once more, for the actual table to appear in |
91 ``\documentclass{article}`` |
234 your document. On the first run, LaTeX has gone through your document |
92 |
235 and generated a temporary file (``.toc``), with the entries that |
93 This line is a command and sets the ``documentclass`` of the document to ``article``. LaTeX has other classes like ``report``, ``book``, ``letter``, etc. The typesetting of the document varies depending on the ``documentclass`` of the document. |
236 should go into the table of contents. These entries are made, when you |
94 |
237 compile your document for the second time. |
95 |
238 |
96 ``\begin{document}`` |
239 Note that any section/block that has been numbered automatically |
97 |
240 appears in the table of contents. It is possible to get un-numbered |
98 This line informs LaTeX that this is the beginning of the content of the document. |
241 sections, for instance a Preface or a Foreword section to appear in |
99 |
242 the Table of Contents. |
100 ``Hello, World!`` |
243 |
101 |
244 Let's change our Introduction section to be an un-numbered one and try |
102 This is the actual text displayed in the document. |
245 to make it appear in the table-of-contents. :: |
103 |
|
104 ``\end{document}`` |
|
105 |
|
106 This line tells LaTeX that the document is complete and LaTeX will simply ignore anything written after this line. |
|
107 |
|
108 Where do we want to go |
|
109 ~~~~~~~~~~~~~~~~~~~~~~ |
|
110 |
|
111 During the course of this session we will learn how to do various things in LaTeX and try to produce the sample document provided. |
|
112 |
|
113 Some Basics |
|
114 ~~~~~~~~~~~ |
|
115 Before we get started with creating the document, let's try to understand a few things that would be useful during the course of this session. |
|
116 |
|
117 Spaces |
|
118 ++++++ |
|
119 |
|
120 LaTeX treats multiple empty spaces (or lines) as a single space (or line). An empty line between two lines of text is considered as a change of paragraphs. |
|
121 |
|
122 Line & Page Breaks |
|
123 ++++++++++++++++++ |
|
124 |
|
125 LaTeX usually does the job of breaking up your content into lines and pages, and does it well. But under some circumstances, you might want to instruct LaTeX to break line or start a new page at a particular point. |
|
126 |
|
127 ``\\`` or ``\newline`` command is used to create a new line at the point where the command is issued. |
|
128 Appending ``*`` to ``\\``, instructs LaTeX to create a new line, without creating a new page at that point. |
|
129 |
|
130 Paragraphs |
|
131 ++++++++++ |
|
132 |
|
133 As already mentioned, LaTeX considers an empty line between two lines of text as a new paragraph. ``\par`` command may also be used to start a newline. It is equivalent to the blank line. |
|
134 |
|
135 By default LaTeX indents new paragraphs. If you do not wish to have the paragraph indented, you can use the ``\nointend`` command at the beginning of the paragraph. |
|
136 |
|
137 Special Characters |
|
138 ++++++++++++++++++ |
|
139 |
|
140 LaTeX associates special meaning to the characters ``~ # $ % ^ & _ { } \``. |
|
141 |
|
142 To have these characters in the text of your document, you need to prefix a backslash to them. ``\~ \# \% \$ \^ \& \_ \{ \} \textbackslash`` |
|
143 |
|
144 |
|
145 Commands |
|
146 ++++++++ |
|
147 |
|
148 * All LaTeX commands start with a backslash ``\``. |
|
149 * Like the commands in Linux, they are case sensitive. |
|
150 * They usually have a backslash followed by a consisting of letters only. Any character other than letters, like space, numbers or special characters terminate the command. |
|
151 * The commands for producing special characters in the text, is an exception. They contain a backslash followed by a single special character. |
|
152 * Commands may have parameters, which are supplied to them by enclosing them in curly braces ``{ }``. |
|
153 * They may also have a few optional parameters which are added after the name in square brackets ``[ ]``. |
|
154 |
|
155 |
|
156 Environments |
|
157 ++++++++++++ |
|
158 |
|
159 Environments are very similar to the commands, except that they effect larger parts of the document. For example, we used the ``document`` environment in our first LaTeX document. |
|
160 |
|
161 * They begin with a ``\begin`` and end with a ``\end`` |
|
162 * In general environments can be nested within each other. |
|
163 |
|
164 Some Structural Elements |
|
165 ------------------------ |
|
166 |
|
167 ``\documentclass`` |
|
168 ~~~~~~~~~~~~~~~~~~ |
|
169 As already stated, the ``documentclass`` command tells LaTeX, the type of the document that you intend to create. Each class has a few differences in how the content of the document is typeset. We presently have it set to the article class. Let us try changing it to the report class. |
|
170 |
|
171 Note that the top matter of the document appears in a different page for the report class. |
|
172 |
|
173 Some of the LaTeX classes that you may want to use are, article, proc, report, book, slides, letter. |
|
174 |
|
175 The ``documentclass`` command also accepts a few optional parameters. For example:: |
|
176 \documentclass[12pt,a4paper,oneside,draft]{report} |
|
177 |
|
178 ``12pt`` specifies the size of the main font in the document. The relative sizes of the various fonts is maintained, when the font size is changed. If no size is specified, ``10pt`` is assumed by default. |
|
179 |
|
180 ``a4paper`` specifies the size of the paper to be used for the document. |
|
181 |
|
182 ``oneside`` specifies that the document will be printed only on one side of the paper. The ``article`` and ``report`` classes are ``oneside`` by default and the ``book`` class is ``twoside``. |
|
183 |
|
184 ``draft`` marks the hyphenation and justification problems in the document with a small square in the right hand margin of the document, so that they can be easily spotted. |
|
185 |
|
186 Note: Everything written in between the ``\documentclass`` command and the ``\begin{document}`` command is called the Preamble. |
|
187 |
|
188 |
|
189 Parts, Chapters and Sections |
|
190 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
191 |
|
192 Often documents are divided into various parts, chapters, sections and subsections. LaTeX provides an intuitive mechanism to include this in your documents. It has various commands like ``part``, ``chapter``, ``section``, ``subsection``, ``subsubsection``, ``paragraph`` and ``subparagraph``. Note that all these commands are not available in all the document classes. The ``chapter`` command is available only in books and reports. Also, the ``letter`` document class does not have any of these commands. |
|
193 |
|
194 Let us now give our document some structure, using these commands. |
|
195 |
|
196 Note that you do not need to provide any numbers to the commands. LaTeX automatically takes care of the numbering. |
|
197 Also, you do not need to enclose the text of a block within ``\begin`` and ``\end`` commands. LaTeX starts a new block each time it finds a sectioning command. |
|
198 :: |
|
199 |
|
200 \section[Short Title]{This is a very long title and the Short Title will appear in the Table of Contents.} |
|
201 |
|
202 |
|
203 Section Numbering |
|
204 +++++++++++++++++ |
|
205 |
|
206 As already, you don't need to explicitly do any numbering in LaTeX. Parts are numbered using roman numerals; Chapters and sections are numbered using decimal numbers. When the table of contents is inserted into a document, all the numbered headings automatically appear in it. |
|
207 |
|
208 By default LaTeX has numbering up 2 levels, i.e, the parts, chapters, sections and subsections are numbered. You can change this by setting the ``secnumdepth`` counter using the ``\setcounter`` command. The following command removes numbering of the subsections. Only parts, chapters and sections are numbered. |
|
209 :: |
|
210 |
|
211 \setcounter{secnumdepth}{1} |
|
212 |
|
213 A sectioning command appended with an asterisk gives an unnumbered heading that is not included in the table of contents. |
|
214 :: |
|
215 |
246 |
216 \section*{Introduction} |
247 \section*{Introduction} |
217 |
248 \addcontentsline{toc}{section}{Intro} |
218 Top Matter |
249 |
219 ~~~~~~~~~~ |
250 We shall talk about adding and managing bibliographies, later in the |
220 |
251 course. |
221 The information about the document such as it's title, the date, the author(s) information etc, is collectively known as the topmatter. Though there is no command called ``topmatter``, the term topmatter is frequently used in LaTeX documentation. |
252 |
222 |
253 Now, that we have the basic structure of the document, let's get into |
223 Let us input the top matter for our document now. |
254 the content and the details of it. |
224 :: |
255 |
225 |
256 Typesetting Text |
226 \title{LaTeX - A How-to} |
257 ---------------- |
227 \author{The FOSSEE Team} |
258 |
228 \date |
259 Let's begin with adding the second paragraph to the introduction |
229 |
260 section. Let's place the text of the second para, after the first |
230 The commands ``\title`` and ``\author`` are self explanatory. |
261 line, that we already have. Now, compile the document. |
231 The ``\date`` command automatically puts in today's date into the document. Now let us compile and look at the result. |
262 |
232 |
263 Notice, that the second para appears in continuation with the previous |
233 You would observe that the details do not appear in the document after recompilation. This is because, LaTeX has not been instructed what to do with the top matter information that you have given it. Use the ``\maketitle`` command within the document environment to instruct LaTeX to place the top matter information into the document. |
264 line. To start a new paragraph in LaTeX, we need to insert an empty |
234 |
265 line. Multiple empty lines are considered as a single empty line. To |
235 Abstract |
266 start a new line, use the ``\newline`` or ``\\`` command. Notice the |
236 ~~~~~~~~ |
267 difference (in the output), in starting a new paragraph and starting a |
237 Lets now place and abstract in the document using the ``abstract`` environment of LaTeX. The abstract appears in the document after the topmatter but before the main body of the document. |
268 newline. A new paragraph is indented. |
238 :: |
|
239 |
|
240 \begin{abstract} |
|
241 The abstract abstract. |
|
242 \end{abstract} |
|
243 |
|
244 |
|
245 Appendices |
|
246 ~~~~~~~~~~ |
|
247 |
|
248 LaTeX allows for separate numbering for appendices. ``\appendix`` command indicates that the sections following are to be included in the appendix. |
|
249 :: |
|
250 |
|
251 \appendix |
|
252 \chapter{First Appendix} |
|
253 |
|
254 Table of Contents |
|
255 ~~~~~~~~~~~~~~~~~ |
|
256 |
|
257 Parts, chapters or sections that have been auto numbered by LaTeX automatically appear in the Table of Contents (ToC). ``\tableofcontents`` command places a the ToC, where the command has been issued. |
|
258 |
|
259 The counter ``tocdepth`` specifies the depth up to which headings appear in the ToC. It can be set using the ``\setcounter`` command as shown below. |
|
260 :: |
|
261 |
|
262 \setcounter{tocdepth}{3} |
|
263 |
|
264 Unnumbered sections can be placed in the table of contents using the ``\addcontentsline`` command as shown below. |
|
265 :: |
|
266 |
|
267 \section*{Introduction} |
|
268 \addcontentsline{toc}{section}{Introduction} |
|
269 |
|
270 Note: To get the correct entries in your table of contents, you will need to run one extra compilation, each time. This is because, the entries of the table of contents are collected during each compilation of the document and utilized during the next compilation. |
|
271 |
|
272 Elementary Text Typesetting |
|
273 --------------------------- |
|
274 |
|
275 Emphasizing |
|
276 ~~~~~~~~~~~ |
|
277 |
|
278 *Italic* font is generally used to emphasize text. The ``\emph`` command may be used to achieve this effect in LaTeX. |
|
279 :: |
|
280 |
|
281 This is the \emph{emphasized text}. |
|
282 |
|
283 If the ``\emph`` command is nested within another emphasize command, LaTeX emphasized that text using normal fonts. |
|
284 :: |
|
285 |
|
286 \emph{Did you wonder what happens when we try \emph{emphasizing text} within \emph{emphasized text}}? |
|
287 |
|
288 *This is emphasized text, and* this is emphasized text with normal font *, within* emphasized text. |
|
289 |
269 |
290 Quotation Marks |
270 Quotation Marks |
291 ~~~~~~~~~~~~~~~ |
271 --------------- |
292 |
272 |
293 When typing in LaTeX, the double quotation mark ``"`` character shouldn't be used. The grave accent ````` character produces the left quote and the apostrophe ``'`` character produces the right quote. To obtain double quotes they are, each, used twice. |
273 Look at the quotation marks around the text, Sigh Pie. They are not |
294 :: |
274 formatted properly. To place quotation marks in LaTeX, you should use |
295 |
275 ````` character for the left quote & ``'`` character for the right |
296 `` Here is an example of putting `text' in quotes '' |
276 quote. For double quotes, they should be used twice. |
297 |
277 |
298 Dashes and Hyphens |
278 Fonts |
299 ~~~~~~~~~~~~~~~~~~ |
279 ----- |
300 |
280 |
301 LaTeX has four dashes of different lengths. Three of them can be produces with different number of consecutive dashes. The short dashes are used for hyphens, slightly longer ones for number ranges and the longest ones for comments. The fourth one is a mathematical symbol, the minus sign. |
281 The names of the software tools, Scilab, Matlab, etc. appear in |
302 :: |
282 italics or emphasized as it is called in LaTeX. To emphasize text, the |
303 |
283 ``\emph`` command is used. |
304 The names of these dashes are: `-' hyphen, `--' en-dash, `---' em-dash and `$-$' minus sign. |
284 |
305 |
285 Let's also add the contents of the subsection "Sub-packages of |
306 The names for these dashes are: ‘‐’ hyphen, ‘–’ en-dash, ‘—’ em-dash and ‘−’ minus sign. |
286 Scipy". We shall add the table as plain text, until we learn how to |
307 |
287 edit tables. |
308 Footnotes |
288 |
309 ~~~~~~~~~ |
289 Let's try and form a tabular structure by separating the left and |
310 |
290 right columns using spaces. On compiling we find that LaTeX doesn't |
311 With the command:: |
291 add multiple spaces between words. Just like multiple empty lines, |
312 |
292 multiple spaces are considered as a single space. |
313 \footnote{footnote text} |
293 |
314 |
294 The names of the sub-packages appear in a fixed width font in the |
315 a footnote is printed at the foot of the current page. Footnotes should always be put after the word or sentence they refer to. Footnotes referring to a sentence or part of it should therefore be put after the comma or period. |
295 sample document provided to us. The headings of the columns appear in |
316 |
296 bold-face. Let's make changes to this effect. |
317 Note: Look at the ``\marginpar`` command to insert margin notes |
297 |
318 |
298 ``\textbf`` is used to change text to bold face and ``\texttt`` is |
319 Flushleft, Flushright, and Center |
299 used to change text to fixed width font. |
320 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
300 |
321 |
301 We could also change the separating - (hyphen) to an em-dash (or |
322 The environments ``flushleft`` and ``flushright`` generate paragraphs that are either left- or right-aligned. |
302 en-dash) -- is em-dash and --- is an em-dash, to improve the |
323 |
303 appearance of the document. |
324 The ``center`` environment generates centered text. |
304 |
325 |
305 Lists |
326 Itemize, Enumerate, and Description |
306 ----- |
327 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
307 |
328 LaTeX has three different environments for producing lists. Itemize, Enumerate and Description allow you to produce lists of various types in LaTeX. |
308 The section on Use of Scipy in this course, contains lists. Let's now |
329 |
309 add lists to our document. The ``enumerate`` environment adds numbered |
330 Itemize is used to produce unnumbered lists. The bullets of the list can be easily changed to use any character. Enumerate environment allows you to produce auto-numbered lists. The description environment, allows you to produce a list of definitions. These environments can be nested within each other, easily. |
310 lists to our document and the ``itemize`` environment adds un-numbered |
331 |
311 lists. ``\item`` command adds a new entry to a list. Note, that LaTeX |
332 :: |
312 can easily handle nested lists. In fact most environments can be |
333 |
313 embedded within other environments, without any problems. |
334 \begin{itemize} |
314 |
335 \item Now we move onto some elementary \emph{Text Typesetting}. |
315 LaTeX also has a description list, which shall be looked at, during |
336 \item How do we get \emph{emphasized or italic text}? |
316 the lab sessions. |
337 \item \emph{Did you wonder what happens when we try \emph{emphasizing text} within \emph{emphasized text}}? |
317 |
338 \item ``Beautiful is better than ugly.'' |
318 Footnotes, Labels and References |
339 \end{itemize} |
319 -------------------------------- |
340 |
320 |
341 \begin{description} |
321 Let's now add the footnote to pylab. LaTeX provides a footnote command |
342 \item[Description] This list is a description list. |
322 to add a footnote. |
343 \item[Enumerate] Numbered lists are often useful. |
323 |
344 \begin{enumerate} |
324 We added the footnote with Appendix A, as plain text. But, in case we |
345 \item First |
325 added another Appendix before the section on using ``pylab``, the |
346 \item Second |
326 footnote will have to be edited. To avoid this, LaTeX provides a handy |
347 \item Third |
327 system of labels and referencing. |
348 \item \ldots |
328 |
349 \end{enumerate} |
329 We first add a label to the section that we want to refer in this |
350 \item[Itemize] The list above this description list is an itemize list. |
330 footnote. Then, we change the footnote, and add the reference to this |
351 \end{description} |
331 label instead of the character A. If you look at the output after |
352 |
332 compiling the document once, you will see that the footnote has |
353 Quote, Quotation, and Verse |
333 question marks instead of the section number. You will have to |
354 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
334 compile once again, for the section number to appear in the footnote. |
355 |
335 |
356 LaTeX provides a ``quote`` environment that can be used for quoting, highlighting important material, etc. |
336 |
357 :: |
337 Including code |
358 |
338 -------------- |
359 The Zen of Python |
339 |
360 \begin{quote} |
340 In the footnote above, and in the table for the sub-packages list, we |
361 The Zen of Python, by Tim Peters |
341 used the ``\texttt`` command to get a fixed width font. But we could |
362 |
342 instead use an environment provided by LaTeX to include pre-formatted |
363 Beautiful is better than ugly. |
343 text or code. LaTeX by default provides the verbatim environment to |
364 Explicit is better than implicit. |
344 include pre-formatted text. You can try that out during the lab |
365 Simple is better than complex. |
345 session. We shall look at using the listings package, specifically |
366 Complex is better than complicated. |
346 meant for including code in our document. |
367 Flat is better than nested. |
347 |
368 Sparse is better than dense. |
348 First of all you need to tell LaTeX, that you want to use the listings |
369 Readability counts. |
349 package in your document. We add the directive |
370 Special cases aren't special enough to break the rules. |
350 ``\usepackage{listings}`` to the preamble of our document. |
371 Although practicality beats purity. |
351 |
372 Errors should never pass silently. |
352 Then we set the language of the code that we are going to embed into |
373 Unless explicitly silenced. |
353 our document. For this we use the lstset command. :: |
374 In the face of ambiguity, refuse the temptation to guess. |
354 |
375 There should be one-- and preferably only one --obvious way to do it. |
355 \lstset{language=Python, |
376 Although that way may not be obvious at first unless you're Dutch. |
356 showstringspaces=false,} |
377 Now is better than never. |
357 |
378 Although never is often better than *right* now. |
358 The listings package allows you to use color and do a lot of things |
379 If the implementation is hard to explain, it's a bad idea. |
359 with your embedded code, but all that during a lab exercise. |
380 If the implementation is easy to explain, it may be a good idea. |
360 |
381 Namespaces are one honking great idea -- let's do more of those! |
361 Now, to put a line of code, inline and not as a separate block, we use |
382 \end{quote} |
362 the ``\lstinline`` command. We change the name pylab in the footnote |
383 |
363 to use lstinline instead of the texttt. To embed a block of code, we |
384 LaTeX provides two other similar environments, the quotation and the verse environments. |
364 use the lstlisting environment (``\begin{lstlisting}`` and |
385 |
365 ``\end{lstlisting}``). For example, let's add the code to the Appendix |
386 The quotation environment can be used for longer quotes which have several paragraphs, since it indents the first line of each paragraph. |
366 of our document. |
387 |
367 |
388 The verse environment may be used to quote verses or poems, since the line breaks are important in quoting them. The lines are separated using ``\\\\`` at the end of a line and an empty line after each verse. |
368 Figures, Tables and Floats |
389 |
369 -------------------------- |
390 Verbatim |
370 |
391 ~~~~~~~~ |
371 Let's now add the figure, to the appendix. |
392 The verbatim environment allows us to insert pre-formatted text in a LaTeX document. It is useful for inserting code samples within the document. The verbatim text needs to be enclosed between ``\begin{verbatim}`` and ``\end{verbatim}``. |
372 |
393 :: |
373 To include graphics in a LaTeX document, we need to use the graphicx |
394 |
374 package. Add the ``\usepackage{graphicx}`` directive to the preamble |
395 \begin{verbatim} |
375 of the document. |
396 from numpy import * |
376 |
397 a = linspace(0, 5, 50, endpoint = False) |
377 To add the graphic, use the ``includegraphics`` command. The relative |
398 \end{verbatim} |
378 path of the image that we wish to include is passed as an argument to |
399 |
379 includegraphics. It takes an optional argument of scaling the |
400 from numpy import * |
380 image. We use a scale of 0.4 to scale our image. |
401 a = linspace(0, 5, 50, endpoint = False) |
381 |
402 |
382 It takes other optional arguments. |
403 To insert verbatim text in-line, the ``\verb`` command can be used. |
383 |
404 :: |
384 ``width=x``, ``height=x`` |
405 |
385 If only the height or width is specified, |
406 The verb command allows placing \verb|verbatim text| in-line. |
386 the image is scaled, maintaining the aspect ratio. |
407 |
387 |
408 The | is just an example of a delimiter character. You can use any character except letters, * or space. |
388 ``keepaspectratio`` |
409 |
389 This parameter can either be set to true or false. When set to |
410 Tables, Figures and Captions |
390 true, the image is scaled according to both width and height, |
411 ---------------------------- |
391 without changing the aspect ratio, so that it does not exceed both |
412 |
392 the width and the height dimensions. |
413 The ``\tabular`` environment |
393 |
414 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
394 ``angle=x`` |
415 |
395 This option can be used to rotate the image by ``x`` degrees, |
416 The ``tabular`` environment allows you to typeset tables in LaTeX. ``\begin{tabular}[pos]{col fmt}`` command can be used to specify the parameters of the table and start creating the table. |
396 counter-clockwise. |
417 |
397 |
418 The ``pos`` argument specifies the vertical position of the table relative to the baseline of the surrounding text. It can take on the values ``t`` for top, ``b`` for bottom, or ``c`` for center. |
398 Figures (and tables) are treated specially because, they cannot be |
419 |
399 broken across pages. They are "floated" across to the next page, if |
420 |
400 they donot fit on the current page, filling the current page with |
421 The ``col fmt`` argument specifies the formatting of the columns of the table. You need to explicitly specify the formatting for each of the columns in the table. The ``col fmt`` argument can take on the following values. |
401 text. |
|
402 |
|
403 To make our graphic into a float, we should enlose it within a figure |
|
404 environment. For a table, the table environment should be used. We now |
|
405 move our graphic into a figure environment. The figure environment |
|
406 takes an additional parameter for the location of the |
|
407 float. ``\begin{figure}[hbtp!]``. The specifiers ``htbp`` are |
|
408 permissions to place the float at various locations. ``t`` for top of |
|
409 page, ``b`` for bottom of page, ``p`` for a separate page for floats |
|
410 and ``h`` for here, as in the same place where the command appears in |
|
411 the source. ``!`` mark overrides a few of LaTeX's internal parameters |
|
412 for good position of floats. |
|
413 |
|
414 The figure environment also, allows us to add a caption to the graphic |
|
415 using the ``\caption`` command. |
|
416 |
|
417 To place the graphic in the center aligned in the page, we use the |
|
418 center environment. |
|
419 |
|
420 To label a figure, we just add a label with in the figure |
|
421 environment. Note, that the label to a figure should be added after |
|
422 the caption command. Also, note that tables are auto-numbered. |
|
423 |
|
424 Let us finish the appendix, by adding the content present at the |
|
425 beginning of the appendix. The bibliographic citations will be dealt |
|
426 with later. |
|
427 |
|
428 Tables |
|
429 ~~~~~~ |
|
430 |
|
431 Now, let us look at the other kind of floats - Tables. We shall |
|
432 convert the list of sub-packages in the sub-packages section to a |
|
433 table. |
|
434 |
|
435 To begin a table, we use the tabular environment. And to make this a |
|
436 float, it is enclosed in the table environment. The table environment |
|
437 also allows us to add captions to the table and Tables are also auto |
|
438 numbered. |
|
439 |
|
440 The tabular environment takes as arguments the columns and the |
|
441 formatting of each column. The possible arguments to the tabular |
|
442 environment are |
422 |
443 |
423 +---------------+------------------------------------+ |
444 +---------------+------------------------------------+ |
424 | ``l`` | left justified column content | |
445 | ``l`` | left justified column content | |
425 +---------------+------------------------------------+ |
446 +---------------+------------------------------------+ |
426 | ``r`` | right justified column content | |
447 | ``r`` | right justified column content | |
427 +---------------+------------------------------------+ |
448 +---------------+------------------------------------+ |
428 | ``c`` | centered column content | |
449 | ``c`` | centered column content | |
429 +---------------+------------------------------------+ |
450 +---------------+------------------------------------+ |
430 | ``*{n}{col}`` | produces ``n`` columns with the | |
|
431 | | ``col`` type of formatting | |
|
432 | | ``*{3}{c}`` is the same as {c c c} | |
|
433 +---------------+------------------------------------+ |
|
434 | ``|`` | produces a vertical line. | |
451 | ``|`` | produces a vertical line. | |
435 +---------------+------------------------------------+ |
452 +---------------+------------------------------------+ |
436 |
453 |
437 Now we look at how to input the actual entries of the tables. Each horizontal row in a table is separated by ``\\``. Each column entry of a row is separated by ``&``. |
454 It also takes an optional parameter that specifies the position of the |
438 |
455 table; ``t`` for top, ``b`` for bottom, or ``c`` for center. |
439 The ``\hline`` command allows you to draw horizontal lines between two rows of the table. But it does not allow you do draw partial lines. ``\cline{a-b}`` draws a horizontal line from column ``a`` to column ``b``. |
456 |
440 :: |
457 Each column of a table is separated by an ``&`` symbol and each row is |
441 |
458 separated by a new line. The ``\hline`` command allows you to draw |
442 \begin{tabular}{|c|c|} |
459 horizontal lines between two rows of the table. But it does not allow |
443 \hline |
460 you do draw partial lines. ``\cline{a-b}`` draws a horizontal line |
444 \verb+l+ & left justified column content\\ |
461 from column ``a`` to column ``b``. |
445 \hline |
462 |
446 \verb+r+ & right justified column content\\ |
463 We also add a label to the table and refer to it in the first line of |
447 \hline |
464 the section. |
448 \verb+c+ & centered column content\\ |
465 |
449 \hline |
466 You could also add a listoftables or listoffigures to the document, |
450 \verb+*{n}{col}+ & produces \verb+n+ columns with the\\ |
467 similar to the way we added table of contents. |
451 & \verb+col+ type of formatting\\ |
468 |
452 \cline{2-2} |
469 Typesetting Math |
453 &\verb+*{3}{c}+ is the same as \verb+{c c c}+ \\ |
470 ---------------- |
454 \hline |
471 |
455 \verb+|+ & produces a vertical line\\ |
472 Now we shall move to typesetting the Math in the sample document given |
456 \hline |
473 to us. We shall start with the Matrices subsection. |
457 \end{tabular} |
474 |
458 |
475 In general, it is advised to use the AMS-LaTeX bundle to typeset |
459 Importing Graphics |
476 mathematics in LaTeX. AMS-LaTeX is a collection of packages and |
460 ~~~~~~~~~~~~~~~~~~ |
477 classes for mathematical typesetting. |
461 |
478 |
462 To include images in LaTeX, we require to use an additional package known as ``graphicx``. To load a package, we use the ``\usepackage`` directive in the preamble of the document. |
479 We load ``amsmath`` by issuing the ``\usepackage{amsmath}`` in the |
463 :: |
480 preamble. Through out this section, it is assumed that the ``amsmath`` |
464 |
481 package has been loaded. |
465 \usepackage{graphicx} |
482 |
466 |
483 Let's now typeset the matrix A. |
467 When compiling with ``pdflatex`` command, **jpg**, **png**, **gif** and **pdf** images can be inserted. |
484 |
468 |
485 To typeset math, we just have to enclose it within ``\(`` and ``\)`` |
469 :: |
486 or a pair of ``$`` signs. |
470 |
487 |
471 \includegraphics[optional arguments]{imagename} |
488 To typeset the matrix A, we use the ``bmatrix`` environment. It works |
472 |
489 similar to a tabular environment - ``&`` is used to demarcate columns |
473 A few ``optional arguments``: |
490 and ``\\`` is used to add a new row. ``bmatrix`` environment gives the |
474 |
491 ``[`` ``]`` as delimiters. There are 5 other matrix environments |
475 ``width=x``, ``height=x`` |
492 giving matrices with other delimiters - ``matrix`` (none), ``pmatrix`` |
476 If only the height or width is specified, the image is scaled, maintaining the aspect ratio. |
493 ``(``, ``Bmatrix`` ``{``, ``vmatrix`` ``|`` and ``Vmatrix`` ``||``. |
477 |
494 |
478 ``keepaspectratio`` |
495 To write the name of the matrix A, a bold-faced A is used. This is |
479 This parameter can either be set to true or false. When set to true, the image is scaled according to both width and height, without changing the aspect ratio, so that it does not exceed both the width and the height dimensions. |
496 obtained by using the ``\mathbf`` command. |
480 |
497 |
481 ``scale=x`` |
498 This subsection doesn't have much more math. The next section on |
482 Scale the image by a factor of ``x``. For example, ``scale=2``, will double the image size. |
499 inverse doesn't have anything new except for writing inverse of A. |
483 |
500 |
484 ``angle=x`` |
501 To typeset superscripts in LaTeX, the ``^`` character is used. The |
485 This option can be used to rotate the image by ``x`` degrees, counter-clockwise. |
502 carat operator just acts on the next character. To have multiple |
486 |
503 characters as superscript they must be enclosed in ``{ }``. Similarly |
487 :: |
504 for typesetting text as subscripts the ``_`` character is used. |
488 |
505 |
489 \includegraphics[scale=0.8, angle=30]{lion_orig.png} |
506 To typeset the summation symbol, use the command ``\sum.`` The upper |
490 |
507 and lower limits are specified using the ``^`` and ``_`` |
491 Floats |
508 characters. Similarly, the integral symbol is obtained using the |
492 ~~~~~~ |
509 ``\int`` command. |
493 |
510 |
494 Tables and Figures need to be treated in a special manner, since they cannot be split over pages, and they are referred to as floats in LaTeX. |
511 Next, let us type in the equation present in the section on |
495 |
512 Determinants. Note that it is different from all the math we've typed |
496 When there is not enough space on a page, to fit in a table or figure, it is floated over to the next page filling up the current page with text. LaTeX has float environments called table and figure for tables and images, respectively. |
513 until now, since it is not inline and is "displayed", in the LaTeX |
497 |
514 lingo. LaTeX has a number of environments for displaying equations, |
498 Anything enclosed within the table or figure environments will be treated as floats. |
515 with minor subtle differences. In general use ``\[`` ``\]`` to typeset |
499 :: |
516 displayed equations without numbering them. ``\begin{equation*}`` is |
500 |
517 equivalent to it. To obtain numbered equations use |
501 \begin{figure}[pos] or |
518 ``\begin{equation}``. |
502 \begin{table}[pos] |
519 |
503 |
520 Next we wish to typeset a group of equations. The equation environment |
504 The ``pos`` parameter specifies the placement of the float. The possible values it can take are as follows. |
521 does not accept ``\\`` to get a new line. For multiple equations |
505 |
522 amsmath has a handful of environments with subtle differences. We |
506 +-----------+-------------------------------------------------------------------+ |
523 shall use the ``eqnarray`` environment. ``eqnarray*`` environment |
507 | Specifier | Permission | |
524 gives unnumbered equations, as expected. The ``eqnarray`` environment |
508 +===========+===================================================================+ |
525 works similar to a table environment. The parts of the equation that |
509 | h | at approximately the same place where it occurs in the source | |
526 need to be aligned are indicated using an ``&`` symbol. The |
510 +-----------+-------------------------------------------------------------------+ |
527 ``newline`` command is used to enter a every new equation after the |
511 | t | at the top of the page. | |
528 first one. We now typeset the equations in the section on linear |
512 +-----------+-------------------------------------------------------------------+ |
529 equations using the ``eqnarray`` environment. (The equations in the |
513 | b | at the bottom of the page. | |
530 determinants section use ``eqnarray*``) |
514 +-----------+-------------------------------------------------------------------+ |
531 |
515 | p | on a special page for floats only. | |
532 We next typeset the math in the section on polynomials. To typeset |
516 +-----------+-------------------------------------------------------------------+ |
533 fractions use the ``\frac`` command. To typeset surds, we use the |
517 | ! | Override LaTeX's internal parameters for good positions | |
534 ``\sqrt`` command with the optional paramter of ``[n]``. |
518 +-----------+-------------------------------------------------------------------+ |
535 |
519 | H | nearly equivalent to h! | |
536 Inserting Greek letters into LaTeX is simple. ``\alpha``, ``\beta``, |
520 +-----------+-------------------------------------------------------------------+ |
537 ``\gamma``, ... on for small letters and ``\Alpha``, ``\Beta``, |
521 |
538 ``\Gamma``, ... for capital. |
522 Examples:: |
539 |
523 |
540 Also, math environments do not give extra spaces using the space or |
524 \begin{figure}[h] |
541 tab characters. The following commands are available to specify the |
525 \centering |
542 spacing required. |
526 \includegraphics[scale=0.8, angle=30]{lion_orig.png} |
543 |
527 \end{figure} |
544 +---------+--------------------+---------+ |
528 |
545 | Abbrev. | Spelled out | Example | |
529 |
546 +---------+--------------------+---------+ |
530 Captions |
547 | ``\,`` | ``\thinspace`` | | |
531 ~~~~~~~~ |
548 +---------+--------------------+---------+ |
532 |
549 | ``\:`` | ``\medspace`` | | |
533 The ``\caption{text}`` command allows you to add captions to images or tables. LaTeX automatically numbers your tables and figures and you need not include numbers in the captions that you write. The caption appears below or on top of the image (or table), depending on whether you place it after or before the ``importgraphics`` (or ``tabular``) command. |
550 +---------+--------------------+---------+ |
534 |
551 | ``\;`` | ``\thickspace`` | | |
535 :: |
552 +---------+--------------------+---------+ |
536 \begin{figure}[h] |
553 | | ``\quad`` | | |
537 \centering |
554 +---------+--------------------+---------+ |
538 \includegraphics[scale=0.8]{lion_orig.png} |
555 | | ``\qquad`` | | |
539 \caption{CTAN lion drawing by Duane Bibby; thanks to www.ctan.org} |
556 +---------+--------------------+---------+ |
540 \end{figure} |
557 | ``\!`` | ``\negthinspace`` | | |
541 |
558 +---------+--------------------+---------+ |
542 The caption command also, like the section command, has the short caption optional parameter. The short caption will appear in the list of tables or figures. |
559 | | ``\negmedspace`` | | |
543 |
560 +---------+--------------------+---------+ |
544 List of Figures, Tables |
561 | | ``\negthickspace`` | | |
545 ~~~~~~~~~~~~~~~~~~~~~~~ |
562 +---------+--------------------+---------+ |
546 |
|
547 LaTeX can automatically generate a List of Tables or Figures, with the table or figure numbers, the captions and page numbers on which they appear. This can be done using the ``\listoftables`` or ``listoffigures`` commands. |
|
548 |
|
549 Note: Just like table of contents, these lists also require an extra compilation. |
|
550 |
|
551 Cross References |
|
552 ~~~~~~~~~~~~~~~~ |
|
553 |
|
554 LaTeX has a very efficient mechanism of inserting cross-references in documents. |
|
555 |
|
556 The command ``\label{name}`` is used to label figures, tables or segments of text. ``\ref{name}`` refers to the object marked by the ``name`` by it's numbering (figure, table, section etc.) ``\pageref{name}`` gives the page number of the object which has been labeled with ``name``. |
|
557 |
|
558 Note: Cross referencing also requires an extra compilation, like table of contents. |
|
559 |
563 |
560 Bibliography |
564 Bibliography |
561 ------------ |
565 ------------ |
562 |
566 |
563 Bibliography or references can be added to LaTeX documents in two ways - using the ``thebibliography`` environment, or using BibTeX. Let's first look at using the ``\thebibliography`` environment and then move on to BibTeX. |
567 Let's now look at how to write bibliography and cite references. |
564 |
568 |
565 ``thebibliography`` environment |
569 Writing bibliographies in LaTeX using the ``thebibliography`` |
566 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
570 environment is pretty easy. You simply have to list down all the |
567 |
571 bibliography items within the bibliography environment. |
568 Writing bibliographies in LaTeX using the ``thebibliography`` environment is pretty easy. You simply have to list down all the bibliography items within the bibliography environment. |
572 |
569 |
573 Each entry of the bibliography begins with the command |
570 Each entry of the bibliography begins with the command ``\bibitem[label]{name}``. The name is used to cite the bibliography item within the document using ``\cite{name}``. The label option replaces the numbers from the auto enumeration with the labels given. |
574 ``\bibitem[label]{name}``. The name is used to cite the bibliography |
571 :: |
575 item within the document using ``\cite{name}``. The label option |
572 |
576 replaces the numbers from the auto enumeration with the labels given. |
573 He used this lion in the illustrations for D Knuth's original TeXbook\cite{DKnuth}, for L Lamport's LaTeX book\cite{LLamport} |
577 |
574 |
578 The ``9`` passed as an argument to ``thebibliography`` command |
575 \begin{thebibliography}{99} |
579 indicates the maximum width of the label that the references will |
576 \bibitem{DKnuth} Donald E. Knuth (1984). \emph{The TeXbook} (Computers and Typesetting, Volume A). Reading, Massachusetts: Addison-Wesley. ISBN 0-201-13448-9. |
580 have. In our sample document, we have less than 10 items in the |
577 |
581 Bibliography and therefore we use 9. |
578 \bibitem{LLamport} Lamport, Leslie (1994). \emph{LaTeX: A document preparation system: User's guide and reference}. |
582 |
579 illustrations by Duane Bibby (2nd ed.). Reading, Mass: Addison-Wesley Professional. |
583 Presentations with Beamer |
580 \end{thebibliography} |
584 ------------------------- |
581 |
585 |
582 The ``99`` in the example above indicates the maximum width of the label that the references may get. We here assume that the number of Bibliography items will be less than 100. If your document has less than 10 references, you may want to replace ``99`` with ``9``. |
586 Using beamer for you presentations is a good idea, since you can use |
583 |
587 the LaTeX that you have used for the report/document for the |
584 BibTeX |
588 presentation as well. |
585 ~~~~~~ |
589 |
586 |
590 To write a ``beamer`` presentation, it is recommended that we use one |
587 The previous section explained the process of listing references at the end of a document and embedding cross references. In this section let us explore the BibTeX environment for keeping track of references. |
591 of the templates that beamer provides. We shall use the |
588 |
592 ``speaker_introduction`` template to get started with beamer. |
589 Using BibTeX is a very convenient method to use, when writing multiple documents in a single area or field. BibTeX allows you to create a database of all your references and use them as and when required. |
593 |
590 |
594 As you can see, the document begins with the ``documentclass`` being |
591 The BibTeX database is stored in a ``.bib`` file. The structure of the file is quite simple and an example is shown below. |
595 set to beamer. |
592 :: |
596 |
593 |
597 ``\usetheme`` command sets the theme to be used in the presentation. |
594 @book{Lamport94, |
598 |
595 author = "Leslie Lamport", |
599 ``\usecolortheme`` command sets the color theme of the presentation. |
596 title = "A Document Preparation System: User's Guide and Reference", |
600 |
597 publisher = "Addison-Wesley Professional", |
601 Notice that each slide is enclosed within ``\begin{frame}`` and |
598 year = "1994", |
602 ``\end{frame}`` commands. The ``\begin{frame}`` command can be passed |
599 edition = "second", |
603 the Title and Subtitle of the slide as parameters. |
600 note = "illustrations by Duane Bibby" |
604 |
601 } |
605 The title page of the presentation can be set like any other LaTeX |
602 |
606 document. |
603 Each bibliography entry starts with a declaration of the type of the reference being mentioned. The reference is in the above example is of the book type. BibTeX has a wide range of reference types, for example, ``article, book, conference, manual, proceedings, unpublished``. |
607 |
604 |
608 To do overlays, use the ``\pause`` command. It does sequential |
605 The type of reference is followed by a left curly brace, and immediately followed by the citation key. The citation key, ``Lamport94`` in the example above is used to cite this reference using the command ``\cite{Lamport94}``. |
609 overlays. Non sequential overlays can also be done. (Lab exercise.) |
606 |
610 |
607 This is followed by the relevant fields and their values, listed one by one. Each entry must be followed by a comma to delimit one field from the other. |
611 If you have fragile environments like ``verbatim`` or ``lstlisting``, |
608 |
612 you need to give the frame an optional parameter ``[fragile]``. |
609 To get your LaTeX document to use the bibliography database, you just add the following lines to your LaTeX document. |
613 |
610 :: |
614 To achieve more with beamer, it is highly recommended that you look at |
611 |
615 the ``beameruserguide``. |
612 \bibliographystyle{plain} |
616 |
613 \bibliography{LaTeX} |
|
614 |
|
615 Bibliography styles are files that tell BibTeX how to format the information stored in the ``.bib`` database file. The style file for this example is ``plain.bst``. Note that you do not need to add the ``.bst`` extension to the filename. If you wish to achieve a particular style of listing the bibliography items and citing them, you should use an appropriate style file. |
|
616 |
|
617 The ``bibliography`` command specifies the file that should be used as the database for references. The file used in this example is ``LaTeX.bib`` |
|
618 |
|
619 Compiling |
|
620 +++++++++ |
|
621 |
|
622 Adding BibTeX based references, slightly complicates the process of compiling the document to obtain the desired output. The exact workings of LaTeX and BibTeX will not be explained here. The procedure for obtaining the output (without any explanations) is as follows: |
|
623 |
|
624 1. Compile the ``.tex`` file using ``pdflatex`` - ``$pdflatex LaTeX(.tex)`` |
|
625 2. Compile the ``.bib`` file using ``bibtex`` - ``$bibtex LaTeX(.bib)`` |
|
626 3. Compile the ``.tex`` file again. |
|
627 4. Compile the ``.tex`` file for one last time! |
|
628 |
|
629 Typesetting Math |
|
630 ---------------- |
|
631 |
|
632 It is advisable to use the AMS-LaTeX bundle to typeset mathematics in LaTeX. It is a collection of packages and classes for mathematical typesetting. |
|
633 |
|
634 We load ``amsmath`` by issuing the ``\usepackage{amsmath}`` in the preamble. Through out this section, it is assumed that the ``amsmath`` package has been loaded. |
|
635 |
|
636 |
|
637 Math Mode |
|
638 ~~~~~~~~~ |
|
639 |
|
640 There are a few differences between the *math mode* and the *text mode*: |
|
641 |
|
642 1. Most spaces and line breaks do not have any significance, as all spaces are either derived logically from the mathematical expressions, or have to be specified with special commands such as ``\``, ``\quad`` or ``\qquad`` |
|
643 |
|
644 2. Empty lines are not allowed. |
|
645 |
|
646 3. Each letter is considered to be the name of a variable and will be typeset as such. If you want to typeset normal text within a formula, then you have to enter the text using the \text{...} command |
|
647 |
|
648 Single Equations |
|
649 ~~~~~~~~~~~~~~~~ |
|
650 |
|
651 Mathematical equations can be inserted in-line within a paragraph (*text style*), or the paragraph can be broken to typeset it separately (*display style*). |
|
652 |
|
653 A mathematical equation within a paragraph is entered between ``$`` and ``$``. Larger equations are set apart from the paragraph, by enclosing them within ``\begin{equation}`` and ``\end{equation}``. If you don't wish to number a particular equation, the starred version of equation can be used. ``\begin{equation*}`` and ``\end{equation*}`` |
|
654 |
|
655 The equation can also be cross referenced using the ``\label`` and ``\eqref`` commands. |
|
656 |
|
657 Basic Elements |
|
658 ~~~~~~~~~~~~~~ |
|
659 |
|
660 Greek Letters can are entered as ``\alpha, \beta, \gamma, \delta, ...`` for lowercase letters and ``\Alpha, \Beta, \Gamma, ...`` for uppercase ones. |
|
661 |
|
662 Exponents and subscripts can be typeset using the carat ``^`` and the underscore ``_`` respectively. Most of the math mode commands act only on the next character. If you want a command to affect several characters, they need to be enclosed in curly braces. |
|
663 |
|
664 The ``\sqrt`` command is used to typeset the square root symbol. LaTeX of the root sign is determined automatically. The nth root is generated with ``\sqrt[n]``. |
|
665 |
|
666 To explicitly show a multiplication a dot may be shown. ``\cdot`` could be used, which typesets the dot to the center. ``\cdots`` is three centered dots while ``\ldots`` sets the dots on the baseline. Besides that ``\vdots`` for vertical and ``\ddots`` can be used for diagonal dots. |
|
667 |
|
668 A fraction can be typeset with the command ``\frac{..}{..}`` |
|
669 |
|
670 The integral operator is generated with ``\int``, the sum operator with ``\sum``, and the product operator with ``\prod``. The upper and lower limits are specified with ``^`` and ``_`` like subscripts and superscripts. |
|
671 |
|
672 LaTeX provides all kinds of braces as delimiters. The round and square brackets can be produces using the keys on the keyboard and appending a backslash. Other delimiters can be produced using special commands of LaTeX. Placing ``\left`` in front of an opening delimiter and ``\right`` in front of a closing delimiter, instructs LaTeX to automatically take care of the sizes of the delimiters. |
|
673 |
|
674 Multiple Equations |
|
675 ~~~~~~~~~~~~~~~~~~ |
|
676 |
|
677 Long formulae that run over several lines or equation systems, can be typeset using the ``align`` or ``align*`` environments. ``align`` numbers each of the lines in the environment, and ``align*`` as expected, does not number any of them. |
|
678 |
|
679 The ``&`` is used to align the equations vertically and the ``\\`` command is used to break the lines. Line numbering can be skipped for a particular line in the ``align`` environment by placing a ``\nonumber`` before the line break. |
|
680 |
|
681 :: |
|
682 |
|
683 \begin{align} |
|
684 \alpha^2 + \beta^2 &= \gamma^2 \\ |
|
685 \sum_{i=1}^ni &= \frac{n(n+1)}{2}\\ |
|
686 \sqrt{-1} &= \pm1 \nonumber |
|
687 \end{align} |
|
688 |
|
689 |
|
690 Arrays and Matrices |
|
691 ~~~~~~~~~~~~~~~~~~~ |
|
692 |
|
693 To typeset arrays, use the ``array`` environment. It works similar to the ``tabular`` environment. The ``\\`` command is used to break the lines. |
|
694 :: |
|
695 |
|
696 \begin{equation*} |
|
697 \mathbf{X} = \left( |
|
698 \begin{array}{ccc} |
|
699 a_1 & a_2 & \ldots \\ |
|
700 b_1 & b_2 & \ldots \\ |
|
701 \vdots & \vdots & \ddots |
|
702 \end{array} \right) |
|
703 \end{equation*} |
|
704 |
|
705 The ``array`` environment can also be used to typeset piecewise functions by using a “.” as an invisible ``\right`` delimiter |
|
706 :: |
|
707 |
|
708 \begin{equation*} |
|
709 f(x) = \left\{ |
|
710 \begin{array}{rl} |
|
711 0 & \text{if } x \le 0\\ |
|
712 1 & \text{if } x > 0 |
|
713 \end{array} \right. |
|
714 \end{equation*} |
|
715 |
|
716 Six different types of matrix environments are available in the ``amsmath`` package for typesetting matrices. They essentially have different delimiters: ``matrix`` (none), ``pmatrix`` (, ``bmatrix`` [, ``Bmatrix`` {, ``vmatrix`` | and ``Vmatrix`` ‖. In these matrix environments, the number of columns need not be specified, unlike the ``array`` environment. |
|
717 :: |
|
718 |
|
719 \begin{equation*} |
|
720 \begin{matrix} |
|
721 1 & 2 \\ |
|
722 3 & 4 |
|
723 \end{matrix} \qquad |
|
724 |
|
725 \begin{bmatrix} |
|
726 1 & 2 & 3 \\ |
|
727 4 & 5 & 6 \\ |
|
728 7 & 8 & 9 |
|
729 \end{bmatrix} |
|
730 \end{equation*} |
|
731 |
|
732 Miscellaneous Stuff |
|
733 ------------------- |
|
734 |
|
735 Presentations |
|
736 ~~~~~~~~~~~~~ |
|
737 |
|
738 LaTeX has quite a few options to produce presentation slides. We shall look at the ``beamer`` class, which is well developed and easy to use. We shall only briefly look at some of the features of beamer. For the best documentation, look at the beamer user guide. |
|
739 |
|
740 To write a ``beamer`` presentation, it is recommended that you use one of the templates that beamer provides. We shall use the ``speaker_introduction`` template to get started with beamer. |
|
741 |
|
742 As you can see, the document begins with the ``documentclass`` being set to beamer. |
|
743 |
|
744 The ``\setbeamertemplate`` command sets the template for various parameters. The ``background canvas``, ``headline`` and ``footline`` are being set using the command. |
|
745 |
|
746 ``\usetheme`` command sets the theme to be used in the presentation. |
|
747 |
|
748 Notice that each slide is enclosed within ``\begin{frame}`` and ``\end{frame}`` commands. The ``\begin{frame}`` command can be passed the Title and Subtitle of the slide as parameters. |
|
749 |
|
750 To achieve more with beamer, it is highly recommended that you look at the ``beameruserguide``. |
|
751 |
|
752 Including Code |
|
753 ~~~~~~~~~~~~~~ |
|
754 |
|
755 The ``listings`` package can be used to embed source code into your LaTeX document. We shall briefly explore inserting python code into our document. |
|
756 |
|
757 Obviously, you first need to tell LaTeX that you want it to use the ``listings`` package, using the ``\usepackage`` command. |
|
758 :: |
|
759 |
|
760 \usepackage{listings} |
|
761 |
|
762 Then, we tell LaTeX that we are going to embed Python code into this document. A simple code highlighting for Python code can be achieved using this. |
|
763 :: |
|
764 |
|
765 \lstset{language=Python, |
|
766 showstringspaces=false, |
|
767 } |
|
768 |
|
769 You might want to customize the code highlighting further using other variables like ``basicstyle``, ``commentstyle``, ``stringstyle``, ``keywordstyle`` etc. For detailed information on all this, you should look at the ``listings`` package documentation. |
|
770 |
|
771 You include a block of code into your document by enclosing it within the ``lstlisting`` environment. |
|
772 :: |
|
773 |
|
774 \begin{lstlisting} |
|
775 string="Hello, World! " |
|
776 for i in range(10): |
|
777 print string*i |
|
778 \end{lstlisting} |
|
779 |
|
780 You can also include source code files directly into your latex document, using the ``lstinputlisting`` command. |
|
781 :: |
|
782 |
|
783 \lstinputlisting[lastline=20]{lstexample.py} |
|
784 |
|
785 This command includes the first 20 lines of the file ``lstexample.py`` into out LaTeX document. |
|
786 |
|
787 Including files |
|
788 ~~~~~~~~~~~~~~~ |
|
789 When working on a large document, it is convenient sometimes, to split the large file into smaller input files and club them together at the time of compiling. |
|
790 |
|
791 The ``\input`` or ``\include`` commands may be used to embed one LaTeX file into another. The ``\input`` command is equivalent to a copy and paste of the document, just before the compilation. The ``\include`` command is exactly similar, except for the fact that it creates a new page every time it is issued. |
|
792 |
|
793 ``\input{file}`` or ``\include{file}`` commands will include the file ``file1.tex`` with in the file where the command has been issued. Note that you do not need to specify the ``.tex`` extension of the file. |
|
794 |
|
795 The ``\includeonly`` is useful for debugging or testing the LaTeX document that you are creating, since it restricts the ``\include`` command. Only the files which are given as arguments to the ``\includeonly`` command will be included in the document (wherever a ``\include`` command for those files, has been issued). |
|
796 |
|
797 A note on filenames |
|
798 +++++++++++++++++++ |
|
799 |
|
800 Never use filenames or directories that contain spaces. Make filenames as long or short as you would like, but strictly avoid spaces. Stick to upper or lower case letters (without accents), the digits, the hyphen and the full stop or period. |
|
801 |
|
802 |
|
803 |
|
804 Recommended Reading |
|
805 ------------------- |
|
806 |
|
807 1. *LaTeX Wikibook* |
|
808 |
|
809 2. *The Not So Short Introduction to LaTeX2e* by Tobias Oetikar et al.. |
|
810 |
|
811 |
|