LYX Tutorial
LYX Tutorial
February 3, 2018
1 Introduction 5
1.1 Welcome to LYX! . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 What the Tutorial is and what it is not . . . . . . . . . . . . . 5
1.2.1 Getting the most out of the Tutorial . . . . . . . . . . 6
1.2.2 What you will not find . . . . . . . . . . . . . . . . . . 6
3 Writing Documents 15
3.1 Document Classes . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Templates: Writing a Letter . . . . . . . . . . . . . . . . . . . 16
3.3 Document Titles . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4 Labels and Cross-References . . . . . . . . . . . . . . . . . . . 18
3.4.1 Your first label . . . . . . . . . . . . . . . . . . . . . . . 18
3.4.2 Your first cross-reference . . . . . . . . . . . . . . . . . 19
3.4.3 More fun with labels . . . . . . . . . . . . . . . . . . . 19
3.5 Footnotes and Margin Notes . . . . . . . . . . . . . . . . . . . 20
3.6 Bibliographies . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.7 Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . 22
3
4 CONTENTS
4 Using Math 25
4.1 Math Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.2 Navigating an Equation . . . . . . . . . . . . . . . . . . . . . 26
4.3 Exponents and Indices . . . . . . . . . . . . . . . . . . . . . . 27
4.4 The Math toolbar . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.4.1 Greek and symbols . . . . . . . . . . . . . . . . . . . . 28
4.4.2 Roots, decorations, and delimiters . . . . . . . . . . . 28
4.4.3 Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.4.4 Functions: lim, log, sin and others . . . . . . . . . . . 29
4.4.5 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.4.6 Display mode . . . . . . . . . . . . . . . . . . . . . . . 30
4.5 More Math Stuff . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5 Miscellaneous 33
5.1 Other major LYX Features . . . . . . . . . . . . . . . . . . . . 33
5.2 LYX for LATEX Users . . . . . . . . . . . . . . . . . . . . . . . . 34
5.2.1 TEX Mode . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.2.2 Importing LATEX Documents — tex2lyx . . . . . . . 35
5.2.3 Converting LYX Documents to LATEX . . . . . . . . . . 36
5.2.4 LATEX Preamble . . . . . . . . . . . . . . . . . . . . . . 36
5.2.5 BibTEX . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.3 Errors! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Chapter 1
Introduction
5
6 CHAPTER 1. INTRODUCTION
this manual first, please read the Introduction before you continue with the
Tutorial.
Now that you know which fonts mean what in the documentation, we
want to talk a bit about what this Tutorial is for.
7
8 CHAPTER 2. GETTING STARTED WITH LYX
Congratulations! You have written your first LYX document. All of the rest
is just details.
A hint: You can save time by leaving the PDF viewer running in the
background. Under MacOS and Linux you can use Document . Update or
the toolbar button and just click on the PDF viewer window afterwards.
Under Windows still use Document . View or respectively.
Another hint: In case you are using a high-resolution display, the LyX
toolbar icons are quite small. To change their size, right-click into a toolbar.
2.1. YOUR FIRST LYX DOCUMENT 9
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.
2.2. ENVIRONMENTS 11
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 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 in which environment you
are currently writing. 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 will 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 doc-
ument.”) 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 was Section 2, has
4 Youdo not 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.
12 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 to the Subsection environment as well. As you probably expected,
LYX automatically numbered the section “2.2”. If you put yet another sec-
tion 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
Subparagraph. We will 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 are 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
numbered. 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 heading as it uses for a regular section, but it will not num-
ber that section. There are corresponding “starred” heading environments
for Subsection and Subsubsection. Try changing some of your sections or
subsections to the starred environments, and note how the other section
numbers are updated.
Let us write a list of reasons why LYX is better than other word processors.
Somewhere in your document, type:
LYX is better than other word processors because:
and hit Return. Now select Itemize from the Environment box ( ). LYX
writes a “bullet” on the line. Type in your reasons:
List environments, unlike headings, do not end when you type Return.
Instead, LYX assumes you are 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 key binding
Alt+P S).
You now have 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
14 CHAPTER 2. GETTING STARTED WITH LYX
the reasons? Well, just select the whole list5 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 envi-
ronments, Description and List / Labeling ( and ), in order to see what
they look like. For 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”6 (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 Spaces.
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.
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, man-
uals, 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.
15
16 CHAPTER 3. WRITING DOCUMENTS
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. . .
just replace a couple of parts of the letter with your text each time you
write a letter.
Open a new file with File . New from Template. Select letter.lyx as
the template. Save and print the file to see how the various environments
are typeset.
When you look at the Environment box, you will see several environ-
ments, like the My Address environment, that do not exist in most other
document classes. Others, like Description, are familiar. You can play
around for a while to figure out how the various environments work. You
will notice for example that the Signature environment has the word “Sig-
nature:” in red before the actual text of the signature. This word does not
show up in the actual letter, as you will see if you view/export the file. It
is just there to let you know where the signature goes. Also, note that it
does not 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 do not 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
whenever 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 are first learning LYX, it will be less intimidating if they have a
letter template customized for their company, for example.
3 One warning, if you are writing from a template. If you erase all of the text in an
environment — for example, if you erase the whole My Address field so that you can
replace it with your own — and then you move the cursor without writing any text, the
environment may disappear. This is because most environments cannot exist without
any text in them. Just reselect the environment from the Environment box to get it back.
18 CHAPTER 3. WRITING DOCUMENTS
So far you have not done anything — the output will look exactly the
same, since labels do not show up in the printed document. However,
now that you have added a label, you can refer to that label with cross-
references. We will do that next.
Now, with the cursor before the final period, select Insert . Cross Refer-
ence 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”. First, select the
drop-down menu labeled “Format” and select “<reference>”. Then select
“sec:About-This-Document” (it may be selected by default), and a refer-
ence marker will appear containing “Ref: sec:About-This-Document” (To
be really correct, you should put a Protected Space (shortcut Ctrl+Space)
in between the word “Section” and the reference.) An alternative way
to reference a label is to right-click the label and select Copy as Refer-
ence in the pop-up context menu. 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). In the printed document, this ref-
erence marker will be replaced with the section number. Preview your
document and you will see that LATEX has been even cleverer than that. It
refers to “Section 2”.
Conveniently, a cross-reference acts as a hyperlink when you are edit-
ing a document in LYX; clicking on it will pop up the Cross-reference dia-
log, clicking Go to Label will move the cursor to the referenced label.
will reference Subsection 2.1 instead of Section 3. The page reference will
not change unless you add a whole page of text before the label, of course.
If you want some more practice with labels, then try putting a new la-
bel where your first cross-reference was, and refer to that label from else-
where in the document. If you will be inserting cross-references often, it
may be convenient to leave the Cross-reference dialog open.
If you want to confirm that the cross-referencing gets the pages right
even for larger documents, Copy a couple pages of text from the User’s
Guide to the clipboard, and Paste them into your document.6
Exercise: Fix the references in example_raw.lyx
footnote if you are trying to select the marker itself with the mouse.
3.6. BIBLIOGRAPHIES 21
• 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 mar-
gin note. Run LATEX again to see what the margin note looks like.
3.6 Bibliographies
Bibliographies 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 refer-
ence. 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 appears in output. When no Label is set (default),
you will see the number of the bibliography in the output. Now change
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 Cita-
tion dialog appears. The left 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 is the only item in the bib-
liography), 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.)8 Click the OK button. Now preview your file and you will see that
8 If one uses label names for references that are easy to remember it is easier to find the
entry in the list of references.
22 CHAPTER 3. WRITING DOCUMENTS
Using Math
25
26 CHAPTER 4. USING MATH
Up and the cursor is moved to the level of the superscript, just before the
“2”. Add the “.5”. Now, hitting Down will move the cursor back to the
regular level. If you hit Space instead of Down, the cursor will be placed
after the superscript (so that you can then type the “+1”).
4.4.3 Fractions
To create a fraction, click on the fraction button in the Math Toolbar.
LYX writes two insertion points in a fraction. As you would expect, you
can use arrow keys or the mouse to move around a fraction. Click on the
top square and type “1”. Now hit Down and type “2”. You have made a
fraction! Of course you can type anything within each of the two boxes:
variables with exponents, square roots, other fractions, whatever.
4.4.5 Matrices
Click on the matrix button in the Math Toolbar. A pop-up dialog allows
you to choose how many rows and columns you want in your matrix.
30 CHAPTER 4. USING MATH
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.
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 and over rather than next to the symbols
• Text is centered
4.5. MORE MATH STUFF 31
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 are putting your equation into a new paragraph or not.
If your formula is in the middle of a sentence or paragraph, then do not
press Return. Doing so will cause the text after the formula to start a new
paragraph. That text will be indented or follow a blank line, 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 are typeset differently.
Exercise: Using various tools you have learned in this section, you should
be able to write an equation like:1
log8 x x>0
f (x) = 0 q x=0
∑5 α + − 1 x < 0
i =1 i x
Miscellaneous
33
34 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). Keybind-
ings are also configurable. For information on this, check out Help .
Customization.
LYX by choosing Insert . TeX Code (toolbar button ). This creates a box
where everything within it is passed straight to LATEX.
In a math formula, TEX mode is handled a bit differently. TEX mode is
entered there by typing a backslash. The backslash is not written out, but
anything you type afterwards will be in red. You exit TEX mode by typing
Space or some other non-alphabetic character, like a number, underscore,
caret or parenthesis. Once you exit TEX mode, if LYX knows the TEX com-
mand you have typed in, it will convert it to WYSIWYM. So if you type
“\gamma” in a formula and then press Space, LYX will change the red
“gamma” to a blue “γ”. This will work for almost all, non-complicated
math macros. This may be faster than using the Math Toolbar, and will be
especially convenient for experienced LATEX users.
As a special case, if you type “\{” in a formula, the beginning and
ending braces will be inserted in red while the cursor is placed between
the braces. This makes it more convenient to type those commands that
take an argument.
LYX cannot do absolutely everything that LATEX can do. Some fancy
functions are not supported at all, while some work but are not WYSI-
WYM. TEX mode allows users to get the full flexibility of LATEX, while hav-
ing all the convenient features of LYX, like WYSIWYM math, tables, and
editing. LYX could never support every LATEX package. However, by typ-
ing \usepackage{foo} in the preamble (see Section 5.2.4.2), you can use
any package you want — although you will not have WYSIWYM support
for that package’s features.
users can access via the console command man tex2lyx. The manpage
describes which LATEX commands and environments are not supported,
what bugs you might run into (and how to get around them), and how to
use the various options.
It is important to understand that tex2lyx can only translate files
whose document class is “known” to LYX, that is, for which there is a corre-
sponding LYX layout file. If there is no layout file, then you will get an error
saying that the conversion could not be performed. So, unless you have a
layout for the document class of your LATEX file, tex2lyx simply will not
know how to translate the LATEX that it finds there into things LYX under-
stands. More about layout files and how they are created is explained in
detail in Chapter 5 of the Customization manual.
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 (as
with TEX mode) be sent directly to LATEX.
5.3. ERRORS! 37
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 have done this, you can use citations from any bibliographies
you have included with Insert . Citation (see Section 3.6). The box in the
Citation dialog will show a list of all the references in your BibTEX file.
5.3 Errors!
Sometimes when you try to view a document, there will be errors, things
that LYX or LATEX cannot 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.