View Full Version : Help with removing indents from beginning paragraphs


markpearl
01-10-2012, 11:34 AM
I'm pretty compulsive about having the first paragraph of a chapter -- or beginning paragraphs of a book, where appropriate -- begin with no indent.

Most or all of the Gutenberg ebooks and virtually all of the ones on Mobilread all begin chapters with indents, unlike most commercial ebooks.

My solution so far has been to create an extra parameter in the .css stylesheet...for example:

.calibre9 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
text-align: justify;
text-indent: 15px
}

Added style:
.calibre91 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
text-align: justify;
text-indent: 0;

Following that, I go to the code view and add a "1" to the "<p class="calibre9">" to each beginning paragraph for which I wish to remove the indent. For books with up to 125 - 150 chapters, this becomes very tedious. Especially when many books also contain primitive "&nbsp;&nbsp;" to create indents. Removing these universally with regex removes them for all paragraphs in the book. So it's been all manual.

Is there a regex script I can use for these situations? Anybody??

Thanks!

WS64
01-10-2012, 11:39 AM
You mean something like
search for
<body><class="calibre9">
replace with
<body><class="calibre91">
?

markpearl
01-10-2012, 11:44 AM
You mean something like
search for
<body><class="calibre9">
replace with
<body><class="calibre91">
?

No, because that would remove them for ALL the book's paragraphs. I only want to remove indents for the first paragraph of each chapter -- and chapter breaks, where appropriate -- which is why I have to create the "1" addition to the body class and insert it manually.

WS64
01-10-2012, 11:58 AM
Yes, that's why the body part is there. Just before the first paragraph is a body element (for each file), all other <p class="calibre9"> will have a </p> in front of them

DiapDealer
01-10-2012, 12:48 PM
If the first paragraph of a chapter/section always follows something consistent; hr, h3, or p class="something"... then you can combine css classes to account for those first paragraphs.

I use something like:

.calibre9 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
text-align: justify;
text-indent: 15px
}

h3 + p.calibre9 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
text-align: justify;
text-indent: 0;
}

That way, all paragraphs will be indented except those that immediately follow an h3 tag (or whatever tag.class consistently precedes the first paragraph in your document). That way you don't have to walk through the document and change the css class of each first paragraph manually. You'll still have to manually remove any &nbsp;'s that are being used for indentation purposes, but that's not that difficult.

Just be warned that if you want to subsequently use the same epub to create a mobi file, only calibre (that I know of for sure) will "recognize" (and honor) that css combining method when converting to mobi. I know for a fact that kindlegen will ignore it.

But it works great if you're just fixing up epubs for your own use.

markpearl
01-10-2012, 01:09 PM
If the first paragraph of a chapter/section always follows something consistent; hr, h3, or p class="something"... then you can combine css classes to account for those first paragraphs.

I use something like:

.calibre9 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
text-align: justify;
text-indent: 15px
}

h3 + p.calibre9 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
text-align: justify;
text-indent: 0;
}

That way, all paragraphs will be indented except those that immediately follow an h3 tag (or whatever tag.class consistently precedes the first paragraph in your document). That way you don't have to walk through the document and change the css class of each first paragraph manually. You'll still have to manually remove any &nbsp;'s that are being used for indentation purposes, but that's not that difficult.

Just be warned that if you want to subsequently use the same epub to create a mobi file, only calibre (that I know of for sure) will "recognize" (and honor) that css combining method when converting to mobi. I know for a fact that kindlegen will ignore it.

But it works great if you're just fixing up epubs for your own use.


Yes! After posting my query, I experimented with just what you suggested and it works!! I didn't have to reach as far back as the paragraph tags, just a unique preceding line such as:
<p class="calibre8">&nbsp;</p> -- combined with -- <div class="calibre9"> in regex. :smack:

Calibre converts to perfect mobis with this method...no problem there.

I've just subtracted hours & hours of tedium from my editing -- currently tweaking Anthony Trollope's novels...many of which I obtained here at Mobileread. I only wish future creators would follow the "no-indent" rule for first chapters and paragraph breaks, where needed. :)

alansplace
01-10-2012, 04:34 PM
I'm pretty compulsive about having the first paragraph of a chapter -- or beginning paragraphs of a book, where appropriate -- begin with no indent.Your query made me smile because I'm exactly of the opposite opinion. I can't stand the initial paragraph of each chapter being non-indented. :smack:

