]> git.donarmstrong.com Git - lilypond.git/blob - scm/tex.scm
release: 1.3.134
[lilypond.git] / scm / 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--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
9
10 ;;
11 ;; todo: this dispatch is totally LAME
12  
13 (define (tex-scm action-name)
14   (define (unknown) 
15     "%\n\\unknown%\n")
16
17
18   (define (select-font name-mag-pair)
19     (let*
20         (
21          (c (assoc name-mag-pair font-name-alist))
22          )
23
24       (if (eq? c #f)
25           (begin
26             (display "FAILED\n")
27             (display (object-type (car name-mag-pair)))
28             (display (object-type (caaar font-name-alist)))
29
30             (ly-warn (string-append
31                       "Programming error: No such font known "
32                       (car name-mag-pair) " "
33                       (ly-number->string (cdr name-mag-pair))
34                       ))
35             "") ; issue no command
36           (string-append "\\" (cddr c)))
37       
38       
39       ))
40   
41   (define (beam width slope thick)
42     (embedded-ps ((ps-scm 'beam) width slope thick)))
43
44   (define (bracket arch_angle arch_width arch_height height arch_thick thick)
45     (embedded-ps ((ps-scm 'bracket) arch_angle arch_width arch_height height arch_thick thick)))
46
47   (define (dashed-slur thick dash l)
48     (embedded-ps ((ps-scm 'dashed-slur)  thick dash l)))
49
50   (define (crescendo thick w h cont)
51     (embedded-ps ((ps-scm 'crescendo) thick w h cont)))
52
53   (define (char i)
54     (string-append "\\char" (inexact->string i 10) " "))
55   
56   (define (dashed-line thick on off dx dy)
57     (embedded-ps ((ps-scm 'dashed-line) thick on off dx dy)))
58
59   (define (decrescendo thick w h cont)
60     (embedded-ps ((ps-scm 'decrescendo) thick w h cont)))
61
62   (define (font-load-command name-mag command)
63     (string-append
64      "\\font\\" command "="
65      (car name-mag)
66      " scaled "
67      (ly-number->string (inexact->exact (* 1000  (cdr name-mag))))
68      "\n"))
69
70   (define (ez-ball c l b)
71     (embedded-ps ((ps-scm 'ez-ball) c  l b)))
72   (define (embedded-ps s)
73     (string-append "\\embeddedps{" s "}"))
74
75   (define (comment s)
76     (string-append "% " s))
77   
78   (define (end-output) 
79         (begin
80 ; uncomment for some stats about lily memory      
81 ;               (display (gc-stats))
82     (string-append "\n\\EndLilyPondOutput"
83                    ; Put GC stats here.
84                    )))
85   
86   (define (experimental-on)
87     "")
88
89   (define (font-switch i)
90     (string-append
91      "\\" (font i) "\n"))
92
93   (define (font-def i s)
94     (string-append
95      "\\font" (font-switch i) "=" s "\n"))
96
97   (define (header-end)
98     (string-append
99      "\\special{! "
100
101      ;; URG: ly-gulp-file: now we can't use scm output without Lily
102      (if use-regex
103          ;; fixed in 1.3.4 for powerpc -- broken on Windows
104          (regexp-substitute/global #f "\n"
105                                    (ly-gulp-file "lily.ps") 'pre " %\n" 'post)
106          (ly-gulp-file "lily.ps"))
107      "}"
108      "\\input lilyponddefs\\newdimen\\outputscale \\outputscale=\\lilypondpaperoutputscale pt\\turnOnPostScript"))
109
110   ;; Note: this string must match the string in ly2dvi.py!!!
111   (define (header creator generate) 
112     (string-append
113      "% Generated automatically by: " creator generate "\n"))
114
115   (define (invoke-char s i)
116     (string-append 
117      "\n\\" s "{" (inexact->string i 10) "}" ))
118
119   (define (invoke-dim1 s d)
120     (string-append
121      "\n\\" s "{" (number->dim d) "}"))
122   (define (pt->sp x)
123     (* 65536 x))
124   
125   ;;
126   ;; need to do something to make this really safe.
127   ;;
128   (define (output-tex-string s)
129       (if security-paranoia
130           (if use-regex
131               (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
132               (begin (display "warning: not paranoid") (newline) s))
133           s))
134       
135   (define (lily-def key val)
136     (string-append
137      "\\def\\"
138      (if use-regex
139          ;; fixed in 1.3.4 for powerpc -- broken on Windows
140          (regexp-substitute/global #f "_"
141                                    (output-tex-string key) 'pre "X" 'post)
142          (output-tex-string key))
143      "{" (output-tex-string val) "}\n"))
144
145   (define (number->dim x)
146     (string-append
147      ;;ugh ly-* in backend needs compatibility func for standalone output
148      (ly-number->string x) " \\outputscale "))
149
150   (define (placebox x y s) 
151     (string-append 
152      "\\placebox{"
153      (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
154
155   (define (bezier-sandwich l thick)
156     (embedded-ps ((ps-scm 'bezier-sandwich) l thick)))
157
158   (define (start-line ht)
159       (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
160
161   (define (stop-line) 
162     "}\\vss}\\interscoreline\n")
163   (define (stop-last-line)
164     "}\\vss}")
165   (define (filledbox breapth width depth height) 
166     (string-append 
167      "\\kern" (number->dim (- breapth))
168      "\\vrule width " (number->dim (+ breapth width))
169      "depth " (number->dim depth)
170      "height " (number->dim height) " "))
171
172   (define (text s)
173     (string-append "\\hbox{" (output-tex-string s) "}"))
174   
175   (define (tuplet ht gapx dx dy thick dir)
176     (embedded-ps ((ps-scm 'tuplet) ht gapx dx dy thick dir)))
177
178   (define (volta h w thick vert_start vert_end)
179     (embedded-ps ((ps-scm 'volta) h w thick vert_start vert_end)))
180
181   (define (define-origin file line col)
182     ; use this for column positions
183     (if point-and-click
184         ; ly-number->string breaks point-and-click
185         (string-append "\\special{src:"
186                        (number->string line) ":"
187                        (number->string col) " "
188                        file "}"
189          ;; arg, the clueless take over the mailing list...
190 ;        "\\special{-****-These-warnings-are-harmless-***}"
191 ;        "\\special{-****-PLEASE-read-http://appel.lilypond.org/wiki/index.php3?PostProcessing-****}"
192         )
193      "")
194
195      ; line numbers only:
196     ;(string-append "\\special{src:" (number->string line) " " file "}")
197 )
198
199   ; no-origin not yet supported by Xdvi
200   (define (no-origin) "")
201   
202   ;; TeX
203   ;; The procedures listed below form the public interface of TeX-scm.
204   ;; (should merge the 2 lists)
205   (cond ((eq? action-name 'all-definitions)
206          `(begin
207             (define font-load-command ,font-load-command)
208             (define beam ,beam)
209             (define bezier-sandwich ,bezier-sandwich)
210             (define bracket ,bracket)
211             (define char ,char)
212             (define crescendo ,crescendo)
213             (define dashed-line ,dashed-line) 
214             (define dashed-slur ,dashed-slur) 
215             (define decrescendo ,decrescendo) 
216             (define end-output ,end-output)
217             (define experimental-on ,experimental-on)
218             (define filledbox ,filledbox)
219             (define font-def ,font-def)
220             (define font-switch ,font-switch)
221             (define header-end ,header-end)
222             (define lily-def ,lily-def)
223             (define ez-ball ,ez-ball)
224             (define header ,header) 
225             (define invoke-char ,invoke-char) 
226             (define invoke-dim1 ,invoke-dim1)
227             (define placebox ,placebox)
228             (define select-font ,select-font)
229             (define start-line ,start-line)
230             (define stop-line ,stop-line)
231             (define stop-last-line ,stop-last-line)
232             (define text ,text)
233             (define tuplet ,tuplet)
234             (define volta ,volta)
235             (define define-origin ,define-origin)
236             (define no-origin ,no-origin)
237             ))
238
239         ((eq? action-name 'beam) beam)
240         ((eq? action-name 'tuplet) tuplet)
241         ((eq? action-name 'bracket) bracket)
242         ((eq? action-name 'crescendo) crescendo)
243         ((eq? action-name 'dashed-line) dashed-line) 
244         ((eq? action-name 'dashed-slur) dashed-slur) 
245         ((eq? action-name 'decrescendo) decrescendo) 
246         ((eq? action-name 'end-output) end-output)
247         ((eq? action-name 'experimental-on) experimental-on)
248         ((eq? action-name 'font-def) font-def)
249         ((eq? action-name 'font-switch) font-switch)
250         ((eq? action-name 'header-end) header-end)
251         ((eq? action-name 'lily-def) lily-def)
252         ((eq? action-name 'header) header) 
253         ((eq? action-name 'invoke-char) invoke-char) 
254         ((eq? action-name 'invoke-dim1) invoke-dim1)
255         ((eq? action-name 'placebox) placebox)
256         ((eq? action-name 'bezier-sandwich) bezier-sandwich)
257         ((eq? action-name 'start-line) start-line)
258         ((eq? action-name 'stem) stem)
259         ((eq? action-name 'stop-line) stop-line)
260         ((eq? action-name 'stop-last-line) stop-last-line)
261         ((eq? action-name 'volta) volta)
262         (else (error "unknown tag -- PS-TEX " action-name))
263         )
264   )
265
266 (define (scm-tex-output)
267   (ly-eval (tex-scm 'all-definitions)))