commit d0c5e6fac175d87680fc695d6318609706d42387
parent 795c32b5c2309ef3d21aa2b545e87b4d946d8161
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Thu, 13 Jul 2017 14:56:07 +0200
Fixed aspect of some math.
Diffstat:
4 files changed, 61 insertions(+), 26 deletions(-)
diff --git a/scribblings/adt-row-ty.scrbl b/scribblings/adt-row-ty.scrbl
@@ -8,12 +8,16 @@
@title[#:style (with-html5 manual-doc-style)
#:version (version-text)]{Types (with ρ)}
-@$${σ,τ ⩴ …
- @|P| @ctor[@κ τ] @; same
- @P @variant[@repeated{@ctor[@|κ|ᵢ τᵢ]} @ρc] @; new/changed
- @P @record[@repeated{@|ɐ|ᵢ : τᵢ} @repeatset{-@|ɐ|ᵢ} @${@ρf - @repeatset{@|ɐ|ⱼ}}] @; changed
- @P (∀_c (@repeated{@ρc}) τ) @; new
- @P (∀_f (@repeated{@ρf}) τ) @; new
+@$${
+ @cases["σ,τ" #:first-sep "⩴"
+ @acase{…}
+ @acase{@ctor[@κ τ]} @; same
+ @acase{@variant[@repeated{@ctor[@|κ|ᵢ τᵢ]} @ρc]} @; new/changed
+ @acase{@record[@repeated{@|ɐ|ᵢ : τᵢ}
+ @repeatset{-@|ɐ|ᵢ}
+ @${@ρf - @repeatset{@|ɐ|ⱼ}}]} @; changed
+ @acase{@∀c[@${(@repeated{@ρc})} τ]} @; new
+ @acase{@∀f[@${(@repeated{@ρf})} τ]}] @; new
}
@; new↓
diff --git a/scribblings/adt-utils.rkt b/scribblings/adt-utils.rkt
@@ -14,12 +14,21 @@
(symbol->string (syntax-e #'x))
#'x)]
[pattern e #:with →str #'e]))
-@(define-for-syntax (defop op)
+@(define-for-syntax (defop* op)
(syntax-parser
[(_ :stringify ...)
#`@${(@(add-between (list @textbf{@#,op}
#,@(syntax->list #'(→str ...)))
"\\ "))}]))
+
+@(begin-for-syntax
+ (require (for-syntax racket/base))
+ (define-syntax (defop stx)
+ (syntax-case stx ()
+ [(_ op)
+ (with-syntax ([s (datum->syntax #'op 'syntax)])
+ #'(defop* (s op)))])))
+
@(define-syntax stringify
(syntax-parser
[(_ :stringify)
@@ -40,10 +49,12 @@
@(define |P| @${\ |\ })
@(define ρc @${\rho_{c}})
@(define ρf @${\rho_{f}})
-@(define-syntax atc (defop "@${}_{\\textbf{c}}$"));; TODO text vs math!!!
-@(define-syntax atf (defop "@${}_{\\textbf{f}}$"))
-@(define-syntax Λc (defop "Λ${}_{\\textbf{c}}$"))
-@(define-syntax Λf (defop "Λ${}_{\\textbf{f}}$"))
+@(define-syntax atc (defop (list "@" @${{}_{@textbf{c}}})))
+@(define-syntax atf (defop (list "@" @${{}_{@textbf{f}}})))
+@(define-syntax Λc (defop (list "Λ" @${{}_{@textbf{c}}})))
+@(define-syntax Λf (defop (list "Λ" @${{}_{@textbf{f}}})))
+@(define-syntax ∀c (defop @${\mathbf{∀}_{@textbf{c}}}))
+@(define-syntax ∀f (defop @${\mathbf{∀}_{@textbf{f}}}))
@(define-syntax-rule (ctor-pred c)
@${@(stringify c)\mathbf{?}})
@(define-syntax-rule (record-pred . f*)
diff --git a/scribblings/util.rkt b/scribblings/util.rkt
@@ -542,15 +542,30 @@ EOCSS
(define acase list)
(define cases
(λ (#:first-sep [first-sep "\\vphantom{x}\\mathbin{:=}\\vphantom{x}"]
- #:then-sep [then-sep "|\\;\\ "]
+ #:then-sep [then-sep "\\mathrel{|}"]
term
. the-cases)
- ($$ (list
+ (define first-sep* (list "{}" first-sep "{}"))
+ (define then-sep* (list "{}" then-sep "{}"))
+ @$${
+ \begin{qaligned}
+ @(add-between
+ (for/list ([c (in-list the-cases)]
+ [i (in-naturals)])
+ (list (if (= i 0) term '())
+ " & "
+ (if (= i 0) first-sep* then-sep*)
+ " & "
+ c))
+ "\\\\\n")
+ \end{qaligned}}
+ #;($$ (list
term
- (aligned #:valign 'top @; cl
+ (aligned #:valign 'top
@(for/list ([c (in-list the-cases)]
[i (in-naturals)])
- (list (if (= i 0) first-sep then-sep)
+ (list (minwidth (list first-sep* then-sep*)
+ (if (= i 0) first-sep* then-sep*))
" & "
c
(if (= i (sub1 (length the-cases))) "" "\\\\\n")))
@@ -560,6 +575,13 @@ EOCSS
syntax/parse
syntax/parse/experimental/template))
(define (intertext . l) (list (mathtext "\\text{" l "}")))
+(define (array<l>-no-extra-h-space lst)
+ (list "\\!\\begin{array}{l}"
+ (add-between lst "\\\\")
+ "\\end{array}\\!"))
+(define (minwidth phantoms realcontent)
+ (list "\\rlap{" realcontent "}"
+ @$${\hphantom{@array<l>-no-extra-h-space[phantoms]}}))
(define-syntax cases*
(syntax-parser
#:literals (acase intertext)
@@ -576,25 +598,21 @@ EOCSS
#:with (tmpᵢ ...) (generate-temporaries #'((acaseᵢⱼ ...) ...))
(quasitemplate
(#,(if ((or/c 'expression list?) (syntax-local-context)) #'list #'begin)
- (define (vcenter lst)
- (list "\\begin{array}{l}"
- (add-between (for/list ([e lst]) (list "\\!" e "\\!")) "\\\\")
- "\\end{array}"))
- (define phantom
- @$${\hphantom{@vcenter{@(list (?@ acaseᵢ₀ acaseᵢⱼ ...)
- ...
- (?? (?@ acaseₙ₀ acaseₙⱼ ...)))}}})
+ (define phantoms
+ (list (?@ acaseᵢ₀ acaseᵢⱼ ...)
+ ...
+ (?? (?@ acaseₙ₀ acaseₙⱼ ...))))
(define tmpᵢ @cases[term
(?? (?@ #:first-sep first-sep))
(?? (?@ #:then-sep then-sep))
- (list "\\rlap{" acaseᵢ₀ "}" phantom)
+ (minwidth phantoms acaseᵢ₀)
acaseᵢⱼ
...])
...
(?? (define tmpₙ @cases[term
(?? (?@ #:first-sep first-sep))
(?? (?@ #:then-sep then-sep))
- (list "\\rlap{" acaseₙ₀ "}" phantom)
+ (minwidth phantoms acaseₙ₀)
acaseₙⱼ
...]))
(?? (?@ . intertext₀))
diff --git a/scribblings/util0.rkt b/scribblings/util0.rkt
@@ -34,7 +34,9 @@
;; No need to go down recursively, as the contents should already have
;; been cleaned when the e was created. Plus we risk re-escaping
;; things within \text{…}.
- (element-content e)]
+ (if mathmode?
+ (element-content e)
+ (list "$" (element-content e) "$"))]
[(match e
[(element (style "mathText" _)
content)