;;;; source file of the GNU LilyPond music typesetter
;;;;
;;;; (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
-;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
+;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
;; (debug-enable 'backtrace)
-;; the public interface is tight.
+;; The public interface is tight.
;; It has to be, because user-code is evalled with this module.
+;; ***It should also be clean, well defined, documented and reviewed***
+
+;; To be reasonably safe, you probably do not want to use the TeX
+;; backend anyway, but rather the PostScript backend. You may want
+;; to run gs in a uml sandbox too.
+
+
(define-module (scm output-tex)
#:re-export (quote)
- #:export (font-command
- unknown
+
+ ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
+ #:export (unknown
blank
dot
+ white-dot
beam
bracket
dashed-slur
char
dashed-line
zigzag-line
- symmetric-x-triangle
ez-ball
comment
repeat-slash
filledbox
round-filled-box
text
+ white-text
tuplet
polygon
draw-line
- define-origin
no-origin
+ grob-cause
))
(use-modules (ice-9 regex)
(ice-9 format)
(guile)
(srfi srfi-13)
+ (scm framework-tex)
(lily))
;;;;;;;;
;;;;;;;;
-(define (font-command font)
- (string-append
- "magfont"
- (string-encode-integer
- (hashq (ly:font-filename font) 1000000))
- "m"
- (string-encode-integer
- (inexact->exact (round (* 1000 (ly:font-magnification font)))))))
-
(define (unknown)
"%\n\\unknown\n")
-(define-public (symbol->tex-key sym)
- (regexp-substitute/global
- #f "_" (sanitize-tex-string (symbol->string sym)) 'pre "X" 'post) )
-
-(define (string->param string)
- (string-append "{" string "}"))
-
-(define (number->param number)
- (string->param (ly:number->string number)))
-
-(define (number-pair->param o)
- (string-append (number->param (car o)) (number->param (cdr o))))
-
-(define-public (tex-number-def prefix key number)
- (string-append
- "\\def\\" prefix (symbol->tex-key key) (string->param number) "%\n"))
(define (blank)
(define (dot x y radius)
(embedded-ps (list 'dot x y radius)))
+
+(define (embedded-ps string)
+ (embedded-ps (list 'embedded-ps string)))
+
+(define (white-dot x y radius)
+ (embedded-ps (list 'white-dot x y radius)))
+
(define (beam width slope thick blot)
(embedded-ps (list 'beam width slope thick blot)))
(embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
(define (char font i)
- (string-append "\\" (font-command font)
+ (string-append "\\" (tex-font-command font)
"\\char" (ly:inexact->string i 10) " "))
(define (dashed-line thick on off dx dy)
(define (zigzag-line centre? zzw zzh thick dx dy)
(embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
-(define (symmetric-x-triangle t w h)
- (embedded-ps (list 'symmetric-x-triangle t w h)))
-
-(define-public (font-load-command bookpaper font)
- (string-append
- "\\font\\" (font-command font) "="
- (ly:font-filename font)
- " scaled "
- (ly:number->string (inexact->exact
- (round (* 1000
- (ly:font-magnification font)
- (ly:bookpaper-outputscale bookpaper)))))
- "\n"))
-
(define (ez-ball c l b)
(embedded-ps (list 'ez-ball c l b)))
(lambda () (ps-output-expression expr (current-output-port))))))
(string-append "\\embeddedps{" ps-string "}")))
-(define (comment s)
- (string-append "% " s "\n"))
-
-(define (end-output)
- (begin
- ;; uncomment for some stats about lily memory
- ;; (display (gc-stats))
- (string-append
- "\\lilypondend\n"
- ;; Put GC stats here.
- )))
(define (repeat-slash w a t)
(embedded-ps (list 'repeat-slash w a t)))
-(define-public (sanitize-tex-string s) ;; todo: rename
- (if (ly:get-option 'safe)
- (regexp-substitute/global #f "\\\\"
- (regexp-substitute/global #f "([{}])" "bla{}" 'pre "\\" 1 'post )
- 'pre "$\\backslash$" 'post)
-
- s))
-
-(define (lily-def key val)
- (let ((tex-key
- (regexp-substitute/global
- #f "_" (sanitize-tex-string key) 'pre "X" 'post))
-
- (tex-val (sanitize-tex-string val)))
- (if (equal? (sans-surrounding-whitespace tex-val) "")
- (string-append "\\let\\" tex-key "\\undefined\n")
- (string-append "\\def\\" tex-key "{" tex-val "}%\n"))))
(define (number->dim x)
(string-append
(define (placebox x y s)
(string-append
- "\\lyitem" (number->param x) (number->param y) (string->param s) "%\n"))
+ "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
(define (bezier-sandwich l thick)
(embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
(input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
)
- (string-append "\\hbox{\\" (font-command font)
+ (string-append "\\hbox{\\" (tex-font-command font)
(if (string? input-enc-name)
(string-append "\\inputencoding{" input-enc-name "}")
"{}")
s))
"}")))
-
+(define (white-text scale s)
+ (embedded-ps (list 'white-text scale s)))
+
(define (tuplet ht gapx dx dy thick dir)
(embedded-ps (list 'tuplet ht gapx dx dy thick dir)))
(define (draw-line thick fx fy tx ty)
(embedded-ps (list 'draw-line thick fx fy tx ty)))
-(define (define-origin file line col)
- (if (procedure? point-and-click)
- (string-append "\\special{src:" ;;; \\string ?
- (point-and-click line col file)
- "}" )
- ""))
-
;; no-origin not yet supported by Xdvi
(define (no-origin) "")
+(define (grob-cause grob)
+ (if (procedure? point-and-click)
+ (let* ((cause (ly:grob-property grob 'cause))
+ (music-origin (if (ly:music? cause)
+ (ly:music-property cause 'origin)))
+ (location (if (ly:input-location? music-origin)
+ (ly:input-location music-origin))))
+ (if (pair? location)
+ ;;; \\string ?
+ (string-append "\\special{src:"
+ (apply point-and-click location) "}")
+ ""))
+ ""))