A LyX Thesis Layout for UNSW Theses
Since I’ve had my PhD thesis accepted I’ve had a couple of friends who are writing up their theses at CSE ask me for help. In particular, they’ve wanted to know how I used LyX to write and format my thesis. In case anyone else needs a hand, I’ve made the LyX layout files available below, along with some tips and tricks.
LyX and LateX
For the uninitiated, LyX is a front-end for LaTeX, a command-line driven typesetting system that produces beautiful looking documents. The front-end provided by LyX alleviates some of the more arcane and tedious aspects of working with pure LaTeX. You can use LyX without knowing any LaTeX (although you do have to install it) and still get great results.
The LyX GUI lets you write in a manner similar to a word processor, using buttons, menus or key shortcuts to layout and format your text while giving you a preview of what it looks like. When you’re ready to print or submit your work, LyX translates what is on the screen into LaTeX code and then hands it off to the LaTeX system to do all the heavy typesetting, resulting in a beautifully rendered PDF.
I’ve written an undergraduate thesis and several conference papers in pure LaTeX and a PhD using LyX. For me, LyX wins hands down as many LaTeX annoyances such as forgetting to close environments, including figures, managing citations and dealing with tables become much easier in LyX. This results in more time writing and less time tracking down compile bugs.
For a gentle introduction to LyX, I’d recommend having a look at the Structured Writing with LyX article (even though it’s a little out of date) and the Tutorials section of the excellent LyX wiki.
The Layout File
Much of the presentation of your document that is normally configured through LaTeX commands can be managed through LyX layout files. A layout defines the various styles and blocks (such as titles, headings, author details, code, etc.), how they will appear on screen in LyX and how they are to be translated to LaTeX.
This is not a tutorial on writing LyX layouts but if you are curious about how this stuff works a good place to start is Section 5.2 of the Customization document that can be found in LyX’s Help menu.
To make the UNSW thesis layout file easier to use I embedded the LaTeX mark-up commands into the preamble of the LyX layout file. I realise the “correct” way to do this sort of thing is to write a LaTeX class file (e.g., unswthesis.cls) and create a corresponding layout file (e.g., unswthesis.layout) that references its commands. However, I thought it would be easier for LyX and LaTeX newcomers to only have to deal with a single file and not have to worry about fiddling with their LaTeX configuration too much.
Installing the Layout File
Download the following layout file and save it to the layout section LyX configuration directory. This is usually in Library/Application Support/LyX-1.5/layouts/ relative to your home directory.
- unswthesis.layout - 10KB LyX Layout File
Now open LyX and select LyX > Reconfigure from the menu. LyX will then ask you to restart. Once this is done the thesis layout should be installed and visible in the Document Class field of window opened via the Document > Settings... menu.
For this layout to work correctly, you will also need an image of the UNSW crest. I found a black and white PDF one that works nicely with this layout. You can download it here:
- unswcrest.pdf - 74KB PDF File
This file needs to be in the same folder as the LyX document using the thesis layout.
Using the Layout File
Once you have LyX restarted, open a new document and then go to Document > Settings... and then select “UNSW Thesis” from the document class list and hit OK.
This layout has all of the usual styles found in the Book class. Two of them, Author and Title, are used to control what is displayed on your thesis title page. In your new document, add a title using the Title style and put your name underneath in the Author style.
Save the document in the same directory as the unswcrest.pdf file and then turn it into a PDF document via the View > PDF (pdflatex) menu option. If all goes well you should see something like the following:
Note: As this layout makes use of the graphicx package (found in most LaTeX distributions) and a PDF version of the UNSW crest only the pdflatex view will work.
Templates
It makes sense to split a thesis-sized document into several manageable chunks. This allows you to work on each chunk in isolation, making it easier to zoom around your document and examine the final output without having to build the entire thesis.
I used a separate LyX document for each chapter and appendix and a “main” file to draw them all together when I needed to inspect the entire thesis.
The zip file below has everything you need to get started, including:
unswthesis.layout- The layout file described above.unswcrest.pdf- The UNSW crest described above.main.lyx- The main template used to build the whole thesis.chapter.lyx- An example chapter that is included by themain.lyxfile.example.bib- An example BibTeX file that is included by the main template.copyright.tex- A LaTeX file that is used by themain.lyxtemplate to add the required copyright statement to the beginning of your thesis.originality.tex- Another LaTeX file that is included bymain.lyxand required by UNSW.
You can download the lot here:
- unswthesis.zip - 34KB Zip File
Just unzip the directory somewhere convenient and copy the unswthesis.layout file to your LyX directory as described eariler. Then open the main.lyx file with LyX and you should be able to create a PDF from it using View > PDF (pdflatex) straight away. After that, just use the File > New from Template... menu item to open the chapter.lyx document as a template, replace the text with your thesis chapter and save it. To add your chapter to the main.lyx document use the Insert > File > Child Document... menu to add it.
Happy writing!
Caveats
I originally started writing my thesis using LyX 1.3. Since then LyX has gone from strength to strength and is now up to version 1.5. The files here have all been adapted and improved from the LyX 1.3 versions I originally used and tested using LyX 1.5.1.
I’ve also only tried this on the Mac version of LyX 1.5 using teTeX as the LaTeX system under the hood, though there’s no reason things shouldn’t work with something like MacTeX instead. The only thing I’m not too sure about is whether there are any packages that I use in this layout that don’t come with a standard LaTeX distribution. Let me know if you have any problems.
Also, the format of the title page, margins, declarations, and so on met the submission guidelines for UNSW as of July 2006. You may want to check if they’re still valid. If not, a quick poke around in the files and it should be apparent where to make any changes.
Acknowledgements
Most of the code for formatting the thesis title page comes from a LaTeX class file I found on CTAN as does the formatting for the copyright.tex and originality.tex files. Thanks to Stephen Harker for making these available.
The LyX image in this post is thanks to the LyX page at the Linux Guiden wiki.
34 comments
Massive thanks for this. I tried the test files and all work seamlessly for me (Lyx 1.5, and I don’t actually know which tex/latex installation I’m using – I think it’s gwTeX from either the i-Installer or MacTeX).
I haven’t tried it on my actual thesis documents yet, and at the moment I’m hesitant because I quite like some of the layout from the default book class that seems to be different in your layout (eg the font, the TOC style).
So, I’d really like to know either: (1) how easy is it to just add the copyright.tex and originality.tex to the book class as-is, or (2) how easy is it to modify the unswthesis.layout to change fonts and some layout to my own tastes?
Maybe this is where I need to look into the Customization document you mentioned?
I’m in no massive rush to do this yet, as I still have many words to write before I indulge in layout modification procrastination!
For option 1, you can just do an “Insert > Child Document…”, choose “Input” from the list of Include Types and then include the copyright.tex file.
For option 2, you can control most of the fonts and TOC settings from inside LYX. In the “Document > Settings…” window you can mess with the fonts using the lists in the “Fonts” section and the amount of information in the TOC through the controls in the “Numbering & TOC” section.
As most of the commands in the unswthesis.layout file are copied from the AMS Book style they should also be similar to the standard Book layout.
Good to know that it works on someone else’s machine!
Just a few comments and questions. First, thanks! this is working great for me (i’m also using a mac). Second, a tip for others – I wanted to have an appendix section but found it a bit difficult to layout correctly. I figured out that I could insert a LaTeX command after the bibliography (”appendix”) and it would start treating files based on the chapter template as appendices. Third, a question, when trying to navigate the whole document in Lyx it lists out all the sections correctly, but doesn’t include the “chapter” titles which makes it a bit confusing to know when each chapter starts/ends. Also, I wanted to try and have another level deeper show in the table of contents and wasn’t sure how to do that. Any suggestions?
Thanks!
Regarding the appendix, you can achieve the same effect by selecting `Documents > Start Appendix Here` from LyX’s menu while your cursor is placed somewhere after the bibliography.
I’m not sure how to address the content navigation issue but displaying deeper levels in the table of contents can be done using the `Document > Settings… > Numbering & TOC` dialog. There’ more detail in section 3.3.4 of the LyX User Guide in the `Help` menu.
Unrelated – but I also had issue with any of the styles for definitions, algorithm, etc – so i just didn’t use them, but might make sense to remove those styles if they don’t work.
Also, if you’re a complete newbie – you can quickly edit the layouts and tex files in OpenOffice 2.4.
changing newpage% to newpage in the layout file got rid of the error and allowed me to render the file. Not sure (yet) what side effects that may generate :-) Anyone any thoughts?
just gotta say thank you for the work. It just make life so much easier without need to worry about formatting!
got some questions also, is there anyway I could easily modify the section style? I was trying to modify the Align/AlignPossible attributes, but looks like it only changes how lyx display the section title, but not the final pdf.
Style Section
Align Left (wanna align left)
and is there any way to put a horizontal line on top of each page, below the page no, and above all the text? not very sure what style it is called!
Cheers
There are essentially two parts to the `unsw.layout` file: the “preamble” which contains all the LaTeX commands that determine how the PDF will look, and the “LyX layout” which matches LyX environments and commands to LaTeX environments and commands.
If you only modify the LyX layout part you will only change how the document is display within LyX. To get the changes you want in the PDF you will have to figure out want the appropriate LaTeX commands are.
I can’t really help much since I copied the LaTeX commands in the “preamble” section of `unswthesis.layout` from a LaTeX UNSW thesis class I found on CTAN (details are in the post). You’ll have to poke around in the “preamble” section, consult Google, a TeXpert or a good book on LaTeX to figure out how to make the changes you want. I’m not enough of an expert to help without doing that kind of research myself. Sorry!
thanks for your explanation :-)
I’ve found that for the second question about putting a line on top of each page, it could be easily done by changing the headings style to “fancy” under Document->Settings->Page Layout… in case someone is looking for it. I’ve read from the mailing list that you could further customize what you want in the headers by using preambles like:
lhead{Text on the left top}
rhead{Text you want on the right top}
chead{Text you want over the center}
lfoot{left footer}
rfoot{right footer}
cfoot{center footer}
By the way, would you by any chance know what’s the best way of putting another extra abstract page before the TOC, and possibly another Acknowledgment page at the end?
Cheers
Easiest way to add another abstract would be to create a new lyx doc with the UNSW thesis doc class and select Chapter* for the heading type.
Then in main.lyx include the new lyx doc as a child doc before the TOC.
However, I still cant’ figure out how to get anything after the mainmatter. I tried to put in an extra ERT, “backmatter”, but still, conventional Arabic page number are still used in all the bibliography and appendix
I’m more than happy for you (or anyone) to customise my layout. My layout was only possible due to the work made freely available by others so I have no problem with people building upon my work.
If you put your your modifications up on the web somewhere all I ask is that you link back to this page with an acknowledgement.
Another tip I’ve found – I have been keeping my thesis in svn, and my supervisor wanted some formatting changes so I found it easiest to actually move most/all of the formatting stuff into a new file, then simply include that file in the preamble. This helped me to keep changes to the main file separate from formatting changes.
that’s some great work you’ve done there!
Just one comment – I’m not exactly a LaTeX guru myself, but I think there is a statement missing in unswthesis.layout. It might not affect the functionality of the script at all times, but when I use Lyx 1.5.5 on Mac, I have to add one line to the .layout file, or the PDF creation will fail (see below).
Cheers,
Satu
\ifnum\month=12
\@tempcnta=\year \advance\@tempcnta by 1
\edef\@copyrightyear{\number\the\@tempcnta}
\else
\newcommand{\@copyrightyear}{\number\the\year}
%ADD THE FOLLOWING LINE
\fi
Yesterday, less than 12 hrs before your comment, I was having this exact problem which caused an error: “an empty output file was created” when trying to produce a PDF from these files and unswthesis.layout on LyX version 1.5.6 on Mac OSX 10.5.5.
Your solution fixed the problem after doing another Lyx Reconfigure.
As for me, I am finally at the stage of being able to indulge in layout modification procrastination! (well apart from a list of minor fixes and edits to make)
cheers,
Nick
File does not exist: /tmp/lyx_tmpdir.JL1313/lyx_tmpbuf0/newfile1.pdf
Maybe is the same problem. But I dont knoww how edit the .layout file. When I edit unswthesis.layout with the Texshop editor, and save it into the Layouts folder, I cant select this layout in Document-settings-documentclass.
¿How do you edit it? ¿where do you insert the code?
Thanks
Just a quick note to let you know that I’ll look into the problems you are having with the layout in the new year.
Keep in mind that I wrote the layout for my own purposes which was to finalize my PhD a couple of year ago using LyX 1.3. Things have changed with LyX since then so there’s no guarantee that what worked then will work now even though I tested them on LyX 1.5. Caveat emptor and all that.
Merry Christmas!
Merry Christmas
I am using LyX 1.6 for Mac OS 10.5 and the LaTeX I am using is pdflatex from the TexLive-2007 distribution.
I followed the instructions that I wrote above. That is, I downloaded the zip file, placed `unswthesis.layout` into `~/Library/Application Support/LyX-1.6/layouts/` then opened `main.lyx` using LyX and selected `View > PDF (pdflatex)` from the menu. I got no errors and a PDF of the document appeared, correctly formatted, in Preview.
I do not have time to try all the permutations of LyX versions, OSes, TeX distributions, etc so I will rely on others posting here to clearly describe the problems they are having and the systems they are using in the hope that someone else can solve them.
I’m happy if people fork the layout I’ve created here, modify it, get it working for their own set up and then post here a link to their working version.
“ The control sequence at the end of the top line
of your error message was never def’ed. If you have
misspelled it (e.g., `hobx’), type `I’ and the correct
spelling (e.g., `Ihbox’). Otherwise just continue,
and I’ll forget about whatever was undefined.”
It gives the same error if I comment out the whole part for making a title in the layout file.
Do you have any idea what can be the problem ?
Just wondering how abstract is inserted. I had a look at your thesis, and it contains an Abstract page. However, it doesn’t show up on my dvi so far. I had a look at the Lyx documentation, and it stated that the Book class ignores Abstract.
Still investigating…
Also how to add dots between titles and page numbers in the TOC?
As I pointed out in the post, I built the LyX template from a LaTeX class file I found. If you want to know how to modify the layout of the final PDF you will have to modify the class file. Also, I suspect some of the errors people are encountering are due to variations in the TeX package they have installed.
I don’t have the requisite LaTeX skills to solve these problems so you will be best served by asking a LaTeX forum for help.
Thanks for the great template. It’s working quite well after a few little hitches but I can’t seem to get the Contents to list levels below Sections (i want to list subsections at least). I have tried changing the Document Settings>Numbering and TOC. This seems to be active as reducing levels works.
I have also looked through the layout file for conflicts but don’t see any problems there.
I am on OS X 10.5.6, Lyx 1.6.0
Thanks again
Leave a new comment