Introduction to LaTeX

23
Document Preparation using L A T E X Document Processor not a Word Processor A.B. Raju and Satish Annigeri B.V.B. College of Engineering & Technology Hubli 580 031 20 Sep, 2014 A.B. Raju (BVBCET, Hubli) Document Preparation using L A T E X 20 Sep, 2014 1 / 23

description

LaTeX is a document preparation system with emphasis on logical structure and mathematical and scientific typesetting.

Transcript of Introduction to LaTeX

Page 1: Introduction to LaTeX

Document Preparation using LATEXDocument Processor not a Word Processor

A.B. Raju and Satish Annigeri

B.V.B. College of Engineering & TechnologyHubli 580 031

20 Sep, 2014

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 1 / 23

Page 2: Introduction to LaTeX

LATEXversus MS Word

Microsoft Word is good forshort documents, such as coverpages, letters, or documentswith about 100 pages. Basicfeatures are easy to learn andGUI is useful for normal users.

If you are writing a longdocument like a Technicalpaper, Project report, an article,or a review, you are better offwith LATEX. Initial learning curveis steep, but persist with it andyou will be rewarded.

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 2 / 23

Page 3: Introduction to LaTeX

Document Preparation

Document Preparation is concerned with creating documents for print orelectronic distribution.

Typical document structure for long documentsFront matterMain matterBack matter

Mathematical equation typesetting

Lists

Tables

Reference citation

Cross referencing within the document

LATEX lets the author take care of logical structure while it takescare of visual structure

Word processors require the author to take care of both logical andvisual structure

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 3 / 23

Page 4: Introduction to LaTeX

LATEX History

Donald Knuth

Professor Emeritus, StanfordUniversity

Author of the multi-volume TheArt of Computer Programming

Creator of TEX computertypesetting system andMETAFONT font definitionlanguage

TEX was developed in late 1970sby Donald Knuth Donald Knuth

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 4 / 23

Page 5: Introduction to LaTeX

LATEX History contd

Leslie Lamport

Initially developed the LATEXsystem as a documentpreparation system

Developed when Leslie Lamportwas working at SRI International

Currently works at MicrosoftResearch

LATEX was first released in theyear 1985

Current version is LATEX 2εLeslie Lamport

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 5 / 23

Page 6: Introduction to LaTeX

Installing LATEX

Microsoft WindowsMiKTeX is a popular LATEX distribution for Microsoft WindowsHas a package manager to install additional packages or removeinstalled packagesHas an update manager to update installed packagesCan be downloaded from http://miktex.org

GNU/LinuxTeXLive is a LATEX distribution for GNU/LinuxInstallation and package management is done through the systempackage manager - one of apt-get, yum, zypper depending on yourGNU/Linux distribution

LATEX editorsTeXstudio - Windows and GNU/Linuxhttp://texstudio.sourceforge.net/

TeXMaker - Windows and GNU/Linuxhttp://www.xm1math.net/texmaker/

TeXnicCenter - Windows http://www.texniccenter.org/

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 6 / 23

Page 7: Introduction to LaTeX

LATEX Document Preparation Workflow

1 Write the LATEX source document in a text editor

2 Compile the LATEX source document to your preferred output format

3 View the document

4 Repeat this loop to modify the document

Popular output formats

DVI – DVI viewer (xdvi on GNU/Linux, YAP in MiKTeX)

PDF – Acrobat reader or other PDF viewers (xpdf or evince onGNU/Linux, Sumatra on Windows)

Postscript (PS) – Ghostview viewer (Ghostscript)

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 7 / 23

Page 8: Introduction to LaTeX

Minimal LATEX document

\documentclass{article}

\begin{document}

Hello, World

\end{document}

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 8 / 23

Page 9: Introduction to LaTeX

Structure of a Document

A document can be structured into the followingPart \part BookChapter \chapter Book, ReportSection \section Book, Report, ArticleSub Section \section Book, Report, ArticleSub Sub Section \section Book, Report, ArticleParagraph \subsection Book, Report, ArticleSub Paragraph \subsubsection Book, Report, Article

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 9 / 23

Page 10: Introduction to LaTeX

Choosing the Right Document Class

BookTitle page on a separate page by itselfCan contain parts, chapters, sections, subsections, subsubsections andparagraphsNew chapters begin on a new page, on the right side by defaultDocument is two sided by default, can be changed to one sidedCan optionally have appendices.

ReportTitle page on a separate page by itselfCan contain chapters, sections, subsections, subsubsections, paragraphsNew chapters begin on a new pageDocument is one sided by default. Two sided is optional

ArticleNo separate page for title pageCan contain sections, subsections, subsubsections, paragraphsDocument is one sided by default. Two sided is optional

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 10 / 23

Page 11: Introduction to LaTeX

Adding Sections

\documentclass{article}

\begin{document}

\section{Word} \label{sec:word}

I prefer using \LaTeX{} to using Microsoft Word or

other word processors.

\section{Latex}\label{sec:tex}

I love \LaTeX. As I mentioned in Section~\ref{sec:word},

I do not like word processors.

\end{document}

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 11 / 23

Page 12: Introduction to LaTeX

Some Tips for Beginners

Words are separated by spaces. Number of spaces doesn’t matter,one is as good as 100.

Paragraphs are separated by empty lines. Number of empty linesdoesn’t matter, one is as good as 100.

