Select Git revision
mathml.lisp
mathml.lisp 29.28 KiB
(in-package "MAXIMA")
;; MathML-printing
;; Created by David Drysdale (DMD), December 2002/January 2003
;;
;; closely based on the original TeX conversion code in mactex.lisp,
;; for which the following credits apply:
;; (c) copyright 1987, Richard J. Fateman
;; small corrections and additions: Andrey Grozin, 2001
;; additional additions: Judah Milgram (JM), September 2001
;; additional corrections: Barton Willis (BLW), October 2001
;; Usage: mathml(d8,"/tmp/foo.xml"); mathml(d10,"/tmp/foo.xml"); ..
;; to append lines d8 and d10 to the mathml file. If given only
;; one argument the result goes to standard output.
;; Method:
;; Producing MathML from a macsyma internal expression is done by
;; a reversal of the parsing process. Fundamentally, a
;; traversal of the expression tree is produced by the program,
;; with appropriate substitutions and recognition of the
;; infix / prefix / postfix / matchfix relations on symbols. Various
;; changes are made to this so that MathML will like the results.
;; Instructions:
;; in macsyma, type mathml(<expression>); or mathml(<label>); or
;; mathml(<expr-or-label>, <file-name>); In the case of a label,
;; an equation-number will also be produced.
;; in case a file-name is supplied, the output will be sent
;; (perhaps appended) to that file.
(macsyma-module mathml)
#+franz
($bothcases t) ;; allow alpha and Alpha to be different
(declare-top
(special lop rop ccol $gcprint texport $labels $inchar
vaxima-main-dir
)
(*expr mathml-lbp mathml-rbp))
;; top level command the result of converting the expression x.
(defmspec $mathml(l) ;; mexplabel, and optional filename
;;if filename supplied but 'nil' then return a string
(let ((args (cdr l)))
(cond ((and (cdr args) (null (cadr args)))
(let ((*standard-output* (make-string-output-stream)))
(apply 'mathml1 args)
(get-output-stream-string *standard-output*)
)
)
(t (apply 'mathml1 args)))))
(defun mathml1 (mexplabel &optional filename ) ;; mexplabel, and optional filename
(prog (mexp texport $gcprint ccol x y itsalabel tmpport)
;; $gcprint = nil turns gc messages off
(setq ccol 1)
(cond ((null mexplabel)
(displa " No eqn given to MathML")
(return nil)))
;; collect the file-name, if any, and open a port if needed
(setq texport (cond((null filename) *standard-output* ); t= output to terminal
(t
(open (string (stripdollar filename))
:direction :output
:if-exists :append
:if-does-not-exist :create))))
;; go back and analyze the first arg more thoroughly now.
;; do a normal evaluation of the expression in macsyma