]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/output-tex.scm
small fixes.
[lilypond.git] / scm / output-tex.scm
index 54ea6318e8aaf1dcb6407b2edf37b0297b852db9..7f8259d4a4417569d963b9cb4bd93e5e3c7eba50 100644 (file)
@@ -1,23 +1,61 @@
+;;;; tex.scm -- implement Scheme output routines for TeX
+;;;;
+;;;;  source file of the GNU LilyPond music typesetter
+;;;; 
+;;;; (c)  1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+;;;;                  Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+
+;; (debug-enable 'backtrace)
+(define-module (scm output-tex)
+  #:re-export (quote)
+  #:export (define-fonts
+            unknown
+            output-paper-def
+            output-scopes
+            select-font
+            blank
+            dot
+            beam
+            bracket
+            dashed-slur
+            char
+            dashed-line
+            zigzag-line
+            symmetric-x-triangle
+            ez-ball
+            comment
+            end-output
+            experimental-on
+            repeat-slash
+            header-end
+            header
+            placebox
+            bezier-sandwich
+            start-system
+            stop-system
+            stop-last-system
+            horizontal-line
+            filledbox
+            round-filled-box
+            text
+            tuplet
+            polygon
+            draw-line
+            between-system-string
+            define-origin
+            no-origin
+            start-page
+            stop-page
+            )
+)
 
-;;; tex.scm -- implement Scheme output routines for TeX
-;;;
-;;;  source file of the GNU LilyPond music typesetter
-;;; 
-;;; (c)  1998--2003 Jan Nieuwenhuizen <janneke@gnu.org>
-;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
-
-(define-module (scm output-tex) )
-; (debug-enable 'backtrace)
-(use-modules (scm output-ps)
-            (ice-9 regex)
+(use-modules (ice-9 regex)
             (ice-9 string-fun)
             (ice-9 format)
             (guile)
-            (lily)
-            )
-
-(define this-module (current-module))
+            (srfi srfi-13)
+            (lily))
 
 ;;;;;;;;
 ;;;;;;;; DOCUMENT ME!
@@ -28,6 +66,7 @@
 (define (tex-encoded-fontswitch name-mag)
   (let* ((iname-mag (car name-mag))
         (ename-mag (cdr name-mag)))
+
     (cons iname-mag
          (cons ename-mag
                (string-append  "magfont"
@@ -35,9 +74,9 @@
                           (hashq (car ename-mag) 1000000))
                          "m"
                          (string-encode-integer
-                          (inexact->exact (* 1000 (cdr ename-mag)))))))))
+                          (inexact->exact (round (* 1000 (cdr ename-mag))))))))))
 
-(define (define-fonts internal-external-name-mag-pairs)
+(define-public (define-fonts internal-external-name-mag-pairs)
   (set! font-name-alist (map tex-encoded-fontswitch
                             internal-external-name-mag-pairs))
   (apply string-append
                (font-load-command (car x) (cdr x)))
              (map cdr font-name-alist))))
 
-
-
+;;
 ;; urg, how can exp be #unspecified?  -- in sketch output
 ;;
 ;; set! returns #<unspecified>  --hwn
