Getting a Test File

Note, quite a lot of time has passed between me writing this and having the time to polish it and get in online. During this period, Amazon has improved the file format used in kindles (they currently use KF8). This means that a lot of the limitations I mention no longer exist (at least for newer devices). They have also improved the tools used to create mobi files. One big difference is that you can now convert from epub. This has quite a few advantages, and future versions of this plugin will take this route, but for now, this method will still work.

Right, things are about to get a bit hairy. What we are going to do is write an export plugin for LibreOffice that will convert our novel to xhtml suitable for submission to the Amazon kindle store. The first thing we need to know is how the novel is currently laid out by LibreOffice. A simple way to do this is just to have a look at a .odt file in a text editor (such as gedit). You can either use my test document below or use your actual novel. In order to extract your novel’s text (using Ubuntu Linux) simply right click on it and open with Archive Manager. Select the content.xml file and extract it somewhere.

Unzip showing the contents of an .odt file
The contents of an .odt file. The text is stored in content.xml.

Before you open it in your text editor, we need make it a bit more human friendly. Currently all the text is in one very long line, which is bit difficult to read and will probably exceed the maximum line length the text editor can deal with. To neaten it up, just pass it through tidy (you can use the online version if you can’t install it for some reason: tidy). This will add line breaks and indentations that will make the file much more readable.

tidy -xml -i -o testBook.xml content.xml

You should now have a file called testBook.xml, open it up (or open my test document below) in gedit (or the text editor of your choice).

A document for testingLibreOffice Writer Icon

You will see the file starts with the usual xml declarations and then has a load of namespace declarations followed by lots of style book keeping. I have added the stylesheet declaration for easy testing.

The xml and namespace declarations in test.xml
The xml and namespace declarations in test.xml

We’ll come back to these in a minute. The actual guts of your book starts inside the <office:text> element, which is inside the <office:body> one.

The contents of content.xml
The text of our novel is in <office:text>.

One of the things you might be a bit surprised by is that quite a lot of your lovely styles seem to have gone missing to be replaced with styles with names like “P1”. Don’t despair, this is normal. These weird styles are automatic styles. By default, LibreOffice will use automatic styles to make it easier for it to compare documents. You can turn them off in LibreOffice 5 with the catchily titled “Random number to improve accuracy of document comparison: Store it when changing the document” setting. Be aware though that this won’t delete any that already exist in a document. If you are planning on editing the plugin a lot, you will find it simpler if you create a document that doesn’t use automatic styles, otherwise don’t worry too much about it, they just make the plugin a bit harder to read.

The reason we are looking at these files is because, when LibreOffice exports a file, it first converts it to almost this exact format in memory before applying the export transformation, so these files are effectively what our plugin needs to transform. The only difference is that <office:document-content> is replaced by <office:document>. I don’t know why. So if you are using your own novel’s text to test with, do a quick search and replace on “office:document-content” replacing it simply with “office:document” (make sure to replace both opening and closing tags) and, whilst you’re at, add in a stylesheet declaration (the stylesheet declaration goes right after the xml declaration), then we can conveniently test our plugin as we write it by opening our test file in a browser.

<?xml-stylesheet type="text/xsl" href="odtToXhtml.xsl"?>

This assumes that the stylesheet we are about to write is going to be called “odtToXhtml.xsl” and is in the same directory as the test file. As of this writing, this works fine with Firefox on Linux but not Chrome. Other browsers/platforms are untested. Testing the transformation as we go in a browser ensures that, once the plugin is finished, we can then install it into LibreOffice confident that it is going to work as expected.

Let’s Get Pasting

Before we begin, it is good idea to save our document (and to make sure you have autosave etc. set up sanely), so do that quickly, and then let’s get going. The new document should be ready for you to enter your book’s title: the Novel-FrontMatter-Title paragraph style should be selected and the page style set to Novel-Page-FrontMatter (if they’re not, select them). Take a deep breath, enter the title and hit enter. Automatically the cursor moves down a bit and the style changes to the Novel-FrontMatter-Author style. Enter your name, hit enter again, and you’ll notice that we are magically at the top of a new page thanks to the “page break after” setting of Novel-FrontMatter-Author. You’ll also notice that we have now switched to the Novel-FontMatter-Copyright paragraph style. Enter all your copyright info (and ISBN). When you are done, hit enter one last time, and change the style of this empty paragraph to Novel-Forward-Title (or Novel-Part-Title or Novel-Chapter-Title, depending on how your book is structured), which will start a new a page thanks to “page break before”.

The first page of the example book
The first page of the example book.


When you changed the paragraph style it will have triggered a change in page style to Novel-Page-Forward and reset the page count. To make use of this, click on the footer and change the paragraph style to Novel-Footer. Then click on “Insert->Fields->Page Number”, this will add a page number to all pages with the same page style (i.e. Novel-Page-Forward). When our page style changes in a minute to Novel-Page-First and again to Novel-Page, we will have to add them again. We don’t want a header for our forward, so leave that blank.

Right, back to adding stuff. Enter the title of your forward, hit enter and paste in the text. You can either paste it all in one go and then go back and change any paragraphs that begin sections to Novel-Forward-Section or you can just past them in section by section. Once you are done, hit enter a final time and change the style of the empty paragraph to Novel-Part-Title (or Novel-Chapter-Title if applicable).

The first page of the forward with page numbers inserted.
The first page of the forward with page numbers inserted.

Part One

If your forward finished on a left hand page, you’ll notice that a new page has been started thanks to “page break before”, but if your forward finished on a right hand page, a blank page has also been inserted. This is because our Novel-Part-Title style is set to “right only” so it skips the left hand page, leaving it blank. Our part title has also had its page style changed (to Novel-Page-Part). You’ll notice that this removes the page numbers from the bottom of the page.

Enter the part title and hit enter again. A new page is created and a blank page is inserted.

The part one title with the automatically inserted blank page to its left.
The part one title with the automatically inserted blank page to its left.