theducks
01-10-2012, 04:50 PM
Your query made me smile because I'm exactly of the opposite opinion. I can't stand the initial paragraph of each chapter being non-indented. :smack:
I like variety :D
I want by books to be consistent within a series.
All should have their own personality otherwise.

Drop Caps, Big caps, First line all Caps, Indented, No Indent.

One thing I am fairly consistent on, is always space between paragraphs. More if no indent.

I love to play with Chapter Heading presentation :D

OK 1 other thing I do : I don't like to see 50% white space at a chapter start. 10% top/bottom margins at tops

Keroberos
01-10-2012, 05:05 PM
I have to say, with books that are in the public domain (those you would get from Project Gutenberg, or here at Mobileread), it's entirely consistent with publishing standards at the time for chapters to open with an indented first paragraph. After quick perusal of my p-book library, it seems to be fairly recent when US publishers consistently started formating books with non-indented opening paragraphs.

That being said I have to agree with theducks, I also like variety. I also like the look of old style typography (too many modern books are too plain and sparse, most especially e-books), so I like playing around with the formatting to see what I can make.

cybmole
01-11-2012, 02:32 AM
I prefer no indents at chapter start - but if they are too much hassle to fix, I let them be.
e.g. sometimes there's header line, then some more spacing, then start of chapter which makes for a hard to detect combo.

I also prefer to see no top margin ( =wasted e-reader screen space) above the chapter header, & for the chapter header to be centered, and not huge - 1em is usually sufficient.

May I ask - the h3 + p.calibre9 construct will apply css to only a <p class - ... line which immediately follows the END of a h3 line ?

where can I find more documentation on building compound css definitions such as this please

WS64
01-11-2012, 02:45 AM
cybmole, they are called silbling selectors, sometimes also called child selectors.
Here's a bit: http://www.w3.org/TR/CSS2/selector.html#adjacent-selectors

Jellby
01-11-2012, 04:17 AM
Note that styles are cumulative, so you could just add to your stylesheet:

.noindent { text-indent: 0 }

And then modify the desired paragraphs so that

<p class="calibre8">...</p>

becomes

<p class="calibre8 noindent">...</p>

(i.e., just add "noindent" to whatever class the paragraph has)

DiapDealer
01-11-2012, 09:04 AM
That will certainly work, but I was under the impression that the OP was looking for a shortcut.

The method I described would allow one to achieve the desired effect without ever having to touch the html of the document itself.

Just add a css statement or two to the stylesheet and be done.

I highly recommend your method when building your own epub, but I prefer the "less work is best" approach when simply tweaking someone else's epub for my own personal reading enjoyment. ;)

markpearl
01-14-2012, 05:33 PM
That will certainly work, but I was under the impression that the OP was looking for a shortcut.

The method I described would allow one to achieve the desired effect without ever having to touch the html of the document itself.

Just add a css statement or two to the stylesheet and be done.

I highly recommend your method when building your own epub, but I prefer the "less work is best" approach when simply tweaking someone else's epub for my own personal reading enjoyment. ;)

Yes, if my objective was to build my own epubs, it's a good method. But as DiapDealer commented, I was looking for a shortcut...which works most of the time when the epub on which I'm working wasn't originally built with archaic (so to speak) software in the "pre-sigil" days...:D

JSWolf
01-20-2012, 05:03 PM
[code].noindent {
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
text-align: justify;
text-indent: 1.2em
}

There you go. That's all you need and when you look at your XmL code, you can see which paragraphs have no indents. Personally, I prefer no indent at the first paragraph of a chapter and the first paragraph after a section break.

cybmole
01-21-2012, 01:55 AM
if you are a lazy typist, replace the above 4 margin lines with
margin: 0 0 0 0;

it's possible that just margin: 0; would actually suffice, here

Jellby
01-26-2012, 12:42 PM
it's possible that just margin: 0; would actually suffice, here

It should, unless the CSS parser is broken.

cybmole
01-26-2012, 01:47 PM
It should, unless the CSS parser is broken.

margin: 0
works fine for ADE & for my sony e-reader, but I cannot speak for all epub devices.