# An Introduction to LyX

LyX is a graphical interface, nearly WYSIWYG, to the LaTeX word processing package. One can use it either to import/export LaTeX files (.tex) files, or else just remain in the LyX domain (.lyx files). In the latter case, the processing is still done by LaTeX, but transparently to the user.

LyX adds convenience to the quality and power of LaTeX. It is particularly useful for documents with significant mathematical content.

Overview of this introduction:

## LyX quick start:

If you already have access to a machine with LyX installed, here is how to get started with it quickly.

• If you have an existing LaTeX file and wish to modify it using LyX, just start LyX, by typing "lyx" on the UNIX command line, and then import your LaTeX file as shown below. (You can later export back to LaTeX if you wish.)

• If you wish to create a new LyX file, say x.lyx, simply type "lyx x.lyx" on the UNIX command line.

The file is now in your LyX buffer, and you can then add to or modify it in a manner similar to that of any WYSIWYG word processor. It is fairly intuitive, but refer to the above table of contents for any specific type of operation you wish to perform.

## How to obtain and install LyX:

If you are using a university computer, LyX may already be installed. Just type "lyx" and see if it runs. If not, or if you want to install LyX on your own machine, read on:

If you use Linux, you may wish to use the autoinstaller in your distribution--yum in Fedora, apt-get in Ubuntu, etc.

If you get the source code, just go through the usual "configure; make/make install" sequence. You may need to also acquire some libraries.

Note that some of the files may be dispensable, resulting in slow loading (especially for remote execution via a network), e.g. the non-English tutorials in share/lyx/doc.

You will of course also need the LaTeX package itself. Most Linux and Unix systems already have this.

By the way, there is a package which enables you to write in Chinese, Japanese and Korean with LyX, at http://stone.phys.pusan.ac.kr/cjk.html.

## Important terms and other information:

I will speak here of the "Environment box," by which I mean the box just below File, Edit, and Layout.

I will also use the term "separate paragraph." This means (at least in the setting I use LyX, which is Skip mode, meaning nonindented paragraphs) text which is both preceded and followed by a blank line.

The LyX documentation uses the notation "M-" for various keystroke commands, with M' meaning meta'' (as in emacs). In typical installations, the meta key is Alt.

Note carefully: Newer versions of LyX may have a slightly different interface than what is described here. I have attempted to keep up with changes, but may not catch them all. You may have to do some experimenting to get at certain commands.

## Importing/exporting to/from LaTeX:

Though you can work entirely in LyX and never directly use LaTeX, you may wish to save your work in a LaTeX file, importing into LyX when making a change and then saving back to LaTeX. For example, you may not have LyX installed on all the machines you use, or you may be sharing your work with others who do not have access to LyX, or you may be submitting a research paper to a conference which uses LaTeX. Another reason for exporting to LaTeX is that you may wish to do some fine-tuning to the LaTeX generated by LyX.

(In the latter case, after exporting the file, close the buffer containing the .lyx file, then later re-import it in after modifying the LaTeX file.)

To import a .tex file into LyX, do File->Import->LaTeX. (If, possibly due to your window manager, the File icon is a little "skittish" and opens a file-directory window without your asking for one, hold the mouse button down on the File icon, instead of just briefly clicking the mouse.) Though LyX accommodates most LaTeX constructs, if you have one not covered by LyX, LyX will put it in TeX mode; see "Embedding your own LaTeX commands" below.

To export to LaTex, do File->Export->LaTeX.

## Setting document parameters:

Do Layout->Document and set the parameters. For example, to turn off paragraph indentation, choose Skip.

If you wish to add or change some "setlength" or other parameters in the LaTeX preamble, do so vi Layout->Document->LaTeX Premable.

Type the title, in a separate paragraph. Then go to the Environment box and choose Title. Do the same for author, date and abstract.

