1 lecture 4 a brief introduction to latex introduction to information technology dr. ken tsang...

47
1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾曾曾 Email: [email protected] http://www.uic.edu.hk/~kentsang/IT/IT3.htm Room E408 R9

Upload: christopher-jackson

Post on 01-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

1

Lecture 4 A Brief Introduction to LaTeX

Introduction to Information Technology

Dr. Ken Tsang 曾镜涛Email: [email protected]://www.uic.edu.hk/~kentsang/IT/IT3.htmRoom E408 R9

Page 2: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

2

What is TeX? TeX is a typesetting system (排版系统 )

written by Donald E. Knuth in 1976, who says that it is “intended for the creation of beautiful books — and especially for books that contain a lot of mathematics”

Page 3: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

3

How to Pronounce TeX? The X is really the Greek letter Chi, and

is pronounced by English-speakers like ‘k’. It definitely is not pronounced ‘ks’ (the Greek letter with that sound doesn’t look remotely like the Latin alphabet X)

The name comes from the Greek word for “art” or “craft” (“techni”), which is the root of the English word technology

Page 4: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

4

What is LaTeX? LaTeX is a free high-quality

document processing system that is based on TeX

LaTeX was originally written by Leslie Lamport in 1980s

Page 5: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

5

Lamport never announced how one he thought people should pronounce LaTeX

How to Pronounce TeX?

A lot of people pronounce it “Lay TeX” or “Lah TeX”

Page 6: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

6

Why LaTeX ? It is the premier typesetting package

in the world! It's free!!! It's available for many machines

(Linux, Mac, Windows) LaTeX files are ASCII

Therefore, they are very portable You can use the editor of your choice

(Some people even use MS Word)

Page 7: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

7

Why LaTeX ? The typesetting is better

especially the maths Style changes are neater in LaTeX

Style files for many periodicals exist Many MS Word users don't use styles or

templates, so there's a limit to what they can do

LaTeX is extensible If you want a new feature, find a free

add-on or write one yourself

Page 8: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

8

Disadvantages LaTeX encourages (almost insists

on) structured writing and the separation of style from content This is not the way that many people

(especially non-programmers) are used to working

Without a WYSIWYG (What You See Is What You Get), it's not always easy to find out how to do things

Page 9: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

9

LaTeX vs MS Word If you are writing a document with lots of

maths, tables, cross-references, etc, and you need to format the document and bibliography to suit various publications, then LaTeX is clearly the best choice!

If your document contains many equations / figures / tables, MS Word easily runs out of memory and shows a nice blue screen of death or prints red crosses instead of your equations

Page 10: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

10

LaTeX vs MS Word LaTeX encourages authors not to worry

too much about the appearance of their documents but to concentrate on getting the right content

LaTeX is based on the idea that it is better to leave document design to document designers, and to let authors get on with writing documents

Page 11: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

11

“Hello World” Suppose we want to produce the

following document:

Page 12: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

12

In MS Word To produce this in most typesetting or

word-processing systems, the author would have to decide what layout to use, so would select (say) 18pt Times Roman for the title, 12pt Times Italic for the name, and so on

This has two results: Authors wasting their time with designs A lot of badly designed documents!

Page 13: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

13

In LaTeX\documentclass{article}\title{Introduction to LaTeX}\author{Bill Gates}\date{November 2007}\begin{document} \maketitle Hello world!\end{document}

Page 14: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

14

Or In English This document is an article Its title is An Introduction to

LaTex Its author is Bill Gates It is written in November 2007 The document consists of a title

followed by the text Hello world!

Page 15: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

15

LaTeX Features Typesetting journal articles, technical

reports, books, and slide presentations

Control over large documents containing sectioning, cross-references, tables and figures

Typesetting of complex mathematical formulas

Advanced typesetting of mathematics with AMS-LaTeX

Page 16: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

16

LaTeX Features Automatic generation of

bibliographies and indexes Multi-lingual typesetting Inclusion of artwork, and process or

spot color Using PostScript or Metafont

fonts

Page 17: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

17

Obtaining LaTeX Linux

Your system distribution or vendor has probably provided a TeX system including LaTeX. Check your usual software source for a TeX package

MacOS X A full TeX system including LaTeX, called MacTeX,

is available for installation with i-Installer http://www.tug.org/mactex/

Windows Check out the proTeXt system; this allows you to

install a full TeX system, including LaTeX, while reading about the basics of the installation

http://www.tug.org/protext/ Chinese TeX: http://www.ctex.org

Page 18: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

18

A Quick Start (1) The LaTeX Source: reproduce the

following text in any text-editor and save it as hello.tex

\documentclass{article} \begin{document} Hello World! \end{document}

Page 19: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

19

A Quick Start (2) Generating the documents Type the command:

latex hello.tex Various bits of info about LaTeX and its

progress will be displayed. If all went well, the last two lines displayed in

the console will be: Output written on hello.dvi (1 page, xxx bytes)Transcript written on hello.log

This means that your source file has been processed and the resulting document is called hello.dvi, which takes up 1 page and xxx bytes of space.

Page 20: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

