Lyx Tutorial
Lyx Tutorial
August 3, 2010
1 If
you have comments or error corrections, please send them to the LYX Doc-
umentation mailing list, [email protected].
2
Contents
1 Introduction 1
1.1 Welcome to LYX! . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 What the Tutorial is and what it isn’t . . . . . . . . . . . . . 1
1.2.1 Getting the most out of the Tutorial . . . . . . . . . . 2
1.2.2 What you won’t find . . . . . . . . . . . . . . . . . . . 2
3 Writing Documents 11
3.1 Document Classes . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Templates: Writing a Letter . . . . . . . . . . . . . . . . . . . 12
3.3 Document Titles . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Labels and Cross-References . . . . . . . . . . . . . . . . . . . 14
3.4.1 Your first label . . . . . . . . . . . . . . . . . . . . . . 14
3.4.2 Your first cross-reference . . . . . . . . . . . . . . . . . 15
3.4.3 More fun with labels . . . . . . . . . . . . . . . . . . . 15
3.5 Footnotes and Margin Notes . . . . . . . . . . . . . . . . . . . 16
3.6 Bibliographies . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.7 Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . 18
i
ii CONTENTS
4 Using Math 19
4.1 Math Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 Navigating an Equation . . . . . . . . . . . . . . . . . . . . . 20
4.3 Exponents and Indices . . . . . . . . . . . . . . . . . . . . . . 21
4.4 The Math Toolbar . . . . . . . . . . . . . . . . . . . . . . . . 21
4.4.1 Greek and symbols . . . . . . . . . . . . . . . . . . . . 21
4.4.2 Square roots, accents, and delimiters . . . . . . . . . . 22
4.4.3 Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.4.4 TEX mode: Limits, log, sin and others . . . . . . . . . 23
4.4.5 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.4.6 Display mode . . . . . . . . . . . . . . . . . . . . . . . 24
4.5 More Math Stuff . . . . . . . . . . . . . . . . . . . . . . . . . 25
5 Miscellaneous 27
5.1 Other major LYX Features . . . . . . . . . . . . . . . . . . . . 27
5.2 LYX for LATEX Users . . . . . . . . . . . . . . . . . . . . . . . 28
5.2.1 TEX Mode . . . . . . . . . . . . . . . . . . . . . . . . 28
5.2.2 Importing LATEX Documents — tex2lyx . . . . . . . . 29
5.2.3 Converting LYX Documents to LATEX . . . . . . . . . . 30
5.2.4 LATEX Preamble . . . . . . . . . . . . . . . . . . . . . . 30
5.2.5 BibTEX . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.3 Errors! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Chapter 1
Introduction
1
2 CHAPTER 1. INTRODUCTION
3
4 CHAPTER 2. GETTING STARTED WITH LYX
• Run LATEX to create a DVI file, with View . DVI or the toolbar button
. LYX will open a DVI-viewer program displaying your document
looking like when printed.3
• Export the ready to print document with File . Export to a format you
want.
Congratulations! You’ve written your first LYX document. All of the rest is
just details, which is covered in the other manuals.
Undo LYX has multiple levels of undo, which means you can undo every-
thing you’ve done since your current editing session started, by selecting
3
You can save time by leaving the DVI-viewer running in the background. Then, you
can use View . Update . DVI or the toolbar button and just click on the DVI-viewer
window (or unminimize it) after LATEX finishes running.
2.1. YOUR FIRST LYX DOCUMENT 5
Edit . Undo (toolbar button ) over and over again. If you undo too
much, just select Edit . Redo (toolbar button ) to get it back.
Currently, undo is limited to 100 steps. Undo also doesn’t work for
everything; for instance, not for changes to the document layout what
is really a LYX bug.
Toolbar There are buttons on the toolbar (just below the menus) which
allow you to do some of the more popular functions, such as Paste and
Print.
Of course, you haven’t yet written enough to make most of these functions
useful. As you write more, though, try undoing, pasting, etc.
blank line. As many times as you hit Space, you’ll only get one space. On a
blank line, LYX won’t let you type even one space. The Tab key won’t move
you forward one tab stop; in fact there are no tab stops! There’s no ruler at
the top of the page to let you set tabs or margins, either.
Many word processors are based on the WYSIWYG principle: “What You
See Is What You Get.” LYX, on the other hand, is based on the principle
that “What You See Is What You Mean.” You type what you mean, and
LYX will take care of typesetting it for you, so that the output looks nice.
A Return grammatically separates paragraphs, and a Space grammatically
separates words, so there is no reason to have several of them in a row; a
Tab has no grammatical function at all, so LYX does not support it. Using
LYX, you’ll spend more of your time worrying about the content of your
document, and less time worrying about the format. See the Introduction
for more information on the WYSIWYM concept.
LYX does have (many) ways to fine-tune the formatting of your document.
After all, LYX might not typeset exactly what you mean. The User’s Guide
has information about all that. It includes HFills and vertical space — which
are more powerful and versatile than multiple spaces or blank lines — and
ways to change font sizes, character styles, and paragraph alignments by
hand. The idea, though, is that you can write your whole document, focusing
on content, and just worry about that fine-tuning at the end. With standard
word processors, you’ll be distracted by document formatting throughout the
writing process.
2.2 Environments
Different parts of a document have different purposes; we call these parts
environments. Most of a document is made up of regular text. Section titles
(chapter, subsection, etc.) let the reader know that a new topic or subtopic
will be discussed. Certain types of documents have special environments. A
journal article will have an abstract and a title. A letter will have neither of
these, but will probably have an environment that gives the writer’s address.
Environments are a major part of the “What You See Is What You Mean”
philosophy of LYX. A given environment may require a certain font style, font
size, indenting, line spacing, and more. This problem is aggravated, because
the exact formatting for a given environment may change: one journal may
use boldface, 18 point, centered type for section titles while another uses
2.2. ENVIRONMENTS 7
italicized, 15 point, left justified type; different languages may have different
standards for indenting; and bibliography formats can vary widely. LYX lets
you avoid learning all the different formatting styles.
The Environment choice box is located on the left end of the toolbar and
looks like this: . It indicates which environment you’re
currently writing in. While you were writing your first document, it said
“Standard,” which is the default environment for text. Now you will put a
number of environments in your new document so that you can see how they
work.
Hit Return again, and select Section from the Environment box again. LYX
writes a “2” and waits for you to type a title. Type “More Stuff”, and you’ll
see that LYX again sets it as a section title.
It gets better. Go to the end of Section 1 again (after “my first LYX
document”) and hit Return again, and select Section from the Environment box
again. Again, LYX writes “2” and waits for you to type a title. Type About
This Document. Section “More Stuff”, which used to be Section 2, has been
automatically renumbered to Section 3! In true WYSIWYM fashion, you
just need to identify the text that makes up the section titles, and LYX takes
care of numbering the sections and typesetting them.
Hit Return to get back to the Standard environment, and type the following
five lines:
5
You don’t have to select the line. If nothing is selected, LYX changes the paragraph
you are currently in to the selected environment. Alternatively, you can change several
paragraphs to a different environment by selecting them before picking an environment.
8 CHAPTER 2. GETTING STARTED WITH LYX
Click on the second line and select Subsection from the Environment box.
LYX numbers the subsection “2.1”, and typesets it in a font which is big-
ger than regular text but smaller than the section title. Change the fourth
line Subsection environment as well. As you probably expected, LYX auto-
matically numbered the section “2.2”. If you put yet another section before
Section 2, Section 2 will be renumbered as Section 3, and the subsections
will be renumbered to “3.1” and “3.2”.
Further levels of sectioning include Subsubsection, Paragraph, and Sub-
paragraph. We’ll let you play with these on your own. You may notice that
paragraph and subparagraph headings are not numbered by default, and that
subparagraphs are indented; see the User’s Guide for an explanation and how
to change this. Chapter headings are actually the highest level of sectioning,
above Sections, but you’re only allowed to use them in certain types (text
classes) of LYX documents (see Section 3.1).
Finally, you may want to have sections or subsections that are not num-
bered. There are environments for this as well. If you change one of your
section headings to the Section* environment (you may have to scroll down in
the Environment box to find it), LYX will use the same font size for the head-
ing as it uses for a regular section, but it won’t number that section. There
are corresponding “starred” heading environments for Subsection and Sub-
subsection. Try changing some of your sections or subsections to the starred
environments, and note how the other sections’ numbers are updated.
Exercise: Fix the section and subsection headings in example_raw.lyx.
List environments, unlike headings, do not end when you type Return. In-
stead, LYX assumes you’re going on to the next item in the list. The above
will therefore result in a three-item list. If you want more than one paragraph
within one list item, one way is to use the Protected Break, which you get by
typing Ctrl+Return. In order to get out of the list, you need to reselect the
Standard environment (or just use the keybinding, Alt+P S).
You’ve got a beautiful itemized list. You might want to run LATEX to
see how the list looks when printed out. But what if you wanted to number
the reasons? Well, just select the whole list6 and choose Enumerate from the
Environment box. Pow! As we mentioned, if you add or delete a list item,
LYX will fix the numbering.
While the list is still selected, you can change to the other two list en-
vironments, Description and List, in order to see what they look like. For
6
LYX won’t let you select the first bullet unless you also select the paragraph before the
list, which you probably don’t want to do. Similarly, you can’t select the actual number
in a numbered section title. This is on purpose because the bullet or number depends on
the document settings or text position, respectively.
10 CHAPTER 2. GETTING STARTED WITH LYX
those two environments, each list item is made up of a term, which is the
item’s first word, followed by a definition, which is the rest of the paragraph
(until you hit Return.) The term is either typeset in boldface (Description)
or separated by a “Tab”7 (List) from the rest of the paragraph. If you want
to have more than one word in the definition, then separate the words with
Protected Blanks.
Exercise: Typeset the list in example_raw.lyx
You can nest lists within each other in all sorts of interesting ways. An
obvious example would be writing outlines. Numbered and bulleted lists will
have different numbering and bulleting schemes for sublists. See the User’s
Guide for details on the different sorts of lists and for examples of nestings.
7
But a typesetter’s tab, which will change to fit the size of the largest term, not a
pathetic, rigid, unchangeable typewriter Tab.
8
used in this Tutorial for the long typing examples
Chapter 3
Writing Documents
The previous chapter hopefully allowed you to get used to writing in LYX. It
introduced you to the basic editing operations in LYX, as well as the powerful
method of writing with environments. Most people who use LYX, though,
will want to write documents: papers, articles, books, manuals, or letters.
This chapter is meant to take you from simply writing text with LYX to
writing a complete document. It will introduce you to text classes, which
allow you to write different sorts of documents. It will then describe many of
the additions that turn text into a document, such as titles, footnotes, cross
references, bibliographies, and tables of contents.
11
12 CHAPTER 3. WRITING DOCUMENTS
Try changing to other document classes (using the Document . Settings dia-
log) to see how they are typeset differently. If you change your document
to the Book document class and look at the Environment box, you’ll see that
most of the allowed environments are the same. However, you can now use
the Chapter environment. If you are ever unsure about which environments
you can use in a given document class, just consult the Environment box.
Font sizes, one- or two-column printing, and page headings are just some
of the ways journals’ typesettings differ from one another. As the Computer
Age continues to mature, journals have begun accepting electronic submis-
sions, creating LATEX “style files” so that authors can submit correctly typeset
articles. LYX is set up to support this as well. For example, LYX supports
typesetting (and extra environments) for the American Mathematics Society
journals using the Article (AMS) document class.
Here is a very quick reference to some of the document classes. See the
Special Document Classes section of the Additional Features manual for many
more details.
Name Notes
article one-sided, no chapters
article (AMS) layout & environments for American Math Society
report longer than article, two-sided
book report + front and back matter
presentation transparencies
letter lots of extra environments for address, signature. . .
When you look at the Environment box, you’ll see several environments,
like the My Address environment, which don’t even exist in most other docu-
ment classes. Others, like Quote and Description, are familiar. You can play
around for a while to figure out how the various environments work. You’ll
notice for example that the Signature environment has the word “Signature:“
in red before the actual text of the signature. This word doesn’t show up in
the actual letter, as you’ll see if you view/export the file. It’s just there to let
you know where the signature goes. Also, note that it doesn’t matter where
in the file the Signature line is placed. Remember, LYX is WYSIWYM; you
can put the Signature environment anywhere you want, but LYX knows that
in the printout, the signature should be at the end.
A template is just a regular LYX file. This means you can fill in your
address and signature and save the file as a new template. From now on,
any time you want to write a letter, you can use the new template to save
time. We don’t have to suggest an actual “exercise” here; just write a letter
to someone!3
Templates can be a huge time-saver, and we urge you to use them when-
ever possible. In addition, they can help a person learn how to use some of
the fancier document classes. Finally, they may be useful for a person who is
configuring LYX for a bunch of less computer-aware users. When they’re first
learning LYX, it will be much less intimidating if they have a letter template
customized for their company, for example.
environment. On the next line, write the date in the Date environment. Type
a paragraph or two summarizing your document using the Abstract environ-
ment. Notice how the title is presented when it’s printed out. If you changed
the document format to Book, you’ll get a separate title page, like the first
page of this tutorial.
Exercise: Fix the title, date, and author in example_raw.lyx
Now set the cursor after the word “section” and choose Insert . Cross Reference
or the toolbar button . The Cross-reference dialog pops up. It shows a list
of the possible labels you can reference. At the moment, there should be only
one, “sec:About-This-Document”. Select it (it may be selected by default),
and click Apply. Now put the cursor after the word “page”, and change the
reference format to use the page number then click Apply. (To be really
correct, you should put a Protected Blank in between the word “Section” and
the reference. Same for the page reference.)
Alternatively to that method, you can right-click on a label and use in
the appearing context menu Copy as Reference. The cross-reference to this
label is now in the clipboard and can be copied to the actual cursor position
via the menu Edit . Paste (shortcut Ctrl+V).
LYX puts the references in a box right where the cursor was. In the
printed document, this reference marker will be replaced with either the page
or section number (depending on what you selected in the Cross-reference
dialog). View your document as DVI, and you’ll see that on the last page we
refer to “Section 2” and “Page 1” (or whatever page Section 2’s title is on).
Conveniently, a cross-reference acts as a hyperlink when you are editing
a document in LYX; clicking on it will pop up the Cross-Reference dialog,
clicking Go to Label will move the cursor to the referenced label.
Now click on the button labelled “foot”. The footnote box is closed, leaving
the button showing where the footnote marker will be in the printed text;
this is called “folding” the footnote. You can unfold the footnote at any time
and re-edit its text by clicking again on the “foot” button.
You may wonder why the footnote button is a word instead of a number.
The answer is that LYX takes care about the footnote numbering for you
in the printed text. You can see this yourself by looking at the DVI file (or
printout). If you add other footnotes, LYX will renumber the footnotes. Since
LYX (well, LATEX, actually) takes care of the footnote numbering, there’s
really no need to put the numbers in the LYX file.
A footnote can be cut and pasted like normal text. Go ahead; try it!
All you need to do is select the footnote button7 and Cut and Paste it. In
addition, you can change regular text to a footnote, by selecting it and hitting
the button; change a footnote to regular text by hitting the Backspace key
when the cursor is in the first position of a footnote, or by hitting the Delete
key when the cursor is in the very last position of the footnote, respectively.
6
By the way, copying a chapter title may cause an error, because chapters aren’t allowed
in the article class, see section 3.1. If this happens, just delete the chapter title.
7
It may be easier to select it using the keyboard. You might accidentally open the
footnote if you’re trying to select the marker itself with the mouse.
3.6. BIBLIOGRAPHIES 17
Margin notes can be added using the menu Insert . Marginal Note or the
toolbar button . Margin notes are like footnotes, except that:
• the notes will be placed in the margin, instead of below the text
Change your LYX footnote back to text, then select and change it to a margin
note. Run LATEX again to see what the margin note looks like.
Exercise: Fix the footnote in example_raw.lyx
3.6 Bibliographies
Bibliographies (at least in the exact sciences) are similar to cross references.
The bibliography contains a list of references at the end of the document, and
they can be referenced from within the document. Like section titles, LYX
and LATEX make your job easier by automatically numbering the bibliography
items and changing citations when the item numbers change.
Go to the end of the document and switch to the Bibliography environ-
ment. Now, each paragraph you type will be a reference. Type “The Lyx
Tutorial, by the LYX Documentation Team” as your first reference. Note
that LYX automatically puts a number in a box before each reference. Click
on the boxed reference number, and the Bibliography item dialog box appears.
The Key is to refer to this reference within the LYX document, the Label ap-
pears in output. When no Label is set (default), you will see the number of
the bibliography in the output. Change now the Key field to “lyxtutorial” to
make it easy to remember.
Now pick somewhere in your document that you would like to insert a
reference. Do so with Insert . Citation or the toolbar button . A Citation
dialog appears. The right panel in this dialog lists all the bibliography entries,
and this field allows you to choose which bibliography item you want to cite.
Select “lyxtutorial” (right now, that’s the only item in the bibliography),
then use the Add button in the center to insert it. (You can have multiple
citations in the same place by transferring a number of keys this way.) Now
view your file as DVI, and you’ll see that the citation appears in brackets in
the text, referring to the bibliography at the end of the document.
18 CHAPTER 3. WRITING DOCUMENTS
The Text after field in the Citation dialog will put a remark (such as a
reference to a page or chapter within the referenced book or article) in the
brackets after the reference. If you want the references to have labels instead
of numbers in the printed output (for example, some journals would use
“[Smi95]” to refer to a paper written by Smith in 1995), use the Label field
in the Bibliography item dialog. As usual, see the User’s Guide for details.
Exercise: Fix the bibliography and citation in example_raw.lyx
Using Math
Now, that equation doesn’t look very good in LYX and in the output; there’s
no space between the letters and the equals sign, and you’d like to write an
actual superscript for the “2”. That bad typesetting happened because we
didn’t tell LYX that we were writing a mathematical expression, so it typeset
the equation like regular old text.
Instead, we create a formula that will get typeset properly. In order to
create a formula, just click the toolbar button or use the menu Insert .
Math . Inline Formula. LYX will insert a little blue square, which is an empty
19
20 CHAPTER 4. USING MATH
math formula. Now just type E=mc^2 again. The expression is typed in blue,
and the blue square disappears as soon as the formula is not empty. Now
type Esc to leave the equation The purple markers disappear, leaving the
cursor to the right of the expression, and now if you type something, it will
be regular text.
Run LATEX and look at the output. Notice that the expression was typeset
nicely, with spaces between the letters and the equals sign, and a superscript
“2”. Letters in math mode are assumed to be variables, and come out in
italics. Numbers are just numbers.
This math editor is another example of the WYSIWYM philosophy. In
L TEX, you write a mathematical expression using text and commands like
A
\sqrt; this can be frustrating, because you can’t see what an expression
looks like until you LATEX the file, and may have to spend time to find e. g.
missing brackets. LYX doesn’t attempt to get the expression to look perfect
(WYSIWYG), but it gives you an extremely good idea of what the expression
will look like. LATEX then takes care of the professional typesetting.
4.4.3 Fractions
Of course you can type anything within each of the two boxes: variables with
exponents, square roots, other fractions, whatever.
Exercise: Put equation 2 of example_raw.lyx into math mode.
4.4.5 Matrices
Click on the matrix button in the Math Toolbar. The appearing dialog
allows you to choose how many rows and columns you want in your matrix.
Choose 2 rows and 3 columns and hit OK. LYX prints 6 insertion points in a
2 × 3 matrix. As usual, you can put any sort of formula expression (a square
root, another matrix, etc.) in each insertion point. You can also leave some
of the insertion points empty if you want.
Tab can be used to move horizontally between the columns of a matrix.
Alternatively, you can use the arrow keys to move around - hitting Right at
the end of one box will move to the next box, Down will move to the next
row, etc.
24 CHAPTER 4. USING MATH
If you need to change the number of rows and columns, use the menu
Edit . Rows & Columns or the math toolbar buttons , , , .
See the User’s Guide for information on how to change the horizontal
alignment of each column, and how to change the vertical position of the
whole matrix. Note that if you want to write a table containing text, you
should use LYX’s wonderful table support, rather than trying to write text
in a matrix.
• Subscripts and superscripts for limits and sums (but not integrals) are
written under rather than next to the symbols
• Text is centered
Other than these differences, though, displayed expressions and inline ex-
pressions are very similar.
One final note about the way displayed formulas are typeset: Be careful
about whether you’re putting your equation into a new paragraph or not. If
your formula is in the middle of a sentence or paragraph, then don’t press
4.5. MORE MATH STUFF 25
Return. Doing so will cause the text after the formula to start a new para-
graph. That text will therefore eventually be indented, depending on your
document paragraph settings, which is probably not what you want.
Exercise: Put the various equations in example_raw.lyx into display
mode, and see how they’re typeset differently.
Exercise: Using various tools you’ve learned in this section, you should
be able to write an equation like1 :
log8 x x>0
f (x) = 0 q x=0
5 1
−x x < 0
P
i=1 αi +
• Multi-line equations
• Write macros. These are very powerful, because you just define them
once at the top of the document, and then you can use them throughout
the document.
1
After you’ve done it the hard way, give Insert . Math . Cases Environment a try.
26 CHAPTER 4. USING MATH
Chapter 5
Miscellaneous
• LYX has WYSIWYM support for tables. Use the Insert . Table (toolbar
button ) to get a table. Click on the table with the right button to
get a Table Settings dialog box which allows extensive table editing.
27
28 CHAPTER 5. MISCELLANEOUS
• The LYX menus feature keybindings. This means that you can do File .
Open by pressing Alt+F followed by O or by using the binding which is
shown next to it in the menu (Ctrl+O by default). Keybindings are also
configurable. For information on this, check out Help . Customization.
The Document . Settings dialog takes care of many of the options that you
would input in a \documentclass command. Change the class, default font
size and paper size here. Put any extra options to the \documentclass
command in the Extra Options area.
If you have special commands to put in the preamble of a LATEX file, you
can use them in a LYX document as well. Select Document . Settings .
LATEX Preamble and type in the dialog window (or from the document settings
dialog, depending on the frontend). Anything you type will (like with TEX
mode) be sent directly to LATEX.
5.2.5 BibTEX
LYX has support for BibTEX, which allows you to build databases of bib-
liographical references to be used in multiple documents. Select Insert .
List / TOC . BibTEX Bibliography to include a BibTEX file. In the Database
field you load BibTEX files, in the Style field you can load BibTEX style files.
After you’ve done this, you can use citations from any bibliographies
you’re including with Insert . Citation (see section 3.6). LYX will take care of
running BibTEX. The box in the Citation dialog will show a list of all the
references in your BibTEX file.
5.3. ERRORS! 31
5.3 Errors!
Sometimes when you LATEX a document, there will be errors, things that LYX
or LATEX can’t understand. When this happens, LYX will open a LATEX Errors
dialog. Clicking on individual errors in this dialog will take you to the place
in the LYX document where the error occurs and also display the detailed
LATEX error message.