Home ยป Forum ยป Author Hangout

Forum: Author Hangout

Some recently discovered issues with Calibre

Ernest Bywater ๐Ÿšซ
Updated:

For most of the last 36 hours I've spent a hell of a lot of time trying various things in Calibre to resolve problems which I became aware of with a recent e-pub. When I made the e-pub for the Clan Amir of Berant anthology a couple of months ago I didn't realise there was an issue in the e-pub created finally got to the point it caused an issue with the e-pub. They all relate to the way Calibre uses the CSS code and changes it.

(NB: I'll add extra space when I list code so that it doesn't run.)

Here are the big issues which I've identified and found a work around:

1. The use of the word 'head' in a style name within the CSS code.

2. The use of a style code with 'head' in it's name within the HTML code of the document.

3. The order in which styles with 'head' it their name or the 'headings' are used in the HTML code of the document.

4. Calibre will frequently make styles which have the same attributes into the one style and use the style name of the first listed in the CSS code.

5. The use of the < br > code in the HTML code of the document.

6. Calibre will change style attribute code to what it thinks it should be and will create new styles as it feels it should.

How they cause problems:

a. Calibre automatically assumes that any style type with the word 'head' in it is a heading style and it automatically assumes any paragraph that uses a style with 'head' in it is a heading.

b. Calibre will reassign heading hierarchy designations as it feels it should.

c. Calibre will delete styles it deems aren't needed.

d. Calibre will create new styles as it decides it needs to. Mind you, it will allow itself to create styles with the same attributes and similar names but often won't let you do that.

3. Calibre will change style attributes to what it thinks they should be.

How to stop the problems happening.

a. There are some Calibre setting that will reduce a lot of this problem. Open Calibre and go to the Preferences then got to Common Options

1. In Look & Feel select Fonts place a 'tick' in the box beside Disable font size rescaling by clicking on the box.

2. set the Minimum line height to 100%.

(These changes will ensure whatever font and line sizes you have in your styles will be used by Calibre instead of being adjusted by Calibre.)

3. In Table of Contents set the ToC levels to use your H1, H2, and H3 headings with the code '/ / h : h 1' etc. adjust the number for the appropriate levels. NB: only set for the number of levels you wish to use or do not use the the third level in your HTML code.

Note: Technically you can set the system to detect and use a H3 above H2 or H1 by adjusting the code here, but doing that may cause some issues.

b. There are changes to the CSS styles that will resolve a lot of the issues.

1. Only use the word 'head' in the name of a style type you intend to use only for headings, and ensure those four letters in that order are not used in any other style name.

2. Only every use the styles with 'head' in their name for the headings in your HTML and match them with the appropriate H1, H2, H3 HTML tags.

3. Ensure all of the attributes of a named style in the CSS code does not match that of another style.

4. The named styles have all the attribute settings have a line-height and have as many attribute as you feel needed to ensure they don't match up with another style.

5. Make the attributions listed for each style as complete as you can.

6. Where you wish to use a style that's the same as for a heading create a new one with a different name and give it a slightly different attribute. (examples later)

7. Where ever you wish to use a < br > create a new style with an attribute of 'padding-top : 0.0 em' and the other attributes to suit what you want to match it to. One style for each different type of usage. (examples later)

If you don't have a style set and named Calibre will create its own and add it to the CSS, and it will create a new style for each split the < br > code appears in.

8. Make sure the first headings you use within the document code are in their hierarchy order. The first use of a heading and heading style after the title should always be H1 with the intended H1 style, then you can use another H1 or a H2 but do not use a H3 until after you've used a H1 then a H2 style headings.

You can go H1, H2, H3, H1 or H1, H1, H1, H2, H2, H1, H2, H3 and all will be well. However, if you go H1, H3, H2 Calibre is likely to adjust the style attribute and names of H3 and H2 on you based on the first usage order. Once each has been used the first time it seems you can then use them in any order - but I'm not 100% positive of this, just it seems that way, so far.

...............

One thing I had done in some stories was to use the same style I use for the H2 heading to have it appear mid-story as a special notice. The difference in how I coded it in the HTML was:

< h2 class = " head2 " > Sub-chapter title < / h2 >

< p class = "head2 " > Notice sign within the story < / p >

The above is valid HTML code and will display as I wish it to. However, Calibre will see the style name and disregard the < p > designation as a normal paragraph. I tried resolving this by copying the 'head2' code and creating a new style named 'notice' but Calibre saw they had the same attributes and merged them, thus recreating the initial problem. I got around this by changing the line-height and font-size for the notice style from 1.6 em to 1.4 em.

Another major change was to rename every style that used 'head' in its name except for 'head,' 'head1,' and 'head2' which are the ones I use for story titles, chapter, titles, and sub-chapter titles. This eliminated the mistake by Calibre in the use of the 'head5' which I use for section headings.

I resolved the issue with the < br > commands by creating new styles for the subsequent lines for each situation in which I used them. Most of the times I used < br > was with poetry and lists I didn't want lines between the lines in. I simple copied the style I used for the first line, gave it a new name to be in the css code below what it relates to and changed the 'padding-top' attribute from 1.0 em to 0.0 em.

Note: After all of these changes the HTML code displayed the same when run as HTML, but it also eliminated all of the problems I noticed in the e-pub Calibre created before I made the changes.

The worst part of this is that I recently updated and reposted my writer guide and I now have to update it to include all of this information.

CB ๐Ÿšซ

@Ernest Bywater

