Turnipsoft Forums
Spaces in Poetry - Printable Version

+- Turnipsoft Forums (https://www.turnipsoft.com/forums)
+-- Forum: Freda (https://www.turnipsoft.com/forums/forumdisplay.php?fid=1)
+--- Forum: Support (https://www.turnipsoft.com/forums/forumdisplay.php?fid=2)
+--- Thread: Spaces in Poetry (/showthread.php?tid=11128)



Spaces in Poetry - adaml - 07-01-2025

I am publishing a poetry book using ePub reflowable 3.0 format. Some of the poems have extra spacing between words to position them uniquely relative to other words, for visual effect.

I am using multiple   entities to force spaces, which is working in other readers that I have tested it with (Adobe Digital Editions, Aquile Reader, Calibre eBook Viewer). However, Freda ignores the extra spaces and only renders one space between all words.

Is this by design, or do I need to use a different entity (such as nbsp) to make this work?

Thanks


RE: Spaces in Poetry - jim_chapman - 07-01-2025

(07-01-2025, 04:51 PM)adaml Wrote: I am publishing a poetry book using ePub reflowable 3.0 format. Some of the poems have extra spacing between words to position them uniquely relative to other words, for visual effect.

I am using multiple   entities to force spaces, which is working in other readers that I have tested it with (Adobe Digital Editions, Aquile Reader, Calibre eBook Viewer). However, Freda ignores the extra spaces and only renders one space between all words.

Is this by design, or do I need to use a different entity (such as nbsp) to make this work?

Thanks

Freda is quite aggressive about showing any amount of whitespace as a single space, unless it's actually being told by CSS/XHTML to preserve whitespace.  If you really want to control the position of words in an HTML document you may do better to create suitable spans and set their margins accordingly.  Or even use floating elements.  Putting your text into table elements can also work.  Using space characters (or other whitespace entities) is always going to be a rough and ready solution, because you don't get to control the screen dimensions of the user's device, or the font face (and size) that the user selects.

That said, Freda does offer some possibilities for doing what you need.  Firstly, you can create extra vertical spacing using paragraphs containing only a non-breaking space.
Code:
<p>&nbsp;</p>
Secondly, any text that has 'preserve whitespace' set will keep all the space characters you have in the text.  You can set that in CSS or by using the PRE tag (in which case it will by default switch to a fixed-width font, which is probably what you need if you're trying to use space characters to line up your text).  For example:
Code:
<HTML>
<HEAD>
<meta charset="utf-8">
<TITLE>Poetry Layout Test</TITLE>
</HEAD>
<BODY>

<div><pre>A sentence with single spacing</pre></div>
<div><pre>A  sentence  with  double  spacing</pre></div>
<div><pre>A   sentence   with   triple   spacing</pre></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div>A sentence with a gap above it</div>


</BODY>
</HTML>



RE: Spaces in Poetry - adaml - 07-01-2025

Thanks. It looks like in CSS I could apply "white-space: pre-wrap;" to the whole document. I'll need to see how it responds in different readers and software before committing to it. Thanks for explaining what's happening!


RE: Spaces in Poetry - jim_chapman - 07-02-2025

(07-01-2025, 10:29 PM)adaml Wrote: Thanks. It looks like in CSS I could apply "white-space: pre-wrap;" to the whole document. I'll need to see how it responds in different readers and software before committing to it. Thanks for explaining what's happening!

Yes, that should work.  In Freda, I got reasonable results with:
Code:
<HTML>
<HEAD>
<meta charset="utf-8">
<style>
.white {
    white-space: pre-wrap;
}
</style>
<TITLE>Poetry Layout Test</TITLE>
</HEAD>
<BODY>
<div class="white">
A sentence with single spacing
A  sentence  with  double  spacing
A   sentence   with   triple   spacing

A sentence with a gap above it
</div>
</BODY>
</HTML>

I say 'reasonable' because in fact Freda was then being so assiduous about preserving whitespace that it also preserved the new-line characters, which meant that little white squares were appearing at the end of each line.  That's a bug really!  I'm planning a bug fix release for Freda in the next week or so, and in that update I will fix this, so those ugly little squares won't appear any more.


RE: Spaces in Poetry - adaml - 07-03-2025

(07-02-2025, 07:49 AM)jim_chapman Wrote: I say 'reasonable' because in fact Freda was then being so assiduous about preserving whitespace that it also preserved the new-line characters, which meant that little white squares were appearing at the end of each line.  That's a bug really!  I'm planning a bug fix release for Freda in the next week or so, and in that update I will fix this, so those ugly little squares won't appear any more.
Good to know! I'm not in a rush -- I can update the files later. This drives home the fact that it would be prudent if I added the CSS white-space: pre-wrap to test this in many other readers to make sure that there are not any unexpected results.

Just to clarify, this behavior would still be different than the default of the other readers that I tried. They all ignored multiple white spaces as Freda does. It was only where I inserted explicite non-breaking space characters (&nbsp or &#160) that they displayed multiple spaces.

Adding the explicite space entities seems to be what other people publishing poetry eBooks are doing, as that's where I got the suggestion from others with the same issue. The other solutions aren't practical -- the spacings are unique for each word-gap in the lines, so tables wouldn't work, and controlling positioning with CSS would be a whole lot of extra work to do for one reader -- I want to transfer files from the print book with the least amount of extra work possible. I could experiment with adding the CSS white-space: pre-wrap, but that would just resolve the issue for my book, but not for most others.

Wouldn't it be more HTML standards compliant to ignore multiple white spaces, but to not ignore explicite spaces? Then the behavior would be the same as you would expect in a web browser. I don't know what the behavior of other readers is as far as wrapping, and if I'd get better results on small screens using something such as an n-space instead of an nb-space.


RE: Spaces in Poetry - jim_chapman - 07-03-2025

(07-03-2025, 07:41 AM)adaml Wrote: Wouldn't it be more HTML standards compliant to ignore multiple white spaces, but to not ignore explicite spaces? Then the behavior would be the same as you would expect in a web browser. I don't know what the behavior of other readers is as far as wrapping, and if I'd get better results on small screens using something such as an n-space instead of an nb-space.
I do see your point, but in practice, it wouldn't be easy to change Freda's treatment of no-break space symbols. Full HTML/CSS standard compliance isn't a realistic goal for a project that's just a spare time activity for a single developer (me), and Freda's code for parsing HTML is already quite messy and fiddly (also I wrote most of it over ten years ago!) so I'm reticent about making changes to it. Looking at the code, I actually see various places where I wrote comments like "nbsp doesn't work here, but it's hard to fix". So it will go on my backlog of things to look at one day, but it's unlikely to be changed in the near future.


RE: Spaces in Poetry - adaml - 07-03-2025

(07-03-2025, 04:01 PM)jim_chapman Wrote:
(07-03-2025, 07:41 AM)adaml Wrote: Wouldn't it be more HTML standards compliant to ignore multiple white spaces, but to not ignore explicite spaces? Then the behavior would be the same as you would expect in a web browser. I don't know what the behavior of other readers is as far as wrapping, and if I'd get better results on small screens using something such as an n-space instead of an nb-space.
I do see your point, but in practice, it wouldn't be easy to change Freda's treatment of no-break space symbols.  Full HTML/CSS standard compliance isn't a realistic goal for a project that's just a spare time activity for a single developer (me), and Freda's code for parsing HTML is already quite messy and fiddly (also I wrote most of it over ten years ago!) so I'm reticent about making changes to it.  Looking at the code, I actually see various places where I wrote comments like "nbsp doesn't work here, but it's hard to fix".  So it will go on my backlog of things to look at one day, but it's unlikely to be changed in the near future.

OK, thanks.


RE: Spaces in Poetry - jim_chapman - 07-17-2025

(07-03-2025, 04:45 PM)adaml Wrote: OK, thanks.

I've just made a bug-fix release for Freda, and in that I've included some code to make nbsp entities appear as whitespace.  It's a bit rough and ready, and it might not work quite correctly.  But by all means give it a try and let me have any feedback.


RE: Spaces in Poetry - adaml - 07-17-2025

Thank you!

Testing reveals one bug:
It is working correctly with normal text, but the extra spaces are still ignored with italics text.


RE: Spaces in Poetry - jim_chapman - 07-18-2025

(07-17-2025, 04:58 PM)adaml Wrote: Thank you!

Testing reveals one bug:
It is working correctly with normal text, but the extra spaces are still ignored with italics text.

That's odd - I tested it with some italic text myself and it seemed to be working for me.  Could you share the xhtml or epub file you're using please.  Either as an attachment here, or by email to jim@turnipsoft.co.uk.  Thanks!