LyX made easy

Apps

Regular readers will no doubt remember our LaTeX made easy tutorial on the Latex typesetting application. But although Latex is a hugely powerful piece of software, getting to grips with it can be a real headache if you'd rather just sit down and get to work.

Luckily, that's where Lyx comes in: if Latex has a steep learning curve, Lyx is the cable car that whisks you two thirds of the way up the mountain so you can enjoy the views without having to break a sweat. And just as web editors can create websites without you needing to know HTML, Lyx is able to prepare documents for typesetting without getting too involved in all the intricacies of Latex.

If you enjoyed our other Made Easy tutorials, try this one for size!

Lyx is a GUI editor originally created in the 1990s by Matthias Ettrich that uses Latex macros to pass parameters to the Tex typesetting engine (which was originally created in the 1970s by Donald Knuth after he became upset by the poor quality phototypesetting of one of his books). It's a document processor, not a word processor, producing high-quality documents with Tex looking after font sizes, margins and graphics.

But Lyx isn't WYSIWIG; instead it offers a preview option. The Input screen can show comments, cross-references and so on, but it does more. For example, if you want a rotate a table or figure in the output, you can continue to work on it on the Input screen in normal orientation.

Lyx's GUI harnesses Tex and makes it easy to use.

Lyx's GUI harnesses Tex and makes it easy to use.

Filenames and folders

As Tex was created so long ago, it likes filenames to follow Unix conventions, so avoid spaces and unusual characters in file paths or you may get an error telling you Tex hasn't been able to find a file you know is there. Lyx also prefers all the files relating to a document to be in the same folder.

Format your work

Every Latex document belongs to a class and every class only supports certain paragraph styles; for example, Articles don't have Chapters. If you fire up Lyx and open a new document, you'll be presented with an Article class document. Now if you select Document > Settings and click on the button bar below Document Class, you'll find nearly 40 alternatives installed and another 40 that Lyx knows about, but which may not be available on your system. Each of these classes comes with its own set of allowed paragraph styles.

Select File > Import > Plain Text to import a plain text file to work on – we've put Lyx_example.txt on the in case you don't have anything suitable to work with. Place the cursor on the first line and select the Standard button in the top left-hand corner to discover the available paragraph styles. Select Title and the first line will change font and centre itself. This is not exactly what you'll see in the output, but it's good enough to give you a rough idea of the layout.

If you select View > PDF_(pdfLatex) or the Acrobat icon, you'll get a preview of the document with today's date below the title. You can turn this off by selecting Document > Settings > Latex Preamble and entering:

\date{}

Or if you'd rather change the date, you can select Date from the drop-down list to do this.

By default, the paragraph styles are grouped. The headings form a hierarchy – Part, Chapter (books and reports only), Section, Subsection, Paragraph and Subparagraph – and duplicates are marked with an asterisk. Those without an asterisk are numbered and will appear in any contents list you insert.

There are four types of list: Itemise, Enumerate, List or Labelling and Description. You can nest these styles by using the icons that look like indenting buttons. At every level of nesting, a long red square bracket appears to the left of the nested paragraphs (so you won't lose track of nesting levels) the style of numbering or bullet changes and the space between the paragraphs decreases. All of this is done automatically, although you can customise the bullets with Document > Settings > Bullets.

If you select Section* for each of the single lines in the example file, you should discover the structure of the piece. There's an Itemise list in the section 'What Is Special About Linux?', two in 'What Do I Get With GNU/Linux' and an Enumerate list in 'How Easy Is It To Get Used To Linux?'

Floats

Between the two Itemise lists in 'What Do I Get With GNU/Linux?' a figure within a float has been inserted. You can insert a graphic or a table directly by selecting the icons in the first row or via Insert > Graphics/Table, but this means that Tex will reproduce it exactly where it is, leaving a huge white space if it has to be pushed to the next page.

If you'd rather not worry about its position, you can select Insert >Float. This gives you a caption holder and the choice of placing the inserted material above or below the caption (if you're using the example file, delete the marker left in the file).

Having moved the cursor below the caption, select the Graphics icon on the top row to insert Linux_structure.fig. The Graphics window offers options to scale and to rotate the figure in the output, while the Latex And Lyx option enables you to scale the graphic on the Input screen. When you select OK, you will find that the image is left-justified. If you want it centred or right-justified, place the cursor to one side of the picture and select Edit > Paragraph Settings to change it.

Graphics

Lyx takes advantage of ImageMagick on most Linux systems to accept graphics formats, converting them silently to PNG for display on the Input screen and to EPS for passing to Tex. However, it's best to use vector graphics software wherever possible to create figures and save them in EPS format to ensure high-quality output.

When you insert a table, in or outside a table float, its columns are all narrow, but as you make your entries, Lyx adjusts the column widths to suit them. If the table becomes too wide for the document, make it narrower by selecting Edit > Table Settings from within the column you want to limit the width of and allow Lyx to work out the rest.

There are both drop-down menus and a context-sensitive toolbar to help you to adjust tables as well. You can also import tables in CSV format with File > Import > Table (CSV), which creates a new file with a table in it that you can copy and paste into your document. But it won't be linked to the external file, so you'll have to re-import it if you make changes.

