lyx guide
DESCRIPTION
tutorial about lyxTRANSCRIPT
LYX with Beamer and Sweave
Ziqian Zhou
Department of StatisticsUniversity of Iowa
February 21, 2012
Outline
1 Introduction to LATEX and LYX
2 Basic LYX Walkthrough
3 Advanced Topics
4 LYX and Sweave
5 LYX and Beamer (and Sweave)
6 References
Intro: LATEX
LATEX (pronounced “Lah-tech” or “Lay–tech”, no “s”) is a markuplanguage. It is not WYSIWYG – What You See Is What You Get
Figure 1: LATEX Source and Complied PDF
LATEX, It’s Complicated (For Beginners)
LATEX, It’s Complicated (For Beginners)
LATEX, It’s Complicated (For Beginners)
LATEX, It’s Complicated (For Beginners)
Intro: LATEX
1 Write LATEX code2 Compile3 View output4 Return to Step 1 for editing
Intro: LYX
1 LYXis a graphical editor built on top of a LATEX processor.2 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 andyou CANNOT change layout by clicking and dragging.
3 It displays most LATEX effects while editing but it does NOT compilewhile editing.
Installing LYX
A working LATEX environment.Download the latest LYX from lyx.org or install from packagemanager (linux). This tutorial is based LYX 2.0.2.Alternatively, you can compile LYX directly from source, that enableyou to use the latest beta version.
Basic Text Editing
1 File -> New (or click icon)2 Let’s type something. Can you type two spaces between two words?
Want will “\” do?3 Preview this document by View -> View[PDF(pdflatex)] (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 StyleChange the font, size, color and italicize etc.
What is going on? View the LATEX 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 StyleChange the font, size, color and italicize etc.
What is going on? View the LATEX code: View -> View Source
Figure 3: Advanced Text Editing
Figure and Table1 Directly insert a picture or table. (Equivalent to LATEX code
\includegraphics and \begin{tabular})Insert -> Table or Insert -> Graphics
2 Floating tables and figures will be placed automatically to achieve bestlayout.
1 Insert -> Float -> Figure/Table(Equivalent to LATEX figure and table environment.)
2 Insert the table or graphics.3 For graphics: In the dialog, you can set scaling, rotations etc. Reopen
this dialog by clicking the graphics.4 Use Paragraphic Setting to put it at the center.5 Right click the gray float label to change placement options.
Figure 4: Float Label Figure 5: Paragraph Setting
Math Editor
1 Simply click on Insert -> Math -> Inline formula or Display formula.2 Start typing! Like you do in LATEX. LYX will automatically complete
math command for you.
Figure 6: Math Completion
3 Use math toolbar. View -> Toolbars -> Math etc. You can insertmatrix, case and symbols by clicking.
4 Define math marco: Insert -> Math -> Marco
Export To Different Formats
1 If you have an existing LATEX file, you can import it into LYXYou can also import Table(CSV), RTF file, and ?Sweave?File -> Import
2 Since LYXuses LATEX engine, it can be exported .tex source file and anyformat LATEX supports.Eg. DVI, HTML, Open Document, etc.You can choose to use many different typesetting engines. (Default ispdflatex)File -> Export
Cross Reference1 Insert -> Label (\label{}) name a formula figure or table.2 Insert -> Cross-reference (\ref{}) to refer to it. (Figure 7)
Figure 7: Basic Text Editing Menu
Citation
1 Go to the place in your document where you want the references to bepresented (presumably, the end. You can also have reference at theend of each section). Insert -> Lists & TOC -> BibTEX Bibliography
2 In the dialog, add -> browse look for the .bib file where yourbibliography is stored.You can add multiple libraries...
3 Back in Menu, change style.4 See various styles in http://www.mackichan.com/index.html?
techtalk/632.htm~mainFrame5 Insert -> Citation to cite in the text.
Citation with Zotero/LyZ
1 If you use Zotero and LYX, you should use LyZ to connect them.2 Zotero is a Firefox plugin that allows you to collect and manage
citation info, abstract, PDF from arXiv.org, journal website orlibrary/amazon catalog.
3 LyZ is a plug-in that connects Zotero and LYX.The citation information in Zotero can be exported to BibTex file andthe LYX document by one-click.
4 Instructions see:http://www.klubko.net/wp/?page_id=945&lang=en
Document Settings
Document -> Setting1 Document Class: setting LATEX preamble \documentclass2 Page Layout: choose page size etc.3 Float Placement: Eg: Set global float placement to be Here definitely.
( \begin{Figure}[H] )4 Change default font, bullet style, color, page margin etc.
LATEX Code, ERT and Preamble
1 What if there isn’t a button corresponding to the LATEX command youwant?
1 You CANNOT change the LATEX source directly.2 You insert raw LATEX command as ERT (Evil Red Text) in your
document.3 Or, you can insert raw LATEX command into document preamble.
2 Drawbacks of using raw LATEX code:1 LYXwill not be able to display the result of raw LATEX code.2 Inserting raw LATEX code will make it more error-prone.3 If you have a full latex file, importing it into LYXwould be better.
LATEX Code, ERT and Preamble
1 PreambleDocument -> Settings -> LATEX PreambleIf package simpsons has been installed, add:\usepackage{simpsons}
2 When to use ERT?1 You have a big trunk of LATEX 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.
\Bart
� ��\Left\Homer
���
Key BindingsLYX is not faster than a good LATEX editor.AUCTEX in Emacs has key binding for fonts, environments and mathsymbols.Customized key bindings in LYX: Preference -> Editing -> ShortcutsChoose 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.I R code can be mixed into a LATEX document.I It will be executed in R.I The results are written into the TEX output.
Workflow.Rnw file contains LATEX and R codesIn R, run Sweave("file.Rnw"). Note .Rnw file must be in the Rworking directory.A file.tex file 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 file.
Figure 9: A Look at .Rnw source code and output
Use Sweave in LYX
1 Document -> Settings -> Modules Select Sweave2 Set global Sweave options at the beginning of the document:
Insert -> Custom Insets -> Sweave OptionsE.g. echo=FALSE to suppress all R code
3 Write R code in LYX:Switch to the Chunk environment in the layout styles list.
For more detail: Official LyX manual for Sweave.(Do not use tutorials based on LYX version 1.X)
Beamer
Beamer is a LATEX 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.
I Beamer examples: http://wiki.lyx.org/Examples/BeamerI LYX file for this presentation:
http://www.stat.uiowa.edu/~ziqzhou/files/lyx-how-to.lyx
Frames and Overlays
Frames are the environment for defining ’slides’.You can do basically anything (and more) in frames that you can do in asimple LATEX document
To add a frame:Switch to the BeginFrame environment in the layout styles listThis allows you to present things in any order.You can also use overlay specifications 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 defining ’slides’.You can do basically anything (and more) in frames that you can do in asimple LATEX document
To add a frame:Switch to the BeginFrame environment in the layout styles listThis allows you to present things in any order.You can also use overlay specifications 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 defining ’slides’.You can do basically anything (and more) in frames that you can do in asimple LATEX document
To add a frame:Switch to the BeginFrame environment in the layout styles listThis allows you to present things in any order.You can also use overlay specifications 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 defining ’slides’.You can do basically anything (and more) in frames that you can do in asimple LATEX document
To add a frame:Switch to the BeginFrame environment in the layout styles listThis allows you to present things in any order.You can also use overlay specifications to create overlays.Add ERT <4-> after \item if you want this to the 4th item to appear.
Blocks and Theorems
A Eample BlockYou can have boxed texts by using Block or TheoremSwitch to various Block or Theorems environment in the layout styleslist.
TheoremInsert pause environment from the layout styles list to achieve an overlayeffect.
Blocks and Theorems
A Eample BlockYou can have boxed texts by using Block or TheoremSwitch to various Block or Theorems environment in the layout styleslist.
TheoremInsert pause environment from the layout styles list to achieve an overlayeffect.
We can use Sweave and Beamer together in LYXSet Document Class to presentation (beamer)Add Sweave module.There is an incompatibility between Sweave and Beamer. Need toinstall 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’:I Create a new paragraph and insert an ’EndFrame’ environmentI Then create another paragraph and access Insert > Custom Insets >
FragileFrameI 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’:I Create a new paragraph and insert an ’EndFrame’ environmentI Then create another paragraph and access Insert > Custom Insets >
FragileFrameI 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 Xie’s Sweave-LyX pageOfficial LyX manual for Sweave.Use Sweave in Beamer: Beamer Fragile ModuleSome 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