The LyX Tutorial

by the LyX Team
1
Table of Contents
Chapter 1 Introduction >
Chapter 2 Getting started with LyX >
Chapter 3 Writing Documents >
Chapter 4 Using Math >
Chapter 5 Miscellaneous >

Chapter 1 Introduction

Welcome to LyX!

This file is designed for all of you who have never heard of LaTeX, or do not know it very well. Now, do not panic - you will not need to learn LaTeX to use LyX. That is, after all, the whole point of LyX: to provide an almost-WYSIWYG interface to LaTeX. There are some things you will need to learn, however, in order to use LyX effectively.
Some of you probably found your way to this document because you tried to put two spaces after a “.” or tried to put three blank lines between paragraphs. You found out you could not and in fact, you will find out that most of the little tricks you are accustomed to use in other word processors will not work in LyX. That is because most word processors you have used before allow you to manually enter all spacings, font changes, and so on. So you end up not only writing a document but typesetting it, too. LyX does the typesetting for you, in a consistent fashion, letting you focus on the important things, like the content of your writing.
So read on to learn more about LyX. Reading this tutorial is definitely worth the time.

What the Tutorial is and what it is not

Before we get started with this section, we want to make a quick note of something. The Tutorial uses the notation outlined in the Introduction manual. If you came to this manual first, please read the Introduction before you continue with the Tutorial.
Now that you know which fonts mean what, we want to talk a bit about what this Tutorial is for.

1.2.1 Getting the most out of the Tutorial

This tutorial consists of examples and exercises. To get the most out of this document, you should read through it, typing all the little things we are telling you to type and trying out all of the exercises to see if you get them right. For convenience, you might want to print out the PDF version of this document.
If you are familiar with LaTeX, you will probably be able to read the Tutorial somewhat faster, since many LyX ideas are just LaTeX ideas in disguise. However, LyX has features you will want to learn about. Even if you do not feel like reading the rest of the Tutorial, you should definitely check out Section 5.2, which is specifically written for experienced LaTeX users.

1.2.2 What you will not find

It is time to move onwards, time for your first document …

Chapter 2 Getting started with LyX

Your first LyX document

OK You are ready to start writing. Before you do, there are a few things we need to mention, which will hopefully make the Tutorial more instructive and useful.
Because there is information we cannot give you in the Tutorial, the first thing that you need to do is find the other help files. This is very simple: Start up LyX, Choose the User's Guide from the Help menu. You may want to load the Tutorial as well (if you are not reading it within LyX already). This way, you can read them while you are writing your own file.
1
Note that once you have got more than one document open, you can use the View menu or the document tabs to switch between them.
In this Tutorial, we are going to assume that you have a fully working version of LyX, as well as a LaTeX-distribution and a PDF-viewer. This should be the case on all major Linux- and BSD-distributions, as well as on Windows, where this is setup by the LyX installers.
Finally, we have written a file called example_raw.lyx to let you practice your LyX skills. Imagine that it was typed by someone who did not know about any of LyX's great features. As you learn new LyX functions, we will suggest that you fix those parts of example_raw.lyx. It also contains `subtle' hints about how to fix things.
2
If you want to cheat, or check what you have done, there is also a file called example_lyxified.lyx which contains the same text written and typeset by a LyX master.
The example files can be found in the examples directory of LyX's installation folder. Open the raw document, and use File⇒Save As to save a copy in your own directory for you to work on. As you fix parts of the raw document, check to see how those changes affect the DVI output.
By the way, the examples directory contains lots of other examples files. They will show you how to do various fancy things with LyX. After you have read the Tutorial, or when you are confused about how to do something fancy in LyX, take a look at these files.

2.1.1 Typing, Viewing, and Exporting

Congratulations! You have written your first LyX document. All of the rest is just details, which are covered in the other manuals.

2.1.2 Simple Operations

