• October 23, 2016, 09:10 AM
• Welcome, Guest. Please login or register.
Did you miss your activation email?
Perusing The Shelves

Author Topic: An Introduction to Sigil  (Read 8788 times)

Offline jessadia

  • Moderator
  • PTS Expert
  • *
  • Thank You
  • -Given: 54
  • -Receive: 1523
  • Posts: 5249
  • Thanked: 1 times
  • Rating : 6149
An Introduction to Sigil
« on: April 20, 2012, 11:26 AM »
Don't you wish there was a tool you could use to clean up poorly formatted eBooks?

There is! You are not allowed to view links. Register or Login edits ePub's in their native format, allowing you to modify text/formatting directly or globally through stylesheet changes. I have yet to find a concise guide for using Sigil in the real world so I thought I'd attempt one; it's not an exact science so some sections will be more educational than procedural.

If you want to follow along, I've attached the before and after of book I'm using as an example (Doomed.epub) to the end of this post.

Download You are not allowed to view links. Register or Login here.

To fix Paragraph spacing and/or missing paragraph indentations:
  • Open each HTML file in the "Book browser" panel on the left until you find the first chapter.
    In our example, the first chapter begins in Doomed_split_005.html
  • With the first chapter visible, go into Code View (View -> Code view)
  • Look for the class that ALL body paragraphs are tagged with
    In our example, each normal paragraph begins with   <p class="calibre3"> so the style we can edit which will change all normal text is Calibre3
  • Open the book's style sheet (Book Browser -> Styles -> stylesheet.css) and find the style you wish to change (in this case .calibre3 {
  • To change the margins of each paragraph, or more specifically to remove them, change all margin lines to 0
    In our example I only had to change margin-top from 1em; to 0;
  • To change the paragraph indent, change text-indent from 0 to 1.5em.
    • If your class doesn't have a text-indent line, you can add one. It should look somewhat similar to the following example. (Notice that the last line in the class is the only line that doesn't end with a semicolon)
