100% found this document useful (2 votes)
3K views61 pages

First Lessons in LaTeX

A small book (61 pages) which gives step-by-step instructions to learn the basics of typesetting using LaTeX.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views61 pages

First Lessons in LaTeX

A small book (61 pages) which gives step-by-step instructions to learn the basics of typesetting using LaTeX.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

First Lessons in TEX

Dr. V N Krishnachandran

Department of Computer Applications


Vidya Academy of Science & Technology
Thalakkottukara, Thrissur - 680 501 (http://mca.vidyaacademy.ac.in)

Contents
A 1 TEX and L TEX 1.1 Some terminology . . . . . 1.1.1 Word Processor . . 1.1.2 Typesetting . . . . 1.1.3 Markup Language 1.1.4 TEX . . . . . . . . A 1.1.5 L TEX . . . . . . . A 1.2 L TEX implementations . . 1.3 TEX Editors . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

1 1 1 1 1 1 1 2 2 3 3 3 5 5 5 6 6 6 7 8 8 10

2 TEXworks 2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Customising TEXworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 First Document 3.1 Typesetting a document . . . . . . . . . 3.2 First experiment . . . . . . . . . . . . . 3.2.1 Enter text in the Editor Window 3.2.2 Save the text in a le . . . . . . 3.2.3 Typeset and view the document 3.3 Commands in the rst input le . . . . 3.4 Files generated during compilation . . . 3.5 When errors occur . . . . . . . . . . . . 3.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4 Sectioning of Documents 11 4.1 Sectioning Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5 Special Characters and 5.1 Blank Spaces . . . . 5.2 Special characters . . 5.3 Quotes and Dashes . 5.4 Font Styles . . . . . 5.5 Changing Font Size . 5.6 Changing fonts . . . Fonts . . . . . . . . . . . . . . . . . . . . . . . . 13 13 14 14 14 15 15

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

6 Some Special Formatting 6.1 Centering . . . . . . . . . 6.2 One sided justication . . 6.2.1 Right justication 6.2.2 Left justication . 6.3 Two-sided justication . . 6.4 Reproducing typed text . 6.5 Footnotes . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

17 17 18 18 19 19 20 20 22 22 22 22 24 24 24 26 26 26 27 27 29 29

7 Lists 7.1 Itemization . . . . . . . . . . . 7.1.1 Simple Itemized List . . 7.1.2 Nested Itemized List . . 7.2 Enumerated List . . . . . . . . 7.2.1 Simple Enumerated List 7.2.2 Nested enumerated list .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

8 Tables 8.1 Simple Tables . . . . . . . . . . . . . . . . . . . . . 8.1.1 Tables with horizontal and vertical lines . . 8.1.2 Tables without horizontal and vertical lines 8.1.3 Tables with stretched rows and double lines 8.2 Multicolumns . . . . . . . . . . . . . . . . . . . . . 8.3 Tables with Captions . . . . . . . . . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

9 Graphics 31 9.1 A picture in a document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 9.2 Putting a picture in input le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 10 Mathematics 10.1 amsmath package . . . . . . . . . . . . . 10.2 First lessons . . . . . . . . . . . . . . . . 10.2.1 Keyboard symbols . . . . . . . . 10.2.2 Exponents . . . . . . . . . . . . . 10.2.3 Subscripts . . . . . . . . . . . . . 10.2.4 Both exponents and indices . . . 10.2.5 Fractions . . . . . . . . . . . . . 10.2.6 Roots . . . . . . . . . . . . . . . 10.2.7 Mathematical symbols . . . . . . 10.3 Mathematics in input le . . . . . . . . 10.3.1 Mathematical expressions inline . 10.3.2 Equations without numbering . . 10.3.3 Equations with numbering . . . . 34 34 34 34 34 35 35 35 35 36 36 36 36 37 38 38 38 38 39 39 39 39 39

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

11 Cross References 11.1 Outline of procedure . . . . . . . . . . . . . . . . 11.2 Assigning labels . . . . . . . . . . . . . . . . . . . 11.2.1 Assigning labels to tables and gures . . . 11.2.2 Assigning labels to chapters, sections, etc. 11.2.3 Assigning labels to equations . . . . . . . 11.2.4 Assigning labels to page numbers . . . . . 11.3 Printing the value of a label . . . . . . . . . . . . 11.4 Example for cross referencing . . . . . . . . . . . ii

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

11.4.1 Example input le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.4.2 Example output le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

39 41

12 Simple Index 42 12.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 12.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 13 Generating Bibliography 13.1 Sample bibliography . . . . . . . . . . . A 13.2 L TEX code for the sample bibliography 13.3 Explanatory notes . . . . . . . . . . . . 13.4 The bibtex package . . . . . . . . . . . 44 44 44 45 45

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

14 Page Layouts 46 14.1 Page layout parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 14.2 geometry package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 15 Book Structure 15.1 Front matter, main matter, back matter 15.2 Front matter . . . . . . . . . . . . . . . 15.2.1 Table of contents . . . . . . . . . 15.2.2 Other lists . . . . . . . . . . . . . 15.3 Splitting of documents . . . . . . . . . . Appendix : The Name of the Game Bibliography References Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 48 48 48 49 49 50 51 52 53

iii

List of Figures
2.1 2.2 2.3 3.1 3.2 3.3 3.4 3.5 4.1 5.1 6.1 6.2 6.3 9.1 9.2 9.3 TEXworks icon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The opening Editor Window of TEXworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . TEXworks Preferences ... window with the option Editor selected . . . . . . . . . . . . . . Typeset button in Editor Window in Save File window in TEXworks . . . The output le test01.pdf . . . . . Output panel with error messages . . Indicator of error in input le . . . . TEXworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 4 4 5 6 7 9 9 12 14 17 18 20 31 32 32 40 47

Page 1 (left) and Page 3 (right) of test03.pdf . . . . . . . . . . . . . . . . . . . . . . . . . . Output of test04.tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Example for centered text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Example for right justied text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Example text showing two-sided indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . TeX Lion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TeX Lion enlarged . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TeX lion compressed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11.1 Example for cross referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.1 Page Layout Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

iv

List of Tables
5.1 5.2 5.3 5.4 5.5 7.1 7.2 8.1 Special characters and their meanings in Quotes and dashes . . . . . . . . . . . . Changing font styles . . . . . . . . . . . Commands to change font size . . . . . A Some of the available fonts in L TEX . .
A L TEX . . . . . . . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

14 15 15 16 16 24 25 29

Labels in itemized lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labels in enumerated lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . States, capitals, languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Chapter 1 A TEX and L TEX


1.1
1.1.1

Some terminology
Word Processor

By a word processor we generally mean a WYSIWYG (What You See Is What You Get) system where the formatting takes place while we enter the text; no further processing is done prior to sending our work to a printer. Miccrosoft Oce Word is an example of a word processor.

1.1.2

Typesetting

Typesetting is the composition of text material by means of types. Typesetting requires the prior process of designing a font and storing it in some manner. Typesetting is the retrieval of the stored letters and the arranging them according to a languages orthography for visual display. Over the centuries printers have developed several typesetting conventions to improve the quality of the printed pages and to enhance the readability and visual appeal of each and every page of a printed document.

1.1.3

Markup Language

A markup language is a system for annotating a text in such a way that the annotation is distinguishable from the text. The idea and terminology evolved from the marking up of manuscripts with, for example, the revision instructions by editors. HTML, which stands for HyperText Markup Language, is the predominant markup language for web pages. A markup language is a set of markup tags, and HTML uses markup tags to describe web pages.

1.1.4

TEX

TEX is a computer programme created by Donad E Knuth of Stanford University in late seventies for typesetting documents. TEX is a free software.

1.1.5

A L TEX

A A A L TEX is a markup language used for typesetting documents. L TEX is based on TEX. L TEX is the standard document preparation system in academia. Its mainly used by scientists and mathematicians, and is the accepted submission format for most journals in these elds. The primary strength of LaTeX is its typesetting quality. It eectively enforces a consistent and professional layout and typographical convention for our documents.

1.2

A L TEX implementations

A There are several implementations of the L TEX package.

TEXLive is a distribution provided by TEX User Groups. This supports Unix systems, MacOSX, and 32-bit Windows. MiKTEX is an independent distribution for Windows with a exible package manager. For more information about this package visit [1]).