Once you're happy with the contents of a float, close it by clicking on the greyed out box 'Float: Figure' or 'Float: Table', to ensure that it doesn't have to be redrawn every time you scroll through the document.

Cross-references

No, we don't mean the ones you get from an irate employer, but rather the ones you make within a document. To set up a cross-reference, select Insert > Label, or click on the Label icon when the cursor is at the start of a paragraph or caption. After filling in the caption, place the cursor over the beginning and select the Label icon. The dialog box suggests a human-readable label (including a prefix), in case, for example, a section and a figure have the same title. You can edit this if you decide to revise the wording of a section title.

You can then create a reference to this location by selecting the Book icon. At the moment, there's only one link to select from. Once you've selected it, a greyed-out box appears to say which cross-reference you're using. The default cross-reference is a number, so when Latex has worked out what the correct number for this figure is going to be, it will insert it after 'Figure' in the output, replacing the cross-reference. Note that if you put in another figure before this one, Latex will change the number. You can also choose reference differently, for example, in the style of 'on page n.'

Lyx updates all references based on the contents of the document, which can save you a few tedious formatting tasks.

Lyx updates all references based on the contents of the document, which can save you a few tedious formatting tasks.

Lyx Maths Editor: Beautiful formulae

The AMS Latex maths macros are the best way to typeset maths and Lyx has supported them from the outset. You can enter maths in-line with Ctl+M, or in display mode (that is, as a separate paragraph) with Ctl+Shift+M. Superscripts such as powers are added with ^ and the underscore key _ adds subscripts. You can enter simple equations without ever using the toolbar. Note that the output has spaces generated by Latex; only rarely will you have to add extra spaces.

Sums displayed in-line and as a display fraction.

Sums displayed in-line and as a display fraction

Whenever you use these keyboard combinations, you're creating a nested container in which to place one or more expressions. When a container is empty, it has a blue border; when you fill it, the border disappears and may be replaced with red markers at each corner. To enter something like 'x to the power of a half', you enter 'x' in Math mode and then create a superscript container and a pair of fraction containers.

Having added the 1 and 2 to the fraction, you move out of the fraction container first, then out of the superscript container and finally out of the Math mode container. As you move the cursor, you will normally see it cross the boundaries of the containers as marked by the red corners.

Text in maths mode

When you're in Math mode, you can use Ctl+M to return to Text mode. This lets you print something like 'Speed = Distance/Time' using the fraction from the Basic toolbar where the words are printed as words rather than as mathematical expressions. This means that the whole expression will be typeset perfectly.

The basic toolbar

Whenever you enter Math mode, one or two maths toolbars will appear. If both appear, the icon on the right with a pi symbol enables you to toggle between a display with just the basic toolbar and a display with both toolbars. The first three icons toggle in-line and display mode, and these enable you to enter subscripts and superscripts. After the Square Root and Root icons comes the Simple Fraction icon, followed by the Sum icon, which illustrates the difference between in-line and display modes.