Thanks for this and for your other writer's guide posts and publishments.

Replies:   Ernest Bywater
Ernest Bywater ๐Ÿšซ

@CB

Thanks for this and for your other writer's guide posts and publishments.

You're welcome. If I can provide some information that reduces the frustrations of others enough that they stay with writing, then it's worth the effort of making it public.

Switch Blayde ๐Ÿšซ

@Ernest Bywater

They all relate to the way Calibre uses the CSS code and changes it.

I assume you mean this occurs when you input HTML/CSS to Calibre. Since I input docx, this doesn't apply to me. Right?

Replies:   Ernest Bywater
Ernest Bywater ๐Ÿšซ

@Switch Blayde

I assume you mean this occurs when you input HTML/CSS to Calibre. Since I input docx, this doesn't apply to me. Right?

I'm not sure how Calibre is affected by the docx input, but it's my understanding that docx does have some xhtml code in it, so it's likely to have an effect.

When I noticed the problem I raised a bug report with Calibre for it and got a response of:

"That s the way calibre works, it flattens css into disjoint classes, and
performs various operations on it such as rebasing font sizes, etc."

and later

"calibre will create a class only if the element has some styles applied
to it."

He never tried to detail why Calibre was changing the font sizes or colours within the css style attributions or adding extras.

I found out the above simply by making a change then seeing what it did, then another, then another. Eventually I had a list of changes that always had the same effect.

However, if your file doesn't have a defined style for every type of paragraph, then calibre will make it's own for every split that paragraph type appears, and it regards a < br > command as being a different type of paragraph as well.

helmut_meukel ๐Ÿšซ
Updated:

@Ernest Bywater

7. Where ever you wish to use a < br >

use a < br / > instead. (same for < hr >, use < hr / >).
As I understand it, it's a problem caused by changes in the HTML definitions.
Most HTML codes enclose some text as in < p > sometext < / p >, < div > something more < / div >. There is always a start sequence and an end sequence. Then there are the codes like br and hr which stood alone - start without an end - this is no longer allowed. (I doubt most reader programs will insist on strict use of the rules). Changing it to < br > < / br > would work but adding the closing slash after the br is preferred.

HTH,

HM.

Replies:   Ernest Bywater
Ernest Bywater ๐Ÿšซ
Updated:

@helmut_meukel

What Calibre did was to create a style called 'Calibre 2" and what was

< br >

became

< br class = "calibre 2" / >

so it seemed calibre required it to have a style with set attributes.

I created style 'bodz' with no padding and made each line it's own paragraph with

< p class = "bodz" > text < / p >

which is used for the 2nd line and everyone after that. The result was the same in the display of the html and in the epub and calibre didn't create an extra style to handle it as one existed.

Replies:   Keet
Keet ๐Ÿšซ

@Ernest Bywater

< br >

became

< br class = "calibre 2" / >

The / is required for valid xhtml, html doesn't require it but will accept is as valid. Since epubs require valid xhtml calibre will add the /. It's probably taken care of by a standard conversion/check function that checks all tags, hence the adding of a class. Try using the < br / > and see if calibre still adds a class.

Replies:   Ernest Bywater
Ernest Bywater ๐Ÿšซ
Updated:

@Keet

Try using the < br / > and see if calibre still adds a class.

Just tried that and it added a class then converted the code from

< br / >

to

< br class = "calibre2" / >

edit to add: that makes it clear Calibre insists on a class for every paragraph in the file.

Replies:   Keet  helmut_meukel
Keet ๐Ÿšซ

@Ernest Bywater

Just tried that and it added a class then converted the code from

< br / >

to

< br class = "calibre2" / >

That's just plain weird. There's no logical reason for it so some developer at Calibre must have had a brain fart at the time :)

Replies:   Ernest Bywater  bk69
Ernest Bywater ๐Ÿšซ

@Keet

That's just plain weird. There's no logical reason for it so some developer at Calibre must have had a brain fart at the time :)

agreed

bk69 ๐Ÿšซ

@Keet

There's no logical reason for it so some developer at Calibre must have had a brain fart at the time

At a guess, the design idea would be: "We want to make it easy to modify the style in the future by just modifying the CSS, so we need to ensure that every entity is defined by a class to ensure we only modify the correct parts." (And not checking for boundary conditions like entities that don't need to contain a style.)

Replies:   Keet
Keet ๐Ÿšซ

@bk69

At a guess, the design idea would be: "We want to make it easy to modify the style in the future by just modifying the CSS, so we need to ensure that every entity is defined by a class to ensure we only modify the correct parts." (And not checking for boundary conditions like entities that don't need to contain a style.)

Yep, I also thought it could be something like that. That's why I mentioned laziness to not check for those few exceptions and just bloat the document any further.

helmut_meukel ๐Ÿšซ

@Ernest Bywater

that makes it clear Calibre insists on a class for every paragraph in the file

I assume we are discussing the main Calibre program here.
After some tests some years ago I didn't use it for conversions from HTML into epub, I instead created a empty ebook template with my standard stylesheet in it. When I create an epub I simply start Calibre's ebook editor, open a renamed copy of the template and add the html files and โ€“ if there is a stylesheet for these files โ€“ this stylesheet.
The Calibre editor doesn't add any classes to my stylesheet.

HM.

Back to Top

 

WARNING! ADULT CONTENT...

Storiesonline is for adult entertainment only. By accessing this site you declare that you are of legal age and that you agree with our Terms of Service and Privacy Policy.


Log In