View Full Version : Strange Bug in Kindle Formatting - pls help


traveler212
06-18-2012, 08:48 PM
My epub file that was created in Sigil validated and I successfully uploaded it to Amazon for the Kindle.

However, after purchasing the Kindle book to view it, I noticed that there was some formatting problem:

On the page the eBook opens up to when you click on the book title, there's this code at the top:
justify">Part I: Overview

I have no idea what that -- justify>" is doing there. It shows up in 2 different Kindle readers I have and when I checked it on my iPad, the "justify>" isn't there, but the Part I: Overview is in normal
size font when it has a header tag. It also is in normal font in the Kindle, despite there being a header tag there.

The strange thing is when you click on "Part I: Overview" from the TOC, it shows up normally - normal header font size and no -- justify">

Also, if you go to the preceding page or the page after Part I: Overview, then go back to the Part I: Overview page, it appears normal. It only shows the bug when you open the book and when you click 'go to beginning'.

This bug didn't show up on the original upload to Kindle. It only did when I re-uploaded it after the changes were made.

Any idea what may be causing this and what I can do about? Unfortunately, the problem doesn't show up in the Kindle Previewer that you can download to your computer. And oddly, even though the book is supposed to open to the TOC page (as it does in the Kindle Previewer), in the actual Kindle book that has the bug, it opens to that Part I: Overview page.

Any help would greatly be appreciated. I have my header tags from
the stye.css file in the epub file below.

Thanks!

h1, h2 , h3, h4, h5 {
text-align:justify;
text-indent:0;
margin-top:0;
font-style: normal;
}

Doitsu
06-19-2012, 01:34 AM
This is a known issue. See DiapDealer's answer in this thread (http://www.mobileread.com/forums/showthread.php?t=180223).

traveler212
06-19-2012, 10:27 AM
Thanks, but it's not the same problem as the other poster. Similar, but different.

Here's the tag for the part that is showing the -- justify">Part I: Overview

<h2 id="pI">Part I: Overview</h2>

But, the same html tags are not causing a problem anywhere else in the book. It's just on this page that the book opens to. And if you click on the Part I: Overview from the TOC, the header tag displays normally (bold and large font size). It's only when you open the book and when you click "go to beginning."

Any other ideas anyone?

DiapDealer
06-19-2012, 11:57 AM
But, the same html tags are not causing a problem anywhere else in the book. It's just on this page that the book opens to. And if you click on the Part I: Overview from the TOC, the header tag displays normally (bold and large font size). It's only when you open the book and when you click "go to beginning."

The "Go To Beginning" functionality is achieved by having either a Text or Start reference item in the guide section of the ePub's OPF file. If that reference item contains something like "href='somefile.html#pI'"... then it could very easily be the same issue as all other cases of "there's bits of html code showing up in my mobi when I navigate." You just can't have hrefs pointing to anchors that are IDs inside of html block elements. It will get you in trouble with MOBI files every time (they're perfectly fine in ePubs that will never be turned into MOBIs).

Also... I would highly recommend doing the conversion to MOBI yourself and uploading that to Amazon... rather than hoping their conversion of your ePub will result in an error-free MOBI.

traveler212
06-19-2012, 01:12 PM
Here's what's in the content.opf file:

<guide>
<reference href="Text/cover.xhtml" title="Cover" type="cover" />
<reference href="Text/toc.xhtml" title="Table Of Contents" type="toc" />
<reference href="Text/toc.xhtml" title="Start" type="text" />
<reference href="Text/author.xhtml" title="Text" type="text" />
</guide>

