Top Banner
Preparing Slides Using LaTeX, Pstricks, and Beamer Uday Khedker (www.cse.iitb.ac.in/˜uday) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay August 2010
66

Preparing Slides Using LaTeX, Pstricks, and Beamer

Feb 09, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Preparing Slides Using LaTeX, Pstricks, and Beamer

Preparing Slides UsingLaTeX, Pstricks, and Beamer

Uday Khedker

(www.cse.iitb.ac.in/̃ uday)

Department of Computer Science and Engineering,

Indian Institute of Technology, Bombay

August 2010

Page 2: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Outline 1/40

Outline

• Using LaTeX for document preparation

• Using Pstricks for drawing pictures

• Using Beamer for making presentations

Aug 2010 Uday Khedker, IIT Bombay

Page 3: Preparing Slides Using LaTeX, Pstricks, and Beamer

Part 2

Using LaTeX for

Document Preparation

Page 4: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 2/40

Document Preparation

• Typesetting = Text (To Be Typeset) + Typesetting Commands

• Document Structure : Position, size, shape of entities etc.

◮ Visual Structure : Governed by visual aesthetics◮ Logical Structure : Governed by the meaning

(List, Table, Chapter, Section, etc.)

Aug 2010 Uday Khedker, IIT Bombay

Page 5: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 3/40

WYSIWYG Preparation

• What You See Is What You Get (E.g. MS Word.)

• Interactive : Interleaved typing and typesetting.

◮ As you type the text, the resulting formatting is shown immediatelyand automatically.

◮ Visual structure is more prominent.

Aug 2010 Uday Khedker, IIT Bombay

Page 6: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 4/40

Non-WYSIWYG Preparation

• Execution of formatting commands separate from keying in the text.E.g. LATEX.

• Multi-step batch mode process

◮ Type the text◮ Execute the formatting commands◮ View the resulting document

• Visual structure de-emphasized :Can’t see immediately and automatically.

Aug 2010 Uday Khedker, IIT Bombay

Page 7: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 5/40

Document Preparation with LaTeX

Text andformattingcommands

LATEXDevice

independentrepresentation

Aug 2010 Uday Khedker, IIT Bombay

Page 8: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 5/40

Document Preparation with LaTeX

Text andformattingcommands

LATEXDevice

independentrepresentation

xdvi Screenrendering

Aug 2010 Uday Khedker, IIT Bombay

Page 9: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 5/40

Document Preparation with LaTeX

Text andformattingcommands

LATEXDevice

independentrepresentation

xdvi Screenrendering

dvips

Postscriptrepresentation

Aug 2010 Uday Khedker, IIT Bombay

Page 10: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 5/40

Document Preparation with LaTeX

Text andformattingcommands

LATEXDevice

independentrepresentation

xdvi Screenrendering

dvips

Postscriptrepresentation

gv,evince

screenrendering

Aug 2010 Uday Khedker, IIT Bombay

Page 11: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 5/40

Document Preparation with LaTeX

Text andformattingcommands

LATEXDevice

independentrepresentation

xdvi Screenrendering

dvips

Postscriptrepresentation

gv,evince

screenrendering

lpr printedcopy

Aug 2010 Uday Khedker, IIT Bombay

Page 12: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 5/40

Document Preparation with LaTeX

Text andformattingcommands

LATEXDevice

independentrepresentation

xdvi Screenrendering

dvips

Postscriptrepresentation

gv,evince

screenrendering

lpr printedcopy

ps2pdf pdfdocument

Aug 2010 Uday Khedker, IIT Bombay

Page 13: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 6/40

Using LaTeX

• Create file.tex

• “latex file.tex” produces file.dvi

• “dvips -o file.ps file” produces file.ps

• Can be viewed using “gv file.ps”

• Practical tips for Linux users◮ Use of makefile, simultaneous editing and background viewing.◮ Almost interactive

Aug 2010 Uday Khedker, IIT Bombay

Page 14: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 7/40

Types of Formatting Commands

• Environment : Contains text to be typeset with a specific logicalstructure.Figures, tables, lists, equations, etc.

• Command : Produces some text in a specific waySection headings, footnotes etc.

• Declaration : Customizes the formatting of the text in the scope

Aug 2010 Uday Khedker, IIT Bombay

Page 15: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 8/40

Environments

• Environments explicate a logical structureFigures, tables, lists, equations, etc.

◮ Names : document, itemize, tabular, table, figure, . . .◮ Scope : \begin{env } ... \end{env }