At this point, I would change the page layout of LibreOffice (if you haven’t done so already) to make it easier to see what you are doing. Go to “View->Zoom->Zoom…” and choose “Columns : 2” and check “Book mode”. This will layout your pages in pairs (the two columns bit) that are joined together (book mode) with the odd pages on the right and the even ones on the left (book mode again). It should look like you have opened up a printed copy of your book. This makes it easier to check that everything is to your liking and that you’re getting things in the right place. You also need to set a suitable Zoom Factor. This will vary depending on your monitor size and preference, but will ideally be one that is small enough to fit both pages on the screen and big enough enable you to still be able to read the text. I like using 100% so I can see exactly what it is going to look like.

LibreOffice's Zoom DIalog
The zoom dialogue. Set columns to two, check Book mode and select your preferred Zoom factor.

Chapter One

Right, back to our chapter title. Before we move on, we need to change it from Novel-Chapter-First to Novel-Chapter-Very-First. This style will set our page numbers back to 1. So do that now. To check that it worked, repeat the procedure to insert page numbers that we used for the forward (click the footer, change the paragraph style to Novel-Footer and then go “Insert->Fields->Page Number”). You should find that our first page is numbered page 1.

Ok, enter your first chapter title, hit enter, and we are ready to enter the text of your novel!

Like the forward, you can either paste in the whole chapter in one go and then go back and change the style of the paragraph sections or go section by section (you could actually paste the whole novel in in one go and just go through changing the styles over, but doing things that way is a bit error prone). Once you’ve finished the chapter, hit enter again and change this new empty paragraph to Novel-Chapter-Title. Before we do the rest of the chapters though, it’s a good idea to add the page numbers and the header, as if there are problems, this is where they are likely to be.

Header and Footer

The page numbers for the Novel-Page pages are done just as you did on the first page. You’ll see the page numbers carry on from the first page with 2 (it doesn’t matter which of the Novel-Page pages you add it too, as it will be added to them all).

To add the header, click on a left page header, change its style to Novel-Header-Left and enter your name. On the right hand page (but not the one with the chapter title), click and change the style to Novel-Header-Right and type the Novel’s title (or the Chapter Title or whatever you are using). Now all Novel-Pages will have the same header.

Rinse and Repeat and About

That is pretty much all there is to it. Now it is just a case of repeating the procedure for the rest of your chapters and parts. When the last paragraph of the last chapter has been done, hit enter one more time and, this time, change this empty paragraph into a Novel-About-First. This will start a new page on the next left hand side page and is where you can enter some info about yourself.

Getting Rid of Extra Lines

If you pasted in large sections of your book, we have one more small bit of house keeping to do. We need to get rid of the empty lines. Annoyingly and confusingly, LibreOffice only uses “\n” to mean newline in the “Replace” section of its “Find & Replace” dialogue. In the search section, it means Line Break, which is similar to a newline but different. Anyway, to get round this we need to use a couple of new regex characters: “^”, which means only match at the beginning of a paragraph, and “$”, which means only match at the end of a paragraph. Putting the two together (“^$”) will find us any empty paragraphs. So bring up the Find & Replace dialogue (“Edit->Find & Replace”), click the “Other options” drop down and check “Regular expressions”, and then “Replace All”.

LibreOffice's find and replace dialog
The Find & replace dialogue. Make sure to check Regular expressions.

The End

And that’s it. You’re done! Hit save, and then export to pdf (“File->Export to PDF”, selecting “Archive PDF/A-1a”, as this embeds the fonts in the document). Upload the exported pdf to CreateSpace and you can have a copy of your book in your hands in a day or two. It is probably a good idea to check it quite thoroughly first, though, to make sure you haven’t made any mistakes, but well done!

Once you have checked it all, you can also now export your novel to .doc (using “File->Save As” and selecting .doc as the format) and submit it to Smashwords.

Whilst you wait for your book to get to you from CreateSpace and the royalties to start rolling in from Smashwords, let’s set up this export plugin for the kindle.

Getting Your Book to Use the Template

Ok, so now we actually need to get your book to use our style template. Though you could apply the template to your current document, I would strongly recommend against this. It is much safer to start from scratch and copy and paste into a new document. The reason for this is simply that, though there shouldn’t be strange things going on in your document that, though not visible to the naked eye, trip up our export plugin, there often is. This is especially true if you’ve been working on your novel for years, during which time LibreOffice has gone through various changes, or if you started off in a different word processor and imported your book in or experimented with a different program during your writing. Admittedly it is true that there are ways to get rid of these invisible nasties, but as they aren’t visible, it is quite difficult to tell whether or not you have been successful. It is far far easier to start with a known quantity.

I would also suggest adding in an intermediate step and pasting your novel into a text editor, like gedit. This is so you can remove any strange formatting (tabs, double lines, extra spaces etc.) before pasting your text in, making it easier to apply our new styles to the correct parts the book. It also removes the risk of accidentally hitting “Paste” rather than “Paste Special->Unformatted Text” (which is easier than you might think when dealing with a document as long as a novel that is going to be pasted in multiple chunks), causing all the old formatting we are trying to get rid of to be copied into our shiny new document! So open up your master piece, hit Control-A and copy and paste it into gedit.

As gedit is text editor it can only contain text (not style information), so we know there are no nasty surprises hiding out of sight. Right, before we paste it into our new LibreOffice document, let’s clean it up a bit. What exactly you need to do will depend on how you’ve been formatting your book thus far. I’ll step through the three main things you need to deal with, and hopefully you can figure out the rest (nb. you can do all these things in LibreOffice, I just think it is easier to see if everything is working properly if you clean up the text first).

Getting Rid of Tabs at the Beginning of Paragraphs