1.3

TEX Editors

A There are several editors and front-ends for using L TEX. TEXworks is one such front-end whose features will be discussed in more detail in the next chapter. A few others are WinEdt, WinShell, TeXnicCenter, and LyX.

Chapter 2

TEXworks
2.1 Introduction

A TEXworks is an open source graphical user interface to the typesetting system TEX and its extensions L TEX ConTEXt, and XeTEX. It is available for Windows, GNU/Linux and Mac OS X. This programme comes pre-packaged with TEXLive and MikTEX and can be installed simultaneously with these packages. It is not mandatory that one should use TEXworks along with TEXLive or MiKTEX. One could use any other convenient TEX editor. If we have installed this programme with the default settings, we can see its icon (Fig. 2.1) in the desktop. A double-click on this icon will open the TEXworks window.

Figure 2.1: TEXworks icon When you start a computer in the Lab in Windows you can see a shortcut icon to TEXworks (see Figure 2.1). A double-click on this icon will open the TEXworks window.

2.2

Customising TEXworks

Before starting serious typesetting work using TEXworks, it is advisable to customize TEXworks to suit to your tastes. 1. Double-click the TEXworks icon and start the IDE. 2. A window lling left-half of the screen props up (see Figure 2.2). This is known as the Editor Wndow of TEXworks programme. 3. To customise TEXworks, select: Edit > Preferences ...> Then the window shown in Fig 2.3 is displayed. In this window four options are available General 3

Figure 2.2: The opening Editor Window of TEXworks

Figure 2.3: TEXworks Preferences ... window with the option Editor selected

Editor Preview Typesetting 4. You may do some customisation under the option Editor (see Figure 2.3). (a) Select a font to your liking and x the font-size also. (b) Tick and select the options line numbers and wrap-lines.
A (c) Choose the syntax coloring as L TEX. (d) Choose a language for spell-check (en-US for American English and en-GB for British English).

(e) Press OK and quit Preferences... . 5. Close TEXworks and double-click the TEXworks icon to open it again. This is necessary for the selected preferences to take eect.

Chapter 3

First Document
3.1 Typesetting a document

There are three stages in typesetting a document using TEX. 1. Create a text le, known as the input le, and name it with the extension .tex, say for example, sample.tex. 2. The input le is compiled to produce a PDF le. This is the output le. The compilation programme A is known as pdfL TEX. If the name of the input le is sample.tex the output le would be named as sample.pdf. 3. View and if necessary print the output le using some PDF reader. The TEXworks Editor Window is used to create, edit and save the input le. The second and third stages are executed by applying a single operation, namely, pressing the typeset button at the top left corner of the TEXworks Editor Window (see Figure 3.1). If there are no errors in the input le, another window will open up on right half of the monitor and this will display the contents of the PDF le generated from the input le. This newly created window is known as the Preview Window. One cannot print the PDF le from this window. To print it the le has to be opened using some PDF reader.

3.2

First experiment

Lets now see how to create a rst document: for this youll need to type some text in the editor window of A TEXworks. L TEX is not a WYSIWIG (What You See Is What You Get) software, so youll have to type the text and the instructions for formatting it and youll see the result only after typesetting the text. Now we are ready to do an experiment. Perform the following operations exactly as instructed.

Figure 3.1: Typeset button in Editor Window in TEXworks

Figure 3.2: Save File window in TEXworks

3.2.1

Enter text in the Editor Window

Type the following text exactly as shown in the Editor Window of TEXworks programme. % test01.tex \documentclass{article} \title{Test Document} \author{Student} \date{} \begin{document} \maketitle My first document typeset with TeX. \end{document}

3.2.2

Save the text in a le

We now save the text entered in the editor window in a le in the folder MyFolder, which is a folder created by you. To do this we press the Save button. A Save File window is opened and we have to navigate to MyFolder. Enter the le name as test01 and press the Save bar in the Save File window. The content will be saved in a le named test01.tex. The TEXworks programme automatically assigns the extension .tex to the input le name. The extension .tex is mandatory for all input les.

3.2.3

Typeset and view the document

1. Next we start typesetting the document by clicking the green button in the top left corner of the Editor Window, or by pressing [Ctrl+T] (see Figure 3.1). 2. A new panel, called Output Panel and labeled Log, opens at the bottom of the Editor Window. EvA A erything L TEX is doing when it works is displayed here. When L TEX nishes (if there is no error) this panel disappears. A new window, called the Preview Window, now appears. In this window you can see a page with the following particulars (see Figure 3.3): the title Test Document centred; the name of the author Student centred; the text My rst document typeset with TeX.; 6

Figure 3.3: The output le test01.pdf

a page number at the bottom centre.

3.3

Commands in the rst input le

Let us examine the meanings of the various lines in the rst input le test01.tex. 1. The rst line begins with a %. The symbol % indicates a comment line. Any text in a line that appears after this symbol is ignored by the compiler. Any number of comment lines may be included in the input le. 2. The rst command in an input le must always be \documentclass. There are dierent classes. The choice of a class is given within double braces { and }. In test01.tex the class selected is article. (a) If the document is a short one and is divided into sections, subsections and subsubsections then we choose the class article. (b) If the document is long and has to be divided into chapters, sections, subsections and subsubsections then choose the class book. (c) If the document is still larger and is to be divided into parts, chapters, sections, subsections and subsusbsections then choose the class report. (d) There are other specialised classes also. 3. The second command species the title of the document. It is not necessary that every every input le has the title command.

4. The third command species the name of the author of the document. The command author is also not mandatory. 5. The command \date{} is included to suppress the printing of date in the output le. If this command is not included then the current date will be printed immediately below the name of the author. 6. The content of the document begins with \begin{document} and ends with \end{document}. 7. The text in the input le between \documentclass and \begin{document} is known as the preamble of the document. 8. The command \maketitle gives instructions to the compiler to typeset the title matter of the document. The title is typeset in a predened way as specied in the le which describes the specications for the chosen docuumentclass.

