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>
9 (define-module (scm tex) )
10 (debug-enable 'backtrace)
18 (define this-module (current-module))
23 (define (tex-encoded-fontswitch name-mag)
24 (let* ((iname-mag (car name-mag))
25 (ename-mag (cdr name-mag)))
28 (string-append "magfont"
29 (string-encode-integer
30 (hashq (car ename-mag) 1000000))
32 (string-encode-integer
33 (inexact->exact (* 1000 (cdr ename-mag)))))))))
35 (define (define-fonts internal-external-name-mag-pairs)
36 (set! font-name-alist (map tex-encoded-fontswitch
37 internal-external-name-mag-pairs))
40 (font-load-command (car x) (cdr x)))
41 (map cdr font-name-alist))))
45 ;; urg, how can exp be #unspecified? -- in sketch output
47 ;; set! returns #<unspecified> --hwn
48 (define (fontify name-mag-pair exp)
49 (string-append (select-font name-mag-pair)
56 (define (select-font name-mag-pair)
59 (c (assoc name-mag-pair font-name-alist))
65 (display (object-type (car name-mag-pair)))
66 (display (object-type (caaar font-name-alist)))
68 (ly-warn (string-append
69 "Programming error: No such font known "
70 (car name-mag-pair) " "
71 (ly-number->string (cdr name-mag-pair))
73 "") ; issue no command
74 (string-append "\\" (cddr c)))
79 (define (beam width slope thick)
80 (embedded-ps (list 'beam width slope thick)))
82 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
83 (embedded-ps (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
85 (define (dashed-slur thick dash l)
86 (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
88 (define (hairpin thick w sh eh)
89 (embedded-ps (list 'hairpin thick w sh eh))
93 (string-append "\\char" (inexact->string i 10) " "))
95 (define (dashed-line thick on off dx dy)
96 (embedded-ps (list 'dashed-line thick on off dx dy)))
98 (define (font-load-command name-mag command)
100 "\\font\\" command "="
103 (ly-number->string (inexact->exact (* 1000 (cdr name-mag))))
106 (define (ez-ball c l b)
107 (embedded-ps (list 'ez-ball c l b)))
109 (define (header-to-file fn key val)
110 (set! key (symbol->string key))
111 (if (not (equal? "-" fn))
112 (set! fn (string-append fn "." key))
115 (format "writing header field `~a' to `~a'..."
117 (if (equal? "-" fn) "<stdout>" fn)
119 (current-error-port))
122 (display val (open-file fn "w"))
124 (display "\n" (current-error-port))
128 (define (embedded-ps expr)
130 ((os (open-output-string)))
131 (ps-output-expression expr os)
132 (string-append "\\embeddedps{" (get-output-string os) "}")
136 (string-append "% " s "\n"))
140 ; uncomment for some stats about lily memory
141 ; (display (gc-stats))
142 (string-append "\n\\EndLilyPondOutput"
146 (define (experimental-on)
149 (define (repeat-slash w a t)
150 (embedded-ps (list 'repeat-slash w a t)))
152 (define (font-switch i)
156 (define (font-def i s)
158 "\\font" (font-switch i) "=" s "\n"))
162 "\\special{\\string! "
164 ;; URG: ly-gulp-file: now we can't use scm output without Lily
166 ;; fixed in 1.3.4 for powerpc -- broken on Windows
167 (regexp-substitute/global #f "\n"
168 (ly-gulp-file "music-drawing-routines.ps") 'pre " %\n" 'post)
169 (ly-gulp-file "music-drawing-routines.ps"))
170 (if (defined? 'ps-testing) "/testing true def%\n" "")
172 "\\input lilyponddefs \\outputscale=\\lilypondpaperoutputscale pt\\turnOnPostScript"))
174 ;; Note: this string must match the string in ly2dvi.py!!!
175 (define (header creator generate)
177 "% Generated automatically by: " creator generate "\n"))
179 (define (invoke-char s i)
181 "\n\\" s "{" (inexact->string i 10) "}" ))
183 (define (invoke-dim1 s d)
185 "\n\\" s "{" (number->dim d) "}"))
190 ;; need to do something to make this really safe.
192 (define-public (output-tex-string s)
193 (if security-paranoia
195 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
196 (begin (display "warning: not paranoid") (newline) s))
199 (define (lily-def key val)
202 ;; fixed in 1.3.4 for powerpc -- broken on Windows
203 (regexp-substitute/global
204 #f "_" (output-tex-string key) 'pre "X" 'post)
205 (output-tex-string key)))
206 (tex-val (output-tex-string val)))
207 (if (equal? (sans-surrounding-whitespace tex-val) "")
208 (string-append "\\let\\" tex-key "\\undefined\n")
209 (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
211 (define (number->dim x)
213 ;;ugh ly-* in backend needs compatibility func for standalone output
214 (ly-number->string x) " \\outputscale "))
216 (define (placebox x y s)
219 (number->dim y) "}{" (number->dim x) "}{" s "}%\n"))
221 (define (bezier-sandwich l thick)
222 (embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
224 (define (start-line ht)
225 (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
228 "}\\vss}\\interscoreline\n")
229 (define (stop-last-line)
232 (define (filledbox breapth width depth height)
233 (if (defined? 'ps-testing)
235 (string-append (numbers->string (list breapth width depth height))
238 "\\kern" (number->dim (- breapth))
239 "\\vrule width " (number->dim (+ breapth width))
240 "depth " (number->dim depth)
241 "height " (number->dim height) " ")))
244 (string-append "\\hbox{" (output-tex-string s) "}"))
246 (define (tuplet ht gapx dx dy thick dir)
247 (embedded-ps (list 'tuplet ht gapx dx dy thick dir)))
249 (define (volta h w thick vert_start vert_end)
250 (embedded-ps (list 'volta h w thick vert_start vert_end)))
251 (define (between-system-string string)
254 (define (define-origin file line col)
255 (if (procedure? point-and-click)
256 (string-append "\\special{src\\string:"
257 (point-and-click line col file)
262 ; no-origin not yet supported by Xdvi
263 (define (no-origin) "")
265 (define my-eval-in-module eval)
267 (if (or (equal? (minor-version) "4")
268 (equal? (minor-version) "3.4"))
270 (set! my-eval-in-module eval-in-module)
274 (define-public (tex-output-expression expr port)
275 (display (my-eval-in-module expr this-module) port )