Skip to content

Instantly share code, notes, and snippets.

View mbutterick's full-sized avatar

Matthew Butterick mbutterick

View GitHub Profile
@mbutterick
mbutterick / faq.pdf.pm
Created January 24, 2020 20:59
Pollen + Quad example
#lang pollen
◊subhead{MB Type}
◊subhead{Frequently Asked Questions}
◊subsubhead{The #1 most frequently asked question}
◊qa{I'm a Windows user. I installed the standard OpenType fonts, but they don’t appear correctly in PDFs made with the PDF generator built into WordPerfect or Word on Windows.
This is a ◊link["http://typo.la/wordpdf"]{known limitation} of WordPerfect and Word on Windows. Switching to the OpenType TT fonts will cure the problem. So will switching to other PDF-making software, such as the Adobe PDF printer driver, which is included with Adobe Acrobat. (This advice does not apply to Mac OS.)}
@mbutterick
mbutterick / amaze.rkt
Created November 30, 2019 14:30
Example of using Racket graph library to generate mazelike things
#lang racket/base
(require graph racket/match racket/list racket/sequence)
(require racket/draw racket/gui)
(define (cell-up c) (list (car c) (sub1 (cadr c))))
(define (cell-right c) (list (add1 (car c)) (cadr c)))
(define (cell-down c) (list (car c) (add1 (cadr c))))
(define (cell-left c) (list (sub1 (car c)) (cadr c)))
#lang racket
(require rackunit pollen/decode pollen/template/html)
(define str "Крикну — а в ответ тишина.")
(define (wrap-emdashes str)
;; define match pattern
;; one or more Unicode letters followed by space emdash space
;; letter pattern is parenthesized to produce submatch for word
(define pat #px"(\\p{L}+) — ")
T@"<NSTouchBarCustomizationCursorManagerDelegate>",W,V_delegate
T@"<NSTouchBarPressAndHoldTransposerDelegate>",W,V_delegate
T@"NSTouchBarItem",&,V_touchBarItem
NSTouchBarLogOnTouches
NSTouchBarViewObservationContext
T@"NSTouchBarViewController",R,V_applicationTouchBarViewController
T@"NSTouchBarCustomizationController",R
T@"NSTouchBarCustomizationPreviewItemContainerView",R
/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1504.60/TouchBar.subproj/NSTouchBarCustomizationPreviewCollectionViewItem.m
T@"NSTouchBar",&
#lang racket/base
(require racket/class pollen/setup)
(define tags% (class object%
(super-new)
(define/public (strong) 'default-strong)
(define/public (em) 'default-em)))
(define pdf-tags% (class tags%
(super-new)
#lang racket
(require pollen/decode
pollen/setup ; For current-poly-target
pollen/file ; get-markup-source
txexpr
pollen/tag ; default-tag-function
"util-date.rkt"
"util-template.rkt")
@mbutterick
mbutterick / scribble-xexpr.rkt
Created March 16, 2016 21:45
Scribble to X-expression conversion
#lang at-exp br
(require scribble/manual scribble/core txexpr)
(provide scribble->xexpr)
(define (style->attrs s style-accessor)
(let* ([style-datum (style-accessor s)])
(if (style? style-datum) ; either style struct, or simple symbol name
`((style ,(~a (style-name style-datum)))
(properties ,(string-join (map ~a (style-properties style-datum)) " ")))
`((style ,(~a style-datum))))))
#lang s-exp syntax/module-reader
(submod "daylang.rkt" semantics)
#:read my-read
#:read-syntax my-read-syntax
(define (my-read in) (syntax->datum (my-read-syntax #f in)))
(define (my-read-syntax src in)
(define line (read-line in))
(if (eof-object? line)
#lang racket/base
(require syntax/moddep racket/list sugar/debug)
(provide dynamic-rerequire)
(define (dynamic-rerequire mod #:verbosity [verbosity 'reload])
(unless (module-path? mod)
(raise-argument-error 'dynamic-rerequire "module-path?" mod))
(unless (memq verbosity '(all reload none))
(raise-argument-error 'dynamic-rerequire "(or/c 'all 'reload 'none)" verbosity))
#lang typed/racket/base
(define: default-patterns : (Listof String)
; Knuth and Liang's original hyphenation patterns from classic TeX.
; In the public domain.
(map symbol->string '(.ach4 .ad4der .af1t .al3t .am5at .an5c .ang4 .ani5m .ant4 .an3te .anti5s .ar5s .ar4tie .ar4ty .as3c .as1p .as1s .aster5 .atom5 .au1d .av4i .awn4 .ba4g .ba5na .bas4e .ber4 .be5ra .be3sm .be5sto .bri2 .but4ti .cam4pe .can5c .capa5b .car5ol .ca4t .ce4la .ch4 .chill5i .ci2 .cit5r .co3e .co4r .cor5ner .de4moi .de3o .de3ra .de3ri .des4c .dictio5 .do4t .du4c .dumb5 .earth5 .eas3i .eb4 .eer4 .eg2 .el5d .el3em .enam3 .en3g .en3s .eq5ui5t .er4ri .es3 .eu3 .eye5 .fes3 .for5mer .ga2 .ge2 .gen3t4 .ge5og .gi5a .gi4b .go4r .hand5i .han5k .he2 .hero5i .hes3 .het3 .hi3b .hi3er .hon5ey .hon3o .hov5 .id4l .idol3 .im3m .im5pin .in1 .in3ci .ine2 .in2k .in3s .ir5r .is4i .ju3r .la4cy .la4m .lat5er .lath5 .le2 .leg5e .len4 .lep5 .lev1 .li4g .lig5a .li2n .li3o .li4t .mag5a5 .mal5o .man5a .mar5ti .me2 .mer3c .me5ter .mis1 .mist5i .mon3e .mo3ro .mu5