Example \begin{document} ... \end{document}

Aug 2010 Uday Khedker, IIT Bombay

Page 16: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 9/40

Commands

• Commands carry out a certain formatting(May have side effects)

◮ \chapter{Introduction}Begins a new page.Changes the numbering of sections, figures, equations etc.

◮ \foilhead{Commands}◮ \textbf{Text to be typeset in bold face}◮ \texttt{Text to be typeset in typewrite font}◮ \footnote{Text to be typeset as a footnote}

Aug 2010 Uday Khedker, IIT Bombay

Page 17: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 10/40

Types of Formatting Commands

• Declarations◮ Customization of fonts, shape, thickness, numbering, etc.

\tt indicates typewriter font\bf indicates boldface letter\em indicates emphasized letters

◮ ScopeDelimited by “{” and “}”, “\begin” and “\end” pairs, or . . .

Aug 2010 Uday Khedker, IIT Bombay

Page 18: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 11/40

LATEX: Basic Concepts

• Document Classes (article, report, book etc)

• Use of packages

• Fonts and Colors

• Sectioning: Chapters, sections, appendix etc

• Lists and enumerations

Aug 2010 Uday Khedker, IIT Bombay

Page 19: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 12/40

LATEX: Basic Concepts

• Paragraphs

• Formatting of Math formulae

• Tables and Figures

• Page formatting

• Footnotes

Aug 2010 Uday Khedker, IIT Bombay

Page 20: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 13/40

LATEX: Basic Concepts

• Multiple input files

• Defining new commands

• Importing files

• Citations and references

Aug 2010 Uday Khedker, IIT Bombay

Page 21: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using LaTeX for Document Preparation 14/40

LATEX: Advanced Concepts

• Formatting programs/algorithms

• Bibtex

• Pictures

• Slides

Aug 2010 Uday Khedker, IIT Bombay

Page 22: Preparing Slides Using LaTeX, Pstricks, and Beamer

Part 3

Using Pstricks for Drawing

Pictures

Page 23: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 15/40

Preparing Pictures using Pstricks

• Environment pspicture

• Line and curve drawings

• Frames, circles, ovals,

• Nodes and Node connectorsRelative to the placement of nodes

• Labeling node connectors

Aug 2010 Uday Khedker, IIT Bombay

Page 24: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 16/40

The Power of Pstricks

• Logical components of pictures and relationships between them.⇒ Easy refinements/updates/corrections

◮ xfig does not recognise node-connectors.⇒ If you move a node, a node connector does not move with it.

◮ dia recognises node-connectors but not the relationship betweennodes.⇒ A node connector moves with a node but positioning of two

nodes remains independent.

• Very good quality of pictures.

• Free mixing of graphics and text

Aug 2010 Uday Khedker, IIT Bombay

Page 25: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 17/40

Adding to the Power of Pstricks

• A limitation of pstricksAbsolute coordinates have to be calculated by the user.

• Solution : package pst-rel-points available athttp://www.cse.iitb.ac.in/uday/latex.

• Defines command

\putnode[l/r]{new}{old}{delta x}{delta y}{stuff}

Aug 2010 Uday Khedker, IIT Bombay

Page 26: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 18/40

Drawing Pictures Using Pstricks

\usepackage{pstricks}

\usepackage{pst-node}

\usepackage{pst-text}

\usepackage{etex}

\usepackage{pst-rel-points}

%%

\psset{unit=1mm}

\begin{pspicture}(0,0)(50,70)

\psframe(0,0)(50,70)

\end{pspicture}

Aug 2010 Uday Khedker, IIT Bombay

Page 27: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 18/40

Drawing Pictures Using Pstricks

\usepackage{pstricks}

\usepackage{pst-node}

\usepackage{pst-text}

\usepackage{etex}

\usepackage{pst-rel-points}

%%

\psset{unit=1mm}

\begin{pspicture}(0,0)(50,70)

\psframe(0,0)(50,70)

\putnode{n1}{origin}{25}{50}{%

\pscirclebox{1}}

\putnode{n2}{n1}{-10}{-10}{%

\psframebox{2}}

\ncline{->}{n1}{n2}

\end{pspicture}

1

2

Aug 2010 Uday Khedker, IIT Bombay

Page 28: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 18/40

Drawing Pictures Using Pstricks

\usepackage{pstricks}

\usepackage{pst-node}

\usepackage{pst-text}

\usepackage{etex}

\usepackage{pst-rel-points}

