Sunteți pe pagina 1din 37

LYX with Beamer and Sweave

Ziqian Zhou
Department of Statistics University of Iowa

February 21, 2012

Outline
A Introduction to L TEX and LYX

Basic LYX Walkthrough Advanced Topics LYX and Sweave LYX and Beamer (and Sweave) References

A Intro: L TEX

A L TEX (pronounced Lah-tech or Laytech, no s) is a markup language. It is not WYSIWYG What You See Is What You Get

A Figure 1: L TEX Source and Complied PDF

A L TEX, Its Complicated (For Beginners)

A L TEX, Its Complicated (For Beginners)

A L TEX, Its Complicated (For Beginners)

A L TEX, Its Complicated (For Beginners)

A Intro: L TEX

1 2 3 4

A Write L TEX code Compile

View output Return to Step 1 for editing

Intro: LYX

1 2

A LYXis a graphical editor built on top of a L TEX processor. It is not WYSIWYG either. It is WYSIWYM (What You See Is What You Mean) Eg. You CANNOT add distance by adding more than one spaces and you CANNOT change layout by clicking and dragging. A It displays most L TEX eects while editing but it does NOT compile while editing.

Installing LYX

A A working L TEX environment.

Download the latest LYX from lyx.org or install from package manager (linux). This tutorial is based LYX 2.0.2. Alternatively, you can compile LYX directly from source, that enable you to use the latest beta version.

Basic Text Editing

1 2

File -> New (or click icon) Lets type something. Can you type two spaces between two words? Want will \ do? Preview this document by View -> View[PDF(pdatex)] (or click icon)

Figure 2: Basic Text Editing Menu

More Advanced Text Editing


Layout styles list (droplist in the top-left corner in the toolbar)
Add a numbered list and a itemized list. Add title, author and abstract. Add a section.

Text Style
Change the font, size, color and italicize etc.
A What is going on? View the L TEX code: View -> View Source

Figure 3: Advanced Text Editing

More Advanced Text Editing


Layout styles list (droplist in the top-left corner in the toolbar)
Add a numbered list and a itemized list. Add title, author and abstract. Add a section.

Text Style
Change the font, size, color and italicize etc.
A What is going on? View the L TEX code: View -> View Source

Figure 3: Advanced Text Editing

Figure and Table


1

A Directly insert a picture or table. (Equivalent to L TEX code \includegraphics and \begin{tabular}) Insert -> Table or Insert -> Graphics Floating tables and gures will be placed automatically to achieve best layout.
1

2 3

4 5

Insert -> Float -> Figure/Table A (Equivalent to L TEX figure and table environment.) Insert the table or graphics. For graphics: In the dialog, you can set scaling, rotations etc. Reopen this dialog by clicking the graphics. Use Paragraphic Setting to put it at the center. Right click the gray oat label to change placement options.

Figure 4: Float Label

Figure 5: Paragraph Setting

Math Editor
1 2

Simply click on Insert -> Math -> Inline formula or Display formula.
A Start typing! Like you do in L TEX. LYX will automatically complete math command for you.

Figure 6: Math Completion


3

Use math toolbar. View -> Toolbars -> Math etc. You can insert matrix, case and symbols by clicking. Dene math marco: Insert -> Math -> Marco

Export To Dierent Formats

A If you have an existing L TEX le, you can import it into LYX You can also import Table(CSV), RTF le, and ?Sweave? File -> Import A Since LYXuses L TEX engine, it can be exported .tex source le and any A format L TEX supports. Eg. DVI, HTML, Open Document, etc. You can choose to use many dierent typesetting engines. (Default is pdatex) File -> Export

Cross Reference
1 2

Insert -> Label (\label{}) name a formula gure or table. Insert -> Cross-reference (\ref{}) to refer to it. (Figure 7)

Figure 7: Basic Text Editing Menu

Citation

Go to the place in your document where you want the references to be presented (presumably, the end. You can also have reference at the end of each section). Insert -> Lists & TOC -> BibTEX Bibliography In the dialog, add -> browse look for the .bib le where your bibliography is stored. You can add multiple libraries... Back in Menu, change style. See various styles in http://www.mackichan.com/index.html? techtalk/632.htm~mainFrame Insert -> Citation to cite in the text.

3 4

Citation with Zotero/LyZ

1 2

If you use Zotero and LYX, you should use LyZ to connect them. Zotero is a Firefox plugin that allows you to collect and manage citation info, abstract, PDF from arXiv.org, journal website or library/amazon catalog. LyZ is a plug-in that connects Zotero and LYX. The citation information in Zotero can be exported to BibTex le and the LYX document by one-click. Instructions see: http://www.klubko.net/wp/?page_id=945&lang=en

Document Settings

Document -> Setting


1 2 3

A Document Class: setting L TEX preamble \documentclass Page Layout: choose page size etc.

Float Placement: Eg: Set global oat placement to be Here denitely. ( \begin{Figure}[H] ) Change default font, bullet style, color, page margin etc.

A L TEX Code, ERT and Preamble

A What if there isnt a button corresponding to the L TEX command you want?
1 2

3 2

A You CANNOT change the L TEX source directly. A You insert raw LTEX command as ERT (Evil Red Text) in your document. A Or, you can insert raw L TEX command into document preamble.

A Drawbacks of using raw L TEX code:


1 2 3

