Hello everyone. This probably won’t interest most people, but ive been looking into ways to improve text layout for IF.
I don’t know if any other interpreters do this, and im sure that web browsers don’t, but the idea is “smarter word-wrap”. So it turns out there are better ways to word wrap than simply taking a new line whenever you reach the right margin.
So here is an example. You can see better side by side, but I’ve indicated the areas changed with red arrows.
This is the standard “greedy” algorithm. The areas indicated have untidy white space at the ends of the lines.

So here is the improved version.

You can see the top text is smoother on the right. Also it managed to improve some at the bottom too.
This is using Knuth’s algorithm. It works by assigning a non-linear penalty to unused white space at the ends of lines. So 3 spaces wasted is more than 3 times one space. Minimising this cost over a paragraph leads to a smoother and more consistent right edge.
But there’s more.
In this side-by-side example;

The left panel is the original, and the middle panel, the result of the Knuth wrap. It managed to improve the consistency of the edge on the top paragraph, but it decided to break the hyphenated “high-stakes”.
I didn’t really like this because, although it’s fine to break at hyphens, it would be nice not to. So to tweak the algorithm, the idea is to introduce:
- A penalty for breaking a hyphen that wasn’t broken before.
- A reward for joining a hyphen that was broken before.
The result is the right panel. Which isn’t especially exciting because it put back the unbroken hyphenated “high-stakes” and kept only a small change at the top.
Well, that’s today’s experiment!