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 (if (or (equal? (minor-version) "4")
129 (equal? (minor-version) "3.4"))
130 (define (embedded-ps expr)
132 (with-output-to-string
133 (lambda () (ps-output-expression expr (current-output-port))))))
134 (string-append "\\embeddedps{" ps-string "}")))
135 (define (embedded-ps expr)
137 ((os (open-output-string)))
138 (ps-output-expression expr os)
139 (string-append "\\embeddedps{" (get-output-string os) "}"))))
142 (string-append "% " s "\n"))
146 ; uncomment for some stats about lily memory
147 ; (display (gc-stats))
148 (string-append "\n\\EndLilyPondOutput"
152 (define (experimental-on)
155 (define (repeat-slash w a t)
156 (embedded-ps (list 'repeat-slash w a t)))
158 (define (font-switch i)
162 (define (font-def i s)
164 "\\font" (font-switch i) "=" s "\n"))
168 "\\def\\scaletounit{ "
169 (number->string (cond
170 ((equal? (ly-unit) "mm") (/ 72.0 25.4))
171 ((equal? (ly-unit) "pt") (/ 72.0 72.27))
172 (else (error "unknown unit" (ly-unit)))
175 "\\special{\\string! "
177 ;; URG: ly-gulp-file: now we can't use scm output without Lily
179 ;; fixed in 1.3.4 for powerpc -- broken on Windows
180 (regexp-substitute/global #f "\n"
181 (ly-gulp-file "music-drawing-routines.ps") 'pre " %\n" 'post)
182 (ly-gulp-file "music-drawing-routines.ps"))
183 (if (defined? 'ps-testing) "/testing true def%\n" "")
185 "\\input lilyponddefs \\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit"
186 "\\turnOnPostScript"))
188 ;; Note: this string must match the string in ly2dvi.py!!!
189 (define (header creator generate)
191 "% Generated automatically by: " creator generate "\n"))
193 (define (invoke-char s i)
195 "\n\\" s "{" (inexact->string i 10) "}" ))
198 ;; need to do something to make this really safe.
200 (define-public (output-tex-string s)
201 (if security-paranoia
203 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
204 (begin (display "warning: not paranoid") (newline) s))
207 (define (lily-def key val)
210 ;; fixed in 1.3.4 for powerpc -- broken on Windows
211 (regexp-substitute/global
212 #f "_" (output-tex-string key) 'pre "X" 'post)
213 (output-tex-string key)))
214 (tex-val (output-tex-string val)))
215 (if (equal? (sans-surrounding-whitespace tex-val) "")
216 (string-append "\\let\\" tex-key "\\undefined\n")
217 (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
219 (define (number->dim x)
221 ;;ugh ly-* in backend needs compatibility func for standalone output
222 (ly-number->string x) " \\outputscale "))
224 (define (placebox x y s)
227 (number->dim y) "}{" (number->dim x) "}{" s "}%\n"))
229 (define (bezier-sandwich l thick)
230 (embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
232 (define (start-line ht)
233 (string-append "\\vbox to " (number->dim ht) "{\\hbox{"
237 "}\\vss}\\interscoreline\n")
238 (define (stop-last-line)
241 (define (filledbox breapth width depth height)
242 (if (defined? 'ps-testing)
244 (string-append (numbers->string (list breapth width depth height))
247 "\\kern" (number->dim (- breapth))
248 "\\vrule width " (number->dim (+ breapth width))
249 "depth " (number->dim depth)
250 "height " (number->dim height) " ")))
252 (define (roundfilledbox x y width height blotdiam)
253 (embedded-ps (list 'roundfilledbox x y width height blotdiam)))
256 (string-append "\\hbox{" (output-tex-string s) "}"))
258 (define (tuplet ht gapx dx dy thick dir)
259 (embedded-ps (list 'tuplet ht gapx dx dy thick dir)))
261 (define (volta h w thick vert_start vert_end)
262 (embedded-ps (list 'volta h w thick vert_start vert_end)))
263 (define (between-system-string string)
266 (define (define-origin file line col)
267 (if (procedure? point-and-click)
268 (string-append "\\special{src:" ;;; \\string ?
269 (point-and-click line col file)
274 ; no-origin not yet supported by Xdvi
275 (define (no-origin) "")
277 (define my-eval-in-module eval)
279 (if (or (equal? (minor-version) "4")
280 (equal? (minor-version) "3.4"))
282 (set! my-eval-in-module eval-in-module)
286 (define-public (tex-output-expression expr port)
287 (display (my-eval-in-module expr this-module) port )