cs-m00 research methodology lecture 4b: a taster of latex · cs m00 lecture 4b: latex 22/ 28. more...

28
CS-M00 Research Methodology Lecture 4b: A Taster of L A T E X Anton Setzer http://www.cs.swan.ac.uk/csetzer/lectures/ researchmethodology/11/index.html Friday 14 October 2011 CS M00 Lecture 4b: L A T E X 1/ 28

Upload: others

Post on 14-Aug-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

CS-M00 Research MethodologyLecture 4b: A Taster of LATEX

Anton Setzer

http://www.cs.swan.ac.uk/∼csetzer/lectures/researchmethodology/11/index.html

Friday 14 October 2011

CS M00 Lecture 4b: LATEX 1/ 28

Page 2: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

WYSIWYG Systems

I WYSIWYG = “What You See Is What You Get”.

I What you type in can be seen directly on the screen.

I Microsoft Office Word is the main example of a WYSIWYGsystem.

CS M00 Lecture 4b: LATEX 2/ 28

Page 3: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Advantages/Disadvantages of WYSIWYG Systems

I WYSIWYG systems are relatively easy to use.I In WYSIWYG systems typesetting to be done by the user.

I Problem: most users are not professional type setters.

I In most systems (e.g. Word) you can see only the output, butnot the formatting information.

I Difficult to detect that one headline is in 11 pt and another in12 pt, or one headline in one font, and another in a slightlydifferent font.

I Therefore output is usually inconsistent.

I Usually output not of printable quality.

I Programming is difficult, no possibility for defining macros (ordefinition of macros restricted).

CS M00 Lecture 4b: LATEX 3/ 28

Page 4: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

WYSIWYM

I WYSIWYM = “What You See Is What You Mean”.I Instead of doing the typesetting directly the user says:

I This is a headline.I This is a section title.I This text is normal text.I This is a mathematical formula

I Main examples: TEXand LATEX.

CS M00 Lecture 4b: LATEX 4/ 28

Page 5: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Advantages/Disadvantages of WYSIWYM Systems

I Steeper learning curve.

I Separation of output from input, therefore what you writeneeds to be compiled into text.

I Can create text in print quality.I Many publishers print articles typeset in LATEX directly, or after

adding their own generic macros.

I User sees all formatting information and can therefore producevery uniform text.

I Programmable using macros.I Development of macro packages for many purposes.

I In LATEX macro packages e.g. for chess, for typesetting proofs,chemical formulas exist.

I These slides are typeset in LATEX.

CS M00 Lecture 4b: LATEX 5/ 28

Page 6: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

LATEX

I TEX developed by Donald Knuth in order to typeset a newversion of his books “The art of Computer Programming”.

I LATEX (for Lamport-TEX) developed by Laslie Lamport inorder to make a more userfriendly version of TEX.

I LATEX is essentially a macro package on top of TEX.

CS M00 Lecture 4b: LATEX 6/ 28

Page 7: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Use of LATEX for Reports and Dissertation

I Reports and dissertations can be written using any textprocessing system.

I Use of LATEX will in many cases give you a slight advantagebecause of the higher quality of the output.

I Many lecturers (but not all) use LATEX, especially for scientificpublishing.

I They might help you with LATEX.

CS M00 Lecture 4b: LATEX 7/ 28

Page 8: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Example

I The following shows an example of LATEX code (split into 3codes) plus the output.

I For ease of presentation after each code piece the final output(which is only produced after running latex on the wholecode) is shown.

CS M00 Lecture 4b: LATEX 8/ 28

Page 9: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Example

