Hyphenation
A port of TeX's hyphenation algorithm to Go
Install / Use
/learn @speedata/HyphenationREADME
A port of TeX's hyphenation algorithm to Go
Installation
go get github.com/speedata/hyphenation
Prerequisites
Download a hyphenation pattern file from CTAN, for example from https://ctan.math.utah.edu/ctan/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/txt/
Usage
package main
import (
"fmt"
"log"
"os"
"github.com/speedata/hyphenation"
)
func main() {
filename := "hyph-en-us.pat.txt"
r, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
l, err := hyphenation.New(r)
if err != nil {
log.Fatal(err)
}
var h []int
for _, v := range []string{"Computer", "developers"} {
h = l.Hyphenate(v)
fmt.Println(v, h) // [3 6] and [2 5 7 9]
}
}
Debugging hyphenation patterns
Similar to getting the hyphenation slice, you can get a detailed view of the hyphenation patterns used in a word:
str := l.DebugHyphenate("developers")
fmt.Println(str)
results in
. d e v e l o p e r s .
0 0 1 0 | | | | | | | de1v
| 0 0 0 0 3 0 | | | | evel3o
| | 0 0 4 0 0 | | | | ve4lo
| | | | | 0 0 1 0 0 | op1er
| | | | | | | 0 0 1 0 er1s
| | | | | | | | 4 0 2 4rs2
max: 0 0 1 0 4 3 0 1 4 1 2
final: d e - v e l - o p - e r - s
Other
Contact: gundlach@speedata.de<br> Twitter: @speedata<br> Mastodon: @speedata@typo.social<br> License: cc0 / public domain (https://creativecommons.org/publicdomain/zero/1.0/)<br> Status: used in the boxes and glue library.
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
