EPUB HTML contains classes for styles twice?

I have a quite complicated layout which has some paragraph styles which have a left and right margin to distinguish them from body/main text. They are also in sans-serif opposed to serif for the same reason.

It’s very difficult to get that translated into EPUB and I use Sigil to better understand what happens. What I found is that my paragraph styles are applied twice, once for the p tag, and again for an inner span tag, like this:

<p class="chat-ich"><strong><span class="chat-ich">Some text here.</span></strong></p>

The CSS rules for class chat-ich are like this:

.chat-ich { margin: 0rem 0rem 0rem 1.98rem; text-indent: 0rem; font-size: 1.08rem; font-weight: bold; }

As end result the whole paragraph is indented (as it should be), but the first line is indented again (because of the span) like this:

scriv-problem

I absolutely do not understand why the class is applied twice and how to disable it.

One thing to be aware of is that if your style is only meant to change the paragraph settings, or it’s “shape” such as indenting and spacing, then there is no need to use a Paragraph+Character type style. The latter is where the span is coming from (right or wrong, personally I would say it is not correct to use spans that way, but that is how the HTML exporter works and we haven’t tried to manually correct that yet).

So you can at least get rid of the span by converting your paragraph style by redefining it and changing the “Save all formatting” setting “Save paragraph style” instead. And if that’s good enough for what you need, then that should be all you need to do to fix the problem.

If you do need character formatting preserved to some degree, then I would solve this with a line of CSS, added to the CSS format option pane:

  1. Double-click the compile Format you are using, in the left sidebar of the main compile screen, to edit it.

  2. In the CSS pane, make sure the dropdown above the CSS area says either “Append Custom CSS Stylesheet” or “Use Custom CSS Stylesheet” (the former is better unless you want more control).

  3. Paste the following in the “Custom Stylesheet” column:

    span.test { margin: 0; }
    

That will override the .test formatting, specifically only when the class is assigned to spans, leaving the indent on the paragraph as you desire.

1 Like

Thanks, that was the solution I was looking for! I go with the CSS overruling as I use very different paragraph styles throughout the current project and settled on “Save all formatting”.

I’m still struggling a bit with the decisions when to use “Save all formatting” and “Save paragraph style”. As I need an editor appearance which should be quite near to the final print version and sometimes need to apply style changes to the whole project including font size and family, I mostly go with “Save all” for the basic paragraph styles I need.

Am I right that, if I would use “Use Custom CSS Stylesheet”, I would lose the automatically applied styles (including those for newly added styles) and have to format all that in my custom stylesheet? And that’s the reason you recommend “Append Custom CSS Stylesheet” (which I already used to apply quite a lot of other overrulings as it happens that I know my CSS quite well, although I didn’t get the connection between the span and the character style part of the p+c style, although that’s quite obvious in hindsight … )

I think so.
But you can copy/paste the default (on the right) in the custom, and then edit out what you don’t want.
Or tweak overrides using the custom CSS this time again, but appending it. (What you just did, as per Amber’s advice, actually.)

You could also leave it all as it is and tweak it in Sigil.
Advantage: you see the result right away.
Downside: you kind of have to redo it with every new compile. (Although there are ways around it, it is still quite a disadvantage.)

1 Like

Yes, I use Sigil to test any overrides “live” and if it works out I copy the custom part back to the compile format CSS which is okay for me. (I also make backups of intermediate edits form Sigil or save the changed copy to not lose any edits before they are safely back in Scrivener … Sometimes it’s easy to get lost …)

I struggle a bit with font sizes that are fixed in some readers (like Tolino on Android) but not in others (like Sigil and Calibre, so more browser-like) but that’s for some future thread …

I’m still struggling a bit with the decisions when to use “Save all formatting” and “Save paragraph style”. As I need an editor appearance which should be quite near to the final print version and sometimes need to apply style changes to the whole project including font size and family, I mostly go with “Save all” for the basic paragraph styles I need.

Here are the two things that matter when setting up compile settings in the Styles pane:

  • The name of the style matches what was used in the project.
  • It is a paragraph style or a character style.

