(define cross-char #\multiplication-sign) (define del-char #\nabla) (define diff-char #\partial-differential) (define dot-char #\bullet) (define frac-char #\solidus) (define medsp #\space) (define minus-char #\minus-sign) (define thicksp #\space) (define equalwidth 18pt) (define (node-list-reduce nl combine init) (if (node-list-empty? nl) init (node-list-reduce (node-list-rest nl) combine (combine init (node-list-first nl))))) (define (node-list-length nl) (node-list-reduce nl (lambda (result snl) (+ result 1)) 0)) (define (eqn-colspecs eqparts) (sosofo-append (make table-column width: (table-unit 1) quadding: 'end) (let eqloop ((eqnpts (- eqparts 1))) (sosofo-append (make table-column width: equalwidth quadding: 'center) (if (= eqnpts 1) (make table-column width: (table-unit 1) quadding: 'start) (sosofo-append (make table-column width: (table-unit 1) quadding: 'center) (eqloop (- eqnpts 1)))))))) (element mathtest (make scroll)) (element eqns (make table table-border: #f before-row-border: #f after-row-border: #f before-column-border: #f after-column-border: #f space-before: (inherited-line-spacing) table-width: 6.5in (sosofo-append (eqn-colspecs (let loop ((nl (children (current-node))) (maxeqs 0)) (if (node-list-empty? (node-list-rest nl)) (max maxeqs (node-list-length (children (node-list-first nl)))) (loop (node-list-rest nl) (max maxeqs (node-list-length (children (node-list-first nl)))))))) (process-children)))) ;; eqn: children separated by thicksp '=' thicksp, aligned within eqns (define (do-eqn node) (make table-row (sosofo-append (make table-cell (make paragraph (process-node-list (node-list-first (children node))))) (let loop ((nl (node-list-rest (children node)))) (sosofo-append (make table-cell (make paragraph (literal "="))) (if (node-list-empty? (node-list-rest nl)) (make table-cell (make paragraph (process-node-list (node-list-first nl)))) (sosofo-append (make table-cell (make paragraph (process-node-list (node-list-first nl)))) (loop (node-list-rest nl))))))))) (element (eqns eqn) (do-eqn (current-node))) (element eqn (make table table-border: #f before-row-border: #f after-row-border: #f before-column-border: #f after-column-border: #f space-before: (inherited-line-spacing) table-width: 6.5in (sosofo-append (eqn-colspecs (node-list-length (children (current-node)))) (do-eqn (current-node))))) ;; add: children separated by medsp '+' medsp (element add (let loop ((nl (children (current-node)))) (sosofo-append (process-node-list (node-list-first nl)) (if (node-list-empty? (node-list-rest nl)) (empty-sosofo) (sosofo-append (literal (string medsp #\+ medsp)) (loop (node-list-rest nl))))))) ;; const: a simple number; the usual case need not be treated ;; cross: vector cross-product: medsp cross medsp (element cross (let loop ((nl (children (current-node)))) (sosofo-append (process-node-list (node-list-first nl)) (if (node-list-empty? (node-list-rest nl)) (empty-sosofo) (sosofo-append (literal (string medsp cross-char medsp)) (loop (node-list-rest nl))))))) ;; curl: del cross child (element curl (sosofo-append (make sequence font-weight: 'bold (literal (string del-char))) (literal (string medsp cross-char medsp)) (process-children))) ;; diff: partial differential (element diff (sosofo-append (literal (string diff-char)) (process-node-list (node-list-first (children (current-node)))) (literal (string frac-char diff-char)) (process-node-list (node-list-rest (children (current-node)))))) ;; div: vector divergence, del dot child (element div (sosofo-append (make sequence font-weight: 'bold (literal (string del-char))) (literal (string medsp dot-char medsp)) (process-children))) ;; divide: division, eventually rendered as a fraction (element divide (sosofo-append (process-node-list (node-list-first (children (current-node)))) (literal (string frac-char)) (process-node-list (node-list-rest (children (current-node)))))) ;; dot: vector dot-product: medsp dot medsp (element dot (sosofo-append (process-node-list (node-list-first (children (current-node)))) (literal (string medsp dot-char medsp)) (process-node-list (node-list-rest (children (current-node)))))) ;; exp: exponent (element exp (sosofo-append (process-node-list (node-list-first (children (current-node)))) (make sequence position-point-shift: (/ (inherited-font-size) 2) font-size: (/ (inherited-font-size) 2) (process-node-list (node-list-rest (children (current-node))))))) ;; fact: factorial (element fact (sosofo-append (process-children) (make sequence (literal "!")))) ;; fname: roman function name ;; fxn: named function (element fxn (sosofo-append (process-node-list (node-list-first (children (current-node)))) (literal "(") (let loop ((nl (node-list-rest (children (current-node))))) (sosofo-append (process-node-list (node-list-first nl)) (if (node-list-empty? (node-list-rest nl)) (empty-sosofo) (sosofo-append (literal ", ") (loop (node-list-rest nl)))))) (literal ")"))) ;; index: subscripted variable (element index (sosofo-append (process-node-list (node-list-first (children (current-node)))) (make sequence position-point-shift: (- (/ (inherited-font-size) 4)) font-size: (/ (inherited-font-size) 2) (process-node-list (node-list-rest (children (current-node))))))) ;; mult: multiplication: run children together, no space ;; neg: negation: minus sign in front (element neg (make sequence (literal (string minus-char)) (process-children))) ;; sfxn: standard function (like sin, log, etc.) with no parens and a single arg (element sfxn (sosofo-append (literal (string medsp)) (process-node-list (node-list-first (children (current-node)))) (literal (string medsp)) (process-node-list (node-list-rest (children (current-node)))) (literal (string medsp)))) ;; subt: subtraction (element subt (let loop ((nl (children (current-node)))) (sosofo-append (process-node-list (node-list-first nl)) (if (node-list-empty? (node-list-rest nl)) (empty-sosofo) (sosofo-append (literal (string medsp minus-char medsp)) (loop (node-list-rest nl))))))) ;; var: variable (element var (make sequence font-posture: 'italic)) ;; vec: vector (element vec (make sequence font-weight: 'bold font-posture: 'italic))