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'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.

Novel-Paragraph-Section

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.

Novel-Paragraph-Section-First

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.

Novel-Chapter-Title

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.

Novel-Chapter-Title-First

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!)

Alignment

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.

Font

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.

A Brief Moan About Styles in LibreOffice

Ok, well I think that that’s enough background. It’s time we actually did something useful. The first step we are going to take is to prepare your manuscript in LibreOffice. Depending on how you wrote your novel this might just be a case of few minor tweaks or it might involve a fair bit of work. The thing that is important is whether or not you formatted your novel using styles. For the sake of simplicity, I’m going to assume that you didn’t and that you don’t have clue what I’m talking about. If you did use styles, just use this section as a check-list.

So what are styles? They can be thought of as the poor cousins to XML tags and CSS style rules (discussed in the intro to XML and CSS). That is to say they can be used to both define sections of your LibreOffice document and describe how these sections should be displayed. They have two parts: the style definition (similar to the way CSS defines styles) and application (similar to the way in which XML tags divide your work into logical sections).

However, compared to CSS, LibreOffice’s styles are really limited. The first shortcoming you’re likely to spot is the limited number of options available to LibreOffice’s style rules. However, more annoying in practice is the fact that LibreOffice doesn’t have any cascade and only very limited inheritance. With a bit of thought and planning these drawbacks can be worked around, but what will have you pulling your hair out are direct styles and formatting. This is formatting that LibreOffice ‘helpfully’ creates for you, and if you are not careful, it will very subtly screw up your e-book conversion. We will deal with this latter on in this section.

Some of you out there might remember I said earlier (or might already be aware) that LibreOffice’s ODF format uses XML, so you might be a bit confused by me saying that LibreOffice’s styles do the same job as XML tags, as, surely, the file already has XML tags, and what’s more, if it is XML based, why doesn’t LibreOffice just use CSS (or XSL-FO)? The answer to the first of these two related questions is yes it does use XML, but for better or worse, LibreOffice uses a flat XML format.

A flat XML format is one where the XML hierarchy is collapsed to just one level. If this sounds complicated, it is only because I’m explaining it badly. Hopefully a quick comparison will clear it all up. Here is an example of fairly normal XML document:

<example> 
  <person> 
    <name> 
      <first>Robert</first> 
      <middle>A</middle> 
      <last>Wood</last> 
    </name> 
    <profession>Writer</profession> 
  </person> 
  <person> 
    <name> 
      <first>Ann</first> 
      <last>Example</last> 
    </name> 
    <profession>Scuba Diver</profession> 
  </person> 
</example>

And here is the same information encoded in a flat XML file.

<example> 
    <first-name>Robert</first-name> 
    <middle-name>A</middle-name> 
    <last-name>Wood</last-name> 
    <profession>Writer</profession> 
    <first-name>Ann</first-name> 
    <last-name>Example</last-name> 
    <profession>Scuba Diver</profession> 
</example>

These two files both contain the same information, and they can be converted to and from each other fairly simply using XSL. However, the ‘flat’ example is clearly evil and should be burned at the stake. LibreOffice, though, goes one step further down the path to hell. Its file format is more akin to the following:

<example> 
    <para style=“first-name”>Robert</para> 
    <para style=“middle-name”>A</para> 
    <para style=“last-name”>Wood</para> 
    <para style=“profession”>Writer</para> 
    <para style=“first-name”>Ann</para> 
    <para style=“last-name”>Example</para> 
    <para style=“profession”>Scuba Diver</para> 
</example>

As you can see, if it wasn’t for the style information, we would have no way of telling that our second person had omitted their middle name, as all we would have would be a mess of para elements. But this is pretty much what LibreOffice does, and it is not going to change any time soon, so we need to accept it/drink copious amounts of alcohol until we forget about it and move on with our lives.
However, no amount of alcohol could dull the pain of style inheritance in LibreOffice. The way it is implemented is enough to have you scooping out your eyes with a spoon. In short, inheritance works backwards i.e. rather than children inheriting from their parents, parents inherit from their children.

To a certain extent this is an inevitable result of the flat XML format: as there isn’t any hierarchy in the structure of the document (as everything is on the same level), it is impossible for inheritance to work normally (as nothing has any parents or children). However, I fail to believe that the solution implemented by LibreOffice’s styles to this problem is the best one. But again, realistically, we aren’t going to be able change this, so we had better try to live with it.

The net result of this backwards inheritance is that, as you will see shortly, when defining your styles you have start with the youngest child and work your way back up to the greatest grandparent.

All this goes some way to answering the second question posed earlier (i.e. why CSS or XSL-FO aren’t used by LibreOffice), as without a coherent hierarchy of elements in the XML document, most of the features of these technologies wouldn’t be usable.
Before all this annoys me too much, we need get going, but before we begin we are going to have to do a bit planning, as, though the way we are setting up LibreOffice means we will be able to change the formatting, we need to pick some sort of formatting to begin with and it makes sense to pick an initial formatting that is pretty close to what we want to end up with. Also, because of the backwards way style inheritance works, we need to plan which styles are going to inherit from each other.

A Quick Intro to XSLT

The other type of markup file you’ll be coming to know intimately is an XSLT. Where CSS tells the application to render a certain piece of marked up text in a certain way, XSLT tells the application to change the markup of a certain piece of marked up text. This is incredibly useful when you want to change an XML file from one format to another e.g. from LibreOffice’s XML based .ODT format to Amazon’s XML based .mobi format.

