forked from mbattyani/cl-typesetting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.lisp
52 lines (46 loc) · 1.99 KB
/
math.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
;;; cl-typesetting copyright 2002 Marc Battyani see license.txt for details of the license
;;; You can reach me at [email protected] or [email protected]
(in-package #:typeset)
(defparameter *fraction-rule-thickness-ratio* 0.03)
(defparameter *fraction-spacing-ratio* 0.16)
(defparameter *fraction-baseline-offset* 0.185)
(defmacro display-formula ((&rest args) &body body)
`(let ((*use-exact-char-boxes* t))
(hbox (,@args :adjustable-p t)
:hfill ,@body :hfill)))
(defmacro fraction ((&rest args) numerator denominator)
(with-gensyms (fraction-box spacing thickness num-box)
`(let* ((,thickness (* *font-size* *fraction-rule-thickness-ratio*))
(,spacing (* *font-size* *fraction-spacing-ratio*))
,num-box
(,fraction-box
(vbox (,@args :align :center)
(setf ,num-box (hbox (:align :center) ,@numerator))
(vspace ,spacing)
(hrule :dy ,thickness)
(vspace ,spacing)
(hbox (:align :center) ,@denominator))))
(hspace ,spacing)
(setf (baseline ,fraction-box) (+ (dy ,num-box) ,spacing ,thickness)
(offset ,fraction-box) (* *font-size* *fraction-baseline-offset*))
,fraction-box)))
(defmacro math-super-and-sub-script ((&key (offset+ '(* 0.45 *font-size*))
(offset- '(* -0.2 *font-size*))
(font-size '(* 0.5 *font-size*)))
super sub)
(with-gensyms (up-box low-box full-box space-box)
`(let* (,up-box ,low-box ,space-box
(,full-box (vbox ()
(with-style (:font-size ,font-size)
(setf ,up-box (hbox () (hspace (pdf::get-font-italic-correction
*font* ,offset+))
,@super)
,space-box (vspace 0)
,low-box (hbox () (hspace (pdf::get-font-italic-correction
*font* (- ,offset- *font-size*)))
,@sub))))))
(setf (baseline ,full-box)(+ ,offset+ (internal-baseline ,up-box)))
(setf (dy ,space-box)(- (- (baseline ,full-box)(dy ,up-box))
(+ ,offset- (internal-baseline ,low-box))))
(incf (dy ,full-box)(dy ,space-box))
,full-box)))