3.4

Files generated during compilation

If we examine the folder MyFolder we can see that the folder contains the following les. 1. test01.tex which is the original input le. 2. test01.pdf which is the output le. 3. test01.aux which is an auxiliary le. 4. test01.log which is the log le containing descriptions of what pdfLaTex is doing at the compilation time. 5. test01.synctex.gz which is a le used for syncTeX-ing (see help on TEXworks to know more about this). Depending on the structure of the document several other associated les are also likely to be created during compilation. A few of them are : test01.toc : a le created while generating a table of contents. test01.lot : a le created while generating a list of tables. test01.lof : a le created while generating a list of gures. test01.ind, test01.idx, test01.ilg : les created while generating an index.

3.5

When errors occur

A When you compile an input le and there is an error, L TEX stops. This is shown by scrolling actions in A the output panel stopping, and an error message is displayed with L TEX waiting for an instruction to know what it should do: one sees the typing cursor in the line between the output panel and the status bar: the console bar (see Figure 3.4). To see the eect, do the following:

1. Go back to the Editor Window by clicking on the window. 2. Change the line \maketitle to \maletitle. The contents are as given below.

Figure 3.4: Output panel with error messages

Figure 3.5: Indicator of error in input le

% test02.tex \documentclass{article} \title{Test Document} \author{Student} \date{} \begin{document} \maletitle My first document typeset with TeX. \end{document} 3. Save the le as test02.tex. 4. Compile the le by pressing the green button. 5. Wait to see the changes. The error message reads as follows: ! Undefined control sequence. l.6 \maketitles ? The green button will have changed to a red one with a white cross. Click on that button to terminate the compilation process. The output panel is still visible and so one can still see the error message. Now correct the errors in the input le, save the le and typeset it by pressing the green button. 9

3.6

Exercises

Before proceeding to the next chapter it is advisable to do some simple exercises. A few changes in the input le test01.tex are suggested. You are requested to eect these changes, save the changed le, compile the new le and preview the output le. Learn the eect of the changes in the input le on the output le. 1. Change the documentclass in test01.tex from article to book. 2. Change the title of the document. 3. Change the name of the author. 4. Delete the command \date{}. 5. Delete the command \maketitle. 6. Write \maketitle after the line ending with typeset with TeX.

10

Chapter 4

Sectioning of Documents
4.1 Sectioning Commands

Any document will naturally be divided into chapters, sections and subsections. 1. To typeset a document with divisions into chapters, sections and subsection, we have to use the following line as the rst line of the input le: \documentclass{book} 2. To start a new chapter with title New Chapter include the following line in the input les: \chapter{New Chapter} 3. To start a new section with title New Section, include the following line in the input les: \section{New Section} 4. To start a new subsection with title New Subsection, include the following line in the input les: \subsection{New Subsection} 5. To start a new subsubsection with title New Subsubsection, include the following line in the input les: \subsubsection{New Subsubsection}

4.2

Example
% test03.tex \documentclass{book} % \begin{document} % \chapter{First Lessons} Introductory text. 11

Enter the following text exactly as shown:

Figure 4.1: Page 1 (left) and Page 3 (right) of test03.pdf

\section{First section} Some text in first section. \section{Second section} Some text in second section. % \chapter{More Lessons} Explanations. \section{First section in Chapter 2} Some text in Section 1 of Chapter 2. \section{Second Section in Chapter 2} Some more text Section 2 of Chapter 2. % \end{document} Next save it as the input le test03.tex. Now typeset it by pressing the green button. If there are no errors in the input le, then a PDF le by name test03.pdf with three pages will be displayed in the Preview Window. Pages 1 and 3 of this document are shown in Figure 4.1.

12

Chapter 5

Special Characters and Fonts


5.1 Blank Spaces

Blank spaces have no eect except to as word separators. It could be one or many. Blank lines produce new paragraphs. One or many blank lines could be used.

Example
The input le test04.tex produces the output shown in Figure 5.1. % test04.tex \documentclass{article} % \title{Blank Spaces} \date{} \begin{document} \maketitle % Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. % \end{document}

13

A Table 5.1: Special characters and their meanings in L TEX Characters Character Meaning to be entered in input le # Parameter number \# $ Used in typesetting mathematics \$ % Indicator for beginning of comments \% & Indicator of tab separator \& { Scope delimiter \{ } Scope delimiter \} Used in typesetting mathematics \^{} Used in typesetting mathematics \ \ First character of command $\backslash$

5.2

Special characters

Certain characters when used in the input le have special meanings. For example the character % is used as an indicator for the beginning of comments. Any text after the symbol % in a line in the input le is ignored by the compiler. To get the character % in the running text you have to enter the character combination \% ( a backslash followed by %) in the input le. The special characters, their meanings and the character combinations to be entered in the input le to get these special characters are shown in the table below (see Table 5.1). The sequence \\ is an instruction to break the line. An equivalent command is \newline.

5.3 5.4

Quotes and Dashes Font Styles

There are several font styles like italics, bold, etc. To get some text in the output le in italics, we use the following markup in the input le: enclose the text in double braces and include the command \em within the braces. For example, to get the text Hello world! like this in output le we enter the following in the input le:

Figure 5.1: Output of test04.tex

14

Table 5.2: Quotes and dashes To get Enter Quotes Single left quote Single right quote Double left quote Double right quote " Dashes Hyphen (inter-word dash) Medium dash (number ranges) -Punctuation dash ---

Style To produce To To To To To produce produce produce produce produce

Table 5.3: Changing font styles Command italics style {\em Text} (em for emphasis) bold style {\bf Text} typewriter style {\tt Text} slanted style {\sl Text} small caps style {\sc Text} sans serif style {\sf Text}

Example Text Text Text Text Text Text

{\em Hello world!} The available styles and the markup to produce these styles are tabulated Table 5.3.

5.5

Changing Font Size

A There are some standard pre-dened font sizes in L TEX. Running text can be typeset in these font sizes. For example, there is a font-size referred to as huge. To get the text Hello world! in this size the following markup is used.

{\huge Hello world!} In the output le, the text will appear like this:

Hellow world!
Table 5.4 summarises the available commands for changing the font size.

5.6

Changing fonts

We can use dierent fonts using the following command: \usefont{code}{family}{series}{shape} Some of the available fonts with their code, family, series and shapes are given in Table 5.5. For example: to use the Bookman font in bold italics we include the following command: 15

Table 5.4: Commands to change font size Command Example text \tiny smallest \scriptsize very small \footnotesize smaller \small small \normalsize normal \large large \Large larger \LARGE \huge \Huge

even larger

still larger

largest

A Table 5.5: Some of the available fonts in L TEX

\usefont{T1}{pbk}{b}{it} Any arbitrary fontsize can be selected using the command \fontsize with parameters as in the example below: \fontsize{15mm}{18mm} The \fontsize command is to be issued before the \usefont command. 16

Chapter 6

Some Special Formatting


In this chapter we present a few of the commonly used special formatting of text.

6.1

Centering

