[cl-typesetting-devel] hyphenation patch

Marc Battyani marc.battyani at fractalconcept.com
Tue Oct 5 20:49:00 UTC 2004


Peter Seibel wrote:

> There was a slight bug in hyphenation.lisp that caused it to sometimes
> hyphenate a word after the first character despite
> *left-hyphen-minimum* being 2. Below is a patch to hyphenatation.lisp
> (as well as a tiny bit of tidying to hyphenatation-fp.lisp to get rid
> of some unportable SETFs of undeclared variables.)

OK. Patched.

> If you wanted you might also get rid of the checks in hyphenatation
> that the string and word are greater than 4 characters long--since
> hyphen-find-hyphen-points observes *left-hyphen-minimum* and
> *right-hyphen-minimum* those checks aren't really needed.

I should at least replace 4 by (+ *left-hyphen-minimum*
*right-hyphen-minimum*)
but those tests are faster than looking at the tries for nothing.

The new function is:

(defun hyphenate-string (string)
  (let ((min-word-size (+ nix::*left-hyphen-minimum*
nix::*right-hyphen-minimum*)))
    (when (>= (length string) min-word-size)
      (loop
   for prev-word-end = 0 then word-end
   for word-start = (position-if #'alpha-char-p string :start prev-word-end)
   for word-end = (when word-start (position-if-not #'alpha-char-p string
:start word-start))
   while word-end
   when (>= (- word-end word-start) min-word-size)
   nconc (mapcar #'(lambda (n) (+ word-start n))
   (nix::hyphen-find-hyphen-points
    nix::*american-hyphen-trie* (subseq string word-start word-end)))))))

;untested...

Marc





More information about the cl-typesetting-devel mailing list