From da0f57f461cd02651809e934c7b209f872f95340 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 9 Jan 2019 16:30:21 -0800 Subject: [PATCH] code blocks --- .../{FiraMono-Regular.ttf => fira-mono.ttf} | Bin quad/qtest/hyphenate.rkt | 10 ++++++++-- quad/qtest/markdown.rkt | 16 +++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) rename quad/qtest/fonts/{FiraMono-Regular.ttf => fira-mono.ttf} (100%) diff --git a/quad/qtest/fonts/FiraMono-Regular.ttf b/quad/qtest/fonts/fira-mono.ttf similarity index 100% rename from quad/qtest/fonts/FiraMono-Regular.ttf rename to quad/qtest/fonts/fira-mono.ttf diff --git a/quad/qtest/hyphenate.rkt b/quad/qtest/hyphenate.rkt index a76603a0..e136297e 100644 --- a/quad/qtest/hyphenate.rkt +++ b/quad/qtest/hyphenate.rkt @@ -1,7 +1,13 @@ #lang qtest/markdown - A simple _hyphenation engine_ that uses the Knuth–Liang hyphenation algorithm originally developed for TeX. +A simple _hyphenation engine_ that uses the Knuth–Liang 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. \ No newline at end of file +And now, for something __altogether__ the same. + +At the command line: + +`raco pkg install hyphenate` + +What?! \ No newline at end of file diff --git a/quad/qtest/markdown.rkt b/quad/qtest/markdown.rkt index 9d7972d6..52a78418 100644 --- a/quad/qtest/markdown.rkt +++ b/quad/qtest/markdown.rkt @@ -1,5 +1,5 @@ #lang debug racket/base -(require (for-syntax racket/base) racket/runtime-path racket/promise racket/match racket/list +(require (for-syntax racket/base) racket/runtime-path racket/string racket/promise racket/match racket/list pitfall quad sugar/debug markdown pollen/tag (prefix-in pt: pollen/top)) (provide (except-out (all-from-out racket/base) #%module-begin #%top) (rename-out [mb #%module-begin][pt:#%top #%top]) @@ -8,6 +8,9 @@ (define-syntax-rule (p attrs . exprs) (list 'q 'attrs . exprs)) +(define-syntax-rule (code attrs . exprs) + (list 'q (list* '(font "fira-mono") '(bg "gray") 'attrs) . exprs)) + (define-syntax-rule (strong attrs . exprs) (list 'q (cons '(font "charter-bold") 'attrs) . exprs)) @@ -23,13 +26,15 @@ ;; draw with pdf text routine #:draw (λ (q doc) (font doc (path->string (hash-ref (quad-attrs q) 'font))) - (define str (car (quad-elems q))) - (apply text doc str (quad-origin q))))) + (match-define (list str) (quad-elems q)) + (match-define (list x y) (quad-origin q)) + (text doc str x y)))) (define-runtime-path charter "fonts/charter.ttf") (define-runtime-path charter-bold "fonts/charter-bold.ttf") (define-runtime-path charter-italic "fonts/charter-italic.ttf") (define-runtime-path fira "fonts/fira.ttf") +(define-runtime-path fira-mono "fonts/fira-mono.ttf") (define (->string-quad doc q) (struct-copy quad q:string @@ -40,11 +45,12 @@ ;; but this op should ideally happen earlier (hash-update! attrs 'font (λ (val) (if (path? val) val - (match (string-downcase val) + (match (string-downcase (string-replace val " " "-")) ["charter" charter] ["charter-bold" charter-bold] ["charter-italic" charter-italic] - ["fira" fira])))) + ["fira" fira] + ["fira-mono" fira-mono])))) attrs)] [elems (quad-elems q)] [size (delay