Você está na página 1de 31

Overview

A What is LTEX? A How LTEX reads your input A Syntax of LTEX-commands A A skeleton article in LTEX

Writing in Swedish

02-08-12

L EX KP/JG AT

Page

A Using LTEX

Assume your le is called paper.tex.


A Write it using any text-editor you want. Emacs has a LTEX-mode, of course. A Run LTEX,

$ latex paper.tex This produces paper.dvi which you can either look at on the screen: $ xdvi paper.dvi send to the printer: $ dvips paper.dvi convert to a PostScript le: $ dvips -f paper.dvi > paper.ps

02-08-12

L EX KP/JG AT

Page

A Ports of LTEX

A There are many ports of LTEX to many platforms

For Mac, e.g., OzTex See http://www.trevorrow.com/oztex/ For PC/Windows, e.g.,MiKTEX See http://home.arcor.de/itsfd/texwin.htm or http://www.tug.org/interest.html#free for more. You can download al lot of stu from http://www.latex-project.org/.

02-08-12

L EX KP/JG AT

Page

A So whats so great about LTEX?


A LTEX handles things for you

Numbering of pages, items, footnotes, . . . Handles references, table of contents, . . . Point sizes, line spacing, margin widths, etc.
A LTEX can be customized

Write your own macros. Hundreds of free packages available. Journals supply style les. For example, theres a le ieee.sty. Use it with \documentclass[ieee]{article} Output is more aestethic than e.g. Word.
A LTEXis free of charge

02-08-12

L EX KP/JG AT

Page

But its not WYSIWYG!

A Yes, but LTEX encourages logical design.

Example: I want to write NULL a lot. For this, I dene a command \mynull \newcommand{\mynull}{\tt NULL} Later, if I want to change to Null I can just change the command, not every occurrence of NULL in the document. Studies have shown that WYSIWYG users spend more time on visual appearance than logical structure.

02-08-12

L EX KP/JG AT

Page

A How LTEX reads your input

Some characters have special meaning: # $ % & _ { } ~ ^ \

The rst seven requires a leading \. The characters + = | < > are used in math text. Newlines and space are ignored . . . but a blank line starts a new paragraph % starts a comment (to the end of the line).

02-08-12

L EX KP/JG AT

Page

A How LTEX reads your input

There are dierent quote symbols: Input English quote svenskt citat English svenska Output English quote svenskt citat English svenska

A Notice that " is almost never used in LTEX.

$ . . . $ is used for formuls. $\sum_{i=1}^n k$


n i=1 k

02-08-12

L EX KP/JG AT

Page

A How LTEX reads your input

Tilde (~) is a hard space character. Dr.~Jones Figure.~3 Dr. Jones Figure. 3

TEX will never break a line at a hard space. There are three types of dashes X-ray Oct 12--26 long---like this X-ray Oct 1226 longlike this

02-08-12

L EX KP/JG AT

Page

A Syntax of LTEX-commands

Most commands have the form \cmd come ... here come \ldots here today is \today I use \LaTeX come ... here come . . . here today is August 15, 2002 A I use LTEX

Commands may have an argument: \cmd{args} \emph{emphasized} \section{Summary} emphasized

1. Summary

02-08-12

L EX KP/JG AT

Page

New commands

New commands can be dened with \newcommand.


