main
Matthew Butterick 6 years ago
parent 4425b16241
commit d32865a9eb

@ -1,5 +1,60 @@
#lang qtest/markdown
X
# Hyphenate
Y
A simple _hyphenation engine_ that uses the KnuthLiang hyphenation algorithm originally developed for TeX.
I **have added little** to their work. Accordingly, I take no credit, except a spoonful of *snako-bits.*
And now, for something __altogether__ the same. Yes! No?!ß
## 1. Installation
At the command line:
We said `raco pkg install hyphenate` dude
What?!
```
Code block
Goes here
```
> Hyphenate `xexpr` by calculating hyphenation points and inserting
`joiner` at those points. By default, `joiner` is the soft hyphen
\(Unicode 00AD = decimal 173\). Words shorter than
`#:min-length` `length` will not be hyphenated. To hyphenate words of
any length, use `#:min-length` `#f`.
A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text.A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text.A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text.A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text.A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text.A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text.

@ -148,11 +148,9 @@
(struct line-break quad () #:transparent)
(define lbr (q #:type line-break
#:elems '("")
#:printable #f))
(struct para-break line-break () #:transparent)
(define pbr (q #:type para-break
#:elems '("¶¶")
#:printable #f))
(module+ test
@ -160,15 +158,10 @@
(check-true (line-break? (second (atomize (q "foo" pbr "bar"))))))
(define (line-wrap xs size)
#R xs
#R (line-break? (second xs))
(wrap xs size 'debug
(wrap xs size
#:hard-break line-break?
#:soft-break soft-break-for-line?
#:finish-wrap (λ (pcs q idx)
#R pcs
#R q
#R idx
(define new-elems (consolidate-runs pcs))
(append
(list (struct-copy quad q:line
@ -189,7 +182,7 @@
;; when `line-heights` is empty, this is just h
(pt w (apply max (cons h line-heights))))]
[elems new-elems]))
(if (and q (equal? (quad-elems q) '("¶¶")))
(if (and q (para-break? q))
(list q:line-spacer)
null)))))
@ -282,10 +275,8 @@
#:size "letter")))
(define line-width (- (pdf-width pdf) (* 2 side-margin)))
(define vertical-height (- (pdf-height pdf) top-margin bottom-margin))
(let* ([x (time-name atomize #R (atomize #R (qexpr->quad xs)))]
[x (begin #R (line-break? (second x)) x)]
(let* ([x (time-name atomize (atomize (qexpr->quad xs)))]
[x (time-name ->string-quad (map (λ (x) (->string-quad pdf x)) x))]
[x (begin #R (line-break? (second x)) x)]
[x (time-name line-wrap (line-wrap x line-width))]
[x (time-name page-wrap (page-wrap x vertical-height path))]
[x (time-name insert-containers (insert-containers x))]

@ -65,18 +65,16 @@
(for/list ([elem (in-list (merge-adjacent-strings elems 'isolate-white))])
(match elem
[(? string?)
#|
190116
The conundrum: how to atomize quads that have subtypes and possibly other fields.
We need to make new quads derived from the original.
But we don't have access to the subtype here.
Making the quad mutable doesn't solve the problem: we can change the first one, but we still need copies.
`struct-copy` doesn't work, because it can't see the subtype.
`struct-list` doesn't work, because it can't rely on structs being transparent.
|#
(list (make-quad #:type (quad-type x)
#:attrs next-attrs
#:elems (list elem)))]
;; 190116 caveat: all quads with strings as elements will be atomized.
;; however, if the starting quad has a struct subtype of quad,
;; this subtype will be lost.
;; IOW, all atomized quads are of the base `quad` type.
;; this is because we can't get access to any subtype constructors here.
;; corollary: quads that need to keep their types should not have any strings as elements.
;; also, they will not have any run keys embedded
;; (but they shouldn't need it because they're not part of text runs)
;; overall I am persuaded that `atomize` is very texty and needs a name befitting that role.
(list (make-quad #:attrs next-attrs #:elems (list elem)))]
[_ (loop elem next-attrs next-key)])))]
[_ (list x)])))

Loading…
Cancel
Save