Sunday, October 23, 2011

First steps - TeX scenes (PIP)

This is the second post in my Publishing in Print (PIP) series. Today I'm going to explain how to define a TeX scene in yWriter.

Why would you want to do this? Well, TeX can create an automatic table of contents for your novel with a single command, so why don't we have a go at that? (I'm using the word 'novel', but yWriter can be used for non-fiction too.)

First things first. Create a new chapter in yWriter, move it to the very top, and double-click it. Change the chapter title to @TOC.

The @ stops yWriter exporting the chapter title (which we don't need, since LaTex supplies one.)

Add a scene to the TOC chapter and paste this in:

<TEX>
\thispagestyle{empty}
\tableofcontents

To explain: the <TEX> keyword tells yWriter NOT to convert the rest of the scene during TeX export, and it also suppresses the scene when you're exporting to other formats. (HTML ebook for now, others to follow.)

The <TEX> keyword must be the very first thing in your scene. First line, first characters. (There's another pair of keywords you can use to include TeX code in the middle of a regular scene, but I'll cover those later.)

As for the other two commands:

\thispagestyle{empty} is a TeX statement which suppresses headers and footers and page numbers.

\tableofcontents should be obvious: This is the command which tells the TeX parser to create a table of contents at this position.

Save and close the scene, then right-click your @TOC chapter and select 'Mark as last chapter of frontmatter'. This is important for page numbering reasons, amongst others. Later on, if you add more front matter after the TOC chapter, make sure you apply this setting again.

Now press Ctrl+Alt+X to export, double-click the tex file and (in TeXnicCenter) press Ctrl+Shift+F5 to generate and view it as a PDF. Sometimes the table of contents comes up blank the first time. If so, close your PDF viewer and press Ctrl+Shift+F5 again.

Did it work? If it did, you should have a table of contents for your novel.

That's the end of this tutorial, but here's one useful tip:

If you press Ctrl+Alt+X in yWriter5 when the Tex file is already open, TeXnicCenter will display a dialog asking whether you want to refresh from the new file. Just click yes. This is very handy when you're making small changes to layout in yWriter5.

On the other hand the next step of the process (generating the PDF) should only be done after you've closed the PDF viewer.

One last thing: you may be seeing double chapter headings in your PDF. I'll show you how to fix this in the next article.

Simon Haynes is the author of the Hal Spacejock Series and Hal Junior: The Secret Signal. By day he's a computer programmer and author, and by night he's the same only sleepier.

Simon Haynes is the author of the Hal Spacejock and Hal Junior series (Amazon / Smashwords / other formats)

1 comment:

Boddaert said...

Yep, I'm getting double chapter titles.