[cl-typesetting-devel] Small patch for hyphenation code

Peter Seibel peter at javamonkey.com
Wed Mar 3 00:53:41 UTC 2004


I noticed some bad hyphenations in my generated PDFs such as
hyphenating "store" as "s-tore". Checking with TeX it agrees with me
that there are no good hyphen breaks in "store". Anyway, I figured out
that the problem is cl-typesetting has no concept of \lefthyphenmin
and \righthyphenmin the way TeX does. Here's a patch that adds at
least an approximation of those concepts, set to the default TeX
values.

-Peter


Index: hyphenation-fp.lisp
===================================================================
--- hyphenation-fp.lisp	(revision 10)
+++ hyphenation-fp.lisp	(working copy)
@@ -39,6 +39,13 @@
                                   :directory '(:relative "hyphen-patterns"))
                    *cl-typesetting-base-directory*))
 
+
+(defvar *left-hyphen-minimum* 2
+  "Minimum number of characters that must precede a hyphen.")
+
+(defvar *right-hyphen-minimum* 3
+  "Minimum number of characters that must follow a hyphen.")
+
 ;; An hyphenation object is able to return the list
 ;; of hyphenation points for any word according to
 ;; the language it has been built for
@@ -65,10 +72,16 @@
 	 (result (hyphen-trie-find-exception word-seq (exception-trie hyphen-trie))))
     (unless result
       (setq result (hyphen-trie-find `(#\. , at word-seq #\.) (pattern-trie hyphen-trie))))
-    (mapcar #'first (remove-if
-	     #'(lambda (x) (or (eq (first x) :end) (eq (first x) 0)))
-	     result))))
+    (format t "result : ~a~%" result)
+    (mapcar #'first (remove-if 
+                     #'(lambda (x)
+                         (let ((idx (first x)))
+                           (or (eq idx :end)
+                               (< idx *left-hyphen-minimum*)
+                               (< (- (length word) idx) *right-hyphen-minimum*))))
+                     result))))
 
+
 ;; Format of the language file:
 ;; the first line has 'pattern'
 ;; one pattern per line

-- 
Peter Seibel                                      peter at javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp




More information about the cl-typesetting-devel mailing list