introduction to latex -...

50
Introduction to LaTeX Slides adapted from Byungwon Woo

Upload: others

Post on 19-Apr-2020

23 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

IntroductiontoLaTeX

Slides adapted from Byungwon Woo

Page 2: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

WhatisLaTeX?

• LaTeXispronounced“lay-tech”or“lah-tech,”not“la-teks.”

• LaTeXisadocumentpreparationsystemforhigh-qualitytypesetting.

• LaTeXismostoftenusedtoproducetechnicalorscientificdocuments,butitcanbeusedforalmostanyformofpublishing.

Page 3: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

WhyUseLaTeX?• Designedbyacademicsandeasilyaccommodatesacademic

use.• Professionallycraftedpredefinedlayoutsmakeadocument

reallylookasif“printed.”• Mathematicalsymbolsandequationsareeasilyintegrated.• Evencomplexstructuressuchasfootnotes,references,table

ofcontents,andbibliographiescanbegeneratedeasily.• Forcesauthortofocusonlogicalinsteadofaestheticstructure

ofadocument.• Createsmorebeautifuldocuments.• Portable,compatible,flexible,versatile,andcheap(orfree)!

ImagesfromDarioTaraborelli’sBlog

Page 4: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source
Page 5: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

InstallingLaTeX• InWindows (CTex,中文的)• MiKTeX

– MiKTeXisatypesettingsystemfortheWindows.– Downloadfromwww.miktex.org forfree– ItisgenerallyrecommendedtoinstallMiKTeXfirst,thenWinEdt.

• WinEdt– WinEdtisatexteditor.– WinEdtcreatesthesourcefile(.texandothers).– Downloadfromwww.winedt.com forfreefor30days.– WinEdtcosts$30.

Page 6: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

InstallingLaTeX• Othertexteditors

