-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexamples.lisp
139 lines (123 loc) · 4.91 KB
/
examples.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
;;;; examples.lisp
;;;;
;;;; Copyright (c) 2014-2018 Robert Smith
;;; This file contains some examples of typeset formulas.
(defpackage #:formulador-examples
(:use #:cl #:formulador)
(:export #:pow
#:*chudnovsky*
#:*gauss-law*
#:*thermo*
#:subscript-test
#:draw-all))
(in-package #:formulador-examples)
(defun pow (a b)
(script-box a :superscript b))
(defun sub (a b)
(script-box a :subscript b))
;;; > (draw *chudnovsky*)
;;;
;;; +------------------------------------------------------------------------+
;;; | _______ ∞ |
;;; | | 3 === k|
;;; | 1 \|640320 \ (6k)! (545140134k + 13591409) / 1 \ |
;;; |--- = ----------- > ------------------------------- | - --------- | |
;;; | π 12 / 3 | 3 | |
;;; | === (3k)! (k!) \ 640320 / |
;;; | k = 0 |
;;; +------------------------------------------------------------------------+
(defparameter *chudnovsky*
(let ((pi-letter (box (code-char #x3C0))))
(tape
(frac-box (box "1") pi-letter)
(box "=")
(frac-box (sqrt-box (pow (box "640320")
(box "3")))
(box "12"))
(limits-box +sigma+
:above (box "∞")
:below (box "k = 0"))
(frac-box (tape (box "(6k)!")
(box "(545140134k + 13591409)"))
(tape (box "(3k)!")
(pow (box "(k!)")
(box "3"))))
(pow (parens-box
(tape (box "-") (frac-box (box "1")
(pow (box "640320")
(box "3")))))
(box "k")))))
(defparameter *gauss-law*
(let ((rho (box (code-char #x03C1)))
(S (box "S"))
(dS (glue +partial+ (box "S"))))
(tape (limits-box +triple-integral+ :below S) rho (box "dV")
(box "=")
(limits-box +double-integral+ :below dS) (glue (box "E")
+center-dot+
(box "dA")))))
(defparameter *thermo*
(flet ((tilde (box) (limits-box box :above (box #\~))))
(let ((phi (box (code-char #x3D5)))
(theta (box (code-char #x398)))
(ell (box (code-char #x2113)))
(congruent (box (code-char #x2245))))
(tape
(glue (script-box (tilde (box #\N))
:subscript (script-box phi
:subscript ell
:superscript (box "G/E")))
(pow theta (box #\k))
(parens-box (glue (script-box (box #\I)
:subscript (glue (pow (box #\i)
(box #\*))
(box #\G)))
(parens-box (box #\0)))))
congruent
(glue
(pow theta (box #\k))
(parens-box (glue (script-box (box #\I)
:subscript (glue (pow (parens-box
(script-box phi
:subscript ell
:superscript (box #\E)))
(box #\*))
(box #\G)))
(parens-box (box #\0)))))))))
(defun subscript-test (n)
(assert (and (integerp n)
(not (minusp n))))
(labels ((frob (n)
(parens-box
(if (zerop n)
(box "*")
(let ((next (frob (1- n))))
(script-box next :superscript next
:subscript next))))))
(frob n)))
(defparameter *tb-22-4-ex1*
;; Slightly modified example from the TUGBoat Vol 22 No 4.
(tape
(box "X")
(box "=")
;; Use of CLAP
(limits-box +sigma+
:below (clap (box "1 ≤ i ≤ n")))
(sub (box "X") (box "i"))
(box "=")
;; No use of CLAP
(limits-box +sigma+
:below (box "1 ≤ i ≤ n"))
(sub (box "X") (box "i"))))
(defun draw-all ()
(flet ((demo (string c)
(write-line string)
(princ (draw c))
(terpri)
(terpri)))
(demo "Chudnovsky formula:" *chudnovsky*)
(demo "Gauss's law:" *gauss-law*)
(demo "Random thing from thermo:" *thermo*)
(demo "Nested subscripts:" (subscript-test 2))
(demo "mathclap demo:" *tb-22-4-ex1*)
':done))