A LYXwill not be able to display the result of raw L TEX code. A Inserting raw LTEX code will make it more error-prone. If you have a full latex le, importing it into LYXwould be better.

A L TEX Code, ERT and Preamble

Preamble A Document -> Settings -> L TEX Preamble If package simpsons has been installed, add: \usepackage{simpsons} When to use ERT?
A You have a big trunk of L TEX code (e.g. a table) 3 When you want to do something fancy, like this, add [3] after the \item. 2 Or when you want to use commands from third-party packages.
1

\Bart


\Left\Homer

Key Bindings
A LYX is not faster than a good L TEX editor. AUCTEX in Emacs has key binding for fonts, environments and math symbols. Customized key bindings in LYX: Preference -> Editing -> Shortcuts Choose shortcut style and search for key-bindings

Figure 8: Change Key Bindings

Sweave

Sweave is a tool in the R language for dynamic report generation.


A R code can be mixed into a L TEX document. It will be executed in R. The results are written into the TEX output.

Workow
A .Rnw le contains L TEX and R codes

In R, run Sweave("file.Rnw"). working directory.

Note .Rnw le must be in the R

A file.tex le will be generated, compile to obtain PDF.

Sweave
R code chunk begins after <<>>= and ends before @ In R, run: Sweave(file.Rnw) to generate a file.tex le.

Figure 9: A Look at .Rnw source code and output

Use Sweave in LYX

1 2

Document -> Settings -> Modules Select Sweave Set global Sweave options at the beginning of the document: Insert -> Custom Insets -> Sweave Options E.g. echo=FALSE to suppress all R code Write R code in LYX: Switch to the Chunk environment in the layout styles list.

For more detail: Ocial LyX manual for Sweave. (Do not use tutorials based on LYX version 1.X)

Beamer

A Beamer is a L TEX class for creating slides for presentations. This presentation is made using Beamer in LYX.

To use Beamer in LYX: Document -> Settings -> Document Classes: Choose Presentation (Beamer ) The better way: modify a template.
Beamer examples: http://wiki.lyx.org/Examples/Beamer LYX le for this presentation: http://www.stat.uiowa.edu/~ziqzhou/files/lyx-how-to.lyx

Frames and Overlays

Frames are the environment for dening slides. You can do basically anything (and more) in frames that you can do in a A simple L TEX document To add a frame: Switch to the BeginFrame environment in the layout styles list This allows you to present things in any order. You can also use overlay specications to create overlays. Add ERT <4-> after \item if you want this to the 4th item to appear.

Frames and Overlays

Frames are the environment for dening slides. You can do basically anything (and more) in frames that you can do in a A simple L TEX document To add a frame: Switch to the BeginFrame environment in the layout styles list This allows you to present things in any order. You can also use overlay specications to create overlays. Add ERT <4-> after \item if you want this to the 4th item to appear.

Frames and Overlays

Frames are the environment for dening slides. You can do basically anything (and more) in frames that you can do in a A simple L TEX document To add a frame: Switch to the BeginFrame environment in the layout styles list This allows you to present things in any order. You can also use overlay specications to create overlays. Add ERT <4-> after \item if you want this to the 4th item to appear.

Frames and Overlays

Frames are the environment for dening slides. You can do basically anything (and more) in frames that you can do in a A simple L TEX document To add a frame: Switch to the BeginFrame environment in the layout styles list This allows you to present things in any order. You can also use overlay specications to create overlays. Add ERT <4-> after \item if you want this to the 4th item to appear.

Blocks and Theorems

A Eample Block
You can have boxed texts by using Block or Theorem Switch to various Block or Theorems environment in the layout styles list.

Theorem
Insert pause environment from the layout styles list to achieve an overlay eect.

Blocks and Theorems

A Eample Block
You can have boxed texts by using Block or Theorem Switch to various Block or Theorems environment in the layout styles list.

Theorem
Insert pause environment from the layout styles list to achieve an overlay eect.

We can use Sweave and Beamer together in LYX Set Document Class to presentation (beamer) Add Sweave module. There is an incompatibility between Sweave and Beamer. Need to install and use Beamer Fragile module. For more information about how to install it: http://wiki.lyx.org/Layouts/Modules

Use Fragile Frame with Sweave output

To use a Fragile Frame:


Create a new paragraph and insert an EndFrame environment Then create another paragraph and access Insert > Custom Insets > FragileFrame If you want to use a title for the frame, then within the Fragile Frame inset do Insert > Custom Insets > FragileTitle

An example of verbatim Sweave results:

Some Sweave code


> (x <- 2 + 2) [1] 4

Use Fragile Frame with Sweave output

To use a Fragile Frame:


Create a new paragraph and insert an EndFrame environment Then create another paragraph and access Insert > Custom Insets > FragileFrame If you want to use a title for the frame, then within the Fragile Frame inset do Insert > Custom Insets > FragileTitle

An example of verbatim Sweave results:

Some Sweave code


> (x <- 2 + 2) [1] 4

References

Yihui Xies Sweave-LyX page Ocial LyX manual for Sweave. Use Sweave in Beamer: Beamer Fragile Module Some LYX tricks: http://www2.warwick.ac.uk/fac/soc/ economics/staff/phd_students/yerushalmi/computing/lyx/ LYX wiki tutorial page: http://wiki.lyx.org/LyX/Tutorials

S-ar putea să vă placă și