# Thesis writing using Lyx

When it came time to write my thesis several months ago I decided to use Lyx instead of using LaTeX directly. This is a short tutorial explaining this decision and how it was accomplished.

Lyx is a front-end for LaTeX. It gives you all of the power of LaTeX if you want it but also offers a more traditional word processor like interface. Lyx lets LaTeX handle all of the document layout and gives you the professional look that drives so many people to LaTeX. Lyx also allows you to write without having to see the LaTeX commands or worry about the document layout. The most important thing to realize is that Lyx is not a WYSIWYG editor like MS Word. This is a good thing. If you are used to WYSIWYG editors this can at first seem very strange. I personally find it quite liberating because I have the tendency to obsess over the visual details as I write. In a normal word processor this tendency manifests as losing my train of thought when I stop to format the document. When writing in LaTeX or HTML the same problem occurs when I switch to formating the tags. Lyx does however give you enough feedback about the layout through changing the font of chapter and section titles among other things that the writer does still get some idea of the eventual layout. Lyx also handles cross references and the bibliography in a nice intuitive manor.

Since the Lyx file format is text based it is also very easy to use standard version control software on the document as work progresses. Just as when coding, I view the use of version control software with a document of the size of a thesis as being absolutely essential. The ability to scrap a paragraph and know that you can quickly and easily revert to the old version if necessary frees the writer to attempt larger changes than would otherwise be convenient. It really doesn’t matter what version control system you use with Lyx. Any of Subversion, Mercurial, Bazaar or, if you are on Linux, Git will work great. At completion my thesis Git repository consisted of over three hundred commits.

A short note about figure creation is also in order. I used Inkscape for all of the figures in my thesis. Inkscape is a vector graphics program which uses SVG as the standard file format and is available for Linux, MacOS and Windows. I am not a graphic artist in any way but I found Inkscape easy to use once I figured out how all of the tools work. Making use of the various alignment and transformation tools is especially time saving. Since Lyx cannot make use of native SVG files my solution was to save the figure in SVG format in case I wanted to do future editing and also export an .eps file which Lyx has no trouble consuming.

If you writing a thesis it is quite likely that your university or department has a LaTeX document class available. You should make use of this resource because it will save you the large amount of work involved in getting the document to match the university requirements. Obviously using Lyx would lose some of its appeal if it was impossible to use the provided document class. Fortunately this is not the case.

If you look at your document settings in Lyx you will see a long list of document classes. I used the report class for my thesis. When first attempting to use the LaTeX document class from my university I spent a lot of time trying to get the document class to show up as an option in Lyx. You can find various pointers on how to do this but it never worked well for me and it was too much trouble. Fortunately I found a simpler solution. Rather than get Lyx to use the document class I wrote the document using the standard report class. When the document was complete I exported the document from Lyx to LaTeX (pdflatex). Once I had the LaTeX file it was simple to edit it and replace the document class name with the one provided by the University and add the additional LaTeX commands which were required. This task was probably simplified by the fact that the provided document class inherited from the standard report class. Modifying the LaTeX file may seem like a lot of work, especially having to make the changes manually again each time the document requires revision. Fortunately it is a simple matter to maintain a patch file with the necessary changes and apply it to the exported LaTeX file after revisions have been made. Note that there is little point exporting the document until it is very near completion.

The rest of this tutorial is specific to the UWO Computer Science document class. I hope this information will be useful to others as well. If you don’t already have a copy of the UWO CS Latex template I have made a local copy available.

After exporting your Lyx document to LaTeX (pdflatex) open up the file in an editor. In these examples the exported file is named thesis.tex. The first thing you need to do is replace

 \documentclass[12pt,english]{report}

with

 \documentclass[12pt,english]{uwo-thesis}

The rest of the modifications basically involve adding new LaTeX commands to the file. Since it is the way I did things, I am going to assume that within Lyx the beginning of your document contains the following in this order: title, abstract, table of contents, list of tables and list of figures. This is the order that the UWO thesis style guide requires.

Immediately after the \title LaTeX command add lines similar to the following (obviously filling in the values for your thesis).

\spinetitle{a shorter title}
\firstname{Dan L.}
\lastname{Siemon}
\degreeaward{Master of Science}
\university{University of Western Ontario}
\copyyear{\the\year}
\examinerA{first examiner}
\examinerB{second examiner}
\examinerC{third examiner}
\dedication{a dedication if you want}

These LaTeX commands are used to create the certificate that goes at the front of the completed thesis.

Next locate the \maketitle command in the file. Immediately after this command and before the \begin{abstract} add the following.

\makecertificate
\begin{frontmatter}

Following the close of the abstract section with \end{abstract} command you can add an acknowledgment section if you desire.

\begin{acknowledgements}
The past and present residents of MC240.
\end{acknowledgements}

Now you need to close the frontmatter section. This is accomplished by adding the following text after the \listoffigures command.

\end{frontmatter}

This leaves just one more requirement, the Vita which must be at the end of the thesis. I handled this requirement by creating a short LaTeX document called vita.tex and including it at the end of the file. Place the following immediately before the \end{document} command.

\include{vita}

All of these changes may seem like a lot of work. Fortunately this can be automated by creating a patch file. To create a patch file both the unmodified and modified files are required. First make a copy of your newly modified file. Then re-export the file from Lyx to obtain the unmodified version.

cp thesis.tex thesis.tex.mod

Export from Lyx again.

diff -u thesis.tex.mod thesis.tex > thesis.patch

Reapplying this patch after exporting from Lyx should be as simple as:

patch < thesis.patch

If you make large changes to the document the patch may fail to apply cleanly. In this case fix the file manually and re-create the patch file for future use.

Thanks to Andrew for a couple of the ideas presented here.

## 4 Replies to “Thesis writing using Lyx”

1. Jeff Shantz says:

Thanks for this. I’m going to be starting my Master’s at UWO in the fall and already use LaTeX for everything. Nice to have a tutorial on their document class. I always shunned Lyx as I found it strange, but maybe I’ll give it another look.

2. harris says:

cheers for this, first year student at Cambridge here trying to write lab reports for engineering. this page helps a lot!

3. Jayo says:

How can I export a document from lyx? I tried several times and it fails. please help am in tense situation to submit my thesis, thanks!!

4. Doc says:

LyX has come a long way since 2007. Universities should provide for theses the modules in LyX as well as a class in LaTeX.

I tried to make a LyX module for my university’s LaTeX class file, and found that it contained a lot of “hacks” in LaTeX that were non-standard (e.g., not using Babel for optional language formats of French or English, not using standard BibTeX to include both References and a Bibliography). Because of the hacks, it was almost impossible to cleanly map LyX to their class file. I had to make the changes to the LaTeX class. This process also made me appreciate LyX since it hides a lot of the complexity of LaTeX and wraps it in configuration options in a GUI.