]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/output-tex.scm
* scm/output-ps.scm (make-title, output-scopes): Further
[lilypond.git] / scm / output-tex.scm
index 8a531626f6e531beca556d763f4942c192638e42..4698e8ee4108abce3490acea5594ca6dd9b5f392 100644 (file)
@@ -1,19 +1,19 @@
-
 ;;; tex.scm -- implement Scheme output routines for TeX
 ;;;
 ;;;  source file of the GNU LilyPond music typesetter
 ;;; 
-;;; (c)  1998--2003 Jan Nieuwenhuizen <janneke@gnu.org>
+;;; (c)  1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
 
 (define-module (scm output-tex) )
-(debug-enable 'backtrace)
+(debug-enable 'backtrace)
 (use-modules (scm output-ps)
             (ice-9 regex)
             (ice-9 string-fun)
             (ice-9 format)
             (guile)
+            (srfi srfi-13)
             (lily)
             )
 
@@ -28,6 +28,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,7 +36,7 @@
                           (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)
   (set! font-name-alist (map tex-encoded-fontswitch
 (define (unknown) 
   "%\n\\unknown\n")
 
+(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))
+            (tex-key (symbol->string sym)))
+        
+        (if (memq sym fields)
+            (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)))
+
 (define (select-font name-mag-pair)
-  (let*
-      (
-       (c (assoc name-mag-pair font-name-alist))
-       )
+  (let ((c (assoc name-mag-pair font-name-alist)))
 
-    (if (eq? c #f)
+    (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:number->string (cdr name-mag-pair))))
+         
+         (display "FAILED\n" (current-error-port))
+         (if #f ;(pair? name-mag-pair))
+             (display (object-type (car name-mag-pair)) (current-error-port))
+             (write name-mag-pair (current-error-port)))
+         (if #f ;  (pair? font-name-alist)
+             (display
+              (object-type (caaar font-name-alist)) (current-error-port))
+             (write font-name-alist (current-error-port)))
+
+         ;; (format #f "\n%FAILED: (select-font ~S)\n" name-mag-pair))
+         ""))))
+
+;; top-of-file, wtf?  ugh: tagline?
+(define (top-of-file)
+  (string-append
+   "% generated by LilyPond "
+    (lilypond-version) " (http://lilypond.org).\n"
+    "\\def\\lilypondtagline{Engraved by LilyPond (version "
+    (lilypond-version)
+    ")}\n"
     ))
 
 (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)))
    "\\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)
   ""
   )
 
-(if (or (equal? (minor-version) "4.1")
-       (equal? (minor-version) "4")
-       (equal? (minor-version) "3.4"))
-    (define (embedded-ps expr)
-      (let ((ps-string
-            (with-output-to-string
-              (lambda () (ps-output-expression expr (current-output-port))))))
-       (string-append "\\embeddedps{" ps-string "}")))
-    (define (embedded-ps expr)
-      (let
-         ((os (open-output-string)))
-       (ps-output-expression expr os)
-       (string-append "\\embeddedps{" (get-output-string os) "}"))))
-
+(define (embedded-ps expr)
+  (let ((ps-string
+        (with-output-to-string
+          (lambda () (ps-output-expression expr (current-output-port))))))
+    (string-append "\\embeddedps{" ps-string "}")))
+  
 (define (comment s)
   (string-append "% " s "\n"))
 
    "\\lilypondspecial\n"
    "\\lilypondpostscript\n"))
 
-;; Note: this string must match the string in ly2dvi.py!!!
+;; Note: this string must match the string in lilypond.py!!!
 (define (header creator generate) 
   (string-append
    "% Generated automatically by: " creator generate "\n"))
                 (ly:number->string x) "}{"
                 s "}%\n"))
 
-(define (bezier-bow l thick)
-  (embedded-ps (list 'bezier-bow  `(quote ,l) thick)))
-
 (define (bezier-sandwich l thick)
   (embedded-ps (list 'bezier-sandwich  `(quote ,l) thick)))
 
                     (ly:number->string depth) "}{"
                     (ly:number->string height) "}")))
 
-(define (roundfilledbox x y width height blotdiam)
-  (embedded-ps (list 'roundfilledbox  x y width height blotdiam)))
+(define (round-filled-box x y width height blotdiam)
+  (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
 
 (define (text s)
   (string-append "\\hbox{" (output-tex-string s) "}"))
 (define (no-origin) "")
 
 (define-public (tex-output-expression expr port)
-  (display (eval expr this-module) port )
-  )
-
+  (display (eval expr this-module) port ))
 
+(define (make-title port) "")