I'm looking for a sample project that will perform hyphenation of text in C#. Ideally, this would be derived from the TeX hyphenation algorithm, or similar. I'm interested in English currently, although other languages may be required in the future. Anyone seen something like that? background I'm planning on including this in a MonoTouch project using CoreText.
Asked
Active
Viewed 3,990 times
2 Answers
5
I found a C# implementation of Knuth-Liang hyphenation algorithm at https://github.com/alkozko/NHyphenator and it seems to work fine.
But there are currently two drawbacks:
- It can't load TeX hyphenation pattern files out-of-the-box (however, adding support for them seems trivial).
- It's unclear which kind of license applies to the source code.

Lukas Pokorny
- 1,449
- 12
- 12
-
If you could provide some hints on how to convert files like this http://mirror.ctan.org/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex/hyph-el-monoton.tex into the format that NHyphenator uses, for the people who have no idea what the file contents of either format mean, it would be great. I am finding myself wanting to use this library too and I am afraid that if I start reading the algorithm details in order to understand the file contents, I will probably end up reimplementing the thing myself... :( – NoOne Jun 04 '17 at 15:57
-
After looking inside both of the file formats, I would -quite safely- speculate that you just need to copy the contents of `\hyphenation{}` to the `hyph-***.hyp.txt` file and the contents of `\patterns{}` to the `hyph-***.pat.txt` file. Hm... Not much work to build a parser for that... – NoOne Jun 04 '17 at 16:11
-
1The License is (as of now anyway) Apache-2.0 License as stated in the [License](https://github.com/alkozko/NHyphenator/blob/master/LICENSE) file – dstj Sep 13 '21 at 21:38
3
Obviously, Donald Knuth's algorithms are excellent. Although there is not a C# implementation available, have you considered converting another implementation to C#? (For example, you could convert the Java implementation which is fairly close to C#.)
Another option is to use a simpler implementation which can be found over at this answer here on StackOverflow.
-
Thanks, Jason. I was really hoping someone out there had already converted the TeX version to C# I may have to go the route of converting it myself. Do you know where I can find a descent Java version to start from? – Ethan May 17 '11 at 22:17
-
For a Java implementation of Liang's work, you can take a look at TeXHyphenator-J: http://www.davidashen.net/texhyphj.html – Jeremy Apr 23 '13 at 17:46