-(define (fontify name-mag-pair exp)
+;;
+(define-public (fontify name-mag-pair exp)
   (string-append (select-font name-mag-pair)
                 exp))
 
 
-(define (unknown) 
+(define-public (unknown) 
   "%\n\\unknown\n")
 
-(define (select-font name-mag-pair)
-  (let*
-      (
-       (c (assoc name-mag-pair font-name-alist))
-       )
+(define (symbol->tex-key sym)
+  (regexp-substitute/global
+   #f "_" (output-tex-string (symbol->string sym)) 'pre "X" 'post) )
+
+(define (tex-string-def prefix key str)
+  (if (equal? "" (sans-surrounding-whitespace (output-tex-string str)))
+      (string-append "\\let\\" prefix (symbol->tex-key key) "\\undefined%\n")
+      (string-append "\\def\\" prefix (symbol->tex-key key) "{"  (output-tex-string str) "}%\n")
+      ))
+
+(define (tex-number-def prefix key number)
+  (string-append "\\def\\" prefix (symbol->tex-key key) "{" number "}%\n"))
+
+(define (output-paper-def pd)
+  (apply
+   string-append
+   (module-map
+    (lambda (sym var)
+      (let ((val (variable-ref var))
+           (key (symbol->tex-key sym)))
+
+       (cond
+        ((string? val)
+         (tex-string-def "lilypondpaper" sym val))
+        ((number? val)
+         (tex-number-def "lilypondpaper" sym
+                         (if (integer? val)
+                             (number->string val)
+                             (number->string (exact->inexact val)))))
+        (else ""))))
+      
+    (ly:output-def-scope pd))))
+
+(define (output-scopes paper scopes fields basename)
+  (define (output-scope scope)
+    (apply
+     string-append
+     (module-map
+     (lambda (sym var)
+       (let ((val (variable-ref var))
+            ;;(val (if (variable-bound? var) (variable-ref var) '""))
+            (tex-key (symbol->string sym)))
+        
+        (if (and (memq sym fields) (string? val))
+            (header-to-file basename sym val))
+
+        (cond
+         ((string? val)
+          (tex-string-def "lilypond" sym val))
+         ((number? val)
+          (tex-number-def "lilypond" sym
+                          (if (integer? val)
+                              (number->string val)
+                              (number->string (exact->inexact val)))))
+         (else ""))))
+     scope)))
+  
+  (apply string-append
+        (map output-scope scopes)))
 
-    (if (eq? c #f)
+(define (select-font name-mag-pair)
+  (let ((c (assoc name-mag-pair font-name-alist)))
+    (if c
+       (string-append "\\" (cddr c))
        (begin
-         (display "FAILED\n")
-         (display (object-type (car name-mag-pair)))
-         (display (object-type (caaar font-name-alist)))
-
-         (ly:warn (string-append
-                   "Programming error: No such font known "
-                   (car name-mag-pair) " "
-                   (ly:number->string (cdr name-mag-pair))
-                   ))
-         "") ; issue no command
-       (string-append "\\" (cddr c)))
-    
-    
-    ))
+         (ly:warn
+          (format "Programming error: No such font: ~S" name-mag-pair))
+         ""))))
 
 (define (blank)
   "")
 (define (dot x y radius)
   (embedded-ps (list 'dot x y radius)))
 
-(define (beam width slope thick)
-  (embedded-ps (list 'beam  width slope thick)))
+(define (beam width slope thick blot)
+  (embedded-ps (list 'beam  width slope thick blot)))
 
 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
   (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
 
 (define (char i)
-  (string-append "\\char" (inexact->string i 10) " "))
+  (string-append "\\char" (ly:inexact->string i 10) " "))
 
 (define (dashed-line thick on off dx dy)
   (embedded-ps (list 'dashed-line  thick on off dx dy)))
    "\\font\\" command "="
    (car name-mag)
    " scaled "
-   (ly:number->string (inexact->exact (* 1000  (cdr name-mag))))
+   (ly:number->string (inexact->exact (round (* 1000 (cdr name-mag)))))
    "\n"))
 
 (define (ez-ball c l b)
 
 (define (end-output) 
   (begin
-                                       ; uncomment for some stats about lily memory      
-                                       ;               (display (gc-stats))
+    ;; uncomment for some stats about lily memory        
+    ;; (display (gc-stats))
     (string-append
      "\\lilypondend\n"
-                                       ; Put GC stats here.
-                  )))
+     ;; Put GC stats here.
+     )))
 
 (define (experimental-on)
   "")
    "\\lilypondspecial\n"
    "\\lilypondpostscript\n"))
 
-;; Note: this string must match the string in ly2dvi.py!!!
-(define (header creator generate) 
+(define (header creator time-stamp page-count)
   (string-append
-   "% Generated automatically by: " creator generate "\n"))
+   "% Generated by " creator "\n"
+   "% at " time-stamp "\n"
+   ;; FIXME: duplicated in every backend
+   "\\def\\lilypondtagline{Engraved by LilyPond (version "
+   (lilypond-version)")}\n"))
 
 (define (invoke-char s i)
   (string-append 
-   "\n\\" s "{" (inexact->string i 10) "}" ))
+   "\n\\" s "{" (ly:inexact->string i 10) "}" ))
 
-;;
-;; need to do something to make this really safe.
-;;
+;; FIXME: explain ploblem: need to do something to make this really safe.  
 (define-public (output-tex-string s)
-  (if security-paranoia
+  (if safe-mode?
       (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
       s))
 
 (define (filledbox breapth width depth height)
   (if (and #f (defined? 'ps-testing))
       (embedded-ps
-       (string-append (numbers->string (list breapth width depth height))
+       (string-append (ly:numbers->string (list breapth width depth height))
                      " draw_box" ))
       (string-append "\\lyvrule{"
                     (ly:number->string (- breapth)) "}{"
 ;; no-origin not yet supported by Xdvi
 (define (no-origin) "")
 
-(define-public (tex-output-expression expr port)
-  (display (eval expr this-module) port )
-  )
-
+(define (start-page)
+  "\n%\\vbox{\n")
 
+(define (stop-page last?)
+  (if last?
+      "\n%}\n"
+      "\n%}\n\\newpage\n"))