Figure 6.1: Example for centered text The page shown in Figure 6.1 is produced by the following input le. \documentclass{article} % \title{Centred Text} \date{} \begin{document} \maketitle % Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, % 17

\begin{center} quis nostrud exercitation ullamco \\ laboris nisi ut aliquip ex ea commodo \\ consequat. Duis aute irure dolor in reprehenderit in \\ voluptate velit esse cillum dolore eu fugiat nulla pariatur. \end{center} % Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. % \end{document} Observe the following features in this input le. the text to be centred is enclosed within an environment which begins with \begin{center} and ends with \end{center}. These behave like the beginning and closing braces. Note the spelling of center. It is not centre. The two backslashes \\ are used to indicate the end of lines and to instruct the compiler to start a new line.

6.2
6.2.1

One sided justication


Right justication

Figure 6.2: Example for right justied text The page shown in Figure 6.2 is produced by the following input text. \documentclass{article} % \title{Right Justified Text} \date{} 18

\begin{document} \maketitle % Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, % \begin{flushright} quis nostrud exercitation ullamco \\ laboris nisi ut aliquip ex ea commodo \\ consequat. Duis aute irure dolor in reprehenderit in \\ voluptate velit esse cillum dolore eu fugiat nulla pariatur. \end{flushright} % Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. % \end{document} Observe the following features in this input le. The text to be right justied is enclosed within an environment which begins with \begin{flushright} and ends with \end{flushright}. These behave like the beginning and closing braces. The two backslashes \\ are used to indicate the end of lines and to instruct the compiler to start a new line.

6.2.2

Left justication

Left justied text can be produced in a similar way. For this, one has to replace flushright with flushleft.

6.3

Two-sided justication
\documentclass{article} % \title{Two-sided Indentation} \date{} \begin{document} \maketitle % Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore. % \begin{quotation} Et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco 19

The page shown in Figure 6.3 is produced by the following input text.

Figure 6.3: Example text showing two-sided indentation

laboris nisi ut

aliquip ex ea commodo.

Consequat, duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. \end{quotation} % Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. % \end{document} Observe the following features in this input le. The text to be right justied is enclosed within an environment which begins with \begin{quotation} and ends with \end{quotation}. These behave like the beginning and closing braces.

6.4

Reproducing typed text

Occasionally it is necessary to print text exactly as it is typed, with all special characters, blanks, and line breaks appearing literally, unformatted, and in a typewriter font. Lines of computer code or samples of A L TEX input text are examples of such literal text. This is accomplished with the verbatim environment: \begin{verbatim} text \end{verbatim} A new line is inserted before and after these environments.

6.5

Footnotes

Footnotes are generated with the command \footnote{footnote text} which comes immediately after the word requiring an explanation in a footnote. 20

The text footnote text appears as a footnote in a smaller typeface at the bottom of the page. The rst line of the footnote is indented and is given the same footnote marker as that inserted in the main text. The rst footnote on a page is separated from the rest of the page text by means of a short horizontal line. Footnotes are numbered serially in the article class. Footnote numbering is reset to 1 for each new chapter for book and report classes.

21

Chapter 7

Lists
7.1
7.1.1

Itemization
Simple Itemized List

Let it be required to produce the following list in the outputle: Civil Engg Computer Science Mechanical Engg Production Engg EEE E& C Engg We enter the following in the input le. \begin{itemize} \item Civil Engg \item Computer Science \item Mechanical Engg \item Production Engg \item EEE \item E\& C Engg \end{itemize}

7.1.2

Nested Itemized List

Let it be required to produce the following in the outputle. Civil Engg Teaching Sta Professor Lecturers Non-teaching Sta 22

Computer Science Teaching Sta Non-teaching Sta Mechanical Engg Teaching Sta Non-teaching Sta Production Engg Teaching Sta Non-teaching Sta EEE E& C Engg We enter the following in the input le. \begin{itemize} \item Civil Engg \begin{itemize} \item Teaching Staff \begin{itemize} \item Professor \item Lecturers \end{itemize} \item Non-teaching Staff \end{itemize} \item Computer Science \begin{itemize} \item Teaching Staff \item Non-teaching Staff \end{itemize} \item Mechanical Engg \begin{itemize} \item Teaching Staff \item Non-teaching Staff \end{itemize} \item Production Engg \begin{itemize} \item Teaching Staff \item Non-teaching Staff \end{itemize} \item EEE \item E\& C Engg \end{itemize} In itemized (bulleted) lists labels are assigned as per the scheme in Table 7.1.

23

7.2
7.2.1

Enumerated List
Simple Enumerated List

Let it be required to produce the following in the output le. 1. Civil Engg 2. Computer Science 3. Mechanical Engg 4. Production Engg 5. EEE 6. E& C Engg We include the following in the input le. \begin{enumerate} \item Civil Engg \item Computer Science \item Mechanical Engg \item Production Engg \item EEE \item E\& C Engg \end{enumerate}

7.2.2

Nested enumerated list

let it be required to produce the following in the output le. 1. Civil Engg (a) Teaching Sta i. Professor ii. Lecturers (b) Non-teaching Sta 2. Computer Science (a) Teaching Sta (b) Non-teaching Sta 3. Mechanical Engg

Table 7.1: Labels in itemized lists Level Label First level (bullet) Second level (long dash) Third level * (asterisk) Fourth level . (dot)

24

Level First level Second level Third level Fourth level

Table 7.2: Labels in enumerated lists Labels Description 1. ,2. , Arabic numerals with a period (a), (b), Lower case letters in parentheses i. ii. , Lower case Roman numerals with a period A,B, Capital letters

(a) Teaching Sta (b) Non-teaching Sta 4. Production Engg (a) Teaching Sta (b) Non-teaching Sta 5. EEE 6. E& C Engg We include the following in the input le: \begin{enumerate} \item Civil Engg \begin{enumerate} \item Teaching Staff \begin{enumerate} \item Professor \item Lecturers \end{enumerate} \item Non-teaching Staff \end{enumerate} \item Computer Science \begin{enumerate} \item Teaching Staff \item Non-teaching Staff \end{enumerate} \item Mechanical Engg \begin{enumerate} \item Teaching Staff \item Non-teaching Staff \end{enumerate} \item Production Engg \begin{enumerate} \item Teaching Staff \item Non-teaching Staff \end{enumerate} \item EEE \item E\& C Engg \end{enumerate} In enumerated lists, the labels are assigned as specied in Table 7.2. 25

Chapter 8

Tables
8.1
8.1.1

Simple Tables
Tables with horizontal and vertical lines
State Kerala Tamil Nadu Karnataka Capital Thiruvananthapuram Chennai Bengaluru Language Malayalam Tamil Kannada

Examine the following table:

This table has the following features: There are three columns in the table. The entries in the rst column are aligned left. The entries in the second column are centred. The entries in the third column are aligned right. There are horizontal lines separating the various rows. There are vertical line lines separating the columns. The entries in the rst row are in boldface. This table is produced by the following lines of text in the input le. \begin{tabular}{|l|c|r|} \hline {\bf State} & { \bf Capital} & {\bf Language} \\ \hline Kerala & Thiruvananthapuram & Malayalam \hline Tamil Nadu & Chennai & Tamil \\ \hline Karnataka & Bengaluru & Kannada \\ \hline \end{tabular} 26