\newcommand{\pair}[2]{\langle #1, #2 \rangle} Consider a pair $\pair{a}{b}$ where \ldots

Consider a pair a, b where . . .

02-08-12

L EX KP/JG AT

Page

10

Environments
\begin{name} . . . \end{name} begin{document} normal paragraph. \begin{math} x^2+y^2=z^2 \end{math} another paragraph \begin{quote} some text \end{quote} more paragraphs \begin{verbatim} \begin{eqn} \end{verbatim} \end{document}
02-08-12

normal paragraph. x2 + y 2 = z 2 another paragraph some text more paragraphs \begin{eqn}

L EX KP/JG AT

Page

11

Typefaces

\textrm{roman text} \textsf{sans serif text} \texttt{typewriter text} \textmd{medium text} \textbf{boldface text} \textup{upright text} \textit{italic text} \textsl{slanted text} \textsc{Small Capitals} \emph{emphasized}

roman text sans serif text typewriter text medium text boldface text upright text italic text slanted text Small Capitals emphasized

02-08-12

L EX KP/JG AT

Page

12

Lists

\begin{itemize} \item Eat \item Sleep \item Work \end{itemize} \begin{enumerate} \item Eat \item Sleep \item Work \end{enumerate} \begin{description} \item[Eat] at 12 \item[Sleep] at 21 \item[Work] at 8 \end{description}

Eat Sleep Work

1. Eat 2. Sleep 3. Work

Eat at 12 Sleep at 21 Work at 8

02-08-12

L EX KP/JG AT

Page

13

References

\label{name} denes name. \ref{name} generates names section number. \pageref{name} generates names page number.
A Youll have to run LTEX twice

1. generate label values in lename.aux; 2. read label values.

02-08-12

L EX KP/JG AT

Page

14

References example

\section{Summary} We have demonstrated \label{summary} . . In section~\ref{summary} on page~\pageref{summary}

7. Summary
We have demonstrated . . In section 7 on page 14

02-08-12

L EX KP/JG AT

Page

15

Figures
Heres a figure. \begin{figure} code to insert PostScript (shown later) \caption{A parody on Intels logo.} \label{linux} \end{figure} Now you can easily make a reference to Figure~\ref{linux}.

Heres a gure.

Figure 1: A parody on Intels logo.


Now you can easily make a reference to Figure 1.
02-08-12 L EX KP/JG AT Page 16

Mathematics

Formuls are surrounded either by $ formula $ in running text The formula $\sum_{k=1}^n k = n(n+1)/2$ is not displayed The formula
n k=1 k

= n(n + 1)/2 is not displayed

02-08-12

L EX KP/JG AT

Page

17

Mathematics

$$ displayed formula $$ when you want to emphasize it The formula $$\sum_{k=1}^n k = n(n+1)/2$$ is displayed The formula
n

k = n(n + 1)/2
k=1

is displayed

02-08-12

L EX KP/JG AT

Page

18

Importing graphics

A LTEX2e has the graphics-package.

\usepackage{graphics} \includegraphics{picture.eps} Options for scaling, rotation, etc, are supported. But PostScript pictures does not have TEX fonts.

02-08-12

L EX KP/JG AT

Page

19

Drawing gures

MetaPost is a picture language that can compile to TEX code. MetaPost code (pics.mp):
beginfig(1); pickup pencircle scaled 1pt; boxit.c0(btex boxit.c1(btex boxit.c2(btex boxit.c3(btex boxit.c4(btex boxit.c5(btex \strut$~0~$ \strut$~1~$ \strut$~2~$ \strut$~3~$ \strut$~4~$ \strut$~5~$ etex); etex); etex); etex); etex); etex); c3.c = c2.c - (0,1.5u);

c1.c = c0.c - (0,1.5u); c2.c = c1.c - (0,1.5u); c4.c = c3.c - (0,1.5u); c5.c = c4.c - (0,2u); drawboxed(c0,c1,c2,c3,c4,c5);

w:=1.9; h:=0.5; draw (c0.c+(-w*u,h*u)--c0.c+(w*u,h*u)--c5.c+(w*u,-h*u)--c5.c+(-w*u,-h*u)-- c0.c+(-w*u,h*u)) dashed evenly; label.top(btex {\tt main} etex, c0.c+(-w*u,h*u)); w:=1.7; h:=1; draw (c1.c+(-w*u,h*u)--c1.c+(w*u,h*u)--c4.c+(w*u,-h*u)--c4.c+(-w*u,-h*u)-- c1.c+(-w*u,h*u)) dashed evenly;

02-08-12

L EX KP/JG AT

Page

20

label.top(btex {\tt L1} etex, c1.c+(-w*u,h*u)); w:=1.1; h:=0.8; draw (c2.c+(-w*u,h*u)--c2.c+(w*u,h*u)--c3.c+(w*u,-h*u)--c3.c+(-w*u,-h*u)-- c2.c+(-w*u,h*u)) dashed evenly; label.top(btex {\tt L2} etex, c2.c+(-w*u,h*u)); label.top(btex etex, chopedge(c0,c1) c0.c..c1.c); label.top(btex etex, chopedge(c1,c2) c1.c..c2.c); label.top(btex etex, chopedge(c2,c3) c2.c..c3.c); label.top(btex label.top(btex label.top(btex label.top(btex endfig; etex, etex, etex, etex, chopedge(c1,c5) chopedge(c2,c4) chopedge(c3,c2) chopedge(c4,c1) c1.c{dir225}..1/2[c2.c,c2.c]-(1.2u,0)..{dir315}c5.c); c2.c{dir225}..1/2[c2.c,c4.c]-(0.8u,0)..{dir315}c4.c); c3.s{down}..1/2[c3.c,c2.c]+(0.8u,0)..{down}c2.n); c4.s{down}..1/2[c4.c,c1.c]+(1.5u,0)..{down}c1.n);

02-08-12

L EX KP/JG AT

Page

21

Drawing gures
Compile with mpost pics.mp Insert into document with \includegraphics{pics.1}
main 0 L1

1 L2 2

02-08-12

L EX KP/JG AT

Page

22

Come on, were in the 21th century . . .

Do you really use that stu? Yes, you can use MPost for simple pictures. Use xfig in Unix for drawing more complicated ones. or, use your favourite drawing tool in PC/Mac and convert to PostScript.

02-08-12

L EX KP/JG AT

Page

23

Bibliographies

BibTEX compiles .bib-les. Example: paper.bib:


@book{lamport-94, author = "Leslie Lamport", title = "{{\LaTeX}: A Document Preparation System}", publisher = "Addison-Wesley", year = 1994}

Others: @article, @inproceedings, @techreport, . . . You can then cite references in paper.tex: Lamport \cite{lamport-94} is a good book. Lamport [Lam94] is a good book.

02-08-12

L EX KP/JG AT

Page

24

Reference list

At the end of paper.tex, you need \bibliography{latex} \bibliographystyle{alpha} which produces . . .

References
A [Lam94] Leslie Lamport. LTEX: A Document Preparation System. Addison-Wesley, 1994. A But you need to run LTEX and BibTEX like this

1. 2. 3. 4.

latex paper generates paper.aux bibtex paper compiles paper.bib latex paper to generate the source list latex paper one last time
L EX KP/JG AT Page 25

02-08-12

A A skeleton article in LTEX

\documentclass{article} \title{your title} \author{your name} \begin{document} \maketitle \begin{abstract} abstract goes here \end{abstract} \section{section name} paragraphs . . . \subsection{subsection name} paragraphs . . . \section{section name} . . . \bibliography{lename} \bibliographystyle{alpha} \end{document}

02-08-12

L EX KP/JG AT

Page

26

Styles for documentclass

\documentclass{article} \documentclass{report} (gives a cover page) \documentclass{letter} \documentclass{book}

02-08-12

L EX KP/JG AT

Page

27

Options for @documentclass

\documentclass[a4paper]{ . . . } \documentclass[11pt]{ . . . } (default is 10pt) \documentclass[12pt]{ . . . } \documentclass[twocolumn]{ . . . } \documentclass[twoside]{ . . . } Example: \documentclass[a4paper,12pt]{article}

02-08-12

L EX KP/JG AT

Page

28

Writing in Swedish

\documentclass[a4paper]{article} \usepackage[T1]{fontenc} \usepackage[swedish]{babel} . . 2nd line selects a font with Swedish characters. 3rd line generates Swedish names, e.g. Innehll instead of Table of a Contents. May not work on older installations.

02-08-12

L EX KP/JG AT

Page

29

Common errors

Misspelled command. Mismatch between parenthesis (e.g. [ ] or { }). Trying to use a special character (e.g. &). Trying to use math characters outside $ . . . $. Missing \end{ . . . }. A missing argument.
A When LTEX stops, press ? for a list of commands.

02-08-12

L EX KP/JG AT

Page

30

A LTEX-related documentation

http://www.tug.org/ - TEXusers group


A Leslie Lamport. LTEX: a document preparation system, 2nd ed. Addison-Wesley, 1994. ISBN: 0-201-52983-1.

See also links at the course homepage.

02-08-12

L EX KP/JG AT

Page

31

Você também pode gostar