LATEX is a markup language. To make something to be printed inbold in the document, you mark it in the source with\textbf{this will be in bold}.

Following characters are reserved for use by LATEX –# $ % & ~ _ ^ \ { }. To print these characters in your document,you will have to escape tem. For example \& to print &.The characters that can appear in your text are:

Alphabets: a-z, A-ZDigits: 0-9

Punctuation: . : ; , ? ! ‘ ’ ( ) [ ] - / * @

Mathematical symbols: + = < >

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 12 / 23

Page 13: Introduction to LaTeX

Some More Tips

A soft return is introduced with two backslashes: \\

A non-breaking space is: ~ as in Chapter~1

LATEX automatically hyphenates words where necessary

Beginners must look out for some common errors:

A misspelled command or environment nameImproperly matching bracesTrying to use one of the ten special characters # $ % & _ { } ~ ^ \,as an ordinary printing symbol without escaping themImproperly matching formula delimiters – for example, \( without amatching \)

The use in ordinary text of a command like ^ that can appear only in amathematical formulaA missing \end commandA missing command argument

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 13 / 23

Page 14: Introduction to LaTeX

All the Fuss about Spaces

Space after a sentence is longer than a normal space. Can you see itjust before this sentence begins?

Sometimes the period does not represent end of a sentence, such as,Prof. Donald Knuth. The period after Prof. does not end a sentence.You can tell this to LATEX. \ prints a normal space. Compare thefollowing in the printed document:Prof. Donald Knuth – Prof. Donal Knuth

Prof. Donald Knuth – Prof.\ Donald Knuth

Non-breaking space is introduced with ~

Prof. Donald Knuth – Prof. Donal Knuth

Prof. Donald Knuth – Prof.\ Donald Knuth

Prof. Donald Knuth – Prof.~Donald Knuth

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 14 / 23

Page 15: Introduction to LaTeX

Equation Example

\documentclass{article}

\begin{document}

\begin{equation} \label{eq:sum}

s = \sum_{i=1}^{n}x_{i}

\end{equation}

\end{document}

Mathematical equations can be displayed in displaymath orequation environment, with or without numbers.

Displaymath mode without numbering: \[ x’ + y^2 = z_i \] oruse the \begin{equation*} x’ + y^2 = z_i \end{equation*}

environment

Inline math mode: Mathematical expressions within runningsentences: radius of a circle is $r^2 = x^2 + y^2$ orradius of a circle is \( r^2 = x^2 + y^2 \), which willprint as: radius of a circle is r2 = x2 + y2

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 15 / 23

Page 16: Introduction to LaTeX

\documentclass{article}

\begin{document}

\begin{equation} \label{eq:mean}

\bar{x} = \frac{\sum_{i=1}^{n}x_{i}} {n}

\end{equation}

The equation for mean is given in Equation \ref{eq:mean}.

\end{document}

x̄ =

∑ni=1 xin

(1)

The equation for mean is given in Equation 1.

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 16 / 23

Page 17: Introduction to LaTeX

Document Class Examples

\documentclass{book}

\documentclass{report}

\documentclass{article}

\documentclass[a4paper]{article}

\documentclass[a4paper,11pt,twocolumn]{report}

\documentclass[12pt,letterpaper,oneside]{book}

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 17 / 23

Page 18: Introduction to LaTeX

\documentclass{report}

\title{Learn \LaTeX}

\author{A.B. Raju}

\begin{document}

\maketitle

\tableofcontents

\end{document}

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 18 / 23

Page 19: Introduction to LaTeX

\documentclass{report}

\title{Learn \LaTeX}

\author{A.B. Raju}

\begin{document}

\maketitle

\tableofcontents

\include{chapter_1}

\include{chapter_2}

\include{chapter_3}

\end{document}

In the above example, each chapter is typed in a separate file, andincluded into the main document in the right sequence.

Filenames usually have the .tex extension, but it is not included inthe \include{filename} command

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 19 / 23

Page 20: Introduction to LaTeX

Including Graphics

Convert images into .jpg/.eps or .pdf format

Include package graphicx

Use the \includegraphics{filename} command

Filename is case sensitive on some GNU/Linux and Mac OS X

To specify options, use the\includegraphics[options]{filename} command

Options may include [width=2.5cm], [height=5cm] etc

LATEX understand several standard length units such as:in for inch, cm for centimeter, pt for point. 1 inch is 72 points

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 20 / 23

Page 21: Introduction to LaTeX

An example

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{figure}

\includegraphics{MyBat}

\caption{This is My Bat} \label{fig:bat}

\end{figure}

In Figure \ref{fig:bat}

\end{document}

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 21 / 23

Page 22: Introduction to LaTeX

TikZ Pictures

\begin{tikzpicture}

\draw[step=0.5,blue!20,very thin] (-1.5,-1.5) grid (1.5,1.5);

\draw[thick] (-1.5,0) -- (1.5,0);

\draw[thick] (0,-1.5) -- (0,1.5);

\draw[very thick] (-1,0) .. controls(-1,0.555) and (-0.555,1)

.. (0,1) .. controls(0.555,1) and (1,0.555) .. (1,0);

\end{tikzpicture}

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 22 / 23

Page 23: Introduction to LaTeX

Thank You

A.B. Raju (BVBCET, Hubli) Document Preparation using LATEX 20 Sep, 2014 23 / 23