\\

8.1.2

Tables without horizontal and vertical lines

Now examine the following table. State Kerala Tamil Nadu Karnataka This has the following features. There are three columns in the table. All entries in the table entries are aligned left. There are no horizontal lines separating rows. There are no vertical lines separating columns. the entries in the rst row are in boldface. This is generated by the following lines of code. \begin{tabular}{lll} {\bf State} & {\bf Capital} & {\bf Language} \\ Kerala & Thiruvananthapuram & Malayalam \\ Tamil Nadu & Chennai & Tamil \\ Karnataka & Bengaluru & Kannada \\ \end{tabular} Capital Thiruvananthapuram Chennai Bengaluru Language Malayalam Tamil Kannada

8.1.3

Tables with stretched rows and double lines

Next, let us have a look at the following table. State Kerala Tamil Nadu Karnataka Capital Thiruvananthapuram Chennai Bengaluru Language Malayalam Tamil Kannada

Some special features of this table are listed below. The distances between rows have been increased. All entries are centre aligned. There is a double-line between rst and second rows. There is a double-line between rst and second columns. The following lines of code produce this table.

27

\renewcommand{\arraystretch}{2} \begin{tabular}{|c||c|c|c|} \hline State & Capital & Language \\ \hline\hline Kerala & Thiruvananthapuram & Malayalam \\ \hline Tamil Nadu & Chennai & Tamil \\ \hline Karnataka & Bengaluru & Kannada \\ \hline \hline \end{tabular} Here \arraystretch is the command to increase the distance between rows. The number 2 is the value of the parameter which species how much the distances between rows have to be increased. If we require still higher distances replace this by a higher value. The value 1 gives the normal distance. Tables with cells in paragraph mode State Kerala Capital Thiruvananthapuram Study the next table. Language The language of the state is Malayalam. The language is Tamil, a classical language. Kannada is the language of the state.

Tamil Nadu

Chennai

Karnataka

Bengaluru

Sometimes the entries to be written into a cell may be longer. Usually there will be only one line in a cell. However, we can have cells with multiple lines of text by typesetting cells in the paragraph mode. the above table is an example for such a table. It is produced by the following lines of code. \renewcommand{\arraystretch}{2} \begin{tabular}{|c||l|p{4cm}|} \hline State & Capital & Language \\ \hline\hline Kerala & Thiruvananthapuram & The language of the state is Malayalam. \\ \hline Tamil Nadu & Chennai & The language is Tamil, a classical language. \\ \hline Karnataka & Bengaluru & Kannada is the language of the state. \\ \hline \hline \end{tabular} The code p{4cm} species that the third column is to be typeset in the paragraph mode, the horizontal width of the cells in the column being 4 cm. 28

8.2

Multicolumns

Example Finally examine the next table. State Kerala Tamil Nadu Karnataka Capital Thiruvananthapuram Chennai Not available Language Malayalam Tamil

This is produced by the following text in the input le. \begin{tabular}{|c||c|c|} \hline State & Capital & Language \\ \hline\hline Kerala & Thiruvananthapuram & Malayalam \\ \hline Tamil Nadu & Chennai & Tamil \\ \hline Karnataka & \multicolumn{2}{|c|}{Not available} \hline \hline \end{tabular}

\\

8.3

Tables with Captions

1. Study the table given in the next display. State Kerala Tamil Nadu Karnataka Capital Thiruvananthapuram Chennai Bengaluru Language Malayalam Tamil Kannada

Table 8.1: States, capitals, languages

2. You may note the following. There is a table in the display. Below the table, there is a line of text. The line of text begins with the word Table.

29

This is followed by 8.1. Here, the rst number 8 is the Chapter number and the second number 1 is the serial number of the gure in the chapter. The text States, capitals, languages is the title of the image. 3. To produce this we follow the following steps: At the place where the image is to be displayed, add the following lines in the input le: \begin{table}[h] \begin{center} \begin{tabular}{|l|c|r|} \hline State & Capital & Language \\ \hline Kerala & Thiruvananthapuram & Malayalam \hline Tamil Nadu & Chennai & Tamil \\ \hline Karnataka & Bengaluru & Kannada \\ \hline \end{tabular} \caption{States, capitals, languages} \end{center} \end{table}

\\

If we compile the input le and preview the output le, it will be seen that the table has been created at the appropriate place as shown above. 4. With reference to the above code, the following facts are to be observed. The letter h in [h] refers to here. This is an instruction to the complier to place the table exactly at the place where the command appears. There are other options: t, meaning top, instructs the compiler to place the table at the top of the page; b, meaning bottom, instructs the compiler to place the table at the bottom of the page. The word Table and the number 8.1 are generated by the compiler.

30

Chapter 9

Graphics
9.1 A picture in a document

Study the following display:

Figure 9.1: TeX Lion

You may note the following. There is an image1 in the display. Below the image there is a line of text. The line of text begins with the word Figure. This is followed by 9.1. Here, the rst number 8 is the Chapter number and the second number 1 is the serial number of the gure in the chapter. The text TeX Lion is the title of the image.

9.2

Putting a picture in input le

To produce a picture in a le we follow the following steps: Save the image as a .JPG le, say texlion.JPG, in MyFolder.
1 CTAN

(Comprehensive TeX Archive Network) lion drawing by Duane Bibby; thanks to www.ctan.org.

31

Figure 9.2: TeX Lion enlarged

Figure 9.3: TeX lion compressed

Add the command \usepackage{graphicx} in the preamble of the document. (Note the spelling of the package; it ends with an x.) At the place where the image is to be displayed, add the following lines in the input le: \begin{figure}[h] \begin{center} \includegraphics{texlion.JPG} \caption{TeX Lion} \end{center} \end{figure} If we compile the input le and preview the output le, it will be seen that the image has been created at the appropriate place as shown above. With reference to the above code, the following facts are to be observed. The letter h in [h] refers to here. This is an instruction to the complier to place the image exactly at the place where the command appears. There are other options: t, meaning top, instructs the compiler to place the gure at the top of the page; b, meaning bottom, instructs the compiler to place the gure at the bottom of the page. The word Figure and the number 9.1 are generated by the compiler. Several options are available to control the size of the image. If the image is to be displayed with a width of 7 cm, the command is to be modies as follows. 32

\includegraphics[width = 7cm]{texlion.JPG} With this changed command the output gure will be as in Figure 9.2. We can also specify the height. If the height of the displayed image in the output le is to be 2 cm, it is specied as follows: \includegraphics[height = 2cm]{texlion.JPG} The output image will now appear as in Figure 9.3.

33

Chapter 10

Mathematics
A TEX was created to typeset documents containing a lot of mathematics. So TEX and L TEX have a large number of features to produce beautifully typeset mathematics. This chapter is only a rst introduction to A this vast area of L TEX. More elaborate descriptions can be found in the literature. For example see [?] or [4].

10.1

amsmath package