It does not actually matter if the style is character + para or just para. That means you can keep styles less “overbearing” in your project and in the editor, and for compile formats that do not need them (like eBook), while doing full character and paragraph formatting overrides for other outputs.

It is a little complex, the relationship between the two, but think of it as working a bit like CSS ideally. You can override a little or a lot, with your compile settings, and what you don’t override is set by the project’s style formatting.

Am I right that, if I would use “Use Custom CSS Stylesheet”, I would lose the automatically applied styles (including those for newly added styles) and have to format all that in my custom stylesheet?

Yes, you can test what it does fairly simply by duplicating a copy of “Ebook”, setting it that way, deleting the prefab stuff we stick in there, and looking at the stylesheet.css file in the output .epub file. It should be largely empty save for any styles in active use.

So that setting is ideal if you have your own design you want to implement from top to bottom, rather than struggling against the compile settings and fighting to turn things off or nullify settings.

If you do like a blend, and overriding things here and there, then the default setup is fine. You can even override what styles do entirely if you want, since we append below the automatically generated classes.

I struggle a bit with font sizes that are fixed in some readers (like Tolino on Android) but not in others (like Sigil and Calibre, so more browser-like) but that’s for some future thread …

I haven’t seen that happen, but like you say it depends on the ebook reader. The best approach is to establish everything as percentages or em adjustments relative to the body text (which should be left default). That should scale everything proportionally based on the individual user’s magnification setting. Trying to force fixed sizes could result in odd things like titles being smaller than body text.

1 Like

I remember a user a while back had quite a hard time as far as formatting for Tolino is concerned.
I don’t precisely recall what it was about, but I remember being under the impression that it is user unfriendly.
Just sayin’ – perhaps you’d want to search the forum for “Tolino”.
(I think that that user was referring to it as a physical device, though.)

Else, I’ll agree with Amber that fixed size fonts is something to avoid anyways.
It can only do two things in my opinion: No difference whatsoever in some cases, cause issues the rest of the time.
(I guess that if you insist, at least don’t mix them with em font sizes.)

Thanks, that helps a lot! It looks like I was mostly on the right path …

The weird thing with this Tolino reader app is that I don’t use fixed font sizes at all. I leave alone in my CSS and style all paragraph styles rem-based. Time will tell, maybe … :slight_smile:

Ok. I think I might see what you mean.

Know that most android ereader apps DITCH/IGNORE the stylesheet.
For ex: Heading1 looks a certain way, a certain size no matter what.
You can css it to be huge? doesn’t matter ; it’ll look just as it looks for any other book.
Same is true for everything else. Your css stylesheet is as good as nonexistent.
If you want to cheat that, you need to use inline span definitions.

1- It is messy and can quickly turn into a nightmare to do.
2- You’d be doing it to improve the experience of readers who are most likely reading an illegal copy of your book. (People with genuine copies use a kindle, the kindle app, a Kobo, the Kobo app, etc. etc.)

What is Tolino worth on android? I have no clue.

Tolino has quite a market share for ebooks in Germany and is an alliance of the biggest independent book store chains, they have their own ereaders and this Android app.

But I’m absolutely new to ebooks, I usually prefer to read on paper, so I cannot say much about the real relevance of Tolino but as they are an important ebook and PoD publisher I thought I should at least try to solve the puzzle.

It’s difficult enough to come up with a working and good-looking stylesheet anyway, so I take it as it for now, and maybe ask some people at Tolino if that’s a bug of the app.

Thanks for all your insights!

1 Like

I noticed this sort of thing in my xhtml

<p class="messaging-right-sender"><strong><span class="messaging-right-sender">Tianlong</span></strong></p>

i.e. the style is being applied twice by classing the paragraph and then the text: this happens because that style is both paragraph and character attributes.

Which is OK unless one starts with a style that has margin, indents etc., in which case it seems they can stack up for bizarre and unpredictable results on indents etc… (could be other effects, but that’s what made me look at this)

(Update: changing the style to paragraph only ?and re-adding it to the compile format styles does make the character attribute duplication go away.)

Is this a bug?

See above for solutions, though I suspect you may have figured them out already.

I was distracted and I didn’t check the forum. Thanks.