1 ;;; tex.scm -- implement Scheme output routines for TeX
3 ;;; source file of the GNU LilyPond music typesetter
5 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 ;; todo: this dispatch is totally LAME
13 (define (tex-scm action-name)
18 (define (select-font name-mag-pair)
21 (c (assoc name-mag-pair font-name-alist))
27 (display (object-type (car name-mag-pair)))
28 (display (object-type (caaar font-name-alist)))
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))
35 "") ; issue no command
36 (string-append "\\" (cddr c)))
41 (define (beam width slope thick)
42 (embedded-ps ((ps-scm 'beam) width slope thick)))
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)))
47 (define (dashed-slur thick dash l)
48 (embedded-ps ((ps-scm 'dashed-slur) thick dash l)))
50 (define (hairpin thick w sh eh)
51 (embedded-ps ((ps-scm 'hairpin) thick w sh eh)))
54 (string-append "\\char" (inexact->string i 10) " "))
56 (define (dashed-line thick on off dx dy)
57 (embedded-ps ((ps-scm 'dashed-line) thick on off dx dy)))
59 (define (font-load-command name-mag command)
61 "\\font\\" command "="
64 (ly-number->string (inexact->exact (* 1000 (cdr name-mag))))
67 (define (ez-ball c l b)
68 (embedded-ps ((ps-scm 'ez-ball) c l b)))
69 (define (embedded-ps s)
70 (string-append "\\embeddedps{" s "}"))
73 (string-append "% " s))
77 ; uncomment for some stats about lily memory
78 ; (display (gc-stats))
79 (string-append "\n\\EndLilyPondOutput"
83 (define (experimental-on)
86 (define (repeat-slash w a t)
87 (embedded-ps ((ps-scm 'repeat-slash) w a t)))
89 (define (font-switch i)
93 (define (font-def i s)
95 "\\font" (font-switch i) "=" s "\n"))
101 ;; URG: ly-gulp-file: now we can't use scm output without Lily
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"))
108 "\\input lilyponddefs\\newdimen\\outputscale \\outputscale=\\lilypondpaperoutputscale pt\\turnOnPostScript"))
110 ;; Note: this string must match the string in ly2dvi.py!!!
111 (define (header creator generate)
113 "% Generated automatically by: " creator generate "\n"))
115 (define (invoke-char s i)
117 "\n\\" s "{" (inexact->string i 10) "}" ))
119 (define (invoke-dim1 s d)
121 "\n\\" s "{" (number->dim d) "}"))
126 ;; need to do something to make this really safe.
128 (define (output-tex-string s)
129 (if security-paranoia
131 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
132 (begin (display "warning: not paranoid") (newline) s))
135 (define (lily-def key val)
138 ;; fixed in 1.3.4 for powerpc -- broken on Windows
139 (regexp-substitute/global
140 #f "_" (output-tex-string key) 'pre "X" 'post)
141 (output-tex-string key)))
142 (tex-val (output-tex-string val)))
143 (if (equal? (sans-surrounding-whitespace tex-val) "")
144 (string-append "\\let\\" tex-key "\\undefined\n")
145 (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
147 (define (number->dim x)
149 ;;ugh ly-* in backend needs compatibility func for standalone output
150 (ly-number->string x) " \\outputscale "))
152 (define (placebox x y s)
155 (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
157 (define (bezier-sandwich l thick)
158 (embedded-ps ((ps-scm 'bezier-sandwich) l thick)))
160 (define (start-line ht)
161 (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
164 "}\\vss}\\interscoreline\n")
165 (define (stop-last-line)
167 (define (filledbox breapth width depth height)
169 "\\kern" (number->dim (- breapth))
170 "\\vrule width " (number->dim (+ breapth width))
171 "depth " (number->dim depth)
172 "height " (number->dim height) " "))
175 (string-append "\\hbox{" (output-tex-string s) "}"))
177 (define (tuplet ht gapx dx dy thick dir)
178 (embedded-ps ((ps-scm 'tuplet) ht gapx dx dy thick dir)))
180 (define (volta h w thick vert_start vert_end)
181 (embedded-ps ((ps-scm 'volta) h w thick vert_start vert_end)))
183 (define (define-origin file line col)
184 (if (procedure? point-and-click)
185 (string-append "\\special{src:"
186 (point-and-click line col file)
191 ; no-origin not yet supported by Xdvi
192 (define (no-origin) "")
195 ;; The procedures listed below form the public interface of TeX-scm.
196 ;; (should merge the 2 lists)
197 (cond ((eq? action-name 'all-definitions)
199 (define font-load-command ,font-load-command)
201 (define bezier-sandwich ,bezier-sandwich)
202 (define bracket ,bracket)
204 (define dashed-line ,dashed-line)
205 (define dashed-slur ,dashed-slur)
206 (define hairpin ,hairpin)
207 (define end-output ,end-output)
208 (define experimental-on ,experimental-on)
209 (define filledbox ,filledbox)
210 (define font-def ,font-def)
211 (define font-switch ,font-switch)
212 (define header-end ,header-end)
213 (define lily-def ,lily-def)
214 (define ez-ball ,ez-ball)
215 (define header ,header)
216 (define invoke-char ,invoke-char)
217 (define invoke-dim1 ,invoke-dim1)
218 (define placebox ,placebox)
219 (define select-font ,select-font)
220 (define start-line ,start-line)
221 (define stop-line ,stop-line)
222 (define stop-last-line ,stop-last-line)
224 (define tuplet ,tuplet)
225 (define volta ,volta)
226 (define define-origin ,define-origin)
227 (define no-origin ,no-origin)
228 (define repeat-slash ,repeat-slash)
231 ((eq? action-name 'beam) beam)
232 ((eq? action-name 'tuplet) tuplet)
233 ((eq? action-name 'bracket) bracket)
234 ((eq? action-name 'hairpin) hairpin)
235 ((eq? action-name 'dashed-line) dashed-line)
236 ((eq? action-name 'dashed-slur) dashed-slur)
237 ((eq? action-name 'end-output) end-output)
238 ((eq? action-name 'experimental-on) experimental-on)
239 ((eq? action-name 'font-def) font-def)
240 ((eq? action-name 'font-switch) font-switch)
241 ((eq? action-name 'header-end) header-end)
242 ((eq? action-name 'lily-def) lily-def)
243 ((eq? action-name 'header) header)
244 ((eq? action-name 'invoke-char) invoke-char)
245 ((eq? action-name 'invoke-dim1) invoke-dim1)
246 ((eq? action-name 'placebox) placebox)
247 ((eq? action-name 'bezier-sandwich) bezier-sandwich)
248 ((eq? action-name 'start-line) start-line)
249 ((eq? action-name 'stem) stem)
250 ((eq? action-name 'stop-line) stop-line)
251 ((eq? action-name 'stop-last-line) stop-last-line)
252 ((eq? action-name 'volta) volta)
253 (else (error "unknown tag -- PS-TEX " action-name))
257 (define (scm-tex-output)
258 (ly-eval (tex-scm 'all-definitions)))