%%

\psset{unit=1mm}

\begin{pspicture}(0,0)(50,70)

\psframe(0,0)(50,70)

\putnode{n1}{origin}{25}{50}{%

\pscirclebox{1}}

\putnode{n2}{n1}{-10}{-10}{%

\psframebox{2}}

\ncline[nodesepA=-1]{->}{n1}{n2}

\end{pspicture}

1

2

Aug 2010 Uday Khedker, IIT Bombay

Page 29: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 18/40

Drawing Pictures Using Pstricks\usepackage{pstricks}

\usepackage{pst-node}

\usepackage{pst-text}

\usepackage{etex}

\usepackage{pst-rel-points}

%%

\psset{unit=1mm}

\begin{pspicture}(0,0)(50,70)

\psframe(0,0)(50,70)

\putnode{n1}{origin}{25}{50}{%

\pscirclebox{1}}

\putnode{n2}{n1}{-10}{-10}{%

\psframebox{2}}

\ncline[nodesepA=-1]{->}{n1}{n2}

\nccurve[angleA=270,angleB=90]%

{->}{n2}{n1}

\end{pspicture}

1

2

Aug 2010 Uday Khedker, IIT Bombay

Page 30: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 18/40

Drawing Pictures Using Pstricks\usepackage{pstricks}

\usepackage{pst-node}

\usepackage{pst-text}

\usepackage{etex}

\usepackage{pst-rel-points}

%%

\psset{unit=1mm}

\begin{pspicture}(0,0)(50,70)

\psframe(0,0)(50,70)

\putnode{n1}{origin}{25}{50}{%

\pscirclebox{1}}

\putnode{n2}{n1}{-10}{-10}{%

\psframebox{2}}

\ncline[nodesepA=-1]{->}{n1}{n2}

\nccurve[angleA=300,angleB=60]%

{->}{n2}{n1}

\end{pspicture}

1

2

Aug 2010 Uday Khedker, IIT Bombay

Page 31: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 18/40

Drawing Pictures Using Pstricks\usepackage{pstricks}

\usepackage{pst-node}

\usepackage{pst-text}

\usepackage{etex}

\usepackage{pst-rel-points}

%%

\psset{unit=1mm}

\begin{pspicture}(0,0)(50,70)

\psframe(0,0)(50,70)

\putnode{n1}{origin}{25}{50}{%

\pscirclebox{1}}

\putnode{n2}{n1}{-10}{-10}{%

\psframebox{2}}

\ncline[nodesepA=-1]{->}{n1}{n2}

\nccurve[angleA=300,angleB=60,%

ncurv=2]{->}{n2}{n1}

\end{pspicture}

1

2

Aug 2010 Uday Khedker, IIT Bombay

Page 32: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 18/40

Drawing Pictures Using Pstricks\usepackage{pstricks}

\usepackage{pst-node}

\usepackage{pst-text}

\usepackage{etex}

\usepackage{pst-rel-points}

%%

\psset{unit=1mm}

\begin{pspicture}(0,0)(50,70)

\psframe(0,0)(50,70)

\putnode{n1}{origin}{25}{50}{%

\pscirclebox{1}}

\putnode{n2}{n1}{0}{-10}{%

\psframebox{2}}

\ncline[nodesepA=-1]{->}{n1}{n2}

\nccurve[angleA=300,angleB=60,%

ncurv=2]{->}{n2}{n1}

\end{pspicture}

1

2

Aug 2010 Uday Khedker, IIT Bombay

Page 33: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 19/40

More Pictures Using Pstricks

\newcommand{\sphere}{%

\psset{unit=1mm,arrowsize=6pt}

\begin{pspicture}(0,5)(120,110)

\rput(30,60){%

\pscirclebox*[fillcolor=blue]{%

\rule{5.7cm}{0cm}}}

\rput{-15}(30,60){%

\psovalbox*[fillcolor=lightblue]{%

\rule{4cm}{0cm}\rule{0cm}{1cm}}}

\psline{->}(30,60)(70,50)

\psline{->}(30,60)(30,100)

\psline{->}(30,60)(0,30)

\end{pspicture}}

%%

\scalebox{.6}{\sphere}

Aug 2010 Uday Khedker, IIT Bombay

Page 34: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Pstricks for Drawing Pictures 20/40

A Demo of Using Pstricks

• \ncline, \nccurve \ncloop

• Optional arguments

• Minipage and footnote

• \rnode and connectors between text and picture