20

A Quick Start (3) Viewing the documents LaTeX has now done its job, so we can view

the output The default format is DVI (device

independent), of which viewers exist freely for most platforms

However, the chances are that you would prefer to have a postscript file or PDF

Fortunately, there exist tools that can convert DVI to PS (and PDF) easily

Page 21: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

21

A Quick Start (4)To Convert the document into a postscript (PS)

file Type the command:

dvips hello.dvi -o hello.ps dvips is the utility that actually performs the

conversion. The first argument hello.dvi is the DVI file to

be converted. The -o argument says that you want the

output to be saved as a file. And the argument immediately after, hello.ps,

is the name you wish to call it.

Page 22: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

22

A Quick Start (5)To Convert the document into a PDF file Type the command:

dvipdf hello.dvi hello.pdf Note that there is no -o with this command, because

although the utilities look almost identical, they have slightly differing syntax)

If you already have a postscript version, then type: ps2pdf hello.ps hello.pdf

Now it is simply a matter of using your preferred PS or PDF viewer to see the output

What you should see at the top left of the page are the words Hello World! and at the bottom is the current page number. All in a standard times font

Page 23: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

23

LaTeX Document Structure% A simple article to illustrate document % structure.

\documentclass[12pt]{article} \usepackage{times} \begin{document} …… \end{document}

Page 24: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

24

%: comments \documentclass[12pt]{article}

The type of document we want to produce: article Other classes that exist are book, report, thesis etc 12pt: the font

\usepackage{times} It tells Latex to utilise some external macros

\begin{document} … \end{document}

LaTeX Document Structure

Page 25: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

25

Top Matter \title{How to Structure a \LaTeX{}

Document} \author{ Bill Gates\\ Computer Science

and technology Program,\\ United International College,\\ Zhuhai, China\\ \texttt{[email protected]}} \date{\today}

\maketitle

Page 26: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

26

Output

Page 27: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

27

Abstract\begin{abstract} In this article, I shall introduce to you \

LaTeX{}, a typesetting software that is much better than Microsoft Word. I shall discuss some of the fundamental topics in producing a structured document. This document itself does not go into much depth, but is instead the output of an example of how to implement structure.

\end{abstract}

Page 28: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

28

Output

Page 29: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

29

Sectioning Commands \section{Introduction}

This section's content... \section{Structure}

This section's content... \subsection{Top Matter}

This subsection's content... \subsubsection{Article Information}

This subsubsection's content...

Page 30: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

30

Output

Page 31: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

31

Bulleted List \begin{itemize}

\item \texttt{\textbackslash address} - The author's address. Use the new line command (\texttt{\textbackslash\textbackslash}) for line breaks.

\item \texttt{\textbackslash thanks} - Where you put any acknowledgments.

\item \texttt{\textbackslash email} - The author's email address.

\item \texttt{\textbackslash urladdr} - The URL for the author's web page.

\end{itemize}

Page 32: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

32

Output

Page 33: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

33

The Bibliography \begin{thebibliography}{9}

\bibitem{lamport94} Leslie Lamport, \emph{\LaTeX: A Document

Preparation System}. Addison Wesley, Massachusetts, 2nd Edition, 1994.

\end{thebibliography}

Page 34: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

34

Citation In the text, This small document is designed to illustrate

how easy it is to create a well structured document within \LaTeX\cite{lamport94}. You should quickly be able to see how the article looks very professional, despite the content being far from academic. Titles, section headings, justified text, textformatting etc., is all there, and you would be surprised when you see just how little markup was required to get this output.

Page 35: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

35

Output

Page 36: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

36

The Tabular Environment \begin{tabular}{ l c r } 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\

\end{tabular}

\begin{tabular}{|l|l|} \hline stuff & stuff \\ \hline stuff & stuff \\ \hline \end{tabular}

Page 37: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

37

Rows spanning multiple columns

Page 38: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

38

Columns spanning multiple rows

Page 39: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

39

Mathematics Environments text formulae

\begin{math}...\end{math} $...$

displayed formulae \begin{displaymath}...\end{displaymath} \[...]\ \begin{equation}...\end{equation}

Page 40: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

40

Fraction

Page 41: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

41

Powers and Indices

Page 42: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

42

Roots

Page 43: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

43

Matrices

Page 44: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

44

Equations

Page 45: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

45

Multi-lined equations

Page 46: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

46

Summary This lecture has given a very brief

introduction to the facilities provided in LaTeX

There are many other features and packages that have not been covered

The best way to improve your LaTeX skills is to use it for ALL your assignments and papers!

Page 47: 1 Lecture 4 A Brief Introduction to LaTeX Introduction to Information Technology Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk kentsang@uic.edu.hk kentsang/IT/IT3.htm

47

References for Further Study http://www.tug.org/ http://www.latex-project.org http://www.latex-project.org/guides/

usrguide.pdf LaTeX: an introduction

(http://www.techscribe.co.uk/ta/latex-introduction.pdf)

The (Not So) Short Introduction to LaTeX2e (http://ctan.tug.org/tex-archive/info/lshort/english/lshort.pdf)