Code: You are not allowed to view links. Register or Login
.calibre3 {
    display: block;
    margin-bottom: 0;
    margin-left: 0;
    margin-right: 0;
    margin-top: 0;
    text-align: justify;
    text-indent: 1.5em

To properly tag chapters:
Why do this? Chapters must be tagged properly for the Auto TOC Generator and SFG Chapter Splitter to work.
  • Go back to your first chapter's HTML file
    In our example, the first chapter begins in Doomed_split_005.html
  • Make sure you're in code view
  • Look at the beginning of each CHAPTER title for a string of text that appears only on chapter title lines. Copy it with Ctrl+c.
    In our example, all chapters begin with:  <p class="calibre3">Chapter
  • Open the Find tool and paste your string into the "find what" field
  • Drop down the "look in" box and select "All HTML Files", then click "Count"
  • If the count results in something reasonable for the number of chapters you expect, your string is probably correctly unique to chapters.
    In my case I got 30, which seems reasonable.
    • If you can't find a unique chapter-only string -- if they're indistinguishable from normal text -- you'll have to manually tag your chapters (see below)
  • Click the "replace" tab and paste your string into the "Replace with" field, then make a couple modifications: Add <hr class="sigilChapterBreak" /> to the beginning and replace the <p with <H1
    In my example, we end up with: <hr class="sigilChapterBreak" />  <H1 class="calibre3">Chapter
  • Click Replace All

To manually tag chapters:
Why? If you couldn't tag them with find/replace and/or to add extras to the TOC
  • In book view, highlight the first chapter/section you want to tag ("chapter," "prologue," etc), drop down the heading chooser in the upper left (usually says "normal"), and choose heading 1.
  • If you choose heading 2, that chapter will show up as a sub-chapter in the TOC when it's generated.  This is useful for organizing TOC's in books that have multiple "books" or "parts."
  • Optional: If the chapters need to be split onto its own page, place the cursor before each chapter title and hit Ctrl+enter
  • Optional: While you're doing this, you can also add title="chapter#" to the <h1 tag in code view (once you've added the heading tag of course). This will override the title that's picked up automatically during auto TOC generation and is really only necessary for chapters titled with pictures.  It should end up looking something like this:
      <h1 class="calibre3" title="Chapter 1">Chapter one or some image or whatever</p>[/b
    • In this example, the TOC will show "Chapter 1" regardless of what's in the actual book as the chapter title.
  • Repeat for each section/chapter/html file.

To create a Table of contents (TOC):
IMPORTANT! - Chapters must be tagged properly for this to work.  Why:
Sorry but you are not allowed to view spoiler contents.
  • Simply click "Generate TOC from headings" (it's in the the Table of Contents window on the right)
    • If the TOC window isn't there, click View -> Table of Contents to show it
  • Confirm that the included items are correct.  If they are not, you were unsuccessful in correctly tagging your chapters. You can uncheck blank ones and/or you can try to tag your chapters again.  If everything looks correct, click OK.

To create page-breaks between chapters
Note: only try this if page breaks don't already exist, otherwise you may end up with duplicate breaks:
  • Once you've confirmed your chapters are tagged properly, go back into to your first chapter-containing html file that needs to be split (if you are not already -- in my example, it is Doomed_split_005.html
  • Click "Tools -> Split on SFG chapter markers"
  • Open each subsequent HTML file containing chapters that need to be split (eg. Doomed_split_006.html and so on) and run Tools -> Split... again. Yes, for each html file.
  • Stop when you pass the last chapter. Most books have extras at the end of the book, and you may not need to split these HTML files. Use your discretion. In my case, Doomed_split_007.html did not contain any chapters, so I stopped after only two splits

Removing headers and footers left over from PDF conversion
This isn't an exact science so I can't provide a list of steps. In short, you'll use either of the advanced Find & Replace modes to search for the header/footer patterns and replace them with nothing.:
  • Be sure to SAVE before doing a find and replace - undo doesn't work here. You should also click try "find next" a few times before doing "replace all" to make sure it's finding only the headers/footers.
  • Find & Replace using Wildcard mode: (Easy but not very powerful)
    Open the Find & Replace tool, click "More" to drop down the search options (if it's not already there) and change your search mode to Wildcard mode. Build a search term using the following wildcards: ? is a wildcard for any 1 character, while * is a wildcard for zero or more of any characters.  The [...] means ONE of any character you included in the brackets. You can include individual numbers/letters in a group, or ranges like a-z and/or 0-9.
    For example, if you want to search for something like Page 1 or Page 2,  you would enter Page [0-9] as a search term. This will find everything from Page 0 to Page 9. You would have to repeat the search for two-digit numbers by adding another number-group as follows: Page [0-9][0-9].  Add another for three-digit numbers.
  • Find & Replace using Regular Expression mode: Powerful but more complicated
    As before, go to the Find & Replace tool, click "More" to show your search options and select Regular Expressions. The difference between Wildcard more and RegEx mode is you have You are not allowed to view links. Register or Login]more commands/wildcards in RegEx mode[/url]. 
    Again, for our example, to search for Page ###, you would enter Page [0-9]+. The Plus allows it to find the previous group if it exists one OR MORE times, so it will find Page 1 or Page 89397 just the same. 
  • Finally, I strongly recommend using Find & Replace in Code view (instead of Book view). This allows you replace found items across the entire book in one click (while book view only does one chapter/section/htmlfile at a time).  It also allows you to remove the line/paragraph, move the rest up in its place, instead of leaving a gap. You'll just need to include the rest of the code/tags around the headers/footers.
    For example: Instead of searching for page [0-9]+ you would search for something like <p class="calibre4">Page [0-9]+</p>

General clean up:
  • Take a moment to go back into book view, open each HTML file, and manually edit any glaring issues like poor text justification in the title and copyright sections or extra line breaks
  • Merge extra page breaks, usually left over from previously existing arbitrary splits in books that needed chapter page breaks added. They will appear as HTML files that start in the middle of a chapter.  To repair these, copy the complete text from second half (or third, or so on) and paste it to the end of the chapter it belongs in, usually the HTML file directly above.
  • Delete HTML files that only contain junk from the HTML book list.  If you completed the previous step, you'll have at least one blank HTML file - delete this.  Also delete HTML files that contain broken TOC's, duplicate Book covers, useless previews for other books, excessive copyright information, etc...
  • Click Tools -> Validate ePub to check for errors.
    • Note, If you deleted a hard-written TOC, there'll be an orphaned link to it in the book's guide, called "Content.opf" and you'll probably see this as an error when you validate the ePub.  If this happens, simply open the Content.opf file from the book browser and delete any references to html files that no longer exist.  Usually these will be at the bottom of the file in the "guide" section. In my case I had to delete the entire line "    <reference href="Text/Doomed_split_010.html#filepos555723" title="Table of Contents" type="toc" />"
    • Run the Validation tool until no errors are found.  In truth, even if a couple are found, the book should still read properly.

To Add/Change Fonts: WORK IN PROGRESS
  • Righ-click the Fonts folder in the Book Browser and choose "Add Existing Items..."
  • Navigate to your font and add it.
  • Sigil automatically append the "content.opf" (think of it like the book's internal index) with a line item identifying and locating the font :)
  • Create a style for the font in the stylesheet.  It should look similar to this:
Code: You are not allowed to view links. Register or Login
@font-face {
  font-family: "name";
  src: url(fonts/name.ttf);
  • Now you have to reference the font in the book's code view.  This gets a bit detailed... and I'm still working on this section... sorry :(

This is a work in progress.  Feel free to "guide" me along ;)

Credit for this guide goes to Greyfox
« Last Edit: August 05, 2013, 02:19 AM by nina8 »

Offline jessadia

  • Moderator
  • PTS Expert
  • *
  • Thank You
  • -Given: 54
  • -Receive: 1523
  • Posts: 5249
  • Rating : 6149


Related Topics

  Subject / Started by Replies Last post
1 Replies
Last post June 29, 2010, 04:49 AM
by padam_dhanuk
1 Replies
Last post May 27, 2011, 12:47 PM
by ssapnp
1 Replies
Last post January 14, 2008, 02:58 AM
by anurag08
1 Replies
Last post February 04, 2010, 06:12 AM
by muraligot
0 Replies
Last post September 04, 2009, 12:37 AM
by Mba_Choice
76 Replies
Last post July 18, 2013, 08:57 AM
by ninjumper
1 Replies
Last post August 02, 2013, 03:56 AM
by Bozana