I'm trying to turn a plaintext string like this:

This is a long example sentence. Okay, it wasn't too long, but here is another one. And also another one.

into this:

This is a long example sentence. Okay, it wasn't too long, but here is an-
other one. And also another one.

That is, at 75 letters (or whatever value is chosen for the "line width"), it "cuts off intelligently"; "another" is turned into "an-" on the first line and "other" on the second line.

Even though this is done in PHP context, I'm not looking for a PHP library for this, since I have determined that no such thing exists. Instead, I'm wondering if this exists as a general command-line utility/program, which doesn't care what language is being used (and thus heavily increasing the likelihood that it exists).

Yes, PHP has a wordwrap() function, but it does not do what I ask for. It wraps entire words only, leaving ugly unused whitespace to the right parts of many/most lines.

Simply adding a linebreak at every 75 characters may be optimal in terms of using every single "column" of each line, but it isn't correct typography to just cut off words like that. This is a very complicated matter which is why I don't just code it myself. It has to take into consideration all kinds of rules which vary with the language.

Although it would be a plus with support for other languages as well, this only needs to support English.

Is there such a thing? I don't know for sure that "hyphenator" is the right term, but I've seen it used when this kind of "typography feature" is being described.

  • It can be done via CudaText plugin. For this plugin to be created, you can write "bounty" with donation sum, to CudaText forum. Someone can make this plugin for bounty. – RProgram Dec 27 '19 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.