LyX can of course do most of the things you are used to doing with a word processor. It will word-wrap and indent paragraphs automatically. Here is a quick description of how to do some simple actions.
Undo
LyX has multiple levels of undo, which means you can undo everything you have done since your current editing session started, by selecting Edit⇒Undo (toolbar button image: 3C__Program_Files__x86__LyX_2_0_Resources_images_undo.png ) over and over again. If you undo too much, just select Edit⇒Redo (toolbar button image: 4C__Program_Files__x86__LyX_2_0_Resources_images_redo.png ) to get it back.
Cut/Paste/Copy
Use Edit⇒Cut (toolbar button image: 5C__Program_Files__x86__LyX_2_0_Resources_images_cut.png ), Edit⇒Copy (toolbar button image: 6C__Program_Files__x86__LyX_2_0_Resources_images_copy.png ), and Edit⇒Paste (toolbar button image: 7C__Program_Files__x86__LyX_2_0_Resources_images_paste.png image: 7C__Program_Files__x86__LyX_2_0_Resources_images_paste.png ) to cut, copy, and paste. Or automatically paste selected text (including selections from other programs) with the middle mouse button.
Find/Replace
Use Edit⇒Find & Replace (toolbar button image: 8C__Program_Files__x86__LyX_2_0_Resources_images_dialog-show_findreplace.png ) to search. In the dialog, search with the Find Next button, and use the Replace button to replace a word you have found. If you like, you can specify whether to make the search case-sensitive, or to search for only complete words; you can also search backwards through the document.
Character Formatting
You can emphasize text (which will by default print characters in italics), set it in bold face, in Noun Style (usually small caps, used for people's names), or use your own formatting by using the Edit⇒Text Style dialog (toolbar button image: 9C__Program_Files__x86__LyX_2_0_Resources_images_dialog-show_character.png ).
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 have not yet written enough to make most of these functions useful. As you write more, though, try undoing, pasting, etc.

2.1.3 WYSIWYM: Whitespace in LyX

One of the hardest things for new users to get used to is the way that LyX handles whitespace. As many times as you hit Return, you will only get one blank line. As many times as you hit Space, you will only get one space. On a blank line, LyX will not let you type even one space. The Tab key will not move you forward one tab stop; in fact there are no tab stops! There is 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 will 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 horizontal fills 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 will be distracted by document formatting throughout the writing process.

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 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: image: 10C__Program_Files__x86__LyX_2_0_Resources_doc_clipart_ToolbarEnvBox.png . 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.

2.2.1 Sections and Subsections

Type the word Introduction on the first line of your LyX file, and select Section in the Environment box.
5
Be sure to use Section and not Section*, which will be covered below. LyX numbers the section “1” and typesets the section heading (title) in a larger font. Now hit Return Note that the Environment box changes from “Section” back to “Standard”. Section headings, like most environments, are assumed to end when you type Return Type the document introduction:
This is an introduction to my first LyX document.
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 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 was 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:
Sections and subsections are described below.
Section Description
Sections are bigger than subsections.
Subsection description
Subsections are smaller than sections.
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 bigger 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 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 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 number 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.
Exercise: Fix the section and subsection headings in example_raw.lyx.

2.2.2 Lists and sublists

LyX has several different environments for typesetting lists. The various list environments free you from hitting Tab a million times when writing an outline, or from renumbering a whole list when you want to add a point in the middle of the list. Different types of documents logically require different list environments:
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 (image: 11C__Program_Files__x86__LyX_2_0_Resources_images_layout_Itemize.png ). LyX writes a “bullet” on the line. Type in your reasons:
Typesetting is done for you.
Math is WYSIWYG
Lists are very easy to create!
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 have 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 list
6
and choose Enumerate from the Environment box (image: 12C__Program_Files__x86__LyX_2_0_Resources_images_layout_Enumerate.png ). 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 environments, Description and List / Labeling (image: 13C__Program_Files__x86__LyX_2_0_Resources_images_layout_Description.png and image: 14C__Program_Files__x86__LyX_2_0_Resources_images_layout_List.png ), 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”
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 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.

2.2.3 Other environments: Verses, Quotations, and more

There are two environments for setting quotations apart from surrounding text: Quote for short quotes and Quotation for longer ones. Computer code (the LyX-Code environment
8
) is written in a typewriter font; this environment is the only place in LyX where you are allowed to use multiple spaces to allow code indenting. You can even write poetry using the Verse style, using Return to separate stanzas, and Ctrl+Return to separate lines within a stanza. See the User's Guide for more complete descriptions of all of the available LyX environments.
Exercise: Correctly typeset the Quote, LyX-Code, and Verse in
example_raw.lyx

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.

Document Classes

Different sorts of documents should be typeset differently. For example, books are generally printed double-sided, while articles are single-sided. In addition, many documents contain special environments: letters contain some environments — such as the sender's address and the signature — which do not make sense in a book or article. The LyX document class
1
takes care of these large scale differences between different sorts of documents. This Tutorial, for example, was written in the Book document class. Document classes are another major part of the WYSIWYM philosophy; they tell LyX how to typeset the document, so you do not need to know how.
Your document is probably being written in the Article document class.
2
Try changing to other document classes (using the Document⇒Settings dialog) to see how they are typeset differently. If you change your document to the Book document class and look at the Environment box, you will 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 submissions, 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.

Templates: Writing a Letter

One way to write a letter would be to open a new file, and choose a Letter class in the Document⇒Settings dialog. While this is the most obvious way to write a letter, it seems like extra work. Every time you write a business letter, you want to have your address, the address to which you are sending it, a body, a signature, etc. LyX therefore has a template for letters, which contains a sample letter; once you have a template, you can 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 environments, 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 “Signature:” 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.

Document Titles

LyX (like LaTeX) considers the title — which may contain the actual title, the author, the date, and even an abstract of a paper — to be a separate part of the document.
Go back to your LyX document and make sure it is using the Article document class.
4
Type a title on the first line, and change the line to the Title environment. On the next line, type your name and change it to the Author environment. On the next line, write the date in the Date environment. Type a paragraph or two summarizing your document using the Abstract environment. Notice how the title is presented when it is printed out. If you change the document format to Book, you will get a separate title page, like the first page of this tutorial.
Exercise: Fix the title, date, and author in example_raw.lyx

Labels and Cross-References

You can label section headings, list items, formulas, footnotes, and floats
5
in your document. Once you do so, you can refer to this section in other parts of the document, using cross-references. You can refer either to the section's number, or to the page that the section appears on. As with section numbering, LyX also takes care of cross-reference numbering for you. Automatic management of labels and cross-references is among the most significant advantages of LyX (and LaTeX) over conventional word processors.

3.4.1 Your first label

Go to our second section, whose title is “About This Document”. Click at the end of the section title line, and select Insert⇒Label or the toolbar button image: 15C__Program_Files__x86__LyX_2_0_Resources_images_label-insert.png . A dialog asks you for a label name, and gives you a suggestion. When you click on OK, the label name will be placed in a box next to the section title.
So far you have not done anything — the DVI 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.

3.4.2 Your first cross-reference

Place the cursor somewhere in Section 2 of your document. Type
If you want to know more about this document, then see
Section, which can be found on page.
Now — with the cursor after the word “Section” — choose Insert⇒Cross Reference or the toolbar button image: 16C__Program_Files__x86__LyX_2_0_Resources_images_dialog-show-new-inset_ref.png . 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> on page <page>”. Then select “sec:About-This-Document” (it may be selected by default), and a reference marker will appear containing “Ref+Text: sec:About-This-Document” (To be really correct, you should put a Protected 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 Reference in the appearing 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 reference marker will be replaced with the section number and then the page number. View your document as DVI, and you will see that LaTeX has been even cleverer than that. It refers to “Section 2” and depending how much text you have between the start of Section 2 and this cross-reference you may see “on this page”, “on the previous page” or “on page n” (whereas n is the page number).
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.

3.4.3 More fun with labels

We told you that LyX takes care of numbering cross-references; now you can test this claim. Add a new section before Section 2. Update the DVI view, and — voilà! — the section cross-reference changed to “3”! Change the section “About this Document” to a subsection, and the cross-reference 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 label where your first cross-reference was, and refer to that label from elsewhere 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 it into your document.
6
Exercise: Fix the references in example_raw.lyx

Footnotes and Margin Notes

Footnotes can be added using the toolbar button image: 17C__Program_Files__x86__LyX_2_0_Resources_images_footnote-insert.png or the menu Insert⇒Footnote. Click at the end of the word “LyX” somewhere in your document and insert a footnote. A footnote box appears where you can enter the text of the footnote. LyX should place the cursor at the beginning of the footnote box. Type
LyX is a typesetting word processor.
Now click on the button labeled “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.
A footnote can be cut and pasted like normal text. Go ahead; try it! All you need to do is select the footnote button
7
and Cut and Paste it. In addition, you can change regular text to a footnote, by selecting it and hitting the image: 17C__Program_Files__x86__LyX_2_0_Resources_images_footnote-insert.png 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.
Margin notes can be added using the menu Insert⇒Marginal Note or the toolbar button image: 18C__Program_Files__x86__LyX_2_0_Resources_images_marginalnote-insert.png Margin notes are like footnotes, except that:
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

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 environment. 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 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 image: 19C__Program_Files__x86__LyX_2_0_Resources_images_dialog-show-new-inset_citation.png . 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 is 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 will see that the citation appears in brackets in the text, referring to the bibliography at the end of the document.
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

Table of Contents

You may want to put a table of contents at the beginning of your document. LyX makes this easy to do. Just hit Return after your document title and before your first section title and choose Insert⇒List / TOC⇒Table of Contents. The words “Table of Contents” will appear in a button on the first line of the document.
This may not appear to be very useful. However, if you look at your DVI file, you will see that a table of contents has been generated, listing the various sections and subsections in your document. As usual, if you reorder sections or create new ones, you will see those changes in the DVI file when you update it.
The table of contents is not printed in the on-screen version of the document. But you can display the table of contents in a separate window by clicking on the table of contents button, or by using Document⇒Outline or the toolbar button image: 20C__Program_Files__x86__LyX_2_0_Resources_images_dialog-toggle_toc.png . This menu will work even if you do not have a table of contents inset in your document. This is a very useful tool for rearranging your document parts. Clicking on a (sub)section title in the Outline window will highlight that line and move the display (in the LyX editing window) to that place in the document. You can also use the arrow keys to move up and down in the table of contents. You may therefore find it convenient to leave this window open throughout editing sessions. You can get similar functionality from the Navigate menu, though, where the table of contents appears automatically.
To get rid of the Table of Contents, you can delete the table of contents button just like any other text.
Exercise: Fix the table of contents in example_raw.lyx

Chapter 4 Using Math

LaTeX is used by many scientists because it outputs great looking equations, avoiding the control characters used by word processors and their equation editors. Many of these scientists are frustrated, however, because writing equations in LaTeX is more like programming than writing. Happily, LyX has WYSIWYM support for equations. If you are used to LaTeX, you will find that all of the usual LaTeX math commands can be typed in normally, but they will show up in a WYSIWYM fashion. If, on the other hand, you have never written in LaTeX, then the Math Panel will allow you to write professional-looking math quickly and easily.

Math Mode

Somewhere in your LyX document, type:
I like what Einstein said, E=mc^2, because it is so simple.
Now, that equation does not look very good in LyX and in the output; there is no space between the letters and the equals sign, and you would like to write an actual superscript for the “2”. That bad typesetting happened because we did not 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 image: 21C__Program_Files__x86__LyX_2_0_Resources_images_math-mode.png or use the menu Insert⇒Math⇒Inline Formula. LyX will insert a little blue square, which is an empty math formula. Now 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.
Looking at the output you will 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 LaTeX, you write a mathematical expression using text and commands like \sqrt; this can be frustrating, because you cannot see what an expression looks like until you run the file under LaTeX and you may have to spend time finding e. g. missing brackets. LyX does not 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.

Navigating an Equation

Now let us change E=m c 2 to E=1+m c 2 . Use the arrow keys to move the cursor into the expression. Note that when you enter the expression, the purple markers appear to let you know you are editing math. Now you can use Left and Right to move the cursor past the equals sign, and just type “1+”. Again, you can use the arrow keys or Esc to leave the formula
Other than the special keys described below, typing in math mode is like editing regular text. Use Delete (or Backspace) to delete things. Select text either with the arrow keys or with the mouse. Edit⇒Undo works in math mode as well as cut and paste. One thing to be careful of: if you are left or right outside a formula and you press Delete or Backspace respectively, you delete the whole formula. Luckily, you can just use Undo to get it back.
What if you want to change E=m c 2 to E=m c 2.5 +1 ? Again, you can use the mouse to click in the right place. However, you can also use the arrow keys. If the cursor is just after the “c” but before the “2”, then press 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”).

Exponents and Indices

An exponent can be entered from the Math Toolbar (see below), but it is actually simpler just to type the caret key, “^”. LyX will place another blue rectangle in the superscript, so that whatever you write next will be superscripted, and in a smaller font size. Everything you type until you hit a Space (or Esc to exit the formula entirely) will be in the superscript.
Writing a subscript (index) is just as easy; start one by typing the underscore key “_” . You can subscript and superscript both subscripts and superscripts like this: A a 0 + b 2 + C a 0 + b 2 .
Exercise: Put equation 1 of example_raw.lyx into math mode.

The Math toolbar

The Math toolbar is a convenient way to enter symbols and/or to perform complicated formula operations. Many of these operations can be accomplished from the keyboard or the Edit⇒Math or Insert⇒Math menus. However, we are going to concentrate on using the Math toolbar, just to let you know what is out there; you can learn keyboard shortcuts and commands later from the Math manual.
The Math toolbar is shown when the cursor is in a formula and can also be turned on manually in the menu View⇒Toolbars. When you click there on “Math” (image: 22C__Program_Files__x86__LyX_2_0_Resources_images_toolbar-toggle_math.png ) the toolbar will be shown permanently at the bottom; this state is visualized in the Toolbars menu with a checkmark. When you click in this state again on “Math” in the Toolbars menu, the math toolbar is only shown when the cursor is within a formula; this state is visualized by the renaming of the menu entry from “Math” to “Math (auto)”.

4.4.1 Greek and symbols

The Math toolbar allows you to choose from a large array of symbols used in math: operators, arrows, relationships, delimiters, special characters, sums and integrals. Note that subscripting and superscripting allow you to put lower and upper limits on sums and integrals.

4.4.2 Square roots, accents, and delimiters

To type a square root, just click on the button image: 23C__Program_Files__x86__LyX_2_0_Resources_images_math_sqrt.png . The square root appears, and the cursor is in a new insertion point inside the square root. You can type variables, numbers, other square roots, fractions, whatever you want. LyX will automatically resize the square root to fit what is inside.
Accenting a character ( a ) or group of characters ( a+b ) is done similarly, and is an example of inserting a “frame decoration”. Decorations are available from the toolbar via the button image: 24C__Program_Files__x86__LyX_2_0_Resources_images_math_hat.png . Click on a decoration, and LyX will insert that decoration with an insertion point under (or over) it. Just type what you want in the insertion point. There are two sets of decorations: those that resize with the text you type, and those that have a fixed size, and are most appropriate for a single letter.
Delimiters such as parentheses, brackets, and braces work similarly, but are a bit more complicated. Hit the delimiter button image: 25C__Program_Files__x86__LyX_2_0_Resources_images_dialog-show_mathdelimiter.png to pop up the Delimiter dialog. Your current selection of delimiters is displayed in a box. It is a pair of parentheses by default, but you can choose a pair of braces, a brace and a parenthesis, or choose the empty square to have something like “ a=langle7. ” (the empty delimiter is displayed as a broken line in LyX, but will not show up in the output).
If you are lazy, you can type actual parentheses in math mode, rather than using the Delimiter dialog. However, those parentheses will be the same size as regular text, which will look bad if you have a big fraction or matrix inside the parentheses. So it is better in this case to use one of the three delimiter buttons that insert directly e. g. a ( ) pair.
You can also put delimiters or a square root sign or a decoration on already existing formula parts. Select the portion of the formula that you want to adjust, and then click on the button you want from the Math Toolbar. Try using this to change Newton's second law from scalar to vector form ( f=ma to f =m a ). Once you have learned about matrices, this is how you will put parentheses or brackets around them.

4.4.3 Fractions

To create a fraction, click on the fraction button image: 26C__Program_Files__x86__LyX_2_0_Resources_images_math_frac.png or image: 27C__Program_Files__x86__LyX_2_0_Resources_images_math_frac-square.png 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.
Exercise: Put equation 2 of example_raw.lyx into math mode.

4.4.4 Functions: lim, log, sin and others

Because letters in math mode are considered to be variables, if you type “sin” in math mode, LyX thinks you are typing the product of the three variables s , i , and n . The three letters will be typeset in italics, when what you really wanted was the word “sin” typeset in Roman. In addition, LyX will not put a space between the word “sin” and the “x” (pressing Space will exit the formula). So how do you get “ sin(x) ” instead of “ sin(x) ”?
Click on the Math Toolbar button image: 28C__Program_Files__x86__LyX_2_0_Resources_images_math_functions.png and then on “sin” in the appearing function list. The word “sin” is displayed in LyX in black, and set in upright roman type. The whole word is treated as one symbol, so if you type Backspace, it will delete the whole word. Now type “(x)”, which will be written in blue italics, like you expect in a formula. In the output, the expression will be correctly typeset. Try it out.
The function list includes other trigonometric functions and their inverses, hyperbolic functions, logarithms, limits, and quite a few others. These functions can take subscripts and superscripts, important for typing “ cos 2 θ ” or “ lim n ”.
Exercise: Put equation 3 of example_raw.lyx into math mode.

4.4.5 Matrices

Click on the matrix button image: 29C__Program_Files__x86__LyX_2_0_Resources_images_dialog-show_mathmatrix.png 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.
If you need to change the number of rows and columns, use the menu Edit⇒Rows & Columns or the math toolbar buttons image: 30C__Program_Files__x86__LyX_2_0_Resources_images_tabular-feature_append-row.png , image: 31C__Program_Files__x86__LyX_2_0_Resources_images_tabular-feature_delete-row.png , image: 32C__Program_Files__x86__LyX_2_0_Resources_images_tabular-feature_append-column.png , image: 33C__Program_Files__x86__LyX_2_0_Resources_images_tabular-feature_delete-column.png .
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.

4.4.6 Display mode

All of the expressions we have written so far have been on the same line as the text that came before and after them, otherwise known as inline expressions. This is fine for short, simple expressions, but if you want to write larger ones, or if you want your expressions to stand out from the text, you need to write them in display mode. In addition, only displayed expressions can be labeled and numbered (see the User's Guide), and multi-line equations must be in display mode.
While being in a formula, click on the display button image: 34C__Program_Files__x86__LyX_2_0_Resources_images_math-display.png in the Math Toolbar. This centers the formula and adds a blank line before and after it. Now type in an expression and compile your file to see how it looks. The display button is actually a toggle; use it now to change a couple of your expressions to display mode and back.
Display mode has a couple differences from inline mode:
Other than these differences, though, displayed expressions and inline expressions 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
f(x)={ log 8 x x>0 0 x=0 i=1 5 α i + - 1 x x<0 .

More Math Stuff

Now you are familiar with the basics. LyX's math editor can do a lot more. You can refer to the Math manual for tips on how to:

Chapter 5 Miscellaneous

Other major LyX Features

We have not gone through all the possible commands in LyX, and we are not planning on it. As usual, see the User's Guide and the Embedded Objects manual for more information. We will just mention a couple more major things LyX can do:

LyX for LaTeX Users

If you do not know anything about LaTeX, you do not have to read this section. Actually, you might want to learn about LaTeX, and then read this chapter. However, some who begin to use LyX will be familiar with LaTeX. If you are such a person, you may be wondering if LyX can really do everything LaTeX can do. The short answer is that LyX can do pretty much everything LaTeX can do in one form or another, and it definitely simplifies most parts of writing a LaTeX document.
Because this is just a tutorial, we are only going to mention things that new LyX users will most likely be interested in. In the interests of keeping the Tutorial short, we will give only minimal information here. The Additional Features and the Embedded Objects manual have a great deal of information on differences between LyX and LaTeX, and how to do various LaTeX tricks in LyX.

5.2.1 TeX Mode

Anything that you enter in TeX mode will be passed straight to LaTeX, and will be displayed in red on the screen. You can use TeX commands in LyX by choosing Insert⇒TeX Code (toolbar button image: 38C__Program_Files__x86__LyX_2_0_Resources_images_ert-insert.png ). 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 command 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 WYSIWYM. TeX mode allows users to get the full flexibility of LaTeX, while having all the convenient features of LyX, like WYSIWYM math, tables, and editing. LyX could never support every LaTeX package. However, by typing \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.

5.2.2 Importing LaTeX Documents — tex2lyx

You can import a LaTeX file into LyX by using the File⇒Import⇒LaTeX (plain) menu in LyX. This will call the program tex2lyx which will create a file foo.lyx from the file foo.tex. LyX will then open that file. If the translation does not work, you can try calling tex2lyx from the command line, possibly using fancier options.
Even when the translation does work, tex2lyx may not translate everything, though it does handle most legal LaTeX. It will leave things it does not understand in TeX mode; so, after translating a file with tex2lyx, you can look for the red text and manually edit it to get it right.
tex2lyx has its own documentation (manpage), which Unix/Linux 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 corresponding 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 understands. More about layout files and how they are created is explained in detail in Chapter 5 of the Customization manual.

5.2.3 Converting LyX Documents to LaTeX

You might wish to convert a LyX Document to a LaTeX file. For example, a co-worker or co-author who does not have LyX might want to read it. Select File⇒Export⇒LaTeX. This will create a file whatever.tex from the whatever.lyx file you are editing.

5.2.4 LaTeX Preamble

5.2.4.1 Document Class

The Document⇒Settings dialog takes care of the document-wide options, such as changing the document class, default font size and paper size. Document class options and also options for LaTeX packages can be entered there in the Class options area.

5.2.4.2 Other Preamble Matter

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.2.5 BibTeX

LyX has support for BibTeX, which allows you to build databases of bibliographical 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.