From 025a4a8b76b52af3276e0efbf907d94af02c6d7c Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 29 Jan 2016 17:01:34 -0800 Subject: [PATCH] create `unstable/typography` --- pollen/decode.rkt | 4 +- pollen/misc/tutorial.rkt | 2 +- pollen/scribblings/typography.scrbl | 72 +++++++++++++++++++ .../unstable-module-reference.scrbl | 1 + pollen/unstable/{mb.rkt => typography.rkt} | 0 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 pollen/scribblings/typography.scrbl rename pollen/unstable/{mb.rkt => typography.rkt} (100%) diff --git a/pollen/decode.rkt b/pollen/decode.rkt index 27068a3..66631bc 100644 --- a/pollen/decode.rkt +++ b/pollen/decode.rkt @@ -3,8 +3,8 @@ (require "setup.rkt" "private/whitespace.rkt") -(require "unstable/mb.rkt") -(provide (all-from-out "unstable/mb.rkt")) +(require "unstable/typography.rkt") +(provide (all-from-out "unstable/typography.rkt")) (define (->list/tx x) ;; same as ->list but catches special case of single txexpr, diff --git a/pollen/misc/tutorial.rkt b/pollen/misc/tutorial.rkt index 396abc2..135c2c0 100644 --- a/pollen/misc/tutorial.rkt +++ b/pollen/misc/tutorial.rkt @@ -1,3 +1,3 @@ #lang racket/base -(require pollen/unstable/mb) +(require pollen/unstable/typography) (provide smart-quotes smart-dashes) \ No newline at end of file diff --git a/pollen/scribblings/typography.scrbl b/pollen/scribblings/typography.scrbl new file mode 100644 index 0000000..20faaec --- /dev/null +++ b/pollen/scribblings/typography.scrbl @@ -0,0 +1,72 @@ +#lang scribble/manual + +@(require scribble/eval pollen/decode pollen/setup txexpr (for-label txexpr racket (except-in pollen #%module-begin))) + +@(define my-eval (make-base-eval)) +@(my-eval `(require pollen pollen/unstable/pygments)) +@(require "mb-tools.rkt") + + +@title{TypogrPHY} + +@defmodule[pollen/unstable/typography] + +A few t + + +@defproc[ +(smart-quotes +[str string?]) +string?] +Convert straight quotes in @racket[_str] to curly according to American English conventions. + +@examples[#:eval my-eval +(define tricky-string +"\"Why,\" she could've asked, \"are we in O‘ahu watching 'Mame'?\"") +(display tricky-string) +(display (smart-quotes tricky-string)) +] + +@defproc[ +(smart-dashes +[str string?]) +string?] +In @racket[_str], convert three hyphens to an em dash, and two hyphens to an en dash, and remove surrounding spaces. + +@examples[#:eval my-eval +(define tricky-string "I had a few --- OK, like 6--8 --- thin mints.") +(display tricky-string) +(display (smart-dashes tricky-string)) +(code:comment @#,t{Monospaced font not great for showing dashes, but you get the idea}) +] + + + +@defproc[ +(wrap-hanging-quotes +[tx txexpr?] +[#:single-preprend single-preprender txexpr-tag? 'squo] +[#:double-preprend double-preprender txexpr-tag? 'dquo] +) +txexpr?] +Find single or double quote marks at the beginning of @racket[_tx] and wrap them in an X-expression with the tag @racket[_single-preprender] or @racket[_double-preprender], respectively. The default values are @racket['squo] and @racket['dquo]. + +@examples[#:eval my-eval +(wrap-hanging-quotes '(p "No quote to hang.")) +(wrap-hanging-quotes '(p "“What? We need to hang quotes?”")) +] + +In pro typography, quotation marks at the beginning of a line or paragraph are often shifted into the margin slightly to make them appear more optically aligned with the left edge of the text. With a reflowable layout model like HTML, you don't know where your line breaks will be. + +This function will simply insert the @racket['squo] and @racket['dquo] tags, which provide hooks that let you do the actual hanging via CSS, like so (actual measurement can be refined to taste): + +@verbatim{squo {margin-left: -0.25em;} +dquo {margin-left: -0.50em;} +} + +Be warned: there are many edge cases this function does not handle well. + +@examples[#:eval my-eval +(code:comment @#,t{Argh: this edge case is not handled properly}) +(wrap-hanging-quotes '(p "“" (em "What?") "We need to hang quotes?”")) +] \ No newline at end of file diff --git a/pollen/scribblings/unstable-module-reference.scrbl b/pollen/scribblings/unstable-module-reference.scrbl index 63b48b5..576a3f7 100644 --- a/pollen/scribblings/unstable-module-reference.scrbl +++ b/pollen/scribblings/unstable-module-reference.scrbl @@ -7,3 +7,4 @@ An ``unstable'' module is safe to use. But it's not part of the settled public i @local-table-of-contents[] @include-section["pygments.scrbl"] +@include-section["typography.scrbl"] diff --git a/pollen/unstable/mb.rkt b/pollen/unstable/typography.rkt similarity index 100% rename from pollen/unstable/mb.rkt rename to pollen/unstable/typography.rkt