From 9c373bfd829277f91467465cca9123143bce7761 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 13 Feb 2014 11:42:39 -0800 Subject: [PATCH] update docs with ligature example --- hyphenate/scribblings/hyphenate.scrbl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hyphenate/scribblings/hyphenate.scrbl b/hyphenate/scribblings/hyphenate.scrbl index c1955cc2..80752065 100644 --- a/hyphenate/scribblings/hyphenate.scrbl +++ b/hyphenate/scribblings/hyphenate.scrbl @@ -107,7 +107,16 @@ Like @racket[hyphenate], but only words matching @racket[_pred] are hyphenated. #\-) ] -It's possible to do fancier kinds of hyphenation restrictions that take account of context, like not hyphenating the last word of a paragraph. But @racket[hyphenatef] only operates on words. So you'll have to write some fancier code. Separate out the hyphenatable words, and then send them through good old @racket[hyphenate]. +Sometimes you need @racket[hyphenatef] to prevent unintended consequences. For instance, if you're using ligatures in CSS, certain groups of characters (fi, fl, ffi, et al.) will be replaced by a single glyph. That looks snazzy, but adding soft hyphens between any of these pairs will defeat the ligature substitution, creating inconsistent results. With @racket[hyphenatef], you can skip these words: + +@examples[#:eval my-eval +(hyphenate "Hufflepuff golfing final on Tuesday" #\-) +(define (no-ligs? word) + (not (ormap (λ(lig) (regexp-match lig word)) '("ff" "fi" "fl" "ffi" "ffl")))) +(hyphenatef "Hufflepuff golfing final on Tuesday" no-ligs? #\-) +] + +It's possible to do fancier kinds of hyphenation restrictions that take account of context, like not hyphenating the last word of a paragraph. But @racket[hyphenatef] only operates on words. So you'll have to write some fancier code. Separate out the words eligible for hyphenation, and then send them through good old @racket[hyphenate]. @defproc[ (unhyphenate