Aug 2010 Uday Khedker, IIT Bombay

Page 35: Preparing Slides Using LaTeX, Pstricks, and Beamer

Part 4

Using Beamer for Preparing Slides

Page 36: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 21/40

An Overview of Beamer

• Presentations based on frames consistings of slides

• In beamer terminology, “slides” refers to overlays appearing in aframeFacilitate animations

• Convenient overlay mechanism

• Same source can be compiled to presentations, handouts,documents

• Multiple themes or templates

Aug 2010 Uday Khedker, IIT Bombay

Page 37: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 22/40

Instantiating a Template

• \title[short title]{long title}

• \subtitle[short subtitle]{long subtitle}

• \author[short name]{long name}

• \date[short date]{long date}

• \institution[short name]{long name}

Aug 2010 Uday Khedker, IIT Bombay

Page 38: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 23/40

Template Instantiation for this Presentation

\usetheme{iitb}

%%

\title[LaTeX]{Preparing Slides Using \\ LaTeX, Pstricks,

and Beamer}

\author[Aug 2010]{Uday Khedker}

\institute[Uday Khedker, IIT Bombay]{Department of

Computer Science and Engineering, \\

Indian Institute of Technology, Bombay}

\titlegraphic{\scalebox{.4}{\includegraphics{IITBlogo.epsi}}}

\date[Prabhat Workshop]{August 2010}

Aug 2010 Uday Khedker, IIT Bombay

Page 39: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 24/40

Frames

• A separately numbered page in the presentation

• All overlays (i.e. slides) in a frame share the same page number

• Created by the following options

\begin{frame}[options]\frametitle{Title}

%% LaTeX commands for

%% frame contents

\end{frame}

\frame{

\frametitle{Title}

%% LaTeX commands for

%% frame contents

}

Aug 2010 Uday Khedker, IIT Bombay

Page 40: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 25/40

Useful Options for Frames

• [plain]. No header, title or footer

• [fragile]. Required for using verbatim environment

Aug 2010 Uday Khedker, IIT Bombay

Page 41: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 26/40

Using verbatim Environment

• Use option [fragile] for a frame

• Use minipage

\begin{minipage}{width}\begin{verbatim}

\end{verbatim}\end{minipage}

Aug 2010 Uday Khedker, IIT Bombay

Page 42: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 27/40

Using semiverbatim Environment

• LaTeX commands can be used but text is typeset like verbatim

• Example uses: changing color or size of text

Aug 2010 Uday Khedker, IIT Bombay

Page 43: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 28/40

Creating Overlays

• Common Commands: \only, \onslide, \pause

• Common Environments: \begin{onlyenv} ...\end{onlyenv}

• Common Range Specification:◮ From n to m: <n-m>◮ From n onwards: <n->◮ After the previous one and until m: <+-m>◮ From beginning until m: <-m>◮ On m, n, and i: <m,n,i>

Aug 2010 Uday Khedker, IIT Bombay

Page 44: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 29/40

Overlays in a List

• Explicitly ordered

\begin{itemize}

\item<1-> This is the first item

\item<2-> This is the second item

\item<3-> And this is the third

\end{itemize}

Aug 2010 Uday Khedker, IIT Bombay

Page 45: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 29/40

Overlays in a List

• Explicitly ordered

\begin{itemize}

\item<1-> This is the first item

\item<2-> This is the second item

\item<3-> And this is the third

\end{itemize}

• Implicitly ordered

\begin{itemize}

\item<+-> This is the first item

\item<+-> This is the second item

\item<+-> And this is the third

\end{itemize}

Aug 2010 Uday Khedker, IIT Bombay

Page 46: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 30/40

More on Overlays and Themes

• Excellent examples athttp://www.uncg.edu/cmp/reu/presentations/Charles Batts -Beamer Tutorial.pdf(include spaces in the file name and replace new line by a space)

Aug 2010 Uday Khedker, IIT Bombay

Page 47: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 31/40

Converting Slides to Handouts

• Step 1: Modify the range specifications

◮ If slides that appear between 1 to 5 should appear on handout slide 2<1-5|handout:2>

◮ Slide 6 to 8 should appear only in the presentation but not in thehandout<6-8|handout:0>

◮ Slide 9 onwards should appear only in the handout but not in thepresentation<0|handout:9->

Aug 2010 Uday Khedker, IIT Bombay

Page 48: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Using Beamer for Preparing Slides 32/40

Converting Slides to Handouts

• Step 2: Add handout declarations in the preamble