To set up a table of contents, put the cursor right after the title section (after the abstract if any, or else after the date), then hit Enter. Then do Insert->ListsTOC->Table of contents. The table will then appear as a clickable, linking box, and will show up as a real table of contents in the final .dvi file.

## Sections, subsections, appendices etc:

To make a section (or subsection, etc.) title, type the title as a separate paragraph, then choose Section from the Environment box.

LyX does not provide direct support for creating appendices. However, you can still create them, as follows.

First, at the point in your document at which the appendix will begin, use the procedure for embedding raw LaTeX code to insert this line of LaTeX code:

\appendix


Then begin a new section, as shown above. This will be Section A of your appendix, and you create further sections as usual. Note carefully that this will not be displayed properly by LyX, but it will work properly later when you create the .dvi file or print.

## Labels and references:

To make a label, move the cursor to the point just before the item to be labeled, and then do Insert->Label. (Assign any unique name to the label; it will not appear in your final output.) Then at each point where you wish to reference that label (e.g. "Section 5," "Page 29," etc.), place the cursor and then do Insert->Cross-Reference. The labels and references will temporarily show up as gray boxes (which are mouse-clickable, which aids in the editing process), and as genuine references in the final document.

Labels and cross references for equations work the same way. However, when inserting a label, make sure you are in the Math Editor box for the expression first (pink box).

## Lists:

E.g. to make an itemized, i.e. bulleted list, choose Itemize from the Environment box; a bullet will appear. Type the item, and hit Enter; each time you type a carriage return, another bullet will appear. If you want to have another paragraph within the same bulleted item, hit ctrl-Enter instead of Enter. To leave Itemize mode, choose Paragraph from the Environment box.

If you want to nest a list within a list, click on Layout and then Change Environment Depth. Or, use the quicker method of clicking on the icon at the top of the LyX screen, which is a picture of a page with arrows on both sides.

## Tables:

Select Insert, then Table. A window will pop up to enable you to set the number of rows and columns. Just use the mouse to drag the indicator to the value you want.

To do the latter, place the mouse pointer in the table at a point where you wish to add/delete a row or column, and then select Layout and Table. Then select Add Row, Delete Row or whatever is appropriate.

To fill in entries in the table, just click the mouse in the entry, and then type the entry. The size of the cell will automatically expand as needed.

## Math:

Math Mode:

If your document has a lot of math, you'll want to bring up the Math Panel first. Select Insert | Math | Math Panel. You'll see icons for fractions, super/subscripts, matrices, Greek letters and special symbols, and so on.

First enter Math Mode. You can do this by clicking the (a+b/c) icon, or you might find it easier via the keyboard, as M-c m, where M is the Meta key, typically Alt. A box will then appear, inside which you type math. Then you have two choices, each of which is sometimes more convenient than the other:

• While in the purple box, you can simply type raw LaTeX, e.g. c^2 for c-squared, and LyX will then automatically display it properly.

• Or you can choose the Math icon and then choose whatever you need, e.g. Fraction. The components of the math item will be drawn as little boxes which you can type in. Use the arrow keys or mouse pointer to move from one of these boxes to another.

I find that it is usually more convenient to take the first approach. For example, to form a fraction, instead of clicking on Math then on Fraction, I get into Math Mode (M-c m), then type "\frac " (including the space), and LyX draws the fraction (two empty boxes and a division bar) for me.

Math Text Mode:

If you wish to type text within a math expression, it will look better if you use Math Text Mode, which you can enter by typing M-m m, where again M is the Meta key. Note that in order to get a blank space, you will need to type ctrl-blank. Also note that if you insert a math symbol, even an equal sign, you will leave Math Text Mode, and must re-enter it if you want to type more text. If you want to leave Math Text Mode, type M-m m again. (However, this apparently will fail if you do it right after typing a blank, an apparent bug. If so, type the blank after) switching out of Math Text Mode.)

Subscripts and superscripts:

A subscript operation is obtained by hitting Index within the Math menu. Superscripts are obtained by hitting Exponent. (For quick subscripts or superscripts, it is easier to just type the raw LaTeX, as mentioned earlier.) After you have filled in a subscript or superscript, use the up- or down-arrow key to return to the base level.

Leaving Math Mode:

Leave Math mode by either moving the cursor or hitting Esc, or simply moving the cursor out of the purple box. Later, if you move the cursor back into a math region, the purple box will reappear, automatically placing you in Math mode.

Greek letters, math symbols, etc.:

Greek letters, summation and integral signs, and so on, are available via Math->Math Panel. Each square within that panel displays a few summary symbols; click on it to see the entire choice of symbols.

To put limits on a summation or integral sign, use Index and Exponent as for subscripts and superscripts above. (Use the arrow keys to make sure the cursor is next to the summation or integral sign first.) If you wish the limits to go "north" and "south" of the integral sign instead of "northeast" and "southeast," use the int, sum, min, max, etc. items in the Functions window within the Math Panel.

Displayed equations:

To display an equation, choose Math then Display. (In newer versions of LyX, click on Insert then Display Formula.) This can be done before typing in the equation, or for an already-existing equation.

To create a multiline displayed equation with the = signs of a lines being aligned with each other, generating the LaTeX \eqnarray command, get into displayed mode first, and hit C-Enter (control-enter). Three boxes will be displayed, one of the left-hand side of your equation, one for the = sign, and one for the right-hand side. You then fill them in. Each time you need a new line, hit C-Enter.

Matrices:

To draw a matrix, first set up the enclosing delimiters (brackets, parentheses, etc.), by choosing the Delimiter icon in the Math Panel (blue square within black brackets). Click on Left, then click on the left delimiter you want, then click on Right and click on the right delimiter you want, then OK. Then in the box within the delimiters you just chose, select the Matrix icon from the Math Panel (blue "3x3 array"), then set your rows and columns, then OK. Now fill in your matrix.

"Cases" construct:

To get the LaTeX \cases construct, with k cases, first set up delimiters (see the entry Matrices'' above), with a left brace for the left delimiter and a blank for the right delimiter. Then set up a kx2 matrix; the second column is for the "if" portions of the \cases construct. I recommend (somewhat counter to the LyX manual) that in the Horizontal Align portion of the Matrix popup window you fill in "rl", meaning to right-justify the first column and left-justify the second one. In filling matrix, in the right column you probably will wish to use Math Text Mode.

Overbars, underbars, hats, etc.

Click on Math, then Math Panel, then the square with a tilde over it. Then click on the desired symbol, which will appear along with a box in which you insert the base symbol.

Doing Cut-and-Paste/Copy-and-Paste Operations with Math

An inline math expression can be cut/copied-and-pasted elsewhere. By contrast, in the case of a displayed equation, apparently only the entire equation can be used in this manner. (In the latter case, do not create a math edit box at the destination; simply do the operation into a "blank" destination.)

## Bold face, etc.:

Highlight the text you wish to put in bold face, then click on Layout, then Character, then Series (and choose Bold), then Apply, then Close.

Italics can be chosen by clicking on Shape instead of Series.

To revert to standard font, click on Reset instead of Bold or Italics.

## Editing and buffer management:

LyX offers the standard (though primitive) editing operations, e.g. cut-and-paste, undo/redo, find/replace and so on.

Use the Documents icon to move from one buffer to another. To delete a buffer, go to the buffer and then do File->Close.

If you wish to do a copy-and-paste operation from another X11 application, first use the mouse the highlight the given text as usual. Then click on Edit and then Paste Primary Selection as Lines/Paragraphs.

## Embedding your own LaTeX commands:

To embed sophisticated LaTeX commands which LyX does not handle (for example, the verbatim newpage construct), type the raw LaTeX material, highlight it by dragging the mouse, and then click the TeX icon. The embedded LaTeX material will be shown in red, not WYSIWYG, but will show up correctly in the final .dvi file.

