File: math.lisp

package info (click to toggle)
cl-typesetting 117-3
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 808 kB
  • ctags: 508
  • sloc: lisp: 4,073; makefile: 33; sh: 22
file content (52 lines) | stat: -rw-r--r-- 2,036 bytes parent folder | download
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
;;; cl-typesetting copyright 2002 Marc Battyani see license.txt for details of the license
;;; You can reach me at marc.battyani@fractalconcept.com or marc@battyani.net

(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)))