]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
*** empty log message ***
[lilypond.git] / scm / output-tex.scm
1 ;;;; tex.scm -- implement Scheme output routines for TeX
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;;                 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
9 ;; The public interface is tight.
10 ;; It has to be, because user-code is evalled with this module.
11
12 ;; ***It should also be clean, well defined, documented and reviewed***
13
14 ;; To be reasonably safe, you probably do not want to use the TeX
15 ;; backend anyway, but rather the PostScript backend.  You may want
16 ;; to run gs in a uml sandbox too.
17
18
19 (define-module (scm output-tex)
20   #:re-export (quote)
21
22   ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
23   #:export (unknown
24             blank
25             circle
26             dot
27             beam
28             dashed-slur
29             named-glyph
30             dashed-line
31             zigzag-line
32             comment
33             repeat-slash
34             placebox
35             bezier-sandwich
36             filledbox
37             round-filled-box
38             text
39             setcolor
40             resetcolor
41             polygon
42             draw-line
43             no-origin
44             grob-cause))
45
46 (use-modules (ice-9 regex)
47              (ice-9 string-fun)
48              (ice-9 format)
49              (guile)
50              (srfi srfi-13)
51              (scm framework-tex)
52              (lily))
53
54
55
56 ;;;;;;;;
57 ;;;;;;;; DOCUMENT ME!
58 ;;;;;;;;
59
60
61 (define (char font i)
62   (string-append "\\" (tex-font-command font)
63                  "\\char" (ly:inexact->string i 10) " "))
64
65 (define (unknown) 
66   "%\n\\unknown\n")
67
68 (define (url-link url x y)
69   "")
70
71 (define (blank)
72   "")
73
74 (define (circle radius thick)
75   (embedded-ps (list 'circle radius thick)))
76
77 (define (dot x y radius)
78   (embedded-ps (list 'dot x y radius)))
79
80 (define (embedded-ps string)
81   (embedded-ps (list 'embedded-ps string)))
82
83 (define (beam width slope thick blot)
84   (embedded-ps (list 'beam  width slope thick blot)))
85
86 (define (dashed-slur thick on off lst)
87   (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
88
89 (define (named-glyph font name)
90   (let* ((info (ly:otf-font-glyph-info font name))
91          (subfont (assoc-get 'subfont info))
92          (subidx  (assoc-get 'subfont-index info)))
93     
94     ;;(stderr "INFO: ~S\n" info)
95     ;;(stderr "FONT: ~S\n" font)
96     (if (and subfont subidx)
97         (string-append "\\" (tex-font-command-raw
98                              subfont
99                              (ly:font-magnification font))
100                        "\\char" (number->string subidx))
101
102         (begin
103           (ly:warning (_ "can't find ~a in ~a" name font))
104           ""))))
105
106 (define (dashed-line thick on off dx dy)
107   (embedded-ps (list 'dashed-line  thick on off dx dy)))
108
109 (define (zigzag-line centre? zzw zzh thick dx dy)
110   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
111
112 (define (embedded-ps expr)
113   (let ((ps-string
114          (with-output-to-string
115            (lambda () (ps-output-expression expr (current-output-port))))))
116     (string-append "\\embeddedps{" ps-string "}")))
117
118 (define (repeat-slash w a t)
119   (embedded-ps (list 'repeat-slash  w a t)))
120
121 (define (number->dim x)
122   (string-append
123    ;;ugh ly:* in backend needs compatibility func for standalone output
124    (ly:number->string x) " \\outputscale "))
125
126 (define (placebox x y s) 
127   (string-append
128    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
129
130 (define (bezier-sandwich lst thick)
131   (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
132
133 (define (filledbox breapth width depth height)
134   (if (and #f (defined? 'ps-testing))
135       (embedded-ps
136        (string-append (ly:numbers->string (list breapth width depth height))
137                       " draw_box" ))
138       (string-append "\\lyvrule{"
139                      (ly:number->string (- breapth)) "}{"
140                      (ly:number->string (+ breapth width)) "}{"
141                      (ly:number->string depth) "}{"
142                      (ly:number->string height) "}")))
143
144 (define (round-filled-box x y width height blotdiam)
145   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
146
147 (define (text font s)
148   (format
149    "\\hbox{\\~a{}~a}" (tex-font-command font)
150    (sanitize-tex-string s)))
151
152 (define (setcolor r g b)
153   (string-append "\\color[rgb]{"
154   (number->string r) ", "
155   (number->string g) ", "
156   (number->string b) "}"))
157
158 ;; FIXME
159 ;; The PostScript backend saves the current color
160 ;; during setcolor and restores it during resetcolor.
161 ;; We don't do that here.
162 (define (resetcolor)
163   (string-append "\\color[rgb]{0,0,0}\n"))
164
165 (define (polygon points blotdiameter fill)
166   (embedded-ps (list 'polygon `(quote ,points) blotdiameter fill)))
167
168 (define (draw-line thick fx fy tx ty)
169   (embedded-ps (list 'draw-line thick fx fy tx ty)))
170
171 ;; no-origin not yet supported by Xdvi
172 (define (no-origin) "")
173
174
175
176
177 (define-public (line-location  file line col)
178   "Print an input location, without column number ."
179   (string-append (number->string line) " " file))
180
181 (define-public point-and-click #f)
182
183 (define (grob-cause offset grob)
184   (define (line-column-location file line col)
185     "Print an input location, including column number ."
186     (string-append (number->string line) ":"
187                    (number->string col) " " file))
188
189   (if (procedure? point-and-click)
190       (let* ((cause (ly:grob-property grob 'cause))
191              (music-origin (if (ly:music? cause)
192                                (ly:music-property cause 'origin)))
193              (location (if (ly:input-location? music-origin)
194                            (ly:input-file-line-column music-origin))))
195         (if (pair? location)
196              ;;; \\string ? 
197             (string-append "\\special{src:"
198                            (line-column-location location) "}")
199             ""))
200       ""))