justify not working for epubs

I found a strange one. When I set up a preset to justify (right and left justification) text, it doesn’t work when compiling .epub. It works for .mobi, however, and when I use Calibre to convert the mobi to epub, that works. (Don’t use Adobe Editions to try to view this problem. Its interpretation of the epub is different from those of the Caliber viewer and the IPad’s iBooks app.)

I looked inside the epub with Sigil, and the Scrivener-generated CSS does specify text-align:justify; for the paragraph styles. But something in the way paragraph styles are set up overrides it, and I was unable to find out what. And unable to hard-code some CSS to force it to work. And it’s weird. center and right both work. Only justify doesn’t work.

Just for the heck of it, I used Sigil to extract one of the xhtml files and used Firefox to display it. Got this message:

So, I changed the name to a .html file, and IE and Firefox both display it with a ragged right margin.

After several experiments, I found that the only way to get it to display justified was to remove the
!DOCTYPE statement at the top. But that works only in IE. Firefox still displays a ragged right margin.

There must be something else in the CSS that overrides the text-align:justify; statements.

There is a CSS statement that is conflicting with justification. Check above the main style block and you should find a single line setting white-space: pre-wrap, to p and ul. Remove that and you should be seeing flush edges again. Removing the doctype will cause the ePub file to no longer validate, and at best all you are doing is triggering the browser into sloppy rendering mode, where it may be disregarding the pre-wrap hint.

We’ve already located this problem and where it was coming from (the built in QT output was producing it), and it’ll be fixed for the next release.

Yep, that’s it. Sigil lets me do a global find and replace, so I have a workaround. Many thanks.