diff options
author | Ludovic Courtes | 2006-02-28 20:08:45 +0000 |
---|---|---|
committer | Ludovic Courtes | 2006-02-28 20:08:45 +0000 |
commit | 9c00c232438cb83430397080e1c810aa33da460a (patch) | |
tree | b7898ddffdc4f95de1c058b9c815aeddf7c6503c /src/guile/skribilo/package/eq.scm | |
parent | a0d8397787ffcaaec7c885542fb5e7f3de3fdc9a (diff) | |
parent | 22ad7aedd2d325150f4e54d7e8cf123fbc4a32b1 (diff) | |
download | skribilo-9c00c232438cb83430397080e1c810aa33da460a.tar.gz skribilo-9c00c232438cb83430397080e1c810aa33da460a.tar.lz skribilo-9c00c232438cb83430397080e1c810aa33da460a.zip |
Merge from lcourtes@laas.fr--2004-libre
Patches applied:
* lcourtes@laas.fr--2004-libre/skribilo--devel--1.2 (patch 55-59)
- Made `make-string-replace' faster.
- `eq': Implemented the text-based markup writers.
- `eq': Added the `:renderer' option to `eq'. Support `lout'.
- Changed the way `slide' implementations are loaded. Doc is buildable now.
- Doc: Added a chapter (stub) about the `eq' package.
git-archimport-id: lcourtes@laas.fr--2005-mobile/skribilo--devel--1.2--patch-36
Diffstat (limited to 'src/guile/skribilo/package/eq.scm')
-rw-r--r-- | src/guile/skribilo/package/eq.scm | 170 |
1 files changed, 155 insertions, 15 deletions
diff --git a/src/guile/skribilo/package/eq.scm b/src/guile/skribilo/package/eq.scm index 687a3f5..45a863f 100644 --- a/src/guile/skribilo/package/eq.scm +++ b/src/guile/skribilo/package/eq.scm @@ -27,6 +27,8 @@ :use-module (skribilo utils syntax) :use-module (skribilo module) :use-module (skribilo skribe utils) ;; `the-options', etc. + :autoload (skribilo skribe api) (it symbol sub sup) + :autoload (skribilo engine lout) (lout-illustration) :use-module (ice-9 optargs)) ;;; Author: Ludovic Courtès @@ -125,7 +127,7 @@ ;;; Markup. ;;; -(define-markup (eq :rest opts :key (ident #f) (class "eq")) +(define-markup (eq :rest opts :key (ident #f) (renderer #f) (class "eq")) (new markup (markup 'eq) (ident (or ident (symbol->string (gensym "eq")))) @@ -208,25 +210,163 @@ ;;; -;;; Text-only implementation. +;;; Base and text-only implementation. ;;; + + (markup-writer 'eq (find-engine 'base) :action (lambda (node engine) - (output (apply it (markup-body node)) engine))) - -(markup-writer 'eq:/ (find-engine 'base) + ;; The `:renderer' option should be a symbol (naming an engine + ;; class) or an engine or engine class. This allows the use of + ;; another engine to render equations. For instance, equations + ;; may be rendered using the Lout engine within an HTML + ;; document. + (let ((renderer (markup-option node :renderer))) + (cond ((not renderer) ;; default: use the current engine + (output (it (markup-body node)) engine)) + ((symbol? renderer) + (case renderer + ;; FIXME: We should have an `embed' slot for each + ;; engine class similar to `lout-illustration'. + ((lout) + (let ((lout-code + (with-output-to-string + (lambda () + (output node (find-engine 'lout)))))) + (output (lout-illustration + :ident (markup-ident node) + lout-code) + engine))) + (else + (skribe-error 'eq "invalid renderer" renderer)))) + ;; FIXME: `engine?' and `engine-class?' + (else + (skribe-error 'eq "`:renderer' -- wrong argument type" + renderer)))))) + +(define-macro (simple-markup-writer op . obj) + `(markup-writer ',(symbol-append 'eq: op) (find-engine 'base) + :action (lambda (node engine) + (let loop ((operands (markup-body node))) + (if (null? operands) + #t + (let ((o (car operands))) + (display (if (equation-markup? o) "(" "")) + (output o engine) + (display (if (equation-markup? o) ")" "")) + (if (pair? (cdr operands)) + (begin + (display " ") + (output ,(if (null? obj) + (symbol->string op) + (car obj)) + engine) + (display " "))) + (loop (cdr operands)))))))) + +(simple-markup-writer +) +(simple-markup-writer -) +(simple-markup-writer /) +(simple-markup-writer * (symbol "times")) + +(simple-markup-writer =) +(simple-markup-writer != (symbol "neq")) +(simple-markup-writer ~= (symbol "approx")) +(simple-markup-writer <) +(simple-markup-writer >) +(simple-markup-writer >= (symbol "ge")) +(simple-markup-writer <= (symbol "le")) + +(markup-writer 'eq:sqrt (find-engine 'base) + :action (lambda (node engine) + (display "sqrt(") + (output (markup-body node) engine) + (display ")"))) + +(define-macro (simple-binary-markup-writer op obj) + `(markup-writer ',(symbol-append 'eq: op) (find-engine 'base) + :action (lambda (node engine) + (let ((body (markup-body node))) + (if (= (length body) 2) + (let ((first (car body)) + (second (cadr body))) + (display (if (equation-markup? first) "(" " ")) + (output first engine) + (display (if (equation-markup? first) ")" " ")) + (output ,obj engine) + (display (if (equation-markup? second) "(" "")) + (output second engine) + (display (if (equation-markup? second) ")" ""))) + (skribe-error ',(symbol-append 'eq: op) + "wrong argument type" + body)))))) + +(markup-writer 'eq:expt (find-engine 'base) + :action (lambda (node engine) + (let ((body (markup-body node))) + (if (= (length body) 2) + (let ((first (car body)) + (second (cadr body))) + (display (if (equation-markup? first) "(" "")) + (output first engine) + (display (if (equation-markup? first) ")" "")) + (output (sup second) engine)))))) + +(simple-binary-markup-writer in (symbol "in")) +(simple-binary-markup-writer notin (symbol "notin")) + +(markup-writer 'eq:apply (find-engine 'base) :action (lambda (node engine) - (let loop ((operands (markup-body node))) - (if (null? operands) - #t - (begin - (display " ") - (output (car operands) engine) - (display " ") - (if (pair? (cdr operands)) - (display " / ")) - (loop (cdr operands))))))) + (let ((func (car (markup-body node)))) + (output func engine) + (display "(") + (let loop ((operands (cdr (markup-body node)))) + (if (null? operands) + #t + (begin + (output (car operands) engine) + (if (not (null? (cdr operands))) + (display ", ")) + (loop (cdr operands))))) + (display ")")))) + +(markup-writer 'eq:sum (find-engine 'base) + :action (lambda (node engine) + (let ((from (markup-option node :from)) + (to (markup-option node :to))) + (output (symbol "Sigma") engine) + (display "(") + (output from engine) + (display ", ") + (output to engine) + (display ", ") + (output (markup-body node) engine) + (display ")")))) + +(markup-writer 'eq:prod (find-engine 'base) + :action (lambda (node engine) + (let ((from (markup-option node :from)) + (to (markup-option node :to))) + (output (symbol "Pi") engine) + (display "(") + (output from engine) + (display ", ") + (output to engine) + (display ", ") + (output (markup-body node) engine) + (display ")")))) + +(markup-writer 'eq:script (find-engine 'base) + :action (lambda (node engine) + (let ((body (markup-body node)) + (sup* (markup-option node :sup)) + (sub* (markup-option node :sub))) + (output body engine) + (output (sup sup*) engine) + (output (sub sub*) engine)))) + + ;;; |