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)
19 (define this-module (current-module))
25 (define font-name-alist '())
27 (define (tex-encoded-fontswitch name-mag)
28 (let* ((iname-mag (car name-mag))
29 (ename-mag (cdr name-mag)))
32 (string-append "magfont"
33 (string-encode-integer
34 (hashq (car ename-mag) 1000000))
36 (string-encode-integer
37 (inexact->exact (* 1000 (cdr ename-mag)))))))))
39 (define (define-fonts internal-external-name-mag-pairs)
40 (set! font-name-alist (map tex-encoded-fontswitch
41 internal-external-name-mag-pairs))
44 (font-load-command (car x) (cdr x)))
45 (map cdr font-name-alist))))
49 ;; urg, how can exp be #unspecified? -- in sketch output
51 ;; set! returns #<unspecified> --hwn
52 (define (fontify name-mag-pair exp)
53 (string-append (select-font name-mag-pair)
60 (define (select-font name-mag-pair)
63 (c (assoc name-mag-pair font-name-alist))
69 (display (object-type (car name-mag-pair)))
70 (display (object-type (caaar font-name-alist)))
72 (ly-warn (string-append
73 "Programming error: No such font known "
74 (car name-mag-pair) " "
75 (ly-number->string (cdr name-mag-pair))
77 "") ; issue no command
78 (string-append "\\" (cddr c)))
83 (define (beam width slope thick)
84 (embedded-ps (list 'beam width slope thick)))
86 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
87 (embedded-ps (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
89 (define (dashed-slur thick dash l)
90 (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
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 (if (or (equal? (minor-version) "4.1")
129 (equal? (minor-version) "4")
130 (equal? (minor-version) "3.4"))
131 (define (embedded-ps expr)
133 (with-output-to-string
134 (lambda () (ps-output-expression expr (current-output-port))))))
135 (string-append "\\embeddedps{" ps-string "}")))
136 (define (embedded-ps expr)
138 ((os (open-output-string)))
139 (ps-output-expression expr os)
140 (string-append "\\embeddedps{" (get-output-string os) "}"))))
143 (string-append "% " s "\n"))
147 ; uncomment for some stats about lily memory
148 ; (display (gc-stats))
149 (string-append "\n\\EndLilyPondOutput\n"
153 (define (experimental-on)
156 (define (repeat-slash w a t)
157 (embedded-ps (list 'repeat-slash w a t)))
159 (define (font-switch i)
163 (define (font-def i s)
165 "\\font" (font-switch i) "=" s "\n"))
169 "\\def\\scaletounit{ "
170 (number->string (cond
171 ((equal? (ly-unit) "mm") (/ 72.0 25.4))
172 ((equal? (ly-unit) "pt") (/ 72.0 72.27))
173 (else (error "unknown unit" (ly-unit)))
176 "\\special{\\string! "
178 ;; URG: ly-gulp-file: now we can't use scm output without Lily
180 ;; fixed in 1.3.4 for powerpc -- broken on Windows
181 (regexp-substitute/global #f "\n"
182 (ly-gulp-file "music-drawing-routines.ps") 'pre " %\n" 'post)
183 (ly-gulp-file "music-drawing-routines.ps"))
184 ; (if (defined? 'ps-testing) "/testing true def%\n" "")
186 "\\input lilyponddefs \\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit"
187 "\\turnOnPostScript"))
189 ;; Note: this string must match the string in ly2dvi.py!!!
190 (define (header creator generate)
192 "% Generated automatically by: " creator generate "\n"))
194 (define (invoke-char s i)
196 "\n\\" s "{" (inexact->string i 10) "}" ))
199 ;; need to do something to make this really safe.
201 (define-public (output-tex-string s)
202 (if security-paranoia
204 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
205 (begin (display "warning: not paranoid") (newline) s))
208 (define (lily-def key val)
211 ;; fixed in 1.3.4 for powerpc -- broken on Windows
212 (regexp-substitute/global
213 #f "_" (output-tex-string key) 'pre "X" 'post)
214 (output-tex-string key)))
215 (tex-val (output-tex-string val)))
216 (if (equal? (sans-surrounding-whitespace tex-val) "")
217 (string-append "\\let\\" tex-key "\\undefined\n")
218 (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
220 (define (number->dim x)
222 ;;ugh ly-* in backend needs compatibility func for standalone output
223 (ly-number->string x) " \\outputscale "))
225 (define (placebox x y s)
228 (number->dim y) "}{" (number->dim x) "}{" s "}%\n"))
230 (define (bezier-bow l thick)
231 (embedded-ps (list 'bezier-bow `(quote ,l) thick)))
233 (define (bezier-sandwich l thick)
234 (embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
236 (define (start-system ht)
237 (string-append "\\vbox to " (number->dim ht) "{\\hbox{"
240 (define (stop-system)
241 "}\\vss}\\interscoreline\n")
242 (define (stop-last-system)
245 (define (filledbox breapth width depth height)
246 (if (and #f (defined? 'ps-testing))
248 (string-append (numbers->string (list breapth width depth height))
251 "\\kern" (number->dim (- breapth))
252 "\\vrule width " (number->dim (+ breapth width))
253 "depth " (number->dim depth)
254 "height " (number->dim height) " ")))
256 (define (roundfilledbox x y width height blotdiam)
257 (embedded-ps (list 'roundfilledbox x y width height blotdiam)))
260 (string-append "\\hbox{" (output-tex-string s) "}"))
262 (define (tuplet ht gapx dx dy thick dir)
263 (embedded-ps (list 'tuplet ht gapx dx dy thick dir)))
265 (define (draw-line thick fx fy tx ty)
266 (embedded-ps (list 'draw-line thick fx fy tx ty)))
268 (define (between-system-string string)
271 (define (define-origin file line col)
272 (if (procedure? point-and-click)
273 (string-append "\\special{src:" ;;; \\string ?
274 (point-and-click line col file)
279 ; no-origin not yet supported by Xdvi
280 (define (no-origin) "")
282 (define my-eval-in-module eval)
284 (if (or (equal? (minor-version) "4.1")
285 (equal? (minor-version) "4")
286 (equal? (minor-version) "3.4"))
287 (set! my-eval-in-module eval-in-module))
289 (define-public (tex-output-expression expr port)
290 (display (my-eval-in-module expr this-module) port )