In a nutshell, you create templates that identify bits of XML, describe how to transform them, and which of the identified bits of XML’s children should be processed next. When the parser reads the original XML file, each time it finds something that matches a template, it applies the changes. Because of this, it doesn’t matter in what order you write the templates in the XSLT file. However, this can get a bit confusing because it means that order in which things are output depends upon a combination of the order in which things appear in the original XML file, the order in which the templates match and the order in which the templates allow the children of the matched XML to be processed.

To give a better idea of what a real XSLT stylesheet looks like we’ll create one that’ll convert our Hello, World example from XML to HTML (the language used on the web).

The first is thing to note about XSLT is that it is written in XML. This has the advantage that you can use all the same tools to work on them as you would other XML files, but because XML isn’t really intended for marking up programming, it can sometimes be a bit clunky and, sometimes, things that are very common and very easy to do in other languages can be less straight forward. An example of this is looping. In most languages looping over a set of variables is pretty trivial; however, though it is possible in XSLT, it isn’t intuitive, especially when you consider that program flow in the XSLT is controlled by the original XML file (rather than the code defining the loop).

Another thing worth noting before we begin our example is that the text the XSLT outputs needs to be well formed XML. This doesn’t necessarily mean that you have to output XML (though it is by far the most common thing to do) it just needs to be compatible with it. For example, from our Hello, World XML file we will be outputting HTML, we just have to be careful not to use features of HTML that are invalid in XML (such as omitting closing tags etc.)

So lets begin. The first thing to do is tell helloWorld.xml that we are going to be transforming it. This is done by adding a processing instruction (this step isn’t necessary if you want to use command line XSLT processor to which you would supply both the original XML file and the XSLT).

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xml" href="./helloWorld.xslt"?>
<!-- This is a simple example of an XML file -->
<raw:greeting xmlns:raw="http://www.robertawood.com/xmlExample" raw:language="English">
  Hello, World!
</raw:greeting>

We then need to create our XSLT file (called helloWorld.xslt).(Nb. if you want to test this yourself in your browser, as of this writing, Chrome doesn’t support xslt, but it works fine in Firefox.)

<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:transform>

This should look very familiar to you. As you can see, all we have done is create a top level stylesheet element that we use to map the xsl namespace to the xsl prefix and raw namespace to the raw prefix (we could map it to a different prefix if wished). You can use either “stylesheet” or “transform” as your top level element. I’ll use transform throughout, but you might see stylesheet used if you look at other examples on the web.

This is a very minimal yet functional XSLT file. You might expect that, as we haven’t defined any templates, it won’t have any effect on the XML file. However, surprisingly, the output of this XSLT is

Hello, World!

All the markup has been stripped. How did this happen? Well, XSLT has a set of built in templates that will be applied if you don’t supply your own in a given situation. Most notably these match all the elements and instruct the processor to process their children whilst matching any text that is found and outputting it. Thus <raw:greeting>Hello, World!</raw:greeting> becomes plain old “Hello, World!”

Ok, lets add a template to our XSLT file so we can control the output ourselves.

<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="greeting">
    We found a greeting!
  </xsl:template>
</xsl:transform>

We now get the output “We found a greeting!” Here we matched based on element name, but more complicated matches are possible by utilsing XPath (though we shouldn’t have to use this functionality). However, we will need to be able to match attribute names. To do this you simply prefix the name with the @ symbol to indicate you are matching an attribute not an element.

<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="greeting">
    We found a greeting!
  </xsl:template>
  <xsl:template match="@language">
    We found a language attribute!
  </xsl:template>
</xsl:transform>

And ta daa!

Hello, World!

Oh, we seem to have got the same output we did before. Why is this? It’s because of the slightly confusing program flow of the XSLT processor. You have to explicitly tell it to apply templates to an element’s children. We do this by adding an “apply-templates” element to our template’s output, which also indicates where any output from any children should be placed. We can either apply all templates to the elements children or just a subset by using the “select” attribute.

<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="greeting">
    We found a greeting!
    <xsl:apply-templates select="@language"/>
  </xsl:template>
  <xsl:template match="@language">
    We found a language attribute!
  </xsl:template>
</xsl:transform>

We now get the expected output of:

We found a greeting! We found a language attribute!

We need to add one more feature to our template before we actually get it to output HTML and that is we want to get at the text encased in our greeting element and language attribute. There are two ways of doing this. The first is by creating a rule to match the text and telling the XSLT proceesor to process the text children of the element (or using the built in rule that does this). The second way is by using the “value-of” element. As you can probably guess, the “value-of” element returns the value of the element or attibute it matches. In our case, using the “value-of” element is slightly clearer so that is what we’ll do. Note that “.” means get the value of the current element.

<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="greeting">
    We found a greeting! The greeting was: <value-of selection="."/>
    <xsl:apply-templates select="@language"/>
  </xsl:template>
  <xsl:template match="@language">
    We found a language attribute! The language was: <value-of selection="@language"/>
  </xsl:template>
</xsl:transform>

Ok, now we have all the pieces we need to create our XSLT that will convert hellowold.xml into HTML. The most common way to convert XML to HTML is to convert the XML element name to an HTML class name, and that is what we’ll do (note that XSLT has a built in template that outputs the value of an attribute so we don’t need to supply our own).

<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="greeting">
    <html>
      <head><title>Greetings</title></head>
      <body>
        <h1>Greetings in <xsl:apply-templates select="@language"/></h1>
        <div class="greeting"><xsl:value-of select="."/></div>
      </body>
    </html>
  </xsl:template>
</xsl:transform>