Ironically, in the Kindle Previewer that you download to your computer, my eBook opens to the TOC page (which is what it's coded to do). And in the Kindle Previewer, this error doesn't show up.

However, on a real Kindle when the book is purchased and downloaded, the book opens up to the Part I: Overview page. Not sure why.

Here's the html code on the Part I: Overview page:

<body>
<h2 id="pI">Part I: Overview</h2>

the header tags are used the same throughout the eBook without any other problems (Part II, Part III, etc.). It's just that Part I: Overview page that has the bit of html code:
justify">Part I: Overview

And, if I access that Part I: Overview page from the TOC, it displays without any errors. And if I page forward or page back to that Part I: Overview page, it also doesn't display any errors.

When viewing it on the iPad (Kindle app), the html code doesn't show. However, the Part I: Overview is in regular font size and isn't bolded, when it should be in <h2> size. However, as when viewing it on a regular Kindle reader, when you access the Part I: Overview page from the TOC on an iPad, it displays normally. Same as when you page forward or page back to the Part I: Overview page.

DiapDealer
06-19-2012, 01:35 PM
My guess is there's some confusion over the guide items that Kindlegen is having trouble resolving satisfactorily. I've never tried building a MOBI where the "toc" reference item and the "start" reference item pointed to the same html page (probably not an issue though). In addition, Kindlegen uses the "start" OR the "text" item to create the point that a book opens to when first being read. There's never any need to have both a "start" AND a "text" item in a MOBI source ePub. There can be only one start point, after all.

I would be tempted to get rid of the "<reference href="Text/author.xhtml" title="Text" type="text" />" line and see if that solves the problem. Either that, or I would create a one page frontmatter/title page that the "start/text" item (just one not both) pointed to that's then followed immediately by the TOC page that the "toc" reference item points to (in addition to removing the extraneous "text" entry).

Also note that Kindlegen doesn't recognize/use the "Cover" reference item (it will usually strip a cover xhtml page, in fact). So I'd shoot for a guide section that looks something like:
<guide>
<reference href="Text/fmatter.xhtml" title="Start" type="start" />
<reference href="Text/toc.xhtml" title="Table Of Contents" type="toc" />
</guide>

traveler212
06-19-2012, 05:18 PM
Forgot to mention that the html code that shows (justify">) is not even anywhere in my epub file. That html code doesn't exist, which adds to the mystery.

The other strange thing is why the Kindle book opens to the Part I: Overview page to begin with given the TOC page is the start page. In the Kindle Previewer, it correctly opens to the TOC page.

traveler212
06-19-2012, 05:28 PM
Here's the sequence of the start of the book:
Cover
Copyright Page
TOC
Message from the Author page
Part I: Overview

Here's what's in the content.opf file:

<guide>
<reference href="Text/cover.xhtml" title="Cover" type="cover" />
<reference href="Text/toc.xhtml" title="Table Of Contents" type="toc" />
<reference href="Text/toc.xhtml" title="Start" type="text" />
<reference href="Text/author.xhtml" title="Text" type="text" />
</guide>

I wonder why it would skip to starting at the Part I: Overview page - perhaps this is all tied together - maybe it has a problem with the TOC listed as the start page and the author page listed underneath it as the 'Text' page...? And then for some reason it skips to the Part I: Overview page as the start page...but what the (justify">) is doing there is hard to figure.

And if it has a problem with the start page, you would think it would show the same issue in the Kindle Previewer...

Doitsu
06-19-2012, 05:41 PM
Forgot to mention that the html code that shows (justify">) is not even anywhere in my epub file. That html code doesn't exist, which adds to the mystery.
KindleGen hard-codes stylesheet definitions. I.e. text-align:justify; in the css becomes <h1 align="justify">.
(If you want to see the source code of the compiled .mobi file, install DiapDealer's mobiunpack Calibre plugin (www.mobileread.com/forums/showthread.php?t=171529) and unpack your compiled .mobi file with Calibre (http://calibre-ebook.com/download).)

The other strange thing is why the Kindle book opens to the Part I: Overview page to begin with given the TOC page is the start page. In the Kindle Previewer, it correctly opens to the TOC page.
That most likely happened because you defined your TOC both as "toc" and "text" and you also defined the author page as "text." Usually, only the first page of the first chapter is defined as "text" (or "start").
For more information on recommended guide items see this article (http://epubsecrets.com/where-do-you-start-an-epub-and-what-is-the-guide-section-of-the-opf-file.php).

DiapDealer
06-19-2012, 05:55 PM
Forgot to mention that the html code that shows (justify">) is not even anywhere in my epub file. That html code doesn't exist, which adds to the mystery.
It's not a mystery at all. The "justify" code is coming from the style that you have assigned to all h2 tags with the following CSS (like Doitsu posted while I was typing ;) ):

h1, h2 , h3, h4, h5 {
text-align:justify;
text-indent:0;
margin-top:0;
font-style: normal;
}
The MOBI format doesn't support CSS at all. So when your epub is being converted into MOBI, the CSS gets translated (as best it can) into HTML 3.2-like attributes.

So after your ePub's html gets run through Kindlegen, your '<h2 id="pI">Part I: Overview</h2>' (styled with the above CSS) becomes something like:

<p height="0pt" width="0pt" align="justify"><font size="6"><b>Part I: Overview</b></font></p>
in the actual internal MOBI markup code.

And if it has a problem with the start page, you would think it would show the same issue in the Kindle Previewer...
It's not all that strange that a software emulator might render a few things slightly different than the actual devices/apps do.

Like I said; if you don't like surprises... don't upload ePubs to Amazon and rely on their conversion to be flawless. Upload MOBIs that you've built and verified yourself before-hand.

traveler212
06-19-2012, 06:29 PM
OK, thanks guys.

Tomorrow, I will try it with these changes to the guide section and see if this fixes it:

<guide>
<reference href="Text/cover.xhtml" title="Cover" type="cover" />
<reference href="Text/toc.xhtml" title="Table Of Contents" type="toc" />
<reference href="Text/author.xhtml" title="Text" type="text" />
</guide>

So the book should open to the 'author' page, correct?

Can I have both title="Text" and type="text" in the author reference line?

DiapDealer
06-19-2012, 07:28 PM
So the book should open to the 'author' page, correct?
It should, yes.
You don't really need the "Cover" reference item either (Kindlegen will ignore it anyway—and likely strip the xhtml file it refers to). That's not what the Kindle (or the apps) uses for its "Go to Cover" functionality. It uses the meta-tag entry and the image itself for that. But it shouldn't hurt anything if you leave it in.

traveler212
06-20-2012, 09:08 PM
Those changes to the <guide> section fixed the problem.

Huge thanks, guys! That was bugging me for a week.