Assuming this is a reflowable ePub rather than a fixed layout ePub, I would suggest not using soft returns to balance text anywhere. If you choose a particular place to break a line with a soft return, it will be a mess if it’s viewed on a narrow screen, or with larger type than you expect, because the turn lines will wrap back to the left margin giving an odd choppy right margin. I don’t imagine anyone would expect to read an eBook about coding on a smart phone, but they might try to read it on a smallish eReader.
If you have the book set up for print publication with your preferred line breaks, make a copy of the file specifically for ePub export and remove all the soft returns. Then set up the code paragraph style with a hanging indent that is wider than the furthest left indent you are using. For instance, using a block left indent of 10p with a first line negative indent of –7p makes your code lines begin with a 3p left indent (code is indented in your example), and lets the lines rebreak as needed on any width eReader, with all turn lines further indenting to 10p. You’d have to figure out the right amounts for the first line indent and hanging indent, of course, so the monospace font stays aligned when text over-runs turn text to the next lne.
Thanks for your reply much appreciated.
Yes, I have working on reflowable ePUB.
When the Hanging Indent to the code is given referring to a specific line, the Indent to the continued line comes proper. But if there is a new line with spaces before it, the indentation doesn't come properly in the Print file, but the epub file is fine I cant see any extra space in between.
I have attached the screenshot for your reference. The content Hightlighted in red is coming fine, as I have the Hanging Indent is given in reference to the 1st line. But there are space before the 2nd Line Highlighted in green and the Hanging Indent is not coming as required.
Please reply if any changes needs to be done.
The hanging indent is not based on the first letter in a line, it is based on the left margin. Your indent for continued lines is not deep enough. You need to find the code line that begins with the most spaces and then set the continued-line indent so that it indents further than those spaces at the beginning of the line.
If you want different hanging indents for lines that begin with spaces, you’ll need to create more than one paragraph style. I would advise against that, though, because it is clearer to the reader if all turn lines indent to the same place. That way they know a turn line is not a new indented code line.
Thanks for the reply Rebecca.
Your are absolutely right. We cant have paragraph style with hanging indents for lines that begin with spaces.