From 332e3b7f3c359e19f20df5ca2f7ca595d8ecba64 Mon Sep 17 00:00:00 2001
From: Ludovic Court`es
Date: Mon, 27 Feb 2006 16:02:14 +0000
Subject: `eq': Added the `:renderer' option to `eq'.  Support `lout'.

* src/guile/skribilo/package/eq.scm (eq): Added a `renderer' option.
  Modified the `eq' writer for `base'.
  (!=): Use the appropriate symbol.
  (~=): Likewise.
  (>=): Likewise.
  (<=): Likewise.

git-archimport-id: lcourtes@laas.fr--2004-libre/skribilo--devel--1.2--patch-57
---
 src/guile/skribilo/package/eq.scm | 45 +++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 7 deletions(-)

diff --git a/src/guile/skribilo/package/eq.scm b/src/guile/skribilo/package/eq.scm
index 8a4ad3b..45a863f 100644
--- a/src/guile/skribilo/package/eq.scm
+++ b/src/guile/skribilo/package/eq.scm
@@ -28,6 +28,7 @@
   :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
@@ -126,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"))))
@@ -209,12 +210,40 @@
 
 
 ;;;
-;;; Text-only implementation.
+;;; Base and text-only implementation.
 ;;;
 
+
+
 (markup-writer 'eq (find-engine 'base)
    :action (lambda (node engine)
-	      (output (it (markup-body node)) engine)))
+	     ;; 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)
@@ -242,12 +271,12 @@
 (simple-markup-writer * (symbol "times"))
 
 (simple-markup-writer =)
-(simple-markup-writer !=)
-(simple-markup-writer ~=)
+(simple-markup-writer != (symbol "neq"))
+(simple-markup-writer ~= (symbol "approx"))
 (simple-markup-writer <)
 (simple-markup-writer >)
-(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)
@@ -337,6 +366,8 @@
 	       (output (sup sup*) engine)
 	       (output (sub sub*) engine))))
 
+
+
 
 ;;;
 ;;; Initialization.
-- 
cgit v1.2.3