In embedding LaTeX's verbatim command, hit ctrl-Return instead of Return when going from one line to the next, in order to avoid generation of blank lines. Similarly, to get embedded blanks, hit C-Space (control-space bar).

Very well done. Click on the Help icon. Use the Documents icon to flip back and forth between your document window and the help window(s).

Note too that the LyX package comes with a man page, in the file lyx.man, which gives helpful information on search paths, etc.

## The final product:

LyX will create a .dvi or .ps file (using LaTeX behind the scenes) which you can then print out, or you can simply ask LyX to print for you.

## Previewing the final product:

LyX is nearly-but-not-100% WYSIWYG, especially if you have your own embedded LaTeX code in the document. So you may wish to preview the final .dvi file, which you can do by File->View dvi (or View may be displayed in the toolbar at the top of the LyX window).

Note carefully: The first time you run this command, LaTeX or dvips may need to generate some fonts for you, which may take about 5 minutes. Don't worry about the delay, as it is one-time only, since the fonts are kept.

You may get an error message saying something like "Error in LaTeX processing. (Typically this is due to your importing a .tex file into LyX even though the .sty files requested by the .tex file are not present, or due to your inserting your own LaTeX commands via LyX.) To track down the error, you can first click on Edit and Go to Error, and check whether the error is obvious. If it isn't, export the .lyx file to LaTeX, and run LaTeX directly on it, yielding information on the error.

## Embedding Postscript figures:

Do Insert->Figure. Various options will be offered. Your figure will indeed show up in the LyX window for your document.

I have found that sometimes LyX will cause problems, by producing LaTeX code like this:


\vspace{0.3cm} \par\centering \includegraphics{Sine5.eps}  \par{}
\vspace{0.3cm}

The centering'' command never gets turned off. One way to avoid this is to change it to

\vspace{0.3cm} \par\centerline{\includegraphics{Sine5.eps}}  \par{}
\vspace{0.3cm}

`

## Bibliographies and citations:

To create a bibliography (if you don't have one already via importing your document from a .tex file created earlier), move to the end of your document and then go to the Environment box and choose Bibliography. The screen will show a heading "References" and a box numbered 1, for the first reference. You can then type the reference there. Then click the reference number box (1); a window will then pop up in which you can enter a Key, which will be your own private name for this reference, to be used for the actual citations. Each time you hit the carriage return, you will start a new reference.

Now, wherever you wish to enter a citation in your text portion, simply click the mouse at the point at which you want the citation, then choose Insert and Citation Reference. You will be asked for the key, which you can either type in, or if you have forgotten it, click the arrow and choose from the list of all keys in your entire bibliography. If you want to ask a page or chaapter number for the reference, use the Remark field in the popup window.

The order can also be reversed. You cna put in the citations first, with keys, and then later add the bibliography, as long as you make sure to use the same keys.

## Errors:

It is possible, occasionally, for you to somehow misuse LyX and create a LaTeX error. LyX will tell you so when you try to view the DVI file, print, etc., and it will display a red-letter box labeled "Error" at the beginning of the offending line. Often, though, the nature of the error may be unclear. If so, you could just delete the entire line and retype it (sometimes the error is due to unseen characters), or export to LaTeX, run LaTeX and then see more detail on the nature of the error.

## Conversion to HTML:

If you are interested in creating an HTML document from your LyX file, there are many LaTeX-to-HTML converters available, some of which are listed on my LaTeX tutorial Web page. The LyX home page mentions an integration of LyX with one of those packages, tth. but you could just use tth separately, without this integration.

You can embed a URL link in your .lyx file, for eventual use in an HTML version of the file, by doing Insert->URL. Just type in the URL; the name is optional. The LaTeX \url construct will be generated, which in .tex will merely display the URL, but when processed by tth (or other converters), will produce a link whose anchor is the same as the URL itself.