When typesetting mathematics always load the amsmath package. This package contains several features developed by the American Mathematical Society (AMS). (For a detailed discussion see [5].) \usepackage{amsmath}

10.2
10.2.1

First lessons
Keyboard symbols

The following mathematical symbols are available on the keyboard: + = < > / : ! | [ ] ( ) ]

10.2.2

Exponents

The character command sets the next character as an exponent (raised). Mathematics a2 a2 n a2n (a + b)ij
A L TEX code

a^2 a^2n a{2n} (a+b){i-j}

34

10.2.3

Subscripts
sets the next character as an index (lowered). Mathematics a2 a2 n a2n (a + b)ij
A L TEX code

The character command

a2 a 2n a {2n} (a+b) {i-j}

10.2.4

Both exponents and indices


to the exponents and indices

Multiple raisings and lowerings are generated by applying and Mathematics xy


2

A L TEX code

x^{y^2} x^{y 1} A^{x i^2} {j^{2n} {n,m} }

xy1
i Aj 2n

x2

n,m

10.2.5

Fractions
Mathematics
a b a2 b2 ab
c 1+ d a b

A L TEX code

\frac{a}{b} \frac{a^2 - b^2}{a-b} \frac{\frac{a}{b}} {1 + \frac{c}{d}}

10.2.6

Roots
Mathematics A+B A+B q + q 2 + p3
A L TEX code

\sqrt{A+B} \sqrt[3]{A+B} \sqrt[3]{- q + \sqrt{q^2 + q^3 }}

3
3

35

10.2.7

Mathematical symbols

There is a very wide range of symbols used in mathematical text. Only a few are directly available from the A keyboard. L TEX provides many of the mathematical symbols that are commonly used. They are called with the symbol name prexed with the \ character. The names themselves are derived from their mathematical meanings. For example to get we type \pi and to get type \pm. Hundreds of such symbols can be used A A in L TEX. A comprehensive list of all mathematical and other symbols that can be used in L TEX is available at [6].

10.3
10.3.1

Mathematics in input le
Mathematical expressions inline

To produce equations and formulas inline use one the following formats: \begin{math} formula text \end{math}

\( formula text \) $ formula text $ Example input: The equation $ax+b=0$ has no solution when $a=0$ and $b\ne 0$. Example output: The equation ax + b = 0 has no solution when a = 0 and b = 0.

10.3.2

Equations without numbering

To display equations without equation numbers, use the following format. \begin{displaymath} formula text \end{displaymath} \[ formula text \] $$.

$$ formula text Example input

The equation $$ax+b=0$$ has a unique solution $$ x = -\frac{b}{a} $$ when $a\ne 0$. Example output: The equation ax + b = 0 has a unique solution x= when a = 0. 36 b a

10.3.3

Equations with numbering

To displayed equations with equation numbers use the following format: \begin{equation} formula text \end{equation} Example input: The equation \begin{equation} ax+b=0 \end{equation} has a unique solution \begin{equation} x = -\frac{b}{a} \end{equation} when $a\ne 0$. Example output: The equation ax + b = 0 has a unique solution x= when a = 0. b a (10.2) (10.1)

37

Chapter 11

Cross References
11.1 Outline of procedure

Let there be several gures and tables in a document. Let it be required to refer to these gures and tables at other points in the document. Cross referencing methods are used to tackle this problem. Cross referencing involves three steps: 1. Assigning labels to items to be referenced. Some of the items to which labels can be assigned are the following: Tables Figures Chapter numbers Section numbers Equation numbers Page numbers Items in enumerated lists. Items are assigned labels using the \label command. 2. Inserting commands in the input les indicating the places where these references are to be printed. These are inserted using the \ref and \pageref commands. 3. Compiling the input le to get the the references properly printed in the output le. To get the references printed, the input le is to compiled twice. In the rst compilation the programme collects all the labels and stores them in a le. During the second compilation the labels are assigned values and placed at the appropriate locations.

11.2
11.2.1

Assigning labels
Assigning labels to tables and gures

We have seen in Section 8.3 how to produce captions to tables. To reference a table at another point in the document, we assign a unique label to the table. The label may be any combination of letters, numbers, or symbols. Let the label be MyLabel. The command to assign this label is 38

\label{MyLabel}. Include this command immediately after the closing brace of the \caption command. The compiler assigns to the label MyLabel a value which is the number assigned to the table by the compiler. The procedure described above can also be applied to assign a unique label to every gure in a document. Examples: \caption{States, capitals, languages}\label{FirstTable} \caption{An image of TeXlion}\label{Fig:001}

11.2.2

Assigning labels to chapters, sections, etc.

Labels can be assigned to chapter numbers, section numbers, etc. using the \label command. We write this command adjacent to the respective sectioning commands as in the following examples. \chapter{Introduction}\label{xyz} \section{Prliminaries}\label{ch1.sec.001} \subsection{Basics}\label{ab:123}

11.2.3

Assigning labels to equations

The number assigned to an equation with numbering can be assigned to a label by invoking the \label command. The next example illustrates the procedure. \begin{equaion}\label{Eq.1} (a+b)^2=a^2+2ab+b^2 \end{equation}

11.2.4

Assigning labels to page numbers

A page number can be assigned a label by issuing the \label command in the page.

11.3

Printing the value of a label

The value assigned to a label is printed by using the \ref command. If the label is Mylabel, the value of this label is printed by issuing the command \ref{Mylabel}. The page number on which the \label command was issued can be printed with \pageref{marker} at any point earlier or later in the document.

11.4
11.4.1

Example for cross referencing


Example input le

\documentclass{book} \usepackage{graphicx} \begin{document} \chapter{Cross Referencing} Some examples. \section{Tables and figures} % Consider the following table: 39

Figure 11.1: Example for cross referencing

\begin{table}[h] \begin{center} \begin{tabular}{ll} \hline State & Capital \\ \hline Kerala & Thiruvanathapuram \\ Tamiil Nadu & Chennai \\ \hline \end{tabular} \end{center} \caption{States and capitals}\label{Table:01} \end{table} Next consider the following figure: \begin{figure}[h] 40

\begin{center} \includegraphics[height = 2cm]{texlion.JPG} \end{center} \caption{TeX lion}\label{Figure:01} \end{figure} \section{References to tables and figures} The picture in Figure \ref{Figure:01} is a compressed image of the TeXLion. The data in Table \ref{Table:01} is a short table of states and their capitals. \end{document}

11.4.2

Example output le

The output of the input le given in Section 11.4.1 is shown in Figure 11.1.

41

Chapter 12

Simple Index
12.1 Procedure

The various steps for the creation of an index are summarised below. 1. If an index is to be created, the package makeidx must be loaded. This is done by including the following line in the preamble: \usepackage{makeidx} 2. Next the command \makeindex must also be included in the preamble. (Note that the package is makeidx and the command is makeindex.) 3. Include the command \printindex at the end of the document. 4. In the main body of the document, mark those entries which are to be included in the index as follows: Let the entry to be included in index be Automation. The we mark it as \index{Automation} In this way mark all other entries also.
A 5. We compile the source le by running pdfL TEX once.

