From 85bc77eef9715f726eefe71ac74ecf6e17656bf5 Mon Sep 17 00:00:00 2001 From: Ludovic Court`es Date: Mon, 27 Feb 2006 13:16:08 +0000 Subject: `eq': Implemented the text-based markup writers. * src/guile/skribilo/package/eq.scm: Implemented the text-based markup writers for the `base' engine. git-archimport-id: lcourtes@laas.fr--2004-libre/skribilo--devel--1.2--patch-56 --- src/guile/skribilo/package/eq.scm | 135 ++++++++++++++++++++++++++++++++++---- 1 file changed, 122 insertions(+), 13 deletions(-) diff --git a/src/guile/skribilo/package/eq.scm b/src/guile/skribilo/package/eq.scm index 687a3f5..8a4ad3b 100644 --- a/src/guile/skribilo/package/eq.scm +++ b/src/guile/skribilo/package/eq.scm @@ -27,6 +27,7 @@ :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) :use-module (ice-9 optargs)) ;;; Author: Ludovic Courtès @@ -213,20 +214,128 @@ (markup-writer 'eq (find-engine 'base) :action (lambda (node engine) - (output (apply it (markup-body node)) engine))) - -(markup-writer 'eq:/ (find-engine 'base) + (output (it (markup-body node)) engine))) + +(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 !=) +(simple-markup-writer ~=) +(simple-markup-writer <) +(simple-markup-writer >) +(simple-markup-writer >=) +(simple-markup-writer <=) + +(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 ((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 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 ((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)))) ;;; -- cgit v1.2.3 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 From 6c57bbe42b5cfa694b3336ad4e5b5ba8b8ca2d5d Mon Sep 17 00:00:00 2001 From: Ludovic Court`es Date: Mon, 27 Feb 2006 16:31:00 +0000 Subject: Changed the way `slide' implementations are loaded. Doc is buildable now. * src/guile/skribilo/package/slide.scm: Change the initialization method for the engine-specific writers: don't rely on `autoload' which is too non-deterministic, use `resolve-module' instead. * src/guile/skribilo/package/slide/html.scm: Call `%slide-html-initialize!' from here. * src/guile/skribilo/package/slide/latex.scm: Likewise. * src/guile/skribilo/package/slide/lout.scm (%slide-lout-initialize!): Removed. git-archimport-id: lcourtes@laas.fr--2004-libre/skribilo--devel--1.2--patch-58 --- src/guile/skribilo/package/slide.scm | 11 +- src/guile/skribilo/package/slide/html.scm | 9 ++ src/guile/skribilo/package/slide/latex.scm | 9 ++ src/guile/skribilo/package/slide/lout.scm | 176 ++++++++++++++--------------- 4 files changed, 109 insertions(+), 96 deletions(-) diff --git a/src/guile/skribilo/package/slide.scm b/src/guile/skribilo/package/slide.scm index 8968d00..629abdf 100644 --- a/src/guile/skribilo/package/slide.scm +++ b/src/guile/skribilo/package/slide.scm @@ -21,10 +21,7 @@ (define-skribe-module (skribilo package slide) - :autoload (skribilo engine html) (html-width html-title-authors) - :autoload (skribilo package slide html) (%slide-html-initialize!) - :autoload (skribilo package slide lout) (%slide-lout-initialize!) - :autoload (skribilo package slide latex) (%slide-latex-initialize!)) + :autoload (skribilo engine html) (html-width html-title-authors)) ;*---------------------------------------------------------------------*/ @@ -47,13 +44,13 @@ ;; Register specific implementations for lazy loading. (when-engine-is-loaded 'latex (lambda () - (%slide-latex-initialize!))) + (resolve-module '(skribilo package slide latex)))) (when-engine-is-loaded 'html (lambda () - (%slide-html-initialize!))) + (resolve-module '(skribilo package slide html)))) (when-engine-is-loaded 'lout (lambda () - (%slide-lout-initialize!))) + (resolve-module '(skribilo package slide lout)))) ;*---------------------------------------------------------------------*/ diff --git a/src/guile/skribilo/package/slide/html.scm b/src/guile/skribilo/package/slide/html.scm index 5398fbf..128b7e3 100644 --- a/src/guile/skribilo/package/slide/html.scm +++ b/src/guile/skribilo/package/slide/html.scm @@ -59,6 +59,7 @@ (markup-writer 'slide-vspace he :action (lambda (n e) (display "
"))))) + ;*---------------------------------------------------------------------*/ ;* slide-body-width ... */ ;*---------------------------------------------------------------------*/ @@ -103,4 +104,12 @@ (display "\n"))) + +;;; +;;; Initialization. +;;; + +(%slide-html-initialize!) + + ;;; arch-tag: 8be0cdf2-b755-4baa-baf6-739cdd00e193 diff --git a/src/guile/skribilo/package/slide/latex.scm b/src/guile/skribilo/package/slide/latex.scm index 15f4535..4105e74 100644 --- a/src/guile/skribilo/package/slide/latex.scm +++ b/src/guile/skribilo/package/slide/latex.scm @@ -25,6 +25,7 @@ (define-public %slide-latex-mode 'seminar) (define-public (%slide-latex-initialize!) + (skribe-message "LaTeX slides setup...\n") (case %slide-latex-mode ((seminar) (%slide-seminar-setup!)) @@ -35,6 +36,7 @@ (else (skribe-error 'slide "Illegal latex mode" %slide-latex-mode)))) + ;*---------------------------------------------------------------------*/ ;* &slide-seminar-predocument ... */ ;*---------------------------------------------------------------------*/ @@ -382,4 +384,11 @@ (set! %slide-latex-mode 'advi))))) + +;;; +;;; Initialization. +;;; + +(%slide-latex-initialize!) + ;;; arch-tag: b99e2c65-55f7-462c-8482-f47c7e223538 diff --git a/src/guile/skribilo/package/slide/lout.scm b/src/guile/skribilo/package/slide/lout.scm index f816469..39e0175 100644 --- a/src/guile/skribilo/package/slide/lout.scm +++ b/src/guile/skribilo/package/slide/lout.scm @@ -34,98 +34,96 @@ ;;; ;;; Make some more PS/PDF trickery. -(format (current-error-port) "slide/lout.scm~%") - -(define-public (%slide-lout-initialize!) - (format (current-error-port) "Lout slides initializing...~%") - - (let ((le (find-engine 'lout))) - - ;; Automatically switch to the `slides' document type. - (engine-custom-set! le 'document-type 'slides) - - (markup-writer 'slide le - :options '(:title :number :toc :ident) ;; '(:bg :vspace :image) - - :validate (lambda (n e) - (eq? (engine-custom e 'document-type) 'slides)) - - :before (lambda (n e) - (display "\n@Overhead\n") - (display " @Title { ") - (output (markup-option n :title) e) - (display " }\n") - (if (markup-ident n) - (begin - (display " @Tag { ") - (display (lout-tagify (markup-ident n))) - (display " }\n"))) - (if (markup-option n :number) - (begin - (display " @BypassNumber { ") - (output (markup-option n :number) e) - (display " }\n"))) - (display "@Begin\n") - - ;; `doc' documents produce their PDF outline right after - ;; `@Text @Begin'; other types of documents must produce it - ;; as part of their first chapter. - (lout-output-pdf-meta-info (ast-document n) e)) - - :after "@End @Overhead\n") - - (markup-writer 'slide-vspace le - :options '(:unit) - :validate (lambda (n e) - (and (pair? (markup-body n)) - (number? (car (markup-body n))))) - :action (lambda (n e) - (printf "\n//~a~a # slide-vspace\n" - (car (markup-body n)) - (case (markup-option n :unit) - ((cm) "c") - ((point points pt) "p") - ((inch inches) "i") - (else - (skribe-error 'lout - "Unknown vspace unit" - (markup-option n :unit))))))) - - (markup-writer 'slide-pause le - ;; FIXME: Use a `pdfmark' custom action and a PDF transition action. - ;; << /Type /Action - ;; << /S /Trans - ;; entry in the trans dict - ;; << /Type /Trans /S /Dissolve >> - :action (lambda (n e) - (let ((filter (make-string-replace lout-verbatim-encoding)) - (pdfmark " +(format (current-error-port) "Lout slides setup...~%") + +(let ((le (find-engine 'lout))) + + ;; Automatically switch to the `slides' document type. + (engine-custom-set! le 'document-type 'slides) + + (markup-writer 'slide le + :options '(:title :number :toc :ident) ;; '(:bg :vspace :image) + + :validate (lambda (n e) + (eq? (engine-custom e 'document-type) 'slides)) + + :before (lambda (n e) + (display "\n@Overhead\n") + (display " @Title { ") + (output (markup-option n :title) e) + (display " }\n") + (if (markup-ident n) + (begin + (display " @Tag { ") + (display (lout-tagify (markup-ident n))) + (display " }\n"))) + (if (markup-option n :number) + (begin + (display " @BypassNumber { ") + (output (markup-option n :number) e) + (display " }\n"))) + (display "@Begin\n") + + ;; `doc' documents produce their PDF outline right after + ;; `@Text @Begin'; other types of documents must produce it + ;; as part of their first chapter. + (lout-output-pdf-meta-info (ast-document n) e)) + + :after "@End @Overhead\n") + + (markup-writer 'slide-vspace le + :options '(:unit) + :validate (lambda (n e) + (and (pair? (markup-body n)) + (number? (car (markup-body n))))) + :action (lambda (n e) + (printf "\n//~a~a # slide-vspace\n" + (car (markup-body n)) + (case (markup-option n :unit) + ((cm) "c") + ((point points pt) "p") + ((inch inches) "i") + (else + (skribe-error 'lout + "Unknown vspace unit" + (markup-option n :unit))))))) + + (markup-writer 'slide-pause le + ;; FIXME: Use a `pdfmark' custom action and a PDF transition action. + ;; << /Type /Action + ;; << /S /Trans + ;; entry in the trans dict + ;; << /Type /Trans /S /Dissolve >> + :action (lambda (n e) + (let ((filter (make-string-replace lout-verbatim-encoding)) + (pdfmark " [ {ThisPage} << /Trans << /S /Wipe /Dm /V /D 3 /M /O >> >> /PUT pdfmark")) - (display (lout-embedded-postscript-code - (filter pdfmark)))))) - - ;; For movies, see - ;; http://www.tug.org/tex-archive/macros/latex/contrib/movie15/movie15.sty . - (markup-writer 'slide-embed le - :options '(:alt :geometry :rgeometry :geometry-opt :command) - ;; FIXME: `pdfmark'. - ;; << /Type /Action /S /Launch - :action (lambda (n e) - (let ((command (markup-option n :command)) - (filter (make-string-replace lout-verbatim-encoding)) - (pdfmark "[ /Rect [ 0 ysize xsize 0 ] - /Name /Comment - /Contents (This is an embedded application) - /ANN pdfmark + (display (lout-embedded-postscript-code + (filter pdfmark)))))) + + ;; For movies, see + ;; http://www.tug.org/tex-archive/macros/latex/contrib/movie15/movie15.sty . + (markup-writer 'slide-embed le + :options '(:alt :geometry :rgeometry :geometry-opt :command) + ;; FIXME: `pdfmark'. + ;; << /Type /Action /S /Launch + :action (lambda (n e) + (let ((command (markup-option n :command)) + (filter (make-string-replace lout-verbatim-encoding)) + (pdfmark "[ /Rect [ 0 ysize xsize 0 ] +/Name /Comment +/Contents (This is an embedded application) +/ANN pdfmark [ /Type /Action - /S /Launch - /F (~a) - /OBJ pdfmark")) - (display (string-append - "4c @Wide 3c @High " - (lout-embedded-postscript-code - (filter (format #f pdfmark command)))))))))) +/S /Launch +/F (~a) +/OBJ pdfmark")) + (display (string-append + "4c @Wide 3c @High " + (lout-embedded-postscript-code + (filter (format #f pdfmark command))))))))) + ;;; arch-tag: 0c717553-5cbb-46ed-937a-f844b6aeb145 -- cgit v1.2.3 From 22ad7aedd2d325150f4e54d7e8cf123fbc4a32b1 Mon Sep 17 00:00:00 2001 From: Ludovic Court`es Date: Mon, 27 Feb 2006 17:07:32 +0000 Subject: Doc: Added a chapter (stub) about the `eq' package. * doc/user/user.skb: Use `(skribilo package eq)'. Include `eq.skb'. git-archimport-id: lcourtes@laas.fr--2004-libre/skribilo--devel--1.2--patch-59 --- doc/user/eq.skb | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/user/src/eq1.skb | 6 ++++ doc/user/src/eq2.skb | 3 ++ doc/user/user.skb | 8 ++++++ 4 files changed, 94 insertions(+) create mode 100644 doc/user/eq.skb create mode 100644 doc/user/src/eq1.skb create mode 100644 doc/user/src/eq2.skb diff --git a/doc/user/eq.skb b/doc/user/eq.skb new file mode 100644 index 0000000..62bd704 --- /dev/null +++ b/doc/user/eq.skb @@ -0,0 +1,77 @@ +;;; Copyright 2006 Ludovic Courtès +;;; +;;; +;;; This program is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 2 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program; if not, write to the Free Software +;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +;;; USA. + +;;; FIXME: This is a stub and must be completed! + +(chapter :title [Equation Formatting] + + (p [Skribilo comes with an equation formatting package. This package +may be loaded by adding the following form at the top of your document:] + + (disp (prog (source :language scheme + [(use-modules (skribilo package eq))]))) + + [It allows the inclusion of (complex) equations in your documents, +such as, for example, the following:] + + (disp (eq :renderer (if (engine-format? "html") 'lout #f) + :ident "eq-disponibilite" + `(= (apply A D) + (sum :from (= i b) :to (* S b) + (* (script :sup (* S b) :sub i C) + (* (expt mu i) + (expt (- 1 mu) + (- (* S b) i)))))))) + + [This chapter will describe the syntactic facilities available to +describe equations, as well as the rendering options.]) + + (section :title [Syntax] + + (p [To start with, let's have a look at a concrete example. ] + + (example-produce + (example :legend "Example of a simple equation using the verbose syntax" + (prgm :file "src/eq1.skb")) + (disp (include "src/eq1.skb"))) + + [In this example, the ,(tt [eq:]) sub-markups are used pretty +much like any other kind of markup. However, the resulting syntax +is very verbose and hard to read.]) + + (p [Fortunately, the ,(tt [eq]) package allows for the use of a +much simple syntax. ] + + (example-produce + (example :legend "Example of a simple equation" + (prgm :file "src/eq2.skb")) + (disp (include "src/eq2.skb"))) + + [Readers familiar with the Lisp family of programming languages +may have already recognized its ,(emph [prefix notation]). Note that, +unlike in the previous example, the equation itself if ,(emph [quoted]), +that is, preceded by the ,(tt [']) sign. Additionally, when referring +to a symbol (such as the Greek letter ,(symbol "phi")), you no longer +need to use the ,(tt [symbol]) markup (,(ref :text [see subsection] +:subsection "Symbols")).])) + + (section :title [Rendering]) + + ) + +;;; arch-tag: e9c83c13-205f-4f68-9100-b445c21b959c diff --git a/doc/user/src/eq1.skb b/doc/user/src/eq1.skb new file mode 100644 index 0000000..bbd0742 --- /dev/null +++ b/doc/user/src/eq1.skb @@ -0,0 +1,6 @@ +;; The golden ratio, phi. +(eq (eq:= (symbol "phi") + (eq:/ (eq:+ 1 (eq:sqrt 5)) + 2))) + + diff --git a/doc/user/src/eq2.skb b/doc/user/src/eq2.skb new file mode 100644 index 0000000..199fd7d --- /dev/null +++ b/doc/user/src/eq2.skb @@ -0,0 +1,3 @@ +;; The golden ratio, phi. +(eq '(= phi (/ (+ 1 (sqrt 5)) 2))) + diff --git a/doc/user/user.skb b/doc/user/user.skb index f4f6849..fb0c8d2 100644 --- a/doc/user/user.skb +++ b/doc/user/user.skb @@ -17,6 +17,11 @@ (skribe-load "skr/manual.skr") (skribe-load "skr/api.skr") +;*---------------------------------------------------------------------*/ +;* Packages */ +;*---------------------------------------------------------------------*/ +(use-modules (skribilo package eq)) + ;*---------------------------------------------------------------------*/ ;* HTML custom */ ;*---------------------------------------------------------------------*/ @@ -117,6 +122,9 @@ as HTML, Info pages, man pages, Postscript, etc.])))) ;;; Computer programs (include "prgm.skb") +;;; Equations +(include "eq.skb") + ;;; Standard Library (include "lib.skb") -- cgit v1.2.3