Ok let’s start with an easy one, we need to get rid of all the tab stops at the beginning of the paragraphs, as our paragraph style indents the text for us. Click “Search->Replace…” This will bring up the Replace Dialogue. In the “Search for:” box enter “\t”. The backslash (note that it is a backslash “\” not a forwardslash “/”) tells gedit that we are searching for a special character and that character is t, which is short for tab. We want to leave the “Replace with:” box empty because we just want to delete the tabs (i.e replace them with nothing). Hit “Replace All”, and that’s it. This won’t just get rid of those tabs at the beginning of paragraphs but any others you’ve snuck in. So that’s all the tabs dealt with. Let’s move on to extra spaces.

Gedit's search and replace dialog
Gedit's Replace Dialog ready to delete all our tabs.

Getting Rid of Extra Spaces (with a little help from Regular Expressions)

It is important to get rid on any extra spaces you’ve accidentally added to your novel (or even any that you have intentionally added by e.g. hitting space a load of times to centre something rather than using centre alignment) as they can confuse the automatic spacing of your text, especially when using justified alignment.

There are two ways we could go about this. The simple way is to enter two spaces in the “Search for:” box (i.e. hit the spacebar twice) and one in the “Replace with:” box and just hit Replace All, but this won’t work if you have more than two spaces e.g. if you have three spaces in a row, the search will find the first two spaces, replace them with one space, move onto the next character, which is a space on its own, and leave it be. Of course you could just keep hitting “Replace All” until it has removed all your crazily long lines of spaces, two at a time. However, a neater way of doing things is to use regular expressions.

Regular expressions give you a very powerful (if somewhat complex) way of preforming complicated pattern matching and replacing. Anything you can think you’d like to do to a bit of text, regular expressions let you do it. We, though, are going to keep it simple. All we are going to do use them to tell gedit to replace “two or more spaces” with “a single space”. To do this all we need do is enter two spaces in the “Search For:” box followed by a “+”. The plus means “match as many of the preceding characters as possible” i.e. match a space followed by one or more spaces. Then put a single space in the “Replace with” box. Finally and most importantly, check the “Match as regular expression” box, and then click “Replace All”.

Whilst we are here, we will make sure you haven’t left any s paces trailing on the end of your paragraphs. To do this enter a full stop followed by a space followed by a plus sign followed by the newline character (\n), which gives us “. +\n”. And, importantly, delete the space in the “Replace with:” box (it is very easy to forget to delete it as you can’t see it’s there to remind you!) and enter “.\n”. Here we are saying, “find a full stop followed by any number of spaces and then a newline and replace them with a full stop and a newline”.

Of course, because we just replaced all the multiple spaces with single ones, there is no way we could have more than one spaces on the end of a line so we could have unchecked “Match as regular expression” and not used the + sign, but it is not a bad idea to get a bit of practice with regular expressions as, sooner or later, you will have some really complicated bit of search and replacing to do! (nb. Regular expressions give you lots of ways you could accomplish the same thing e.g. they have a special symbol that indicates the end of a line, which we could have used, and they also can stipulate that only certain bits of the search pattern are replaced so we didn’t have to delete the entire search pattern and then add back in the full stop and newline, we could just have deleted the spaces.)

Gedit's search and replace dialog.
Removing unwanted spaces. Though it’s hard to tell, there are two spaces before the + and one in the “Replace with:” Box.

Getting Rid of Extra Lines

Right, getting rid of extra lines is, sadly, slightly tricky. Though we can do it by replacing “\n\n+” with “\n”, we then have no way of distinguishing between paragraphs and sections (as we already got rid of the tabs)! So my suggestion here is just to leave them be and we’ll get rid of them in LibreOffice once we have assigned all the sections the “Novel-Paragraph-Section” style.

Ellipsis, Dashes and Hyphens

Whilst we are here we should also deal with any odd characters that you are using. The most common of these are ellipsis, dashes and hyphens but others exist. Ellipsis are the (three!) little dots you use to indicate someone is trailing off their speech (also, less commonly in fiction, that some quoted text is missing): “I have my passport somewhere…” It is common to enter these as three separate full stops, but they are actually just one single ellipsis character. The reason it is a good idea to change it over is because it affects both the spacing of words and where LibreOffice thinks would be a good place to put a line break. Just in case you have got a bit full stop happy anywhere, just to be on the safe side, we’ll replace any occurrences of three or more full stops with the ellipsis. We could do two or more if your sure you haven’t accidentally hit the full stop twice when ending a particularly exciting sentence. Anyway, let’s get to it enter “…+” in the “Search for:” box and “…” in the “Replace with:” one (you’ll need to turn regular expressions on if they aren’t already). That second symbol is an ellipsis character by the way. In order to enter it, you can either copy and paste it in from here or the Character Map or you can enter it directly by pressing Shift-Ctl-U at the same time and then typing 2026 (you don’t have to keep the other keys held down whilst typing the number) and then hitting return. If you are writing a lot (which you probably are!) you might want to set up your compose key so it is easier to enter awkward characters. A quick google will tell you how.

Inserting an ellipsis using Character Map.
Inserting an ellipsis using Character Map.

Once you’ve done that, the other thing you might want to check whilst you’re here is that you are using dashes and hyphens correctly. As a quick reminder, these are the three different punctuation marks we are talking about here:

em-dash: —
The longest of the dashes you are likely to use (the size of a “M” character) used mainly in fiction to show an interruption in speech: “I’m going to have a—” “No you are not.”
en-dash: –
A mid sized dash (the size of a “n” character). Used mainly in place of bracketing commas to show more emphasis: “I am sure my present – when I get it – will be lovely.”
hyphen: –
Smaller than our two dashes and the only one of three that you have a dedicated key for on your keyboard. It is used to join object-verbal compounds such as “man-eating shark”, and double barrel surnames e.g. “Mrs Horita-Smithe”. The hyphen is also used when a long word is being broken over two lines. LibreOffice’s justification is pretty good so you shouldn’t need to do this unless you are using very long words such as those found in science e.g. pseudopseudohypoparathyroidism. Clearly you don’t want to be hyphenating anything for this reason at the moment as we aren’t in LibreOffice, but if you had previously, delete them.

