Tuesday, August 24, 2010

LaTeX in LyX

If you ever need to write up a paper in LaTeX and you aren't terribly interested in doing it by hand, I'd like to recommend the open source software LyX. It's not a WYSIWYG editor, but when writing in LaTeX that's probably not what you want, anyway. Rather, it abstracts only just enough of the annoying bits of writing a document by hand by creating the codes for you, but still making it quick and easy to do things like write equations and label figures.

(Not sure what LaTeX is or why you'd bother learning to us it? Check out this crash course on the subject to find out. I avoided it for a while because it was just "one more thing to learn," but the investment I finally made was totally worth it.)

If you're a Windows user, I wanted to share a few tips on LyX. Even though I've been using it for a couple of years now, I recently ran into some headaches and had to look all this stuff up, so hopefully I can save you the trouble.

When installing LyX, I like to have LaTeX set up first. I recommend MiKTeX.

Once that's installed, go ahead and install LyX. Get the standard installer here. This version assumes you already have LaTeX installed, and will automatically find where you put MiXTeK. In the past, trying to get everything all at once (i.e. using the bundle install) did not work well at all. Here's more info about LyX for Windows.

Once you start using LyX, you may find that your spell checker doesn't work (the most common checker used is called Aspell). This happened to me recently. Because of some changes to more recent editions of LyX, I couldn't get Aspell to work after installing the newest version of LyX. There are various possible reasons for this, such as needing to install the Aspell dictionaries.

In my case, the registry keys left over from old installs of LyX never got updated, so LyX couldn't find the dictionaries. If you get error messages when you try to start spell checking, try searching your registry keys for "aspell" and double checking that the paths stored in the keys are actually correct. Your copy of aspell might have been installed right on the c:\, or potentially in Program Files. You can even move the installed stuff to your LyX folder if you want to keep things together, just as long as you update those paths in the registry.

Next, if you have a document class file (*.cls) for a conference or something, you need to make sure both LaTeX and LyX know about it. This is pretty easy once you know how. This post tells you exactly how to do it.

One of the greatest things about LaTeX is how easy it is to create a bibliography using BiBTeX. You technically don't need to install anything extra to use BibTeX, but the source file (*.bib) is not so fun to write by hand (and after all, we are using LyX to avoid this sort of hand-coding in the first place!).

Instead, try a reference management tool like JabRef. It makes it easy to format your references and creates a BiBTeX file for you. You can even make adjustments by hand when that's easier.

Once you have a *.bib file, you just tell LyX to "Insert > List / TOC > BiBTeX Bibliography" and point to it. Then when you "Insert > Citation" all the references in your *.bib file will show up there for you to choose from.

If you get errors when trying to compile your LyX file into a PDF (or whatever), check that the codepage for your BiBTeX database supports the characters in your file, but isn't UTF-8 (it's not supported by BiBTeX even if JabRef allows it). You will also need to double check that the font you are using in LyX actually supports the characters you are trying to use. For instance, I recently had to switch from Times to Times Roman to accommodate some of the accented characters that were appearing in authors' names.

That's it for now - I hope you enjoy LyX and don't run into too many problems!


Haz said...

Out of curiosity, why JabRef and not Mendeley? The latter does bibtex exports just as well, and is far more featured.

Gail Carmichael said...

Good question. I actually do use Mendeley (thanks to you!), but find that using JabRef is easier for making sure the references are correct. I once exported a BiBTeX database from Mendeley and it was a mess (not Mendeley's fault, though - mostly the fact that I allowed it to automatically find info about sources and then trusted that too often). So what I end up doing is using Mendeley to organize and read papers, but use JabRef to build each database (I tend to have one for each paper).

rouli said...

I don't know ...
I wrote my first paper in Lyx, and it some cool features (like comments and corrections-a-la-word), but whenever I tried doing something more complex with it (like using an algorithms package) it was liking waging a war.
Moreover, it litters your .tex files with its own symbols, which makes them difficult to edit later on with a standard text editor.

btw, I've just discovered it a month ago, but algorithm2e is the best algorithms package out there (I just need to spread the word).

Gail Carmichael said...

I haven't had to fight with it that way yet, though I also haven't tried to use an algorithms package. I know that version 2 is on its way, so maybe there will enough improvements to make that easier?

Post a Comment

Comments are moderated - please be patient while I approve yours.