\documentclass[12pt]{article}\usepackage{amsmath}\title{\LaTeX}\author{Anton Setzer

\thanks{Dept. of Computer Science,

Swansea University, Singleton Park,

Swansea SA1 4PZ, UK.

Email: {\tt [email protected]}.This article is based on the example in Wikipedia,

http://en.wikipedia.org/wiki/LaTeX}}\date{7 October 2011}

\newcommand{\role}{{r\^{o}le}}

\begin{document}\maketitle

CS M00 Lecture 4b: LATEX 9/ 28

Page 10: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

LATEXOutput

CS M00 Lecture 4b: LATEX 10/ 28

Page 11: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Example (Continued)

\LaTeX{} is a document preparation system for the \TeX{}typesetting program. It offers programmable desktop

publishing features and extensive facilities for

automating most aspects of typesetting and desktop

publishing, including numbering and cross-referencing,

tables and figures, page layout, bibliographies, and

much more.

\LaTeX{} was originally written in 1984 by Leslie

Lamport and has become the dominant method for using

\TeX; few people write in plain \TeX{} anymore.

The current version is \LaTeXe.\LaTeX{} plays an important \role{} in publishing

scientific articles in Science.

% This is a comment; it will not be shown

% in the final output.

CS M00 Lecture 4b: LATEX 11/ 28

Page 12: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

LATEXOutput

CS M00 Lecture 4b: LATEX 12/ 28

Page 13: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

LATEXOutput

CS M00 Lecture 4b: LATEX 13/ 28

Page 14: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Example (Continued)

% The following shows a little of the typesetting power

% of LaTeX:

\begin{align}E &= mc^2 \\m &= \frac{m 0}{\sqrt{1-\frac{v^2}{c^2}}}\end{align}\end{document}

CS M00 Lecture 4b: LATEX 14/ 28

Page 15: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

LATEXOutput

CS M00 Lecture 4b: LATEX 15/ 28

Page 16: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

LATEXOutput

CS M00 Lecture 4b: LATEX 16/ 28

Page 17: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Running LATEX

csetzer@csltas2:∼> latex exampleWikipedia.tex

latex exampleWikipedia.tex

This is pdfTeX, Version 3.1415926-1.40.10

(TeX Live 2009/Debian)

entering extended mode

(./exampleWikipedia.tex

LaTeX2e <2009/09/24>Babel <v3.8l> and hyphenation patterns for english,

usenglishmax, dumylang, nohyphenation, farsi,

arabic, croatian, bulgarian, ukrainian, russian, czech,

slovak, danish, dutch, finnish

... lots of more output ...

Output written on exampleWikipedia.dvi (1 page, 2364 bytes).

Transcript written on exampleWikipedia.log.

csetzer@csltas2:∼> xdvi exampleWikipedia.dvi &

CS M00 Lecture 4b: LATEX 17/ 28

Page 18: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

More Details

I \documentclass[12pt]{article}I Standard Header of a Latex file.I 12pt = font sizeI article = style

(Article is suitable for reports.There are lots of other styles.Style “book” is the simplest style for dissertations.– There are many more fancy ones.)

I \usepackage{amsmath}I Loads package amstmath.I Rich package for mathematics, here used for command \frac.I Lots of packages are available.

I \title{\LaTeX}I Defines the title.I \LaTeX{} is a macro typesetting LATEX.

I \author{Anton Setzer

I Starts defining the author (note { not closed yet)

CS M00 Lecture 4b: LATEX 18/ 28

Page 19: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

More Details

I \thanks{Dept. of Computer Science,

Swansea University, Singleton Park,

Swansea SA1 4PZ, UK.

Email: {\tt [email protected]}.This article is based on the example in

Wikipedia,http://en.wikipedia.org/wiki/LaTeX}}

I Footnote added to author.I {\tt · · · } type sets this part in type writer font.I Second “}” finishes definition of author.

\date{7 October 2011}I Defines the date.

CS M00 Lecture 4b: LATEX 19/ 28

Page 20: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

More Details

I \newcommand{\role}{{r\^{o}le}}I Defines a macro.I From now on \role will expand to{r\ˆ{o}le}.

I Curly brackets will be used to group text but will not beprinted.

I \ˆ{o} typesets oI There are macros for defining lots and lots of special symbols.I http://www.tug.org/tex-archive/info/symbols/comprehensive/I Macros can have parameters as well.

CS M00 Lecture 4b: LATEX 20/ 28

Page 21: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

More Details

I \begin{document}I Start of the content of the document.

I \maketitleI Puts title, author, date at this position.I Without this command no title, author, date will occur in the

document.

CS M00 Lecture 4b: LATEX 21/ 28

Page 22: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

More Details

I \LaTeX{} is a document preparation system for the\TeX{} typesetting program. It offers · · ·

I This is standard text to be typeset.I Aligning the text done by the system.I Line breaks in the text create only space between words.I Double line breaks creates a paragraph

(Equivalently one can use the macro \par).I Several blanks, tabs, line breaks are the same as a single space

(except for double line breaks).I \TeX{} typesets TEX.

CS M00 Lecture 4b: LATEX 22/ 28

Page 23: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

More Details

I \LaTeX{} plays an important \role{} in publishing

I Here the user defined macro \role{} typeset as role is used.I {} here makes sure that there is a blank after LATEXand after

role.Spaces after a macro are ignored.

I % This is a comment; it will not be shownI Everything in a a line after % is a comment

CS M00 Lecture 4b: LATEX 23/ 28

Page 24: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Example (Continued)

I \begin{align}· · ·\end{align}

I Example of an environment.I There are many environments in LATEX.

CS M00 Lecture 4b: LATEX 24/ 28

Page 25: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Example (Continued)

I \begin{align}· · ·& · · · \\· · ·& · · · \\\end{align}

I Environment align typesets several formulae, which arenumbered as (1), (2) consecutively.

I Content of an align environment is mathematical text.I LATEX and TEX have a text mode and a formula mode.I In formula mode different macros (usually for creating

mathematical text) are used.I In mathematical text all blanks are ignored.I Mathematical text is where the full power of LATEX/TEXis

shown.I Seems to be the easiest system for typesetting formulae.

I \\ separates lines in mathmemtical text (can be used forordinary text as well).

I Symbols & mark positions to be aligned.

CS M00 Lecture 4b: LATEX 25/ 28

Page 26: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

Example (Continued)

I cˆ2I Typesets c2 in mathematical text.

I m 0.I Typesets m0 in mathematical text.

I \frac{· · · }{· · · }I Type sets a fraction ···

··· .I Note that we can nest fractions.

I \sqrt{· · · }I Typesets

√· · ·.

I \end{align}I End of align environment.

I \end{document}I End of the document.I Text after this will be ignored.

CS M00 Lecture 4b: LATEX 26/ 28

Page 27: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

LATEX under Windows

I Use any texteditor. Recommended: Emacs or XEmacs.

I MikTeX is a LATEX compiler for Windows.

I For viewing dvi files use the included YAP dvi-viewer.

I For postscript use GhostScript + GSView.

I See for instancehttp://www.pinteric.com/miktex.htmlon how to use LATEX under Windows.

CS M00 Lecture 4b: LATEX 27/ 28

Page 28: CS-M00 Research Methodology Lecture 4b: A Taster of LaTeX · CS M00 Lecture 4b: LATEX 22/ 28. More Details I nLaTeXfgplays an important nrolefgin publishing I Here the user de ned

More to Come

I Lots of documentation on LATEX (tutorials, userguides etc)available online.

I Links will be made available on the module home page athttp://www.cs.swan.ac.uk/∼csetzer/lectures/

researchmethodology/11/index.html

CS M00 Lecture 4b: LATEX 28/ 28