\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps}

\mode<handout>

{

\usepackage{pgfpages}

\pgfpagesuselayout{4 on 1}[a4paper,landscape,%

border shrink=5mm]

}

• Step 3: Change \documentclass[dvips]beamer to\documentclass[handout]beamer

Aug 2010 Uday Khedker, IIT Bombay

Page 49: Preparing Slides Using LaTeX, Pstricks, and Beamer

Part 5

Some Sample Slides

Page 50: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 33/40

Translation Sequence in Our Compiler: Parsing

a=b<10?b:c;

Input

Aug 2010 Uday Khedker, IIT Bombay

Page 51: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 33/40

Translation Sequence in Our Compiler: Parsing

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

Issues:

• Grammar rules, terminals, non-terminals

• Order of application of grammar rules

eg. is it (a = b<10?) followed by (b:c)?

• Values of terminal symbols

eg. string “10” vs. integer number 10.

Aug 2010 Uday Khedker, IIT Bombay

Page 52: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 34/40

Translation Sequence in Our Compiler: Semantic Analysis

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

Aug 2010 Uday Khedker, IIT Bombay

Page 53: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 34/40

Translation Sequence in Our Compiler: Semantic Analysis

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

=name(a,int) ?: (int)

<

(bool)name(b,int)

name(c,int)

name(b,int)

num(10,int)

Abstract Syntax Tree(with attributes)

Issues:

• Symbol tables

Have variables been declared? What are their types?What is their scope?

• Type consistency of operators and operands

The result of computing b<10? is bool and not int

Aug 2010 Uday Khedker, IIT Bombay

Page 54: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 35/40

Translation Sequence in Our Compiler: IR Generation

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

=name(a,int) ?: (int)

<

(bool)name(b,int)

name(c,int)

name(b,int)

num(10,int)

Abstract Syntax Tree(with attributes)

Aug 2010 Uday Khedker, IIT Bombay

Page 55: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 35/40

Translation Sequence in Our Compiler: IR Generation

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

=name(a,int) ?: (int)

<

(bool)name(b,int)

name(c,int)

name(b,int)

num(10,int)

Abstract Syntax Tree(with attributes)

=

T0<

b 10IfGoto

Not L0:

T0

=

T1 bGoto

L1:=

T1 c

L0:

=

T1a

L1:

Tree List

Issues:

• Convert to maximal trees which can beimplemented without altering control flow

Simplifies instruction selection and scheduling,register allocation etc.

• Linearise control flow by flattening nestedcontrol constructs

Aug 2010 Uday Khedker, IIT Bombay

Page 56: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 36/40

Translation Sequence in Our Compiler: Instruction Selection

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

=name(a,int) ?: (int)

<

(bool)name(b,int)

name(c,int)

name(b,int)

num(10,int)

Abstract Syntax Tree(with attributes)

=

T0<

b 10IfGoto

Not L0:

T0

=

T1 bGoto

L1:=

T1 c

L0:

=

T1a

L1:

Tree List

Aug 2010 Uday Khedker, IIT Bombay

Page 57: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 36/40

Translation Sequence in Our Compiler: Instruction Selection

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

=name(a,int) ?: (int)

<

(bool)name(b,int)

name(c,int)

name(b,int)

num(10,int)

Abstract Syntax Tree(with attributes)

=

T0<

b 10IfGoto

Not L0:

T0

=

T1 bGoto

L1:=

T1 c

L0:

=

T1a

L1:

Tree List

T0 ← bT0 ← T0 < 10T0 ← ! T0

if T0 > 0 goto L0:T1 ← bgoto L1:

L0: T1 ← cL1: a ← T1

Instruction List Issues:

• Cover trees with as fewmachine instructions aspossible

• Use temporaries and localregisters

Aug 2010 Uday Khedker, IIT Bombay

Page 58: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 37/40

Translation Sequence in Our Compiler: Emitting Instructions

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

=name(a,int) ?: (int)

<

(bool)name(b,int)

name(c,int)

name(b,int)

num(10,int)

Abstract Syntax Tree(with attributes)

=

T0<

b 10IfGoto

Not L0:

T0

=

T1 bGoto

L1:=

T1 c

L0:

=

T1a

L1:

Tree List

T0 ← bT0 ← T0 < 10T0 ← ! T0

if T0 > 0 goto L0:T1 ← bgoto L1:

L0: T1 ← cL1: a ← T1

Instruction List

Aug 2010 Uday Khedker, IIT Bombay