6. Next we have to run an external program known as MakeIndex.


A 7. Next we have to compile the document again by running pdfL TEX once more.

8. The output le now would have a properly placed index.

12.2

Example

Input le
\documentclass{book} \usepackage{makeidx} \makeindex % \begin{document} % 42

\chapter{First} \section{Examples} We have included example words like Zizigy\index{Zizigy} and Automation\index{Automation} in this section. \section{More exapmles} A few more examples are included here like computer\index{computer}, \index{compiler} which are common words. Ordinary words can also be included in index. % \printindex \end{document}

Output le
After completing the various steps specied in the previous section, we get a le having two pages. the rst page will look as follows:

The second page will look as follows:

43

Chapter 13

Generating Bibliography
13.1 Sample bibliography

Let it be required to produce a bibliography as follows.

13.2

A L TEX code for the sample bibliography

This produced by including the following text at the end of the document.

\begin{thebibliography}{99} % \bibitem{xyz} A Kanetkar, {\em Let Us C}, Prentice hall of India, 2009. \bibitem{abc} D E Knuth, {\em The TeXbook}, Academic Press, 1990. \bibitem{LabelX} Sommerville, {\em Textbook of Software Engineering}, Pearson education, 2010. % \end{thebibliography}

44

13.3

Explanatory notes

The following facts may be observed. 1. The content of the bibliography is placed inside the environment \begin{thebibliography}{sample label} entries \end{thebibliography} 2. Each of the individual entries in the bibliography begins with the command \bibitem{key} entry text The keyword \bibitem produces a running number in square brackets as the label for the reference in the text. The mandatory argument key is a reference key, which is like the cross-referencing key \label used to make the actual citation in the main text. The key name can be made up of any combination of letters, numbers, and symbols except commas. 3. The citation in the text is made with the command \cite{key} where key is the reference key that appears in the \bibitem command.

13.4

The bibtex package

BibTEX is a tool specially devised to handle long lists of references. This tool allows us to store all our A references in an external database. We can then easily link this database to any L TEX document, and cite any reference that is contained within the le. This is often more convenient than embedding them at the end of every document we write. We can have a centralised store of our bibliography, that can be linked to as many documents as we wish. For more details see ??.

45

Chapter 14

Page Layouts
14.1 Page layout parameters

Page layout is concerned with the design of a page. The dimensions of the margins (left, right, top and bottom), page orientation (portrait or landscape) and number of columns in a page are some of the elements that go into the design of a page. A Figure 14.1 (page 47) shows some of the important page layout parameters and the L TEX commands to specify these parameters.

14.2

geometry package

The geometry package can be used to specify the values of the page layout parameters. With this package, one can easily give values for some of the layout parameters, and the rest will be set automatically, taking into account. For example, to set \textwidth to 15 cm and \textheight to 25 cm on A4 paper, one gives \usepackage{geometry} \geometry{a4paper,textwidth=15cm,textheight=25cm} which will also automatically set \oddsidemargin and \topmargin so that the text is centered horizontally and vertically, including the head and footlines. Or, one can set all the margins to be 1 inch on US letter paper with \geometry{letterpaper,margin=1in} \end{vebatim} % Rather than using the {\tt \textbackslash{}geometry} command, one may also place the parameters as options to {\tt \textbackslash{}usepackage}, for example as % \begin{verbatim} \usepackage[a4paper,left=3cm,right=2cm]{geometry} to set the left and right margins to denite values, and \textwidth to what is left over. In general, all the parameters in Figure 14.1 may be specied by geometry by giving their names (without the backslash character). For more details on geometry package refer to manual written by the creator of the package (see [8]).

46

Figure 14.1: Page Layout Parameters

47

Chapter 15

Book Structure
15.1 Front matter, main matter, back matter

The contents of a book can be classied as belonging to three dierent types of structures. Front matter: This consists of preface, acknowledgment, dedication, table of contents, list of tables, list of gures, etc. Main matter: This is the main body of the book. Back matter: This contains bibliography, index, colophon, etc. In well-structured books the three parts are typeset dierently. Commands have been provided in the book class to typeset these three elements of a book as per well established conventions. The \frontmatter command switches page numbering to Roman numerals and suppresses the numbering of chapters. This command is issued immediately prior to the point where the front matter of the book begins. The \mainmatter command resets the page numbering to 1 with Arabic numbers and reactivates the chapter numbering. This command is issued immediately prior to the point where the main matter of the book begins. Finally the \backmatter command is issued immediately prior to the point where the back matters of the book begin.

15.2
15.2.1

Front matter
Table of contents

The table of contents is generated and printed with the command \tableofcontents given at the location where the table of contents is to appear, which is normally after the title page and abstract. To generate a table of contents, the input le has to be compiled at least twice.

48

15.2.2

Other lists

In addition to the table of contents, lists of gures and tables can also be generated and printed automatically A by L TEX. The commands to produce these lists are \listoffigures \listoftables The entries in these lists are made automatically by the \caption command in the gure and table environments.

15.3

Splitting of documents

A When an input le is large, it would be better to split the work into several smaller les. L TEX then merges these smaller les during the processing. The contents of another le may be read into a LATEX document with the command

\input{filename} where the name of the other le is filename.tex. It is only necessary to specify the full name of the le if the A extension is something other than .tex. During the L TEX processing, the text contained in this second le is read in at that location in the rst le where the command is given. The result of the \input command is the same as if the contents of the le filename.tex had been typed into the document le at that position. The command may be given anywhere in the document, either in the preamble or within the text part.

49

Appendix : The Name of the Game


The following is a verbatim reproduction of Chapter 1 The Name of the Game in [11] which is the manual of the TEX program written by the creator of the program.

English words like technology stem from a Greek root beginning with the letters , , ,. . .; and this same Greek word means art as well as technology. Hence the name TEX, which is an uppercase form of . Insiders pronounce the of TEX as a Greek chi, not as an x, so that TEX rhymes with the word blecchhh. Its the ch sound in Scottish words like loch or German words like ach; its a Spanish j and a Russian kh. When you say it correctly to your computer, the terminal may become slightly moist. The purpose of this pronunciation exercise is to remind you that TEX is primarily concerned with highquality technical manuscripts: Its emphasis is on art and technology, as in the underlying Greek word. If you merely want to produce a passably good document something acceptable and basically readable but not really beautiful a simpler system will usually suce. With TEX the goal is to produce the nest quality; this requires more attention to detail, but you will not nd it much harder to go the extra distance, and youll be able to take special pride in the nished product. On the other hand, its important to notice another thing about TEXs name: The E is out of kilter. This displaced E is a reminder that TEX is about typesetting, and it distinguishes TEX from other system names. In fact, TEX (pronounced tecks) is the admirable Text EXecutive processor developed by Honeywell Information Systems. Since these two system names are pronounced quite dierently, they should also be spelled dierently. The correct way to refer to TEX in a computer le, or when using some other medium that doesnt allow lowering of the E, is to type TeX. Then there will be no confusion with similar names, and people will be primed to pronounce everything properly. EXERCISE 1.1 After you have mastered the material in this book, what will you be: A TEXpert, or a TEXnician?

