what is la what is ltex? · what is latex? tex is pronounced /0tεx/, like the nal consonant of...
TRANSCRIPT
Introduction to TEX amp LATEX
Hadi Safari
University of Tehran
ACM Student Chapter
LATEX IntroSummer 1398
httpshadisafariircourseslatex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 1 81
What is LATEX
What is LATEX
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 2 81
What is LATEX
TEX
is pronounced primetεx like the nal consonant of Bach or primetεksource les plain-text tex lesa markup languages describing how your document should lookcreated by Donald Knuth1977frustrated at result of Art of Computer Programming realized high qualitydigital typesetting system was necessaryThe version numbers of TEX are converging toward π with a current versionnumber of 31415926
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 3 81
What is LATEX
LATEX
a set of macros for TEX to simplify TEX typesettingcreated by Leslie Lamport1983LATEX 2ε is the current version of LATEX since it replaced LaTeX 209 in 1994LaTeX Project Public License (LPPL)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 4 81
What is LATEX
LATEX vs WYSIWYG
WYSIWYG What You See Is What You Get such as Microsoft WordApple Pages and LibreOce WriterWYSIWYG programs combine composition and typesettingbibliographies cross-references gure labels and mathematical typesetting isusually hard and should be done manually in WYSIWYG programmesthe nal version of the document usually is not visible when editing it inmark-up languages (like LATEX)generally itrsquos necessary to know commands for writing in mark-up languages(such as LATEX)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 5 81
What is LATEX
LATEX vs WYSIWYGLATEX Pros
allows you to focus on contentconsistency throughout documentautomation of tedious tasks (cross-references bibliographies mathematicaltypesetting etc)document source is plain text so
document sources can be read with any text editor and understoodtables gures equations etc can be generated programmatically with anylanguagelarge les are easy to handledWhat about spell-checking spell-checkers like ispell aspell and aspell
ispell -t yourfiletex
aspell --mode=tex -c yourfiletex
hunspell -l -t -i utf-8 yourfiletex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 6 81
What is LATEX
LATEX vs WYSIWYGLATEX Cons
undeniable learning curvecomplex formatting may occasionally take more time than a word processor(eg tables)
LATEX is not a word processor Donrsquot expect it to behave like one
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 7 81
How to get LATEX
How to get LATEX
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 8 81
How to get LATEX
TEX Distributions
MikTEXhttpsmiktexorg
TEXLivehttpswwwtugorgtexlivequickinstallhtml
each version will be frozen at February of the next yeartlmgr --help
also available over docker image eg volkerraschekdocker-latexMacTEX
based on TEXLivehttpswwwtugorgmactex
BasicTEX httpswwwtugorgmactexmorepackageshtml
install usign HomeBrew (macOS) brew cask install mactex | basictex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 9 81
How to get LATEX
Compilation
[3 Basic]
lualatexxelatexpdflatex
PostScriptPDF DVI
latex
texluatex xetex pdftex
dvi2psps2pdf
pdf2ps
dvipdfm
(pdf png jpg)
(eps)
Source formats
Output formats
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 10 81
How to get LATEX
Compilation
LATEX to pdf compilerspdfLATEXX ELATEX
supports Unicode (UTF-8)X EPersian
LuaLATEX
should be compiled multiple times (up to three) to handle references and etclatexmk -pdf -xelatex filetex
les lots of les tex aux bbl bib blg bst cls dtx ins fd log toc lof lot idx ind ilg sty etc
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 11 81
How to get LATEX
Editor
onlineOverleaf httpswwwoverleafcomShareLATEX (merged into Overleaf) httpswwwsharelatexcomAuthorea (WYSIWYG) httpswwwauthoreacomPapeeria httpspapeeriacom
oineTEXstudio (supports X EPersian since v21210) httpswwwtexstudioorgLyX httpswwwlyxorgTEXShop httpspagesuoregonedukochtexshopTEXworks httpwwwtugorgtexworksTEXMaker httpswwwxm1mathnettexmakerGummi httpsgithubcomalexandervdmgummiKile httpskilesourceforgeioVimLATEX(over Vim) httpvim-latexsourceforgenetLATEXTools (over Sublime Text) httpslatextoolsreadthedocsio
any text editor
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 12 81
LATEX lsquoHello Worldrsquo
LATEX lsquoHello Worldrsquo
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 13 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
begindocument
Hello world
enddocument
Preambleeverything before begindocument
Bodyeverything in the document environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 14 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
usepackage[inline]enumitem
usepackage[colorlinksurlcolor=magenta]hyperref
begindocument
thispagestyleempty
This is a test for what
See hrefhttphadisafariircourseslatexcourse website for
more small more details
beginitemize[noitemsep]
item item~1
item item~2qquad $e = mc^2$
item[] item~3
enditemize
enddocument
Document ClassPackage
Package Options (comma-separated)
Command with Multiple Argument
Command Without Argument
Command Optional Argument (comma-separated)
Group (also bgroup amp egroup)
Comment
Inline Maths
Environment
Environment Optional Arguments (comma-separated)
Special Characters
No new linein output
This is a test See course website for more more details
bull item 1bull item 2 e = mc2
item 3
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 15 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Lines
LATEX compiler normalises whitespaceall whitespace characters including single new line are treated as a single spaceseveral consecutive spaces are treated as onespaces at opening a line is generally ignoredit does not matter whether you enter one or several spaces after a word
a double line break (an empty line) denes the end of a paragraphmultiple empty lines are also treated as the end of a paragraphpar also starts a new paragraph breaks the line without starting a new paragraphnewline does the same
more spaces can be added by or thinspace enspace quad qquadand
negative space can be added by
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 16 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
What is LATEX
TEX
is pronounced primetεx like the nal consonant of Bach or primetεksource les plain-text tex lesa markup languages describing how your document should lookcreated by Donald Knuth1977frustrated at result of Art of Computer Programming realized high qualitydigital typesetting system was necessaryThe version numbers of TEX are converging toward π with a current versionnumber of 31415926
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 3 81
What is LATEX
LATEX
a set of macros for TEX to simplify TEX typesettingcreated by Leslie Lamport1983LATEX 2ε is the current version of LATEX since it replaced LaTeX 209 in 1994LaTeX Project Public License (LPPL)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 4 81
What is LATEX
LATEX vs WYSIWYG
WYSIWYG What You See Is What You Get such as Microsoft WordApple Pages and LibreOce WriterWYSIWYG programs combine composition and typesettingbibliographies cross-references gure labels and mathematical typesetting isusually hard and should be done manually in WYSIWYG programmesthe nal version of the document usually is not visible when editing it inmark-up languages (like LATEX)generally itrsquos necessary to know commands for writing in mark-up languages(such as LATEX)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 5 81
What is LATEX
LATEX vs WYSIWYGLATEX Pros
allows you to focus on contentconsistency throughout documentautomation of tedious tasks (cross-references bibliographies mathematicaltypesetting etc)document source is plain text so
document sources can be read with any text editor and understoodtables gures equations etc can be generated programmatically with anylanguagelarge les are easy to handledWhat about spell-checking spell-checkers like ispell aspell and aspell
ispell -t yourfiletex
aspell --mode=tex -c yourfiletex
hunspell -l -t -i utf-8 yourfiletex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 6 81
What is LATEX
LATEX vs WYSIWYGLATEX Cons
undeniable learning curvecomplex formatting may occasionally take more time than a word processor(eg tables)
LATEX is not a word processor Donrsquot expect it to behave like one
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 7 81
How to get LATEX
How to get LATEX
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 8 81
How to get LATEX
TEX Distributions
MikTEXhttpsmiktexorg
TEXLivehttpswwwtugorgtexlivequickinstallhtml
each version will be frozen at February of the next yeartlmgr --help
also available over docker image eg volkerraschekdocker-latexMacTEX
based on TEXLivehttpswwwtugorgmactex
BasicTEX httpswwwtugorgmactexmorepackageshtml
install usign HomeBrew (macOS) brew cask install mactex | basictex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 9 81
How to get LATEX
Compilation
[3 Basic]
lualatexxelatexpdflatex
PostScriptPDF DVI
latex
texluatex xetex pdftex
dvi2psps2pdf
pdf2ps
dvipdfm
(pdf png jpg)
(eps)
Source formats
Output formats
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 10 81
How to get LATEX
Compilation
LATEX to pdf compilerspdfLATEXX ELATEX
supports Unicode (UTF-8)X EPersian
LuaLATEX
should be compiled multiple times (up to three) to handle references and etclatexmk -pdf -xelatex filetex
les lots of les tex aux bbl bib blg bst cls dtx ins fd log toc lof lot idx ind ilg sty etc
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 11 81
How to get LATEX
Editor
onlineOverleaf httpswwwoverleafcomShareLATEX (merged into Overleaf) httpswwwsharelatexcomAuthorea (WYSIWYG) httpswwwauthoreacomPapeeria httpspapeeriacom
oineTEXstudio (supports X EPersian since v21210) httpswwwtexstudioorgLyX httpswwwlyxorgTEXShop httpspagesuoregonedukochtexshopTEXworks httpwwwtugorgtexworksTEXMaker httpswwwxm1mathnettexmakerGummi httpsgithubcomalexandervdmgummiKile httpskilesourceforgeioVimLATEX(over Vim) httpvim-latexsourceforgenetLATEXTools (over Sublime Text) httpslatextoolsreadthedocsio
any text editor
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 12 81
LATEX lsquoHello Worldrsquo
LATEX lsquoHello Worldrsquo
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 13 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
begindocument
Hello world
enddocument
Preambleeverything before begindocument
Bodyeverything in the document environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 14 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
usepackage[inline]enumitem
usepackage[colorlinksurlcolor=magenta]hyperref
begindocument
thispagestyleempty
This is a test for what
See hrefhttphadisafariircourseslatexcourse website for
more small more details
beginitemize[noitemsep]
item item~1
item item~2qquad $e = mc^2$
item[] item~3
enditemize
enddocument
Document ClassPackage
Package Options (comma-separated)
Command with Multiple Argument
Command Without Argument
Command Optional Argument (comma-separated)
Group (also bgroup amp egroup)
Comment
Inline Maths
Environment
Environment Optional Arguments (comma-separated)
Special Characters
No new linein output
This is a test See course website for more more details
bull item 1bull item 2 e = mc2
item 3
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 15 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Lines
LATEX compiler normalises whitespaceall whitespace characters including single new line are treated as a single spaceseveral consecutive spaces are treated as onespaces at opening a line is generally ignoredit does not matter whether you enter one or several spaces after a word
a double line break (an empty line) denes the end of a paragraphmultiple empty lines are also treated as the end of a paragraphpar also starts a new paragraph breaks the line without starting a new paragraphnewline does the same
more spaces can be added by or thinspace enspace quad qquadand
negative space can be added by
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 16 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
What is LATEX
LATEX vs WYSIWYG
WYSIWYG What You See Is What You Get such as Microsoft WordApple Pages and LibreOce WriterWYSIWYG programs combine composition and typesettingbibliographies cross-references gure labels and mathematical typesetting isusually hard and should be done manually in WYSIWYG programmesthe nal version of the document usually is not visible when editing it inmark-up languages (like LATEX)generally itrsquos necessary to know commands for writing in mark-up languages(such as LATEX)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 5 81
What is LATEX
LATEX vs WYSIWYGLATEX Pros
allows you to focus on contentconsistency throughout documentautomation of tedious tasks (cross-references bibliographies mathematicaltypesetting etc)document source is plain text so
document sources can be read with any text editor and understoodtables gures equations etc can be generated programmatically with anylanguagelarge les are easy to handledWhat about spell-checking spell-checkers like ispell aspell and aspell
ispell -t yourfiletex
aspell --mode=tex -c yourfiletex
hunspell -l -t -i utf-8 yourfiletex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 6 81
What is LATEX
LATEX vs WYSIWYGLATEX Cons
undeniable learning curvecomplex formatting may occasionally take more time than a word processor(eg tables)
LATEX is not a word processor Donrsquot expect it to behave like one
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 7 81
How to get LATEX
How to get LATEX
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 8 81
How to get LATEX
TEX Distributions
MikTEXhttpsmiktexorg
TEXLivehttpswwwtugorgtexlivequickinstallhtml
each version will be frozen at February of the next yeartlmgr --help
also available over docker image eg volkerraschekdocker-latexMacTEX
based on TEXLivehttpswwwtugorgmactex
BasicTEX httpswwwtugorgmactexmorepackageshtml
install usign HomeBrew (macOS) brew cask install mactex | basictex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 9 81
How to get LATEX
Compilation
[3 Basic]
lualatexxelatexpdflatex
PostScriptPDF DVI
latex
texluatex xetex pdftex
dvi2psps2pdf
pdf2ps
dvipdfm
(pdf png jpg)
(eps)
Source formats
Output formats
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 10 81
How to get LATEX
Compilation
LATEX to pdf compilerspdfLATEXX ELATEX
supports Unicode (UTF-8)X EPersian
LuaLATEX
should be compiled multiple times (up to three) to handle references and etclatexmk -pdf -xelatex filetex
les lots of les tex aux bbl bib blg bst cls dtx ins fd log toc lof lot idx ind ilg sty etc
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 11 81
How to get LATEX
Editor
onlineOverleaf httpswwwoverleafcomShareLATEX (merged into Overleaf) httpswwwsharelatexcomAuthorea (WYSIWYG) httpswwwauthoreacomPapeeria httpspapeeriacom
oineTEXstudio (supports X EPersian since v21210) httpswwwtexstudioorgLyX httpswwwlyxorgTEXShop httpspagesuoregonedukochtexshopTEXworks httpwwwtugorgtexworksTEXMaker httpswwwxm1mathnettexmakerGummi httpsgithubcomalexandervdmgummiKile httpskilesourceforgeioVimLATEX(over Vim) httpvim-latexsourceforgenetLATEXTools (over Sublime Text) httpslatextoolsreadthedocsio
any text editor
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 12 81
LATEX lsquoHello Worldrsquo
LATEX lsquoHello Worldrsquo
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 13 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
begindocument
Hello world
enddocument
Preambleeverything before begindocument
Bodyeverything in the document environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 14 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
usepackage[inline]enumitem
usepackage[colorlinksurlcolor=magenta]hyperref
begindocument
thispagestyleempty
This is a test for what
See hrefhttphadisafariircourseslatexcourse website for
more small more details
beginitemize[noitemsep]
item item~1
item item~2qquad $e = mc^2$
item[] item~3
enditemize
enddocument
Document ClassPackage
Package Options (comma-separated)
Command with Multiple Argument
Command Without Argument
Command Optional Argument (comma-separated)
Group (also bgroup amp egroup)
Comment
Inline Maths
Environment
Environment Optional Arguments (comma-separated)
Special Characters
No new linein output
This is a test See course website for more more details
bull item 1bull item 2 e = mc2
item 3
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 15 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Lines
LATEX compiler normalises whitespaceall whitespace characters including single new line are treated as a single spaceseveral consecutive spaces are treated as onespaces at opening a line is generally ignoredit does not matter whether you enter one or several spaces after a word
a double line break (an empty line) denes the end of a paragraphmultiple empty lines are also treated as the end of a paragraphpar also starts a new paragraph breaks the line without starting a new paragraphnewline does the same
more spaces can be added by or thinspace enspace quad qquadand
negative space can be added by
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 16 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
What is LATEX
LATEX vs WYSIWYGLATEX Cons
undeniable learning curvecomplex formatting may occasionally take more time than a word processor(eg tables)
LATEX is not a word processor Donrsquot expect it to behave like one
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 7 81
How to get LATEX
How to get LATEX
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 8 81
How to get LATEX
TEX Distributions
MikTEXhttpsmiktexorg
TEXLivehttpswwwtugorgtexlivequickinstallhtml
each version will be frozen at February of the next yeartlmgr --help
also available over docker image eg volkerraschekdocker-latexMacTEX
based on TEXLivehttpswwwtugorgmactex
BasicTEX httpswwwtugorgmactexmorepackageshtml
install usign HomeBrew (macOS) brew cask install mactex | basictex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 9 81
How to get LATEX
Compilation
[3 Basic]
lualatexxelatexpdflatex
PostScriptPDF DVI
latex
texluatex xetex pdftex
dvi2psps2pdf
pdf2ps
dvipdfm
(pdf png jpg)
(eps)
Source formats
Output formats
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 10 81
How to get LATEX
Compilation
LATEX to pdf compilerspdfLATEXX ELATEX
supports Unicode (UTF-8)X EPersian
LuaLATEX
should be compiled multiple times (up to three) to handle references and etclatexmk -pdf -xelatex filetex
les lots of les tex aux bbl bib blg bst cls dtx ins fd log toc lof lot idx ind ilg sty etc
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 11 81
How to get LATEX
Editor
onlineOverleaf httpswwwoverleafcomShareLATEX (merged into Overleaf) httpswwwsharelatexcomAuthorea (WYSIWYG) httpswwwauthoreacomPapeeria httpspapeeriacom
oineTEXstudio (supports X EPersian since v21210) httpswwwtexstudioorgLyX httpswwwlyxorgTEXShop httpspagesuoregonedukochtexshopTEXworks httpwwwtugorgtexworksTEXMaker httpswwwxm1mathnettexmakerGummi httpsgithubcomalexandervdmgummiKile httpskilesourceforgeioVimLATEX(over Vim) httpvim-latexsourceforgenetLATEXTools (over Sublime Text) httpslatextoolsreadthedocsio
any text editor
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 12 81
LATEX lsquoHello Worldrsquo
LATEX lsquoHello Worldrsquo
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 13 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
begindocument
Hello world
enddocument
Preambleeverything before begindocument
Bodyeverything in the document environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 14 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
usepackage[inline]enumitem
usepackage[colorlinksurlcolor=magenta]hyperref
begindocument
thispagestyleempty
This is a test for what
See hrefhttphadisafariircourseslatexcourse website for
more small more details
beginitemize[noitemsep]
item item~1
item item~2qquad $e = mc^2$
item[] item~3
enditemize
enddocument
Document ClassPackage
Package Options (comma-separated)
Command with Multiple Argument
Command Without Argument
Command Optional Argument (comma-separated)
Group (also bgroup amp egroup)
Comment
Inline Maths
Environment
Environment Optional Arguments (comma-separated)
Special Characters
No new linein output
This is a test See course website for more more details
bull item 1bull item 2 e = mc2
item 3
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 15 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Lines
LATEX compiler normalises whitespaceall whitespace characters including single new line are treated as a single spaceseveral consecutive spaces are treated as onespaces at opening a line is generally ignoredit does not matter whether you enter one or several spaces after a word
a double line break (an empty line) denes the end of a paragraphmultiple empty lines are also treated as the end of a paragraphpar also starts a new paragraph breaks the line without starting a new paragraphnewline does the same
more spaces can be added by or thinspace enspace quad qquadand
negative space can be added by
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 16 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
How to get LATEX
TEX Distributions
MikTEXhttpsmiktexorg
TEXLivehttpswwwtugorgtexlivequickinstallhtml
each version will be frozen at February of the next yeartlmgr --help
also available over docker image eg volkerraschekdocker-latexMacTEX
based on TEXLivehttpswwwtugorgmactex
BasicTEX httpswwwtugorgmactexmorepackageshtml
install usign HomeBrew (macOS) brew cask install mactex | basictex
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 9 81
How to get LATEX
Compilation
[3 Basic]
lualatexxelatexpdflatex
PostScriptPDF DVI
latex
texluatex xetex pdftex
dvi2psps2pdf
pdf2ps
dvipdfm
(pdf png jpg)
(eps)
Source formats
Output formats
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 10 81
How to get LATEX
Compilation
LATEX to pdf compilerspdfLATEXX ELATEX
supports Unicode (UTF-8)X EPersian
LuaLATEX
should be compiled multiple times (up to three) to handle references and etclatexmk -pdf -xelatex filetex
les lots of les tex aux bbl bib blg bst cls dtx ins fd log toc lof lot idx ind ilg sty etc
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 11 81
How to get LATEX
Editor
onlineOverleaf httpswwwoverleafcomShareLATEX (merged into Overleaf) httpswwwsharelatexcomAuthorea (WYSIWYG) httpswwwauthoreacomPapeeria httpspapeeriacom
oineTEXstudio (supports X EPersian since v21210) httpswwwtexstudioorgLyX httpswwwlyxorgTEXShop httpspagesuoregonedukochtexshopTEXworks httpwwwtugorgtexworksTEXMaker httpswwwxm1mathnettexmakerGummi httpsgithubcomalexandervdmgummiKile httpskilesourceforgeioVimLATEX(over Vim) httpvim-latexsourceforgenetLATEXTools (over Sublime Text) httpslatextoolsreadthedocsio
any text editor
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 12 81
LATEX lsquoHello Worldrsquo
LATEX lsquoHello Worldrsquo
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 13 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
begindocument
Hello world
enddocument
Preambleeverything before begindocument
Bodyeverything in the document environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 14 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
usepackage[inline]enumitem
usepackage[colorlinksurlcolor=magenta]hyperref
begindocument
thispagestyleempty
This is a test for what
See hrefhttphadisafariircourseslatexcourse website for
more small more details
beginitemize[noitemsep]
item item~1
item item~2qquad $e = mc^2$
item[] item~3
enditemize
enddocument
Document ClassPackage
Package Options (comma-separated)
Command with Multiple Argument
Command Without Argument
Command Optional Argument (comma-separated)
Group (also bgroup amp egroup)
Comment
Inline Maths
Environment
Environment Optional Arguments (comma-separated)
Special Characters
No new linein output
This is a test See course website for more more details
bull item 1bull item 2 e = mc2
item 3
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 15 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Lines
LATEX compiler normalises whitespaceall whitespace characters including single new line are treated as a single spaceseveral consecutive spaces are treated as onespaces at opening a line is generally ignoredit does not matter whether you enter one or several spaces after a word
a double line break (an empty line) denes the end of a paragraphmultiple empty lines are also treated as the end of a paragraphpar also starts a new paragraph breaks the line without starting a new paragraphnewline does the same
more spaces can be added by or thinspace enspace quad qquadand
negative space can be added by
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 16 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
How to get LATEX
Compilation
LATEX to pdf compilerspdfLATEXX ELATEX
supports Unicode (UTF-8)X EPersian
LuaLATEX
should be compiled multiple times (up to three) to handle references and etclatexmk -pdf -xelatex filetex
les lots of les tex aux bbl bib blg bst cls dtx ins fd log toc lof lot idx ind ilg sty etc
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 11 81
How to get LATEX
Editor
onlineOverleaf httpswwwoverleafcomShareLATEX (merged into Overleaf) httpswwwsharelatexcomAuthorea (WYSIWYG) httpswwwauthoreacomPapeeria httpspapeeriacom
oineTEXstudio (supports X EPersian since v21210) httpswwwtexstudioorgLyX httpswwwlyxorgTEXShop httpspagesuoregonedukochtexshopTEXworks httpwwwtugorgtexworksTEXMaker httpswwwxm1mathnettexmakerGummi httpsgithubcomalexandervdmgummiKile httpskilesourceforgeioVimLATEX(over Vim) httpvim-latexsourceforgenetLATEXTools (over Sublime Text) httpslatextoolsreadthedocsio
any text editor
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 12 81
LATEX lsquoHello Worldrsquo
LATEX lsquoHello Worldrsquo
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 13 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
begindocument
Hello world
enddocument
Preambleeverything before begindocument
Bodyeverything in the document environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 14 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
usepackage[inline]enumitem
usepackage[colorlinksurlcolor=magenta]hyperref
begindocument
thispagestyleempty
This is a test for what
See hrefhttphadisafariircourseslatexcourse website for
more small more details
beginitemize[noitemsep]
item item~1
item item~2qquad $e = mc^2$
item[] item~3
enditemize
enddocument
Document ClassPackage
Package Options (comma-separated)
Command with Multiple Argument
Command Without Argument
Command Optional Argument (comma-separated)
Group (also bgroup amp egroup)
Comment
Inline Maths
Environment
Environment Optional Arguments (comma-separated)
Special Characters
No new linein output
This is a test See course website for more more details
bull item 1bull item 2 e = mc2
item 3
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 15 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Lines
LATEX compiler normalises whitespaceall whitespace characters including single new line are treated as a single spaceseveral consecutive spaces are treated as onespaces at opening a line is generally ignoredit does not matter whether you enter one or several spaces after a word
a double line break (an empty line) denes the end of a paragraphmultiple empty lines are also treated as the end of a paragraphpar also starts a new paragraph breaks the line without starting a new paragraphnewline does the same
more spaces can be added by or thinspace enspace quad qquadand
negative space can be added by
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 16 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
LATEX lsquoHello Worldrsquo
LATEX lsquoHello Worldrsquo
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 13 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
begindocument
Hello world
enddocument
Preambleeverything before begindocument
Bodyeverything in the document environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 14 81
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
usepackage[inline]enumitem
usepackage[colorlinksurlcolor=magenta]hyperref
begindocument
thispagestyleempty
This is a test for what
See hrefhttphadisafariircourseslatexcourse website for
more small more details
beginitemize[noitemsep]
item item~1
item item~2qquad $e = mc^2$
item[] item~3
enditemize
enddocument
Document ClassPackage
Package Options (comma-separated)
Command with Multiple Argument
Command Without Argument
Command Optional Argument (comma-separated)
Group (also bgroup amp egroup)
Comment
Inline Maths
Environment
Environment Optional Arguments (comma-separated)
Special Characters
No new linein output
This is a test See course website for more more details
bull item 1bull item 2 e = mc2
item 3
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 15 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Lines
LATEX compiler normalises whitespaceall whitespace characters including single new line are treated as a single spaceseveral consecutive spaces are treated as onespaces at opening a line is generally ignoredit does not matter whether you enter one or several spaces after a word
a double line break (an empty line) denes the end of a paragraphmultiple empty lines are also treated as the end of a paragraphpar also starts a new paragraph breaks the line without starting a new paragraphnewline does the same
more spaces can be added by or thinspace enspace quad qquadand
negative space can be added by
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 16 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
LATEX lsquoHello Worldrsquo Document Structure
Document Structure
documentclassarticle
usepackage[inline]enumitem
usepackage[colorlinksurlcolor=magenta]hyperref
begindocument
thispagestyleempty
This is a test for what
See hrefhttphadisafariircourseslatexcourse website for
more small more details
beginitemize[noitemsep]
item item~1
item item~2qquad $e = mc^2$
item[] item~3
enditemize
enddocument
Document ClassPackage
Package Options (comma-separated)
Command with Multiple Argument
Command Without Argument
Command Optional Argument (comma-separated)
Group (also bgroup amp egroup)
Comment
Inline Maths
Environment
Environment Optional Arguments (comma-separated)
Special Characters
No new linein output
This is a test See course website for more more details
bull item 1bull item 2 e = mc2
item 3
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 15 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Lines
LATEX compiler normalises whitespaceall whitespace characters including single new line are treated as a single spaceseveral consecutive spaces are treated as onespaces at opening a line is generally ignoredit does not matter whether you enter one or several spaces after a word
a double line break (an empty line) denes the end of a paragraphmultiple empty lines are also treated as the end of a paragraphpar also starts a new paragraph breaks the line without starting a new paragraphnewline does the same
more spaces can be added by or thinspace enspace quad qquadand
negative space can be added by
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 16 81
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
LATEX lsquoHello Worldrsquo Special Behaviours
Spaces amp New Linesthe story of period
LATEX optimizes spaces between sentencesa period after a capital letter signies an abbreviation or an initialevery other period signies the end of a sentenceif an abbreviation does not end with a capital letter and is not the last word inthe sentence then follow the period with an inter-word space ( )if a capital letter is followed by a period and is at the end of a sentenceprecede the period with
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 17 81
LATEX lsquoHello Worldrsquo Special Behaviours
Quotation Marks
single and double quotation marks should be written as `` amp `
LATEXwill convert them to opening and closing quotation marks
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 18 81
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
LATEX lsquoHello Worldrsquo Special Behaviours
Dashes
hyphen (-) intra-word dash a single dash (-)en-dash (ndash) dash between numbers etc double dashes (--)
em-dash (mdash) mark an abrupt change in thought triple dashes (---)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 19 81
LATEX lsquoHello Worldrsquo Special Behaviours
Special Characters
lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo rsquo lsquorsquo lsquorsquo lsquo~rsquo lsquorsquo and lsquorsquo are special charactersuse lsquorsquo lsquo$rsquo lsquo^rsquo lsquoamprsquo lsquo_rsquo lsquorsquo lsquorsquo lsquotextasciitildersquo lsquotextbackslashrsquoand lsquorsquo to enter those characters
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 20 81
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
LATEX lsquoHello Worldrsquo Special Behaviours
Accents amp Ellipses
accents could be added using combination of commands eg a (a) e(e) and ^o (o)ellipses could be added by ldots ( ) dots ( ) or cdots (middot middot middot math modeonly)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 21 81
Formatting Texts
Formatting Texts
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 22 81
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Formatting Texts
Text Decorations
Command Declaration Eectemphtext em emphasizedtextbftext bfseries boldtextittext itshape italictextsctext scshape Small Capstextuptext upshape upright shapetextrmtext rmfamily Roman (Serif)textsftext sffamily Sans Seriftexttttext ttfamily typewriter type
textsltext slshape slanted shape
emph could be used nestedemphemphemphnested nested emphasized text
nested nested emphasized text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 23 81
Formatting Texts
Text Decorationssoul package
Command Eectultext underlinesttext strike throughhltext highlightsotext l e t t e r s p a c i n g
itrsquos possible to change the colours by setstcolorcolour sethlcolorcolourand setulcolorcolour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 24 81
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Formatting Texts
Text Justication
Environment Declaration Eect
beginflushrighttextendflushright raggedright right justied
begincentertextendcenter centering centred
beginflushlefttextendflushleft raggedleft left justied
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 25 81
Formatting Texts
Text Size
Declaration Eecttiny tiny text
scriptsize scriptsize text
footnotesize footnotesize textsmall small textnormalsize normalsize textlarge large textLarge Large textLARGE LARGE texthuge huge textHuge Huge text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 26 81
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Formatting Texts
Text ColourColour Denition
LATEX has got some predened colours black blue brown cyandarkgray gray green lightgray lime magenta olive orangepink purple red teal violet white and yellowxcolor package is used to add extra featuresyou may consider using usenames dvipsnames svgnames andx11names options to access more predened colours(see httpsenwikibooksorgwikiLaTeXColors)new colours could be dened using definecolornamemodelspec wheremodel is one ofgray (0-1) rgb (0-1) RGB (0-255) HTML (00-FF) or cmyk (0-1)you can also combine colourscolorblue20 20 blue and 80 white
colorblue20black 20 blue and 80 black
colorblue20black30green
[(20 30) blue ((100 - 20) 30) black] and (100 - 30) green
colorletnotgreenblue50yellow define new colour
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 27 81
Formatting Texts
Text ColourColour Usage
color[model]colour declaration and color[model]colourtext commandcan be used to colourize textscolorboxcolourtext can be used to change background colour of a textit can be used nested toocolorboxGreencolorboxYellowtextcolorRedtext text
fcolorboxframecolourbgcolourtext can be used to change background ampframe colour of a textpagecolorcolour can be used to change the background colour of the wholepage
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 28 81
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Formatting Texts
Footnotes
footnotetext is used to create footnotesbe careful about the space before the footnotetext command which maycreate extra space it the nal outputfootnotes could not be inserted in section titles and 13oat tables
consider using protect and short title for section titlesconsider using longtable packages for tables or put tabular inside aminipage environment
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 29 81
Formatting Texts
Text Font
in X ELATEX amp LuaLATEX itrsquos possible to use TTF amp OTF fonts by fontspecpackageusepackagefontspec
setmainfont[Ligatures=TeX]Georgia
setsansfont[Ligatures=TeX]Arial
see httpsenwikibooksorgwikiLaTeXFonts for more details
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 30 81
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands
More Basic Commands
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 31 81
More Basic Commands Lists
Lists
LATEX has got three types of listsitemize bullet lists
enumerate numbered listsdescription labeled lists (key-value lists) all items should have got a label
examplebeginitemize
item Hello
item Hi
item[$circ$] Al-salaam
enditemize
Hello
Hi
Al-salaam
list environmentlist item
list item labelconsider using enumitem for list personalization specially inline optionand starred version of list environmentslists can be nested
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 32 81
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Floats
Floats
some parts of document in LATEX are float eg figure amp table
environmentsLATEX tries to put 13oats in a proper position automatically usually at the topor bottom of the page instead of putting them in the middle of textsthe following positioning options are available
t topb bottomh approximately herep 13oat-only page override internal parameters LATEX uses for determining good
13oat positionsH precisely here requires float package
a combination of options is acceptable tooeg when using ht LATEX will try to put the 13oat at the insertion point thenon the top of the next page if it happens to violate its typesetting rulesconsider using [htb] if you want not to use float package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 33 81
More Basic Commands Floats
Cross-Reference
labels can be created using labelkey command usually after caption orsectionrefkey amp pagerefkey can be used to refer to labelskeys traditionally are like typename when type is one of fig tab chapsec eq and fnnamerefkey from nameref package can be used to automatically add prexto references
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 34 81
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Simple Graphics
Simple Graphics
to add external graphics (pictures images graphs etc) to LATEX documentyou need graphicx packageincludegraphics[options]file command can be used to add graphics thenusually the inserted graphic is put in a figure environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the bottom of the picture in the scienticdocumentshowever you may want to put the caption at the top of picture to makepicture visible after clicking a cross-reference to it
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 35 81
More Basic Commands Simple Graphics
Simple GraphicsExample
usepackagegraphicx
beginfigure[h]
centering
includegraphics[width=05textwidth]ut
captionLogo of
textitUniversity of Tehran
labelfigut-logo
endfigure
Figure Logo of University of Tehran
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 36 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingEnvironment
inline formulas can be written between $ $ (TEX) or ( ) (LATEX)displayed formulas can be written between $$ $$ (TEX) or [ ] (LATEX)equations also could be written in equation equation anddisplaymath environmentsthe rst one numbers the equations too and you can label the equationspacing after a comma is dierent in math and textunless the comma is part of the mathematical notation you generally want itoutside of math modeyou may consider using amsmath packageto write text inside math mode use textcnt command (from amsmath
package) or font formatting commands like textrmcnt
see httpsenwikibooksorgwikiLaTeXMathematics
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 37 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingCommands
a b a lowast ba times b atimes ba cdot b a middot b
a b abfrac12 1
21over2 1
2
a_n an
a^n an
a div b adivide b
sqrt[4]-sqrt-1 4radicminusradicminus1
Lambda binomkn Λ(
kn
)
sum_n=1^vartheta n
ϑsumn=1
n
int_a^b x^2 dx
int b
ax2dx
lim_xtoinfty f(x) limxrarrinfin
f (x)
prod_i=a^b f(i)
bprodi=a
f (i)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 38 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingBraces amp symbols
1+Big(2+big(3+(4+5)big)Big) 1 +(
2 +(
3 + (4 + 5)))
( big( Big( bigg( Bigg( (((((
s = langle 0 1rangle langle 0 2rangle s = 〈0 1〉 〈0 2〉
left(2 binomknright) (
2 lowast(k
n))
leftfracx^33right|_0^1 x3
3
∣∣∣10
rightarrowRightarrowlongrightarrow rarrrArrminusrarrR mathnormalR mathrmR mathbfR mathfrakR mathbbR RRRRRRmathbbtext requires amsfonts or amssymb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 39 81
More Basic Commands Simple Mathematical Typesetting
Simple Mathematical TypesettingAccents amp Symbols
a aprime
a aprimeprime
dota a
overrightarrowaminusrarra
overlinea ahata a
tildea awidehata anota 6 a
for i amp j in mathematical environments imath amp jmath may be used$hatjmath$ (ȷ)
pmmp plusmn∓gtgegeqgg gtgegelandlorneg and or notinsubsetsubseteq isinsubsubeneqequivsim 6=equivsimtherefore there4
forallexistsnexists forallexistrightarrowto rarrrarrleftarrowgets larrlarrRightarrowimplies rArr =rArrLeftrightarrowiff hArrlArrrArremptysetvarnothing emptyempty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 40 81
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Simple Mathematical Typesetting
Multiline Mathematical Typesetting
begingather
k = frac12 m v^2
u = m g h
endgather
k =12
mv2
u = mgh
beginalign
f(x) amp =
int_-infty^infty
alpha h(x) dx
amp = alpha
int_-infty^infty
h(x) dx
amp = alpha g(x)
endalign
f (x) =int infinminusinfinαh(x) dx
= αint infinminusinfin
h(x) dx
= αg(x)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 41 81
More Basic Commands Simple Mathematical Typesetting
Matrices
A_mn =
beginpmatrix
a_11 amp a_12 amp cdots amp
a_1n
a_21 amp a_22 amp cdots amp
a_2n
vdots amp vdots amp ddots amp
vdots
a_m1 amp a_m2 amp cdots amp
a_mn
endpmatrix
Amn =
a11 a12 middot middot middot a1na21 a22 middot middot middot a2n
am1 am2 middot middot middot amn
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 42 81
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Simple Mathematical Typesetting
Mathematical TypesettingExample
beginalign
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p land q ampamp (varepsilon)labeleq11
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p ampamp (land -
textrefeq11)labeleq12
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N p rightarrow r ampamp
(varepsilon)labeleq13
(p rightarrow r) (q rightarrow r) (pland q) amp vdash_N r ampamp (rightarrow - textrefeq13
textrefeq12)labeleq14
(p rightarrow r) (q rightarrow r) amp vdash_N (pland q) rightarrow r ampamp (rightarrow +
textrefeq14)labeleq15
quadBox
endalign
(prarr r) (qrarr r) (p and q) `N p and q (ε) (1)(prarr r) (qrarr r) (p and q) `N p (andminus 1) (2)(prarr r) (qrarr r) (p and q) `N prarr r (ε) (3)(prarr r) (qrarr r) (p and q) `N r (rarr minus 3 2) (4)
(prarr r) (qrarr r) `N (p and q)rarr r (rarr + 4) (5)
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 43 81
More Basic Commands Simple Tables
Simple Tables
begintabularcolscntendtabular environment can be used to add tablescols describes the columns of the table by a combination of the followingsymbols
l left-justied columnc centred columnr right-justied column
pwidth vertically aligned paragraph at topmwidth vertically aligned paragraph at middle requires array packagebwidth vertically aligned paragraph at bottom requires array package
| vertical line|| double vertical line
usually the inserted table is put in a table environment making it 13oatit has got an optional argument for positioningyou may want to use centering declaration at the beginning of gureitrsquos possible to add a caption to the 13oat by the captiontitle commandcaption usually should be placed at the top of the table in the scienticdocuments
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 44 81
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Simple Tables
Simple TablesCont
each row of table consists of elds (up to the number of columns described inthe rst argument of tabular environment)elds of each row should be separated by amp
at the end of each row except perhaps last row should be usedrows could be separated by one or more hlines
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 45 81
More Basic Commands Simple Tables
Simple TablesExample
begintable[h]
centering
captionList of universities
labeltabuniversities
begintabularcc
hline
textbfUniversity amp
textbfCity
hline
hline
Tehran amp Tehran
Sharif amp Tehran
Ferdowsi amp Mashad
Isfahan amp Isfahan
hline
endtabular
endtable
Table List of universities
University CityTehran TehranSharif Tehran
Ferdowsi MashadIsfahan Isfahan
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 46 81
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Simple Bibliography
Simple Bibliography
manual bibliography can be created bybeginthebibliographywidestlabelendthebibliography
widestlabel should be a number with the same length as the number of itemseach item can be added by bibitem[label]citekeydescription
itrsquos possible to refer to items by cite[text]keylist
you may need to use nocitekeylist or even nocite to add a hiddenreferencemanual bibliography should be sorted manuallyyou may want to use renewcommandrefnametitle (article class) orrenewcommandbibnametitle (report amp book classes) to changebibliography titleyou may want to use tocbibind package or usephantomsectionaddcontentslinetocsectionRefrences to addbibliography to table of contents
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 47 81
More Basic Commands Simple Bibliography
Simple BibliographyExample
See cite[p1]wikibooks18 Also see citewikibooks18alex17
nocitewikibooks18
beginthebibliography9
bibitemalex17 Alex 2017 Assert and textttstatic_assert Retrieved
from
urlhttpswwwlearncppcomcpp-tutorial7-12a-assert-and-static_assert
bibitemwikibooks18 Wikibooks 2018 ``Unit Tests In
textitWikibooks The Free Textbook Project Retrieved from
urlhttpsenwikibooksorgwikiIntroduction_to_Software_EngineeringTestingUnit_Tests
endthebibliography
See [2 p1] Also see [2 1]
References
[1] Alex 2017 Assert and static assert Retrieved from httpswww
learncppcomcpp-tutorial7-12a-assert-and-static_assert
[2] Wikibooks 2018 ldquoUnit Testsrdquo In Wikibooks The Free TextbookProject Retrieved from httpsenwikibooksorgwikiIntroduction_
to_Software_EngineeringTestingUnit_Tests
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 48 81
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Links
hyperref Package
hyperref package can be used to clickable linkshyperref needs to be the last package you loadhyperref package accepts some options eg
breaklinks allow links to be broken across several linescolorlinks colour the text of the links and anchorslinkcolor colour for normal internal links
anchorcolor colour for anchor textscitecolor colour for bibliographic citations in text
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 49 81
More Basic Commands Links
hyperref pdf options
bookmarks write a set of pdf bookmarkspdftitle document information Title eld
pdfauthor document information Author eldpdfsubject document information Subject eldpdfcreator document information Creator eld
pdfproducer document information Producer eldpdfkeywords document information Keywords eld
These options can be added with either usepackagehyperref orhypersetupoptions command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 50 81
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Links
hyperref Commands
urlURL make a link (url package)hrefURLtext make a linkhyperref[label]text make text a link to where reflabel would point
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 51 81
More Basic Commands Links
Cross-Reference
labels can be created using labelkey command usually after caption orsectionautorefkey amp autopagerefkey can be used to cross-refer to labels withbetter linkingnamerefkey from nameref package can be used to automatically add prexto referenceshyperref package includes nameref package itselfstared version of the aforementioned commands could be used to insertcross-references without links
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 52 81
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Links
Cross-ReferenceExample
captionUT logolabelfigut
beginitemize
item Figure~reffigut
item page~pagereffigut
item namereffigut
item autoreffigut
item autopagereffigut
enditemize
Figure 1 UT logo
bull Figure 1bull page 1bull UT logobull Figure 1bull page 1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 53 81
More Basic Commands Scientic Typesetting
Theorem
amsthm package provides environments for typesetting theoremsexamplenewtheoremdefinitionDefinition
begindefinition
Here is a new definition
enddefinition
Definition 1 Here is a new definition
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 54 81
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Scientic Typesetting
Preformatted Texts
verbatim environment provides environments for typesetting texts which arenot preprocessedeverything input between the begin and end commands are processed as if bya typewriterall spaces and new lines are reproduced as givenis displayed in an appropriate xed-width fontany LATEX command will be ignored and handled as plain textverb command is the equivalent inline commandsee httpsenwikibooksorgwikiLaTeXParagraph_FormattingVerbatim_text
you may want to use fancyvrb package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 55 81
More Basic Commands Scientic Typesetting
Source Code
listings package provides facilities to typesetting source code in thedocumentlistings package oers multiple commands eg
lstlisting environmentlstinlinesrc
lstinputlistingaddr to read from le
examplebeginlstlisting[language=c++]
int main(int argc char const
argv[])
stdcout ltlt Hello World ltlt
stdendl
return 0
endlstlisting
1 int main(int argc char const
argv[])
2 stdcout ltlt Hello World ltlt
stdendl
3 return 0
4
see httpsenwikibooksorgwikiLaTeXSource_Code_Listings
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 56 81
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
More Basic Commands Scientic Typesetting
Algorithms amp Pseudo-codes
algorithmicx (usepackagealgpseudocode) package provides facilities totypesetting pseudo-codes amp algorithms in the documentalgorithm package provides 13oating environments with numberedalgorithmsexamplebeginalgorithm[h]
captionAn example algorithm
beginalgorithmic
If $igeq maxval$
State $igets 0$
Else
If $i+kleq maxval$
State $igets i+k$
EndIf
EndIf
endalgorithmic
endalgorithm
Algorithm 1 An example algorithm
if i ge maxval thenilarr 0
elseif i+ k le maxval then
ilarr i+ kend if
end if
see httpsenwikibooksorgwikiLaTeXAlgorithms
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 57 81
Document Structure amp Layout
Document Structure amp Layout
1 What is LATEX2 How to get LATEX3 LATEX lsquoHello Worldrsquo
Document StructureSpecial Behaviours
4 Formatting Texts5 More Basic Commands
ListsFloatsSimple GraphicsSimple Mathematical Typesetting
Simple TablesSimple BibliographyLinksScientic Typesetting
6 Document Structure amp LayoutDocument ClassTitle amp AbstractSectioningPage StyleMargins amp SpacesPenaltiesMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 58 81
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Document Class
Document Classes
article for articles in scientic journals presentations short reportsprogram documentation invitations etc
proc for proceedings based on the article classreport for longer reports containing several chapters small books thesis
etcbook for real bookletter for letters completely dierent structure
minimal for testAnd there are other non-standard packages like
memoir a class based on book with many optionsbeamer for presentations
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 59 81
Document Structure amp Layout Document Class
Document Class Options
10pt 11pt 12pt the size of the main fonta4paper letterpaper paper size needs geometry package with same
option to change pdf page sizetitlepage notitlepage whether a new page should be started after the
document title or nottwoside oneside whether double or single sided output should be
generatedLATEX distinguishes between odd and even pages intwo-sided output
openright openany makes chapters begin either only on right-hand pagesor on the next page available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 60 81
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Document Class
Document Class OptionsCont
13eqn typesets displayed formulas left-aligned instead ofcentred
leqno places the numbering of formulas on the left-hand sideinstead of the right
twocolumn typeset the document in two columns instead of onelandscape landscape layout
draft makes LATEX indicate hyphenation and justicationproblems with a small square in the right-hand marginof the problem lineand shows only a frame where images would normallyoccur so that document could be compiled faster
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 61 81
Document Structure amp Layout Title amp Abstract
Top Matter amp Abstract
titleA Sample LaTeX Document
author
Hadi Safari
thanksCorresponding author
University of Tehran
and
Colleagues
datetoday
begindocument
maketitle
beginabstract
As you may know or not this is abstract
of this simple sample documentldots
endabstract
ldots and this is the main context
enddocument
default
A Sample LATEX Document
Hadi Safarilowast
University of TehranColleagues
August 1 2019
Abstract
As you may know or not this is abstract of this simplesample document
and this is the main contextLorem ipsum dolor sit amet consectetuer adipiscing elit Etiam
lobortis facilisis sem Nullam nec mi et neque pharetra sollicitudinPraesent imperdiet mi nec ante Donec ullamcorper felis non so-dales commodo lectus velit ultrices augue a dignissim nibh lectusplacerat pede Vivamus nunc nunc molestie ut ultricies vel sem-per in velit Ut porttitor Praesent in sapien Lorem ipsum dolorsit amet consectetuer adipiscing elit Duis fringilla tristique nequeSed interdum libero ut metus Pellentesque placerat Nam rutrumaugue a leo Morbi sed elit sit amet ante lobortis sollicitudin Prae-sent blandit blandit mauris Praesent lectus tellus aliquet aliquamluctus a egestas a turpis Mauris lacinia lorem sit amet ipsumNunc quis urna dictum turpis accumsan semper
lowastCorresponding author
1
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 62 81
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Sectioning
Sectioning
LATEX knows multiple levels of sectioningpart level -1chapter only book and report classessectionsubsectionsubsubsectionparagraphsubparagraph
eg sectionLaTeX vs MS Word
anything between a section command and the next one is considered as thecontent of that section
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 63 81
Document Structure amp Layout Sectioning
SectioningCont
there are starred versions of those commandswhich do not have numberingbut also do not appear in table of contents automatically
eg sectiontitlea more complicated examplesection[e = mc^2]$e=mc^2$protectfootnotea well-known equation
there is an optional argument for providing short simple-text version of longtitles or titles including special characters to show in references by name pdfbookmarks etcprotect should be used before some commands in section titles
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 64 81
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Sectioning
Sectioningbook class
frontmatter mainmatter appendix and backmatter commands used in books tochange section numbering and page style
front matter The front matter chapters will not be numbered Page numberswill be printed in roman numerals Front matter is not supposed tohave sections
main matter The main matter chapters works as usual The command resets thepage numbering Page numbers will be printed in arabic numerals
appendix The appendix macro can be used to indicate that following sectionsor chapters are to be numbered as appendices Appendices can beused for the article class too
back matter The back matter behaves like the front matter It has the same issuewith section numbering
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 65 81
Document Structure amp Layout Sectioning
Table of Contents
table of contents can be created automatically by tableofcontents commandthere are also
listoffigures
listoftables
listofalgorithms algorithm packagelstlistoflistings listings package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 66 81
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Sectioning
Table of ContentsAdding Sections Manually
itrsquos possible to add some section to table of contents manually bysectionIntroduction
addcontentslinetocsectionIntroduction
phantomsection command from hyperref package should be used to correctpdf bookmarksrsquo referencephantomsection
addcontentslinetocsectionIntroduction
sectionIntroduction
for chapters cleardoublepage command may be used toocleardoublepage
phantomsection
addcontentslinetocchapterBibliography
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 67 81
Document Structure amp Layout Page Style
Page Style
pagestylestyle command can be used in preamble to determine page stylethe following styles are available
plain blank header footer contains only the page number (default)empty empty header and footer
headings header provided by document class empty footermyheadings header determined by markrightand amp
markbothleftright
thispagestylestyle changes only the page style of current pagepackage fancyhdr gives you more control on page stylefancypagestylename
lhead chead rhead
lfoot cfoot rfoot
use thepage everywhere to get page number
renewcommandheadrulewidth0pt
renewcommandfootrulewidth0pt
pagestylename
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 68 81
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Margins amp Spaces
Margins
you can manually set the marginparameters with commands likesetlengthparameterlength andaddtolengthparameterlength
take a look at calc and geometrypackages too
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 69 81
Document Structure amp Layout Margins amp Spaces
Marginsgeometry package
geometry package can be used to control marginsyou can use eg margin=1in top=15in height=8in or width=4in options whenincluding packageuse showframes to show page frameslandscape and some options like a4paper are also available in geometry
package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 70 81
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Margins amp Spaces
Breaks
double new lines and par indicates beginning of a new paragraph and newline break the lines without beginning a new paragraphnewpage begins a new pageclearpage prints remaining floats and begins a new page
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 71 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
you can change all the length parameters with setlengthparameterlength
and addtolengthparameterlength commands egsetlengthbaselineskip15baselineskip
minus amp plus commands could be used to show tolerable change range egsetlengthparskip1ex plus 05ex minus 02ex
baselineskip length parameter is used to determine space between linesparindent length parameter is used to determine paragraph indentationparskip length parameter is used to determine space between paragraphsyou can use indent amp noindent commands to add indentation to a paragraphor remove ityou may want to use indentfirst package
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 72 81
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Margins amp Spaces
More on Spaces
horizontal amp vertical spaces could be added by hspacelength ampvspacelength commands respectivelyyou may consider using starred version of those commands to be eectiveeven at the start and end of line or pagestretchn could be used to divide the space by weight nxhspacestretch1
xhspacestretch3xx x x
you may consider using [length] bigskip and smallskip toocommands vfil vfill hfil hfill hlinefill and dotfill could be usedto ll the spaces between texts
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 73 81
Document Structure amp Layout Margins amp Spaces
Units of Length
in addition to mm (millimetre) cm (centimetre) in (inch) and pt (point) therelative units em (approx width of an M in the current font) and ex (approxheight of an x in the current font) are available
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 74 81
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Margins amp Spaces
Rules amp Boxes
in LATEX everything is positioned inside a boxmboxtext fboxtext makebox[width][position]textframebox[width][position]text parbox[position]widthtextbeginminipage[position]widthtextendminipage andraiseboxdistance[extendabovebaseline][extendbelowbaseline]text may beused to work with boxesrule[lift]widththickness could be used to draw linesstrut is dened as rule[-3baselineskip]0ptbaselineskip
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 75 81
Document Structure amp Layout Margins amp Spaces
Multi-column
beginmulticolsncntendmulticols environment from multicol
package make it possible to typeset texts in multiple columnsit balances the columns automatically the starred version of environmentdonrsquot
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 76 81
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Penalties
Penalties
use tolerance=5000 (with a number up to 10000) to deal with overfill lineswhich are indicated with black square in draft modeuse widowpenalty=300 and clubpenalty=300 (with a number up to 10000) toincrease window and orphan penalty
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 77 81
Document Structure amp Layout Macros
Counters
counters are what LATEX uses to keep the right number attached to equationspages theorems etceg equation figure footnote page table chapter sectionsubsection subsubsection enumi enumii enumiii and enumivfor every counter name there is a thename command which shows the currentvalue of the name countersetcountercountervalue is used to set the value of a counterstepcountercounter is used to increment a counter by oneaddtocountercountervalue is used to increment a counter by valueusually LATEX increments the counter and then generates the appropriatenumberexception pageif you want the rst page in your paper to be page 45 you should putsetcounterpage45 line directly after begindocument
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 78 81
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
Document Structure amp Layout Macros
Dening New Commands
itrsquos possible to dene new commands in LATEXLATEX has got three commands for this
newcommandcmd[args][default]def
dene a new already-undened commandrenewcommandcmd[args][default]def
redene an already-dened commandprovidecommandcmd[args][default]def
dene a command regardless of that previous denitions
newenvironmentname[num][default]beforeafter and similar commandsare used to dene new environmentssee httpsenwikibooksorgwikiLaTeXMacros
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 79 81
Document Structure amp Layout Macros
Arithmetic amp Conditionals
calc package provides the common inx notation eg in counter-relatedcalculationssee httpsenwikibooksorgwikiLaTeXMacros
ifthen package provides conditional commands by means ofifthenelsecondthenelse command
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 80 81
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-
References
References
Woerner K Benjamin M and Henrik S LATEX Lab Department of Mechanical Engineeringof MIT 2017 Available Online at httpoceanaimiteduk_wlatex_lab
Higginbottom R Introduction to Scientic Typesetting 2012 Available Online athttpwww2washjeffeduusersrhigginbottomlatexmainhtml
Wikibooks contributors LATEX Wikibooks The Free Textbook Project Available Online athttpsenwikibooksorgwikiLaTeX
Oetiker T Partl H and Hyna I Not So Short Introduction to LATEX 2ε Available Online athttpmirrorsctanorginfolshortenglishlshortpdf
Hadi Safari (UT ACM Student Chapter) Introduction to TEX amp LATEX LATEX Intro Summer 98 81 81
- What is LaTeX
- How to get LaTeX
- LaTeX `Hello World
-
- Document Structure
- Special Behaviours
-
- Formatting Texts
- More Basic Commands
-
- Lists
- Floats
- Simple Graphics
- Simple Mathematical Typesetting
- Simple Tables
- Simple Bibliography
- Links
- Scientific Typesetting
-
- Document Structure amp Layout
-
- Document Class
- Title amp Abstract
- Sectioning
- Page Style
- Margins amp Spaces
- Penalties
- Macros
-
- References
-