Page 59: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 37/40

Translation Sequence in Our Compiler: Emitting Instructions

a=b<10?b:c;

Input

AsgnStmnt

Lhs = E ;

E ? E : E

E < E

name

name name

name numParse Tree

=name(a,int) ?: (int)

<

(bool)name(b,int)

name(c,int)

name(b,int)

num(10,int)

Abstract Syntax Tree(with attributes)

=

T0<

b 10IfGoto

Not L0:

T0

=

T1 bGoto

L1:=

T1 c

L0:

=

T1a

L1:

Tree List

T0 ← bT0 ← T0 < 10T0 ← ! T0

if T0 > 0 goto L0:T1 ← bgoto L1:

L0: T1 ← cL1: a ← T1

Instruction List

lw $t0, 4($fp)slti $t0, $t0, 10not $t0, $t0bgtz $t0, L0:lw $t0, 4($fp)b L1:

L0: lw $t0, 8($fp)L1: sw 0($fp), $t0

Assembly Code

Issues:

• Offsets of variables in thestack frame

• Actual register numbersand assembly mnemonics

• Code to construct anddiscard activation records

Aug 2010 Uday Khedker, IIT Bombay

Page 60: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 38/40

i386 Assembly

Dump file: test.s

jmp .L2

.L3:

addl $1, -4(%ebp)

.L2:

cmpl $7, -4(%ebp)

jle .L3

cmpl $12, -4(%ebp)

jg .L6

movl -8(%ebp), %edx

movl -4(%ebp), %eax

leal (%edx,%eax), %eax

addl -12(%ebp), %eax

movl %eax, -4(%ebp)

.L6:

while (a <= 7)

{

a = a+1;

}

if (a <= 12)

{

a = a+b+c;

}

Aug 2010 Uday Khedker, IIT Bombay

Page 61: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 38/40

i386 Assembly

Dump file: test.s

jmp .L2

.L3:

addl $1, -4(%ebp)

.L2:

cmpl $7, -4(%ebp)

jle .L3

cmpl $12, -4(%ebp)

jg .L6

movl -8(%ebp), %edx

movl -4(%ebp), %eax

leal (%edx,%eax), %eax

addl -12(%ebp), %eax

movl %eax, -4(%ebp)

.L6:

while (a <= 7)

{

a = a+1;

}

if (a <= 12)

{

a = a+b+c;

}

Aug 2010 Uday Khedker, IIT Bombay

Page 62: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 38/40

i386 Assembly

Dump file: test.s

jmp .L2

.L3:

addl $1, -4(%ebp)

.L2:

cmpl $7, -4(%ebp)

jle .L3

cmpl $12, -4(%ebp)

jg .L6

movl -8(%ebp), %edx

movl -4(%ebp), %eax

leal (%edx,%eax), %eax

addl -12(%ebp), %eax

movl %eax, -4(%ebp)

.L6:

while (a <= 7)

{

a = a+1;

}

if (a <= 12)

{

a = a+b+c;

}

Aug 2010 Uday Khedker, IIT Bombay

Page 63: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Some Sample Slides 38/40

i386 Assembly

Dump file: test.s

jmp .L2

.L3:

addl $1, -4(%ebp)

.L2:

cmpl $7, -4(%ebp)

jle .L3

cmpl $12, -4(%ebp)

jg .L6

movl -8(%ebp), %edx

movl -4(%ebp), %eax

leal (%edx,%eax), %eax

addl -12(%ebp), %eax

movl %eax, -4(%ebp)

.L6:

while (a <= 7)

{

a = a+1;

}

if (a <= 12)

{

a = a+b+c;

}

Aug 2010 Uday Khedker, IIT Bombay

Page 64: Preparing Slides Using LaTeX, Pstricks, and Beamer

Part 6

Conclusions

Page 65: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Conclusions 39/40

Conclusions

• LaTeX + Pstricks + Beamer: Magic Potion for MakingPresentations

• We have barely scratched the surface

• Initial learning seems difficult but the payoffs are immense

• Excellent guides and tutorials are available

• All sources and slides of this presentation will be soon uploaded onhttp://www.cse.iitb.ac.in/̃ uday/latex/

Aug 2010 Uday Khedker, IIT Bombay

Page 66: Preparing Slides Using LaTeX, Pstricks, and Beamer

Prabhat Workshop LaTeX: Conclusions 40/40

Last But Not the Least

Thank You!

Aug 2010 Uday Khedker, IIT Bombay