The next four icons offer you the three most common delimiters and access to the full range, omitting one of a pair. Though your keyboard offers you `(', `[' and `{,', these are not scaleable, so you get rather odd effects if you include them in an expression. If you use the equivalent delimiters in Math mode, these are then scaled to match the expression.

This is important when using the next two icons, which insert a matrix or to create an array. The next four icons allow you to add or delete rows and columns to and from matrices and arrays, and the delimiters will change size to match. The last icon toggles between the Basic toolbar and both toolbars.

The Advanced toolbar (above the Basic toolbar) offers a wider range of alternatives, including two smaller styles than in-line mode, several different types of fraction and access to a wide range of mathematical symbols.

Before and after the icons for the alternative styles and fractions are the icons for alternative spaces and fonts. Although you can leave the spacing and fonts for most maths up to Latex, for some expressions editing may be useful, the example given in the Lyx help being integrals where the d in dx should be set upright.

The alternative fonts can also be used to make vectors bold, or you can use Decorations (the box icon with a circumflex on it) to underline a vector. In each of these cases you are creating a second container, which enables you to add more letters in the selected font or within the decoration, but remember you'll need to make two cursor movements to get out of the containers again.

Signing sine

Tex cannot tell whether a sequence of alphabetic characters (such as tan) is supposed to be a word, or stand for 'tangent.' Latex has functions that need to be typeset upright and Lyx lists these when you select the 'Exp/tan' icon.

The remaining icons in the Advanced toolbar provide access to the wide range of mathematical symbols you might need, including alternatives developed by the American Mathematical Society (AMS) if you prefer these.

The figure below-left shows an AMS document class with the function list and Theorem, Corollary and Definition paragraph styles in use. Anyone who intends to use the Advanced toolbar or the AMS document classes is strongly advised to read the Lyx maths help.

Lyx Bibtex: Sort your citations

Anyone struggling to cope with referencing their work can use the Bibliography paragraph style, but Lyx also supports Bibtex, written by Orem Patashnik to work directly with Tex. Bibtex involves two parts: a bibliographic database (.bib file) and a bibliographic style (.bst file). All the bibliographic styles will be superseded by Biblatex, which is now in beta, but the bibliographic database will be retained.

The Bibtex database allows records with different structures to co-exist within the same table. Its structure is:

@RECORDTYPE{identifier,fieldname1=contents,fieldname2=contents, ...}

The first part determines the record type: book, article, chapter in a book, thesis, etc. Each record type has a small number of mandatory fields and one or more optional fields. The identifier acts both as the index key for Bibtex and as the user's identifier, so it needs to be created with care. The best summary of the available record types and fields is at http://tinyurl.com/dbcz3v.

Bibtex vs Biblatex

Development of Bibtex styles has now ceased following the development by Philipp Lehman of Biblatex, which is expected to be incorporated in Tex distributions in the not-too-distant future. Biblatex implements the Bibtex styles with Latex rather than Tex and offers more options. Go to www.ctan.org/tex-archive/help/catalogue/entries/biblatex.html.

Adding citation data

In the screenshot above-right, @BOOK and @ARTICLE are record types, and the identifier is the value in green. Book references may have an author field, an editor field or both. For an @BOOK record, use either the author or the editor field (not both); for an @INCOLLECTION record, there will be the author(s) of the chapter and the editor(s) of the book.

Use and between the names of multiple authors/editors in the author and editor fields, however unnatural this may look, because Bibtex uses and as the delimiter and will use this information to format the reference. Bibtex expects names to consist of two or three parts; put an organisation's name inside braces to prevent Bibtex breaking it up.

Once you've created a file (it only needs one reference; you can add others later), select Insert > Lists/TOC > Bibtex Bibliography in an empty standard paragraph where you want the references to appear. Select Add in the pop-up window and you'll be offered a number of example files; for now, select Browse and, if your Bibtex file is in the same folder as your Lyx document, it will be there to be selected. Once selected, it will appear in the Databases window.

Below this is the Style button, which gives you access to the installed bibliographic styles; Browse enables you to use a different one. If you prefer numerical citations, choose plainnat; for author-date, choose apalike; then OK the dialog. Both need Natbib enabled. Natbib, created by Patrick Daly, lets you vary the style of citation between, for example, '(Daly, 2007),' 'Daly (2007)' or just '(2007)' and to add comments or pages numbers to a citation. You enable it via Documents > Settings > Bibliography > Natbib, where you also choose Numerical or Author-date.

You insert citations at the relevant point by selecting Insert > Citation or the icon that looks like a bunch of papers. The upper left window lists the identifiers from the Bibtex database (shown in the screenshot, left). universitychicago is highlighted because I've just selected Add and it has appeared in the upper-right window.

Adding a citation using LyX is easy and fast.

Adding a citation using LyX is easy and fast.

Below these windows, the highlighted Bibtex record appears as a CSV record showing the braces I added to force Bibtex to treat 'University of Chicago' as a single name and to capitalise the letter 'C.' If you have forgotten an identifier, you may want to use the search facilities to locate the record.

The lower part of the dialog contains the Natbib extensions, which enable you to specify how the citation will appear in the Text, the Text before and Text after dialog boxes and a couple of other options. After that, you can leave everything up to Bibtex; as long as the reference is correct in your database, it will be correct in every document you produce and, when you cite multiple references by the same author in one year, Bibtex will add the 'a', 'b', 'c' to the year.

Hyphen, dash, minus

One quirk of Lyx is that a new user needs to know the difference between a hyphen, an en dash, an em dash and a minus sign. The first three are made with one, two or three '-' characters and the fourth by using Math mode.

One quirk of Lyx is that a new user needs to know the difference between a hyphen, an en dash, an em dash and a minus sign. The first three are made with one, two or three '-' characters and the fourth by using Math mode.

First published in Linux Format

First published in Linux Format magazine

You should follow us on Identi.ca or Twitter


Your comments

SSH Made Easy?

What about a SSH made easy :D

Re: SSH made easy?

man ssh

Will it work well with OpenType fonts?

I heard Xetex was the way to go for using OpenType fonts and their ligatures and other features. I'm a graphic designer, so that sounds cool to me.

Does Lyx work with Xetex somehow, or does it support the cool OpenType features? All these *x words are confusing :P

about Hyphen, dash, minus

You don't have to learn the differences between the different dash types when you don't like to because LyX offers all characters also via the menu
Insert -> Special Character -> Symbols
(For more information about this, see the User's Guide, sec. 3.9.1 that comes with LyX 1.6.4.)

It is possible to use LyX

It is possible to use LyX with XeTeX. You will need to export a .tex-file from LyX, and perhaps make some trivial changes, before using xetex on the file. Read the LyX wiki for more information. Proper support for xetex is planned.

This story

has become tiresome.

trouble when trying to export to pdf

I get many error messages when trying to export to pdf. I got no idea what to do. Be glad if you can help me!

The error messages i am getting are:
use of \@part doesn't match it definition.
use of \@iminipage doesn't match its definition
missing endcsname inserted

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

CAPTCHA
We can't accept links (unless you obfuscate them). You also need to negotiate the following CAPTCHA...

Username:   Password:
Create Account | About TuxRadar