– Thereareothertexteditors.– Winshellforfree(http://www.winshell.de/)– ScientificWorkplace

• CombinationofLaTeXandMathematicsprogram• Doesagoodjobofcalculatingandgraphing,veryuserfriendly,butexpensive

• InMac• TexShop+ TexMaker

– Downloadforfreehttp://www.uoregon.edu/~koch/texshop/

– Includeseverything!

Page 7: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

DIY

Page 8: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

BasicDocumentStructure

• Theformatofadocumentisprettysimple.– Inthepreamble

• Documentclass• Packages

– Inthefrontmatter• Title/author

– Inthebody• Contents

– Inthebackmatter• bibliography

Page 9: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

InthePreamble

• Youspecifyyourdocumentclass.– Documentclasses:letter,article,report,book,slides(beamer,prosper)

• \documentclass[12pt]{article}• Backslash– atthebeginningoftextmarkupcommand

– Packages:numerouspackagesareavailable• \usepackage[margin=1in]{geometry}• \usepackage{setspace}• \usepackage{harvard}

Page 10: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source
Page 11: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

IntheFrontMatter

• \begin{document}• \title{}• \author{}• \maketitle• \begin{abstract}• \end{abstract}• \pagebreak

Page 12: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source
Page 13: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

IntheBody

• Tobeginanewsection• \section{}

– Similarly,\subsection{},\subsubsection{},\subsubsubsection{}

– LaTeX doesautomaticnumbering.Ifyoudon’tlikeit,usesection*{}

• \emph{},\textbf{}• \singlespacing,\doublespacing,\onehalfspacing• \centeringor\begin{centering}&\end{centering}

Page 14: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Footnotes/Quotes/Equations• \footnote{}• \begin{quote}&\end{quote}• `’,``’’forquatations• MathematicalEquations

– Mathalwaysinbetween$&$• Alternatively,\begin{equation}&\end{equation}

– $1+4=5$– \frac{}{},\sqrt{},\sum_{k=1}^{n}– ^{},_{}– \greekletters(e.g.\alphaor\Alpha)– WinEdtalsoprovidesclickandtypefunctions.

Page 15: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Citations

• \cite{bibtexkey},citeyear{bibtexkey}• Itismoreconvenienttocreateabibliographyfile,calledbibtexfile(.bib)anduseitasneeded.

• WinEdtiscapableofcreatingabibfile,buttherearemoreconvenienttoolsoutthere.

• JabRef(http://jabref.sourceforge.net/)

Page 16: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source
Page 17: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source
Page 18: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source
Page 19: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

CreatingaTable• Addnumberedtable

– \begin{table}\caption{}• Creatingatable• Simpletablescanbeproducedby

– \begin{tabular}[pos]{tablespec}– Withinthe{tablespec}section,onedetailsthenumberofcolumns,

thealignment,andthenumberofverticallinesofthetable.• {lrc},{|l|r|c}

– Thentypeinfromlefttoright,thevaluesforeachcellwith&inbetween.

– Put“\\”attheendofeachrow,theninputanotherrowofvaluesifneeded.

– \hline– ForSTATAusers,afterdownloadingthe“outtex”packageonline,one

cansimplytype“outtex”afteranyestimationandSTATAwillspitoutLaTeXcodefortheresultstablepresented.

Page 20: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Creatinga4*3Table• \begin{table}[h]• \caption{SummaryofConclusionsfromDiagnosticTests}• \begin{tabular}{llll}• \hline• \hline• &Macropartisanship &ConsumerSentiment&Presidential

Approval\\• \hline• JointFtest&$d=1$&$d=1$&$d=0$\\• VRtest&$0<d\leq1$&$d=1$&$0<d\leq1$\\• \hline• \end{tabular}• \end{table}

Page 21: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

IntheBackMatter

• Don’tforgetbibliography{filename}– Makesurethatthebibtexfileissavedinthesamelocationwherethemaintexfileissaved.

• Don’tforgetend{document}

Page 22: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

SeeingtheDocument

Pressonthesmilingbeartoconvertto.dvi

PressonthePDF/LaTeXtoconvertto.pdf

PressonthePDF+happybeartoconvertto.pdfandopenit

Page 23: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

CreatingLatexFiles

Your Latex File Your Bibtex File

Latex compile x3

Bibtex compile x2

Latex compile x3

Your Postscript File

dvips compile x1Device independentoutput .dvi

(a text file)

Page 24: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

LatexFileStructure

• DocumentClassPredefinedFormats(article,report,book,..).

• PackagesusedAddedFunctionality(graphics,referencestyle,...).

• MainBodyTextandBibliographyReferences.

Page 25: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

TheBasics• DocumentClass

\documentclass[options]{class}options=a4paper,11pt,12pt,10pt,twocolumn,landscape,...class=article,report,book,...

• Packages\usepackage{package name}epsfig = insert PS pictures into the documentfancyhdr = easy definition of footer and header

Page 26: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

BodyofText• Startwith\begin{document}• Endwith\end{document}• TypesettingText

– \\ or\newline and\newpage– Quotations– Bold\textbf{……………} or \bf – Italics\emph{…………} or\textit{………} or\it– Underline\underline{…………} or \ul

Page 27: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

BodyofTextcont…• IncludingMultipleFiles

– \input{filename.tex}

Page 28: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Format• Sections

– \section{…} =1.LatexisGreat– \subsection{…} =1.1WhyLatexisGreat– \subsubsection{…} =1.1.1ReasonOne– \appendix - changesnumberingscheme– \chapter{…} - Tobeusedwithbookandreportdocumentclasses

• Titles,Authorsandothers– \title{…} \author{…}– \footnote{…}

Page 29: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

FormatContd.• \maketitle - DisplayTitleandAuthor• \tableofcontents - generatesTOC• \listoftables - generatesLOT• \listoffigures - generatesLOF• Labels

– \label{marker} - Markerindocument.– \pageref{marker} - Displayspageno.ofmarker.– \ref{marker} - Displayssectionlocationofmarker.

• Itemize– Useeitherenumerate,itemize ordescription.– seehandoutforexample.

Page 30: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Lists

• Source– \begin{itemize}– \item Apple– \item Orange– \end{itemize}

• Result– Apple– Orange

Page 31: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Lists

• Enumerate insteadofitemize givesanumberedlist

• Listscanberecursive

Page 32: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Environment

• Somethingbetween– \begin{name}– \end{name}

• Manycommand,forexample\bf affectthetextuntiltheendofenvironment

• Environmentscanberecursive• Examples:

– itemize, center, abstract

Page 33: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Group

• Groupissometextbetween{and}• Manycommandsworkuntiltheendofthegroup

• Code– put{oneword\bfinbold}here

• Result– putonewordinbold here

Page 34: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Alignment

• Environmentscenter, flushleft, flushright

• Example– \begin{flushright}– Right aligned– \end{flushright}

• ResultRight aligned

Page 35: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Fontsize

\tiny \scriptsize\footnotesize

\small \normalsize

\large \Large

\LARGE \huge\Huge

Page 36: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

ExampleofLatexdocument

\documentclass{article}

\title{Simple Example}

\author{Andrei Gurtov}

\date{March 2000}

\begin{document}

\maketitle

Hello world!

\end{document}

Page 37: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Tabular• Columns– \begin{tabular}{|…|…|}– \end{tabular}

• Rows– & - Splittextintocolumns– \\ - Endarow– \hline - Drawlineunderrow– e.g.123123 & 34.00\\ \hline

Two Columns

l = automatically adjust size, left justify

r = automatically adjust size, right justify

p = set size e.g p{4.7cm}

c = centre text

Page 38: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Exampleoftable\begin{tabular}{|l|r|c|} \hline

Date & Price & Size \\ \hlineYesterday & 5 & big \\ \hline

Today & 3 & small \\ \hline\end{tabular}

Date Price Size Yesterday 5 Big

Today 3 Small

Page 39: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

FloatingObjects• Floatingobjects canstopsplittingoftablesandimagesoverpages.\begin{figure}[options]

\end{figure}\begin{table}[options]

\end{table}

• Theywillnowappearinthe– ListofFigures(LOF) and– ListofTables(LOT). Options (recommendations)

h = place table heret = place at top of pageb = place at bottom of page

Page 40: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Exampleoffloatingfigure

• \begin{figure}[ht]• \centering\epsfig{file=uni.ps,width=5cm}• \caption{UniversityofHelsinki}• \label{uni}• \end{figure}

Figure~\ref{uni} shows...

Page 41: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Images• Useepsfigpackage• \usepackage{epsfig}

• Includingimagesinmainbody• \epsfig{file=filename.eps, width=10cm, height=9cm, angle=90}

• CreatingEPS- Usexvand/orxfig.• MSPowerPoint,saveasGIFandconverttoEPS.

Page 42: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Bibliographybyhand

\begin{thebibliography}{}\bibitem[Come95]{Come95}Comer,D.E.,{\itInternetworkingwithTCP/IP:Principles,ProtocolsandArchitecture},volume1,3rdedition.Prentice-Hall,1995.\end{thebibliography}

Page 43: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

BibliographyusingBibtex

• Bibliographyinformationisstoredina*.bibfile,inBibtexformat.

• Includechicagopackage– \usepackage{chicago}

• Setreferencingstyle– \bibliographystyle{chicago}

• Createreferencesectionby– \bibliography{bibfilewithnoextension}

Page 44: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

BibliographyusingBibtex

@book{Come95,author=“D.E.Comer”,title={InternetworkingwithTCP/IP:Principles,ProtocolsandArchitecture},

publisher=“Prentice-Hall”,year=1995,volume=1,edition=“Third”}

Page 45: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Bibliographycontd.• Citingreferencesintext

– \cite{cuc98} =(Cuce1998)– \citeN{cru98} =Crud(1998)– \shortcite{tom98} =(Tom,et.al.1998)

• CreatingBibtexFiles– UseEmacswithextensions.– orcopyBibtexentriesfrombibliographydatabase.

Page 46: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

SomeMath\begin{center}{\large$$y=\frac{a^3+2c_{x}}{1+\sqrt{b_{x}}}$$\\\vspace{0.2in}$$

Q=\sum_{i=1}^{j}\int_{\mu}^{\infty}f(x_{j})dx$$\\

\vspace{0.2in}$$\Psi=\oint_{-

\infty}^{\infty}f_{xy}({\frac{\partialQx}{\partialQy}})^{\Im_{\pi}^\prime}$$\\ }

Page 47: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

ToolsUNIXbasedsystems

– xdvi,ghostview,fixps,emacswithlatex/bibtexsupport.

Windows98/NT– Ghostview,AcrobatDistiller,AcrobatReader,ScientificWorkplace(notthebest),theBibtexviewerisgood.PaintShopPro,LatexandEmacs

Page 48: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

Conclusions• Latexisoptimalformasterandphdthesis?• Mathematicalformulaeareeasy.• Usebibtexsearchengines• ConsiderconvertingPostscriptfilestoPDF(morewidespreadinWindowsworld)andtoconservespace.

Page 49: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

CommonMistakes

• Oftentimes,youmakeamistakewhencreatingadocument.Youwillnoticethelogfilereportingaproblem.

• Therearesomecommonmistakes:– “end”doesn’tfollow“begin”– $doesn’tfollow$– Usingcommandsfrompackageslotdefinedinthepreamble

– Don’tforget“\”s.

Page 50: Introduction to LaTeX - Dumitrescuyanweifu.github.io/courses/SLML/chap5/Introduction_to_latex.pdf · then WinEdt. • WinEdt – WinEdt is a text editor. – WinEdt creates the source

OtherResources

• Books– LeslieLampert.1994.LaTeX:ADocumentPreparationSystem.

– HelmutKoptaandPatrickW.Daly.2004.GuidetoLaTex

– FrankMittelbachetal.2004.TheLaTeXCompanion• OnlineGuides

– http://en.wikibooks.org/wiki/LaTeX– http://tobi.oetiker.ch/lshort/lshort.pdf– CVanddissertationtemplatesareavailableonline