They do certainly give very strange and new-fangled names to diseases. PLATO, The Republic, Book 3 (c. 375 B.C.) Technique! The very word is like the shriek Of outraged Art. It is the idiot name Given to eort by those who are too weak, Too weary, or too dull to play the game. LEONARD BACON, Sophia Trenton (1920)

50

Bibliography
[1] MiKTEX project page: Available: http://miktex.org/ [2] Instructions for downloading and installing MikTEX 2.8: Available: http://miktex.org/2.8/setup [3] Comparison of TEX editors (IDEs), Wikipedia, The Free Encyclopedia: Available: http://en. wikipedia.org/wiki/Comparison_of_TeX_editors [4] Chapter 8 of The LaTeX Companion by Frank Mittelbach and Michel Goosens. Available: http: //www.macrotex.net/texbooks/latexcomp-ch8.pdf. [5] Users Guide for the amsmath Package. Available: amsldoc.pdf. [6] The comprehensive LaTeX symbols list. Available: symbols/comprehensive/symbols-a4.pdf. ftp://ftp.ams.org/pub/tex/doc/amsmath/ http://www.ctan.org/tex-archive/info/

[7] MakeIndex: An Index Processor For LaTEX, Leslie Lamport. Available: http://www.tex.ac.uk/ tex-archive/indexing/makeindex/doc/makeindex.pdf, 1987. [8] The geometry package, Hideo Umeki. Available: ftp://ftp.tex.ac.uk/tex-archive/macros/latex/ contrib/geometry/geometry.pdf [9] Tame the BeaST : The B to X of BibTEX, Nicolas Markey, 2009. Available: http://www.ctan.org/ tex-archive/info/bibtex/tamethebeast/ttb_en.pdf
A [10] L TEX , Wikibooks contributors. Available: http://upload.wikimedia.org/wikipedia/commons/2/ 2d/LaTeX.pdf

[11] The TEXbook, Donald E Knuth, Addison-Wesley Publishing Company, 1991. Available: http://net. ytu.edu.cn/share/%D7%CA%C1%CF/texbook.pdf

51

References
1. Online resource
A (a) L TEX , Wikibooks contributors. Available: http://upload.wikimedia.org/wikipedia/commons/ 2/2d/LaTeX.pdf

(b) The Not So Short Introduction to LATEX2, Or LATEX2e in 157 minutes, Tobias Oetiker Hubert Partl, Irene Hyna and Elisabeth Schlegl. Available: http://www.ctan.org/tex-archive/info/ lshort/english/lshort.pdf
A (c) Online tutorials on L TEX, Indian TEX Users Group. Available: http://tug.org.in/tutorials. html

(d) TEX Resources on the Web. Available: http://www.tug.org/interest.html#latexbooks 2. Standard reference books
A (a) A Guide to L TEX2e, by Helmut Kopka and Patrick Daly (Addison-Wesley, ISBN 0-321-17385-6, fourth edition, 2003). A (b) The L TEX Companion, by Frank Mittelbach, Michel Goossens, Johannes Braams, David Carlisle, and Chris Rowley (Addison-Wesley, ISBN 0-201-54199-8, second edition, 2004). A (c) The L TEX Web Companion: Integrating TEX, HTML, and XML, by Michel Goossens, Sebastian Rahtz, Eitan Gurari, Ross Moore and Robert Sutor (Addison-Wesley, ISBN 0-201-43311-7).

(d) The LaTeX Graphics Companion, by Michel Goossens, Sebastian Rahtz, and Frank Mittelbach (Addison-Wesley, ISBN 0-201-85469-4).

52

Index
TEXnician, 50 TEXpert, 50 book class, 7 report class, 7 article class, 7 acknowledgment, 48 amsmath, 34 \arraystretch, 27 \author, 8 auxiliary le, 8 b for bottom, 30 back matter, 48 \backmatter, 48 \backslash, 14 Bacon, 50 \bf, 15 \bibitem, 44 bibliography, 44 bibtex, 45 blank line, 13 blank space, 13 bold, 14 bold style, 15 \caption, 30, 32 center environment, 17 centering, 17 \chapter, 11 \cite, 45 colophon, 48 comment, 14 compilation, 5 dashes, 14 \date, 8 displaymath environment, 36 document environment, 8 \documentclass, 7 double lines, 27 Editor Window, 3 \em, 15 emphasise, 14 en-GB, 4 en-US, 4 enumerate environment, 24 enumeration, 24 environmrnt center, 17 flushleft , 19 thebbliography, 44 displaymath , 36 document , 8 enumerate, 24 equation , 37 figure, 32 flushright , 18 itemize, 22 math , 36 table, 30 tabular, 26 verbatim , 20 equation environment, 37 error, 6, 8 exponents, 34 figure environment, 32 flushleft environment, 19 flushright environment, 18 font size, 15 font style, 14 \fontsize, 16 \footnote, 20 \footnotesize, 15 fraction, 35 front matter, 48 \frontmatter, 48 geometry package, 46 graphicx, 32 h for here, 30 height, 32 \hline, 26 \Huge, 15 53

\huge, 15 \includegraphics, 32 index, 42 \index, 42 \input, 49 input le, 5 italic, 14 italics, 15 \item, 22 itemization, 22 itemize environment, 22 justication, 18 \label, 38 \LARGE, 15 \Large, 15 \large, 15 left justication, 19 line numbers, 4 \listoffigures, 49 \listoftables, 49 Log, 6 main matter, 48 \mainmatter, 48 makeidx, 42 \MakeIndex, 42 \makeindex, 42 \maketitle, 8 math environment, 36 mathematical symbols, 36 MiKTeX project, 2 \multicolummn, 29 MyFolder, 6 nested enumeration, 24 nested itemization, 22 \newline, 14 \normasize, 15 option Editor, 3 output le, 5 Output panel, 6 package geometry, 46 page layout, 46 \pageref, 38 paragraph mode, 28 parameter number, 14 PDF reader, 5

pdfLaTeX, 5 Plato, 50 Preferences ..., 3 Preview Window, 5 \printindex, 42 quotes, 14 \ref, 38 right justication, 18 root, 35 sans serif style, 15 Save File window, 6 \sc, 15 scope delimiter, 14 \scriptsize, 15 \section, 11 sectioning commands, 11 \sf, 15 \sl, 15 slanted style, 15 \slanted style, 15 \small, 15 small caps style, 15 special characters, 14 special symbols, 36 spell-check, 4 splitting documents, 49 stretched row, 27 subscript, 35 \subsection, 11 \subsubsection, 11 symbols, 36 sync-TeXing, 8 t for top, 30 tab separator, 14 table, 26 table environment, 30 table of contents, 48 \tableofcontents, 48 tabular environment, 26 \textheight, 46 \textwidth, 46 The Republic, 50 thebibliography environment, 44 \tiny, 15 \title, 7 \topmargin, 46 \topsidemargin, 46 \tt, 15 typeset button, 5 54

typewriter style, 15 \usefont, 15 verbatim environment, 20 width, 32 wrap-lines, 4 WYSIWYG, 5

55

You might also like