The best way to fix your dashes and hyphens is step through each one using the find function of the Search and Replace dialogue.

Ok, now we have nice clean book that is ready to copy into our new LibreOffice document (which is using our Novel Template).

Save the Template

Right, one way or another, you should now have a blank document with all the styles you need to properly format your novel. Before we go on, you need to save it as a template so it is there for you when you want to start you next book! There are two ways you can do this. You can do a “Save as” and change the type to template (.ott) and then import the template in using the Template Manager or you can save it directly into the Template Manager. In order to do this, you just select “File->Templates->Save As Template”, click “Save” and give it a name. Once it has been saved, close the file, as you don’t want to make changes to the template accidentally. Instead, choose “File->New->Templates” and double click the template you just created. You now have a shiny new document, based on the template we just saved, ready to be filled with your glorious words.

LibreOffice's Template Manager
The Template Manager lets you import, export, edit and, most importantly, create new documents from your templates.

Style Summary and Template

If I haven’t been as clear as I could have been in the last few pages, hopefully the style summary here will help. At the bottom of the page is a LibreOffice template based on the advice below, which you can use if you are still stuck (or lazy!)

Paragraph Styles Summary

Style Name Style Description Style Suggestions
Novel-About Used for your bio at the end of the novel. Similar to Novel-Paragraph-Section but with a different font.
Novel-About-First Used to make sure your bio appears on a left hand page. Based on Novel-Paragraph-About but with page break before it and suitable page style selected.
Novel-Chapter-Title Used for the title of each chapter of your novel if it is divided into chapters. A slightly bigger sans serif font, centred. You probably want to set page break before so your chapters always start on a new page, and if you want them to all start on right hand pages (as is sometimes the case) and/or you want to skip the header on the first page of each chapter, you will have to link the page break to a suitable page style.
Novel-Chapter-Title-First Used for the first chapter of each part of your novel if it is divided into chapters and parts and you want the first chapter of each part to start on a right hand page; whereas, normal chapters can start on either. Based on Novel-Chapter-Title, but linked to a different page style so that it is always on right hand pages (not needed if you want all chapters to start on right hand pages), you will have to link the page break to a suitable page style.
Novel-Chapter-Title-Very-First Used for the first chapter of your novel to restart page numbering on this page i.e to make this page page 1. Based on Novel-Chapter-Title (or Novel-Chapter-Title-First), but linked to a different page style and has it page number set to 1 (rather than 0, which means carry on numbering from the last number).
Novel-Footer Your footer, where the page numbers are going to go. Based on Novel-Header-Left but with its text centred.
Novel-Forward-Paragraph Used for a standard paragraph in the forward of your book. Based on Novel-Paragraph but italicised.
Novel-Forward-Section Used to start a section in the forward of your book. Based on Novel-Paragraph-Section but italicised.
Novel-Forward-Section-First Used to start the first section in the forward of your book. Based on Novel-Paragraph-Section-First but italicised.
Novel-Forward-Title The title of your forward. Also used to start the page numbering (usually done in Roman numerals in the forward). Similar to Novel-Chapter-Title but italicised. Page break before set with the page style set to a suitable one.
Novel-FrontMatter-Author This is used for your name on the first page. Use a nice, big, clear, easy to read font.
Novel-FrontMatter-Copyright Used for text on the copyright page (second page). Use a smart and no nonsense font around 12pt.
Novel-FrontMatter-Title This is used for the books title on the first page. Something big and bold, possibly reusing the font from the front cover.
Novel-Header-Left Your base header and footer style also used as the style for the header on the left hand pages, which have the author’s name on them. Use something different from your main body font either a monospaced one or reuse the font from the front cover. Make it about 10pts big and left aligned.
Novel-Header-Right The style for the header on the right hand pages, which usually has the book title or the chapter title in it. Based on Novel-Header-Left but right aligned. (if you want to have the chapter title in the header, you will need a new page style for each chapter e.g Novel-Page-Chapter1, Novel-Page-Chapter2 etc.
Novel-Header-Right Your base header and footer style. Use something different from your main body font either a monospaced one or reuse the font from the front cover. Make it about 10pts big and left aligned.
Novel-Paragraph Used for a standard paragraph of prose or dialogue. Use a 10pt serif font or bigger, depending on age of reader.
Novel-Paragraph-Section-First Used for the first paragraph in each chapter. Based on Novel-Paragraph-Section but starting approx a third of the way down the page and possibly using drop caps.
Novel-Paragraph-Section Used to indicate the beginning of a new section within a chapter. Based on Novel-Paragraph but without the indented first line and with some white space added above.
Novel-Part-Title Used for the title of each part of your novel if it is divided into parts. A slightly bigger sans serif font spaced halfway down the page. It also needs to have a break before it and a suitable page style linked to it to make sure it is or a right hand page.

Character Styles Summary

Next comes character styles. These are applied
groups of characters within paragraphs.

Style Name Style Description Style Suggestion
Novel-Char-First Used as an alternative for drop caps for the first character of a chapter or if you want your drop cap font to be fancy. Bigger than the normal paragraph size and using some fancy font.
Novel-Char-Date Used any time you want to italicise a date. Italicised.
Novel-Char-*something* Any special cases you need e.g. in my book Equilateral I had a Novel-Char-Screen style for text that was shown on a computer screen. What ever you need it to be.

Page Styles Summary

Finally we have page styles. Because of a short
coming in the way LibreOffice handles headers and page counting we need seven different styles for this. If you want to have your chapter’s title in the right hand side header you will also have to add a page style for each chapter.

Style Name Style Description Suggested Value
Novel-Page A standard page in your book. It needs to have its page size set to the size of book you want to create using create space (13.34cm x 20.32cm in my example template), with suitable margins (1.91cm, 1.27cm, 1.02cm, 0.76cm). The layout should be mirrored and you need to turn on headers and footers, headers should have “Same content left/right” unchecked. Importantly, Register-true should be turned on and Novel-Paragraph selected as the reference style.
Novel-Page-About If you want your chapters to all start on odd pages, you will need to use this page style as the first page of each one. Set the page layout to Only left. Everything else is the same as Novel-Page (Register-true is optional).
Novel-Page-First This style is for the first page in every part. It is necessary if you want to turn off the header for this page and/or if you want to make it always be on the right hand side. The same as Novel-Page except that it has Page layout set to “Only right”.
Novel-Page-Chapter If you want your chapters to all start on odd pages and/or you want to turn off the header for the first page of each chapter, you will need to use this page style as the first page of each one. Set the page layout to “Only right”. Everything else is the same as Novel-Page.
Novel-Page-Forward A page style for the forward. This is needed if you want to number the pages of the forward using Roman numerals (as is normal) and/or if you want to turn off headers for it. Everything is the same as Novel-Page except that page numbers are set to Roman numerals.
Novel-Page-FrontMatter A page style for the bits that go at the front of the book, like the title page, copyright page, dedication etc. Everything here is the same as Novel-Page, Register-true is optional though.
Novel-Page-Part A page style for the part titles. This is needed if you want to hide the page numbers and headers on these pages (as is normal). Everything is the same as Novel-Page (unless you want to make sure that parts titles are all on right hand pages, then you would set layout to “Only right”.
Novel-Page-Very-First This style is for the very first page of the first chapter. It is necessary in order to start/restart the page count from this page. The same as Novel-Page-First.
Novel-Page-ChapterX If you want to have the chapter title in the header you will need a page style for each chapter. The same as Novel-Page-Chapter.

LibreOffice Novel Template and Example Book

Here is my LibreOffice template. Opening it will create a new document using the template. You can also import it into LibreOffice, which will enable you to manage it (edit etc.) through the Template Manager. Click on “File->Templates->Manage” and select import. Then, when you want to create a new novel document, go “File->New->Templates” and double click on the template you just imported.

LibreOffice Novel TemplateLibreOffice Writer Icon

And here is an example document that uses that template. Have a play around with it, especially if you are wanting to do anything funky with your headers and footers.

An Example BookLibreOffice Writer Icon

And for good measure this is what the book looks like when exported to pdf.

An Example Book (pdf)Pdf icon

Advanced Page Numbering and Headers

“What is advanced page numbering and what are advanced headers?” I hear you cry. Well, take a look at a few of the books out there and you’ll see almost as many ways of numbering the pages and displaying information in the header. Page numbering strategies range from just starting the page number count from the first page of the front matter and just going for it, to (the most common) starting the page count on the first page of the forward, using Roman Numerals to render them, restarting the page count on any subsequent forwards (if any) rendered using Roman numerals in a different case, and so on and so forth till you reach the first page of the first chapter, where the page count is again restarted but this time rendered using the more familiar Arabic numerals (1,2,3 etc.) As for headers, some books eschew them altogether, others change them for each chapter and the forward and on various pages omit them entirely for various reasons e.g. if you are using the chapter title as the header, it is somewhat redundant to use it on the first page of the chapter, as it already has the chapter title on it.

My copy of Dead Souls showing how it lays out its header and footer.
My copy of Dead Souls has the book’s name in the left header and the chapter title in the right. It also puts the page number in the header, using Roman numerals for the introduction.

You’ll be pleased to learn that we can deal with almost any layout you choose to use, you also might be pleased to learn that just starting at page one and just going for it and not bothering with the header at all is also completely acceptable. But you do have to make a decision and stick with it. Take a look at a few books and see what you think will work best for you. Once you have done this we need to look at how we actually achieve what we want. Both page numbering and headers are controlled by using paragraph styles in combination with page styles via the “Break before. Really the page style doesn’t do a great deal, you just need a new one for each different numbering scheme and header arrangement you want to use (hopefully this will change in future versions of LibreOffice as it is irritating). You’ll notice as you play with this that the header and footers are set for all pages that use the same page style irrespective of whether or not the pages are contiguous i.e the upshot of this is that you often can’t reuse page styles as much as it would be logical too e.g you will need Novel-Page-First that is exactly the same as Novel-Page even though the change in page number is set in the paragraph style. Also if you wish to have the chapter title in the header you will need a new page style for each chapter.

My copy of Nation showing how it lays out it header and footer.
Nation also has the book's title on the left and chapter title on the right. The page numbers, though, are in the footer, and the chapter title and page number are omitted from the first and last page of each chapter respectively.

Ok we’ll step through setting up the first page in the Novel, hopefully that’ll give you enough info to enable you to go off in full control and create as many as you actually need. Once you get your head round, it isn’t really that tricky but it is error prone. It is very easy to miss that your page numbers have gone weird in the middle of your book when proof reading it.

My copy of Catcher in the Rye showing how it lays out its header and footer
Catcher in the Rye does away with the header and just has a page number in the footer

Let’s start with the page style. It is exactly the same as Novel-Page (13.34cm x 20.32cm in my example template, mirrored with margins of 1.91cm, 1.27cm, 1.02cm, 0.76cm; Register-True enabled and Novel-Paragraph selected as the reference style; Headers and Footers enabled etc.), though if you want to make sure your book starts on a right hand page you can change the layout to Only Right. Now call it Novel-Page-First (depending on what you end up going for you might need a Novel-Page-Very-First but we’ll keep it simple for now), and that’s it for the page style. The paragraph style will inherit from Novel-Chapter-Title and be called Novel-Chapter-Title-First (again, depending on what layout you go for you might need a Novel-Chapter-Title-Very-First), and all needs is to have in the Text Flow tab Breaks enabled (Insert checked) Type set to Page and Position to Before and With page style checked and Novel-Page-First selected and (and this is where the magic happens) Page number set to 1 (0 means carry on from the last page number), and that’s it. When you set your first Chapter Title to use the Novel-Chapter-Title-First paragraph style it will reset the page count to 1. Easy. Now to see your page number you are going to need to click on the footer, change the style to Novel-Footer and Insert->Field->Page Number. If you want to leave off the heading on this page it’s easy, just don’t add one. As a header is associated to a page style you can safely add the header to your normal Novel-Page page with out it affecting this one.

My copy of American Psycho showing how it lays out it pages
America Psycho has the page number back in the header along with the author's name on the left and the book's title on the right. You'll also notice that it doesn't bother with page breaks between chapters.

Honestly, once you get the hang of this, it is quite easy to achieve whatever it is you want to achieve, but it isn’t very intuitive and can get frustrating, so be prepared to spend a little time playing with this and looking at how I got it to work in the example book at the end of this section. Most problems are caused by not using a unique page style where you need one e.g. so one paragraph style is telling LibreOffice that a page style should start its page count at 1 where another is telling it that the same page style should just continue from the last number, or you’re adding a header on one page that uses a certain page style and deleting it on a different page that is also mistakenly using the same style, causing the first page to loose its header etc.

Character and Page Styles

Character Styles

Well done. That’s all the paragraph styles sorted. Next we need to add any character styles we need. Confusingly, these styles can’t directly inherit their font information from a paragraph style, but any settings you don’t change are inherited from their underlying one. In most cases this will do what you expect e.g. if you have a character style called, for example, “Shouting” which just sets the font style to bold and you decide to change the font size in the paragraph style, your text using the “Shouting” style will also be resized; however, if you style shouting by using a bigger font, then a change to the paragraph style’s font won’t change the size of the shouting text. The most frustrating thing about this is that it doesn’t let you have relative sizes e.g. there is no way of saying “make these characters 20% bigger than the rest of the text in the paragraph”. Be aware that if you are wanting to use a character style to increase the size of some text, then, because we have Register-true turned on, the line the bigger text is on will move down the page in increments of paragraph line heights rather than just moving down enough to fit on the bigger text.

You might be wondering at this point why you have to bother with character styles when you could just use direct formatting (e.g. by clicking on the bold and italics icons). There are two reasons for doing it this way. The first reason is that (as of this writing) the Smashwords export has to have all the direct formatting stripped. The second is that it enables us to distinguish between elements that have the same visual appearance but for different reasons (i.e. a date might be italicised for stylistic purposes whereas some words in a piece of dialogue might be italicised to add emphasise to them). Using character styles, these two elements can be rendered differently where appropriate.

Excerpt from Equilateral by Robert A Wood showing a character style being used
Excerpt from Equilateral by Robert A Wood showing a character style being used.

Go on, create any character styles you need. Done? Good, that just leaves us with our page styles to do (the other style types are for things like tables and bulleted lists, which you probably don’t need in a novel, but if you do, add them now).

Page Styles

In the same way that paragraph styles apply to a single paragraph, page styles only apply to a single page, so once you have finished typing a page, a new page is created with a new style. You might, therefore, be surprised to find out that we don’t need to create separate Novel-Page-Odd and Novel-Page-Even styles. The reason for this is that page styles handily understand that odd and even pages commonly have their border etc. mirrored. This convenience goes some way to alleviate the annoyance that page styles currently can’t inherit from other page styles. You’ll just have to remember that if, at a later date, you decide to change, for example, the page size of the book you are going to produce, you have to set it in every page style individually.

Anyway, let’s get to work. Create a new page style (make sure it is a page style and not a frame style!) and call it “Novel-Page” and set the next style to be “Novel-Page” too. On the first tab, “Page”, the most important setting is the page size. This gets set to the size book you want to create on CreateSpace. Here I’m going to use 13.34cm by 20.32cm as this seems like a good size for a quality paperback to me (the reason for the peculiar sounding size is that CreateSpace uses inches). We then need to set the layout to mirrored (so we don’t have deal with odd and even styles). When you select mirrored in the “Page Layout” dropdown, you’ll see that the left and right margins have been renamed inner and outer. The inner margin is the one that appears next to the spine of the book. This inner margin needs to be set slightly bigger than the outer margin to account for the binding. If you have gone with the same size book as me, then an inner margin of 1.91cm and an outer one of 1.27cm are reasonable choices. Whilst you’re at it, set the top and bottom ones. I use 1.02cm and 0.76 for them respectively.

Now we need to turn “Register-true” on and set the reference style. If you remember, “Register-true” is how we make sure that text on all the pages lines up neatly. The reference style we want to snap things to is our Novel-Paragraph style.

That’s that tab done with. The next one we need to deal with is the “Header” one. Here we want to make sure that we have the header turned on, as we are going to be putting stuff in it. Exactly what stuff we put in there isn’t set in stone. I like having the book title and my name up there, other books go for the chapter title. If you’re doing it the same as me, you want to uncheck that “Same content left/right” option as we’ll be putting the book title on the odd pages and the author’s name on the even ones. Next we have the left and right margin, which is in addition to the page’s margin so leave those at 0. “Spacing” refers to the amount of padding between the header and the body text. It can be left at 0.5 cm or you can experiment with other values.

Excerpt from Equilateral by Robert A Wood in which the header shows book title on the odd pages and author&apos;s name on the even ones
Excerpt from Equilateral by Robert A Wood in which the header shows book title on the odd pages and author’s name on the even ones.

Next, the “Footer” tab. This is setup identically to header with the exception that we do want the same content on both even and odd pages (the page number), so don’t uncheck same content left/right. The borders, columns and footnotes tabs are all left as is (nb footnotes are a bit tricky to convert, but they aren’t that common in fiction, so hopefully you don’t need them!)

Ok, so that’s our basic page set up. We also need a page style for our front matter. The main differences between the front matter and the rest of the book is that it doesn’t have headers and footers, nor do its pages count towards the page numbering of the book. So go ahead and create one of those. If you have a forward or prolog in your book, you will need a page style for this too. Forwards in books generally use Roman numerals for their page numbering.

Paragraph styles cont.


Now, not all paragraphs start with an indentation. The first paragraph in every section typically starts flush with the margins and has a blank line above it, so we need to create another new style. Call this one “Novel-Paragraph-Section” and click AutoUpdate again. As the first paragraph of each section is followed by normal paragraphs, select Novel-Paragraph for the “Next Style” and, importantly, set it to inherit from it too. Now that our style is linked to Novel-Paragraph, any changes we make to Novel-Paragraph are copied over automatically to Novel-Paragraph-Section. So, say, for example, you decide to change the font size you only need to do it in the base style, Novel-Paragraph, and it’ll propagate here. Ok, so we need to get rid of the first line indentation, so go and remove it from the Indents & Spacing tab, and add some spacing above the paragraph.

LibreOffice's style organiser only shows how this style differs from the base style, Novel-Paragraph.

Annoyingly, LibreOffice doesn’t allow you to use relative sizes (so you can’t tell it to add space equivalent to the font size you’ve used i.e add an empty line or two) you have to use absolute sizes (cm in the UK). Luckily, Register-True will snap the text to nearest baseline so you don’t have to worry about getting the size exact. That’s it. Save it, and that’s your second style done.


Now you’ve got the idea, go and create a “Novel-Paragraph-Section-First” style. This is the style for the very first paragraph in each chapter, which typically starts roughly halfway down the page. It’ll inherit from Novel-Paragraph-Section, and it’ll have its ‘“Above paragraph’ spacing on the “Indents & Spacing” tab set to an appropriate value. You can also experiment with using drop caps for this style if you like on the “Drop Caps” tab.

The first page of Tommy Lightbreaker by Robert A Wood, showing drop caps.
The first page of Tommy Lightbreaker by Robert A Wood, showing drop caps.


We also need a style for the chapter titles (if you’re not using chapter titles, you can skip this). This time we don’t want to inherit from Novel-Paragraph, so start a new style for it. Font and size are down to your good judgement(!) though I would go for a sans font to differentiate it from the main text of your novel and give it some visual interest, Liberation Sans (based on Ariel) is a good starting point. You will probably want register true on, as in most cases, it’ll make your book look neater. If you want your chapters to start on a new page, turn on “”Break” in the “Text Flow” tab and set it to “Page” and “Before”. If not, set a suitable amount of space before the paragraph instead.


You will also need a special style for the first chapter in your book (if you aren’t using chapters, you’ll need to create a first paragraph style). This serves two purposes. Firstly, it is common to start the first chapter on a right hand page, this style will enable this. Secondly, it is usual to start numbering the books contents from the first page of the actual novel, that is to say that any front matter, prologue etc. aren’t included, again this style will enable that. However, it achieves these feats in combination with a page style, so we’ll come back to it when we look at page styles later.

Headers and Footers

We are going to want different headers for the odd and even pages so the text can be right and left aligned respectively. Create your odd header style first and set its Inheritance to none. The second header style and the footer style can then inherit from it and just have their text alignment changed, left for the even header and centre for the footer. I like to use the same font I’ve used on my cover for the headers and footer, but feel free to use any you think appropriate. If your cover font isn’t appropriate, I’d go for a mono spaced one. Yep you guessed, Liberation Mono.

Left page header is left aligned and right is right aligned. The font used is the same as on the cover
Equilateral by Robert A Wood showing that the left page header is left aligned and right is right aligned. The font used is the same as on the cover.

Parts and Front Matter

If you book is divided into parts, then create styles for the part names in same way you have for the chapter titles and, when we get to to page styles in a minute, add a suitable page style, and that should be all 99% of you need for the main body of your novel. If you do need some extra styles e.g if you have a chapter summary under the chapter title etc. Go and create them, remembering what we have discussed so far and not forgetting to add them when we come to write the export plugin.

That should just leave us needing a few paragraph styles for the front matter. These don’t need to have Register-true enabled. Try it with and without and see what you prefer. By now you should be able to create them on your own so go and do it. My suggestions for the styles can be found at the end if you are a bit stuck.

Paragraph Styles

Right, to the styles. There are three main types that we care about: page styles, paragraph styles and character styles. As you’ve probably guessed, the paragraph and page styles define the pages and paragraphs in your book. The character styles can be best thought of providing overrides to the character style information included in the paragraph styles. We’ll start by creating the paragraph styles, as these are used by the other two types of styles. I’ll step through creating the styles, and then summarise them all in a table. If you are au fait with using styles, you can skip ahead and just use the table.

You should have a brand new, empty LibreOffice document in front of you (Click “File->New->Text Document” if not), and let’s begin! Click the styles button on the tool bar or “Format->Styles and Formatting” from the menus if you don’t have the button there.

LibreOffice Styles and Formatting Button

LibreOffice's Styles and Formatting Menu

Click the paragraph icon along the top of the dialogue box to make sure it’s selected then right click on the list of styles beneath it (which might be empty at this point) and select “New”.

Selecting paragraph styles from LibreOffice's styles and formatting dialog

Creating a new paragraph style in LibreOffice's Styles and Formatting dialog

The Organiser

This pops up the style dialogue box (if the “Organiser” tab isn’t currently selected, select it).

LibreOffice's Paragraph Style dialog

Right, the first thing we have to do is give our style a name. Call it “Novel-Paragraph” (though you can choose your own names for the styles, you must remember this when we write the plugin), and turn AutoUpdate on by clicking the checkbox. This enables you to make changes to the style later on and have the contents update themselves without having to reapply the style. We then have to set which style will follow after it. Paragraph styles only apply to a single paragraph, so when you hit return at the end of one, a new paragraph is created with a new style. What this style is, by default, is set here. Seeing as the most common thing to follow a Novel-Paragraph is another Novel-Paragraph that is what you should set it to (if it isn’t already). We then have the “Inherit from:” selection, as this is our base style we don’t want it linked to anything, so select “-None-”. Our final option is what category we put the style in; add it to custom styles. Finally on this tab, we have a summary of what we have set the style to be. Currently we haven’t set anything, so it is blank but not for long.

LibreOffice's Paragraph Style dialog with values filled in

Let’s crack on and move onto the first tab, “Indents & Spacing”.

Indents & Spacing

As this is a standard paragraph we need to indent the first line of it. How much you want to indent is up to you. To my eye, 0.64 cm looks good. Bear in mind that this is (and all the other setting are) just for the print version. We’ll set style information for the electronic version later, in the export plugin. If you want quite dense text, the other options can all be left as they are. Though, for a younger audience, you might want to experiment with more white space. We do, however, need to turn on “Register-true”.

Setting the indent and turning on Register-true in LibreOffice

Register-true is a somewhat confusingly titled option. Its name is a hangover from the printing era. What it does is make sure that all the text (that has Register-true enabled) is aligned to the same baselines. If you open a book up and place a ruler across both pages, you will find that the text on both facing pages sits happily on it, making the layout more appealing and, when printed on thin paper that shows the other side through, easier to read.

Tommy Lightbreaker by Robert A Wood showing nicely aligned text thanks to Register-true
Tommy Lightbreaker by Robert A Wood showing nicely aligned text thanks to Register-true

The way we achieve this is with Register-true. You want this turned on else your book is going to look messy. It can, though, give you slightly confusing problems. If you find later that some elements of your book’s contents aren’t sitting where you expect them to, consider whether it is because Register-true is moving them out of position and onto to the nearest baseline (nb. we will also have to turn Register-true on in the relevant Page Styles for it do anything!)


Next we have Alignment. Novels are always justified (i.e the text goes right to the edges of the page and extra white space is added between words to enable this). This can look a bit odd if you are used to reading text left aligned on a computer screen, but it is just the way it is done. Other alignments might be technically better, but this is what people reading books expect, live with it. One side effect of justified text you might want to keep an eye out for is what’s called a river of white, where, purely by chance, the way the white space has been distributed over a series of lines creates distracting patterns. If you notice any of these when proofing your book, you’ll have to manually edit the lines till the effect goes away.

An example of text with a river of white
A typographic river running down the middle of a text passage (above bottom word “amet”).
The next tab is “Text Flow”. Though some of the options here might sound like a good idea as they can theoretically prevent things like having a page with just one line on etc., in my experience, they generally introduce more problems than they solve, so I would strongly recommend you leave everything on that tab unchecked.


The next tab allows us to set the font and font size of the text in our paragraph. It can be very tempting to try and do something creative here, but I would urge you to resist. It is very hard to improve significantly on a basic serif font and very easy to turn your book into an unreadable mess (sans-serif fonts might look trendy, but they are harder to read, so steer clear of them for the main body of your book). I would bear in mind when making this decision that, to the readers of your book, there is no difference between an adequate choice of font and an excellent choice of font. Once you start reading, you are completely unaware of the font used (as long as the choice wasn’t abysmal!) Remember, the classics are classic for a reason, so start with Liberation Serif 10pt and don’t go very far away from it (Liberation Serif is a free version of Times New Roman).

Choosing a boring but functional font

As with white space, font size increases as the audience’s age/intelligence decreases. A fairly simple way to gauge what the correct font size is for your audience is to grab a random sample of books aimed at your target audience from the library and copy roughly what size they go for (remember, these choices, as already mentioned, only affect the printed copy of the book).

The rest of the settings can be left at their defaults. So, if we now go back to the Organiser tab, you should see these settings: Western text: 10pt + Register-true + Indent left 0.0cm, First Line 0.64 cm, Indent right 0.0cm (for some reason the fact the Alignment has been set to Justified isn’t shown in the current version, which doesn’t matter other than it is slightly confusing).

Organiser showing selected options.

Get Set

Ok so let’s get some style. If your novel is formatted in a pretty standard manner, the styles I’m going to outline shortly should be all you need to create. However, if you do need to create a few extra styles, do so. Just remember to add them to the export plugin when we write that in a minute. These styles serve a dual purpose. They are most obviously how we lay out the book so we can print it using services such as CreateSpace but they are also what formats our book so it can be exported to ebook formats to be read on things like the kindle.

My suggestions of reasonable defaults for these styles are based on creating a printed book that uses the 5.25″ x 8″ form factor (CreateSpace is American so it is simpler if we deal in backwards imperial measurements). Change them to suit your own needs and aesthetic tastes. There are no set rules, but remember that less is more, and be careful not to make your book hard to read, after all no one is going to recommend your book because it uses a pretty font. They will criticise it if that font is unreadable or just plain annoying (Comic Sans, I’m looking at you).

I’m also assuming here that you want your novel laid out in a fairly standard fashion e.g. the first page has on it the novel’s title and the author’s name, the second page has on it the copyright info, novel parts start on left hand pages, chapters start on right hand pages, the first paragraph in every section starts flush to the margin, all other paragraphs have their first line indented, all dialogue is indented, page numbers are on the footer, the author’s name is on the right page header, book title is on the left, a short bio is on the last left page etc. Again, it’s your book. You’re free to monkey about with the layout as much as you like, but you might find easier if you work through the tutorial with this layout to begin with, and then make the changes you require once you understand what everything does.

Right, hopefully you got from the previous chapter that everything in your book needs to have a style assigned to it. If it doesn’t, it won’t be exported. It is important that you understand that this includes white space. It is quite common, when you are writing, to add white space by hitting the enter key a few times. At best, this padding will be ignored when the file is exported. At worst, it may confuse the export and make your document unreadable. If you want to add some white space, you must do it by defining some padding in the style that you are using. Tabs are included in this. If you are indenting something (such as the beginning of paragraph), don’t use a tab stop to do it. Instead, use a style that has its first paragraph set to be indented.

Now, before we start creating these styles, I strongly recommend starting a new document in LibreOffice (we will paste in the text of your novel later). While it is theoretically possible to add the styles to a pre-existing document, you often encounter strange formatting errors that can easily baffle you if it is your first attempt. So click ‘New’, and let’s begin.