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 :export (tex-output-expression)
22 (define this-module (current-module))
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 l)))
92 (define (hairpin thick w sh eh)
93 (embedded-ps (list 'hairpin thick w sh eh))
97 (string-append "\\char" (inexact->string i 10) " "))
99 (define (dashed-line thick on off dx dy)
100 (embedded-ps (list 'dashed-line thick on off dx dy)))
102 (define (font-load-command name-mag command)
104 "\\font\\" command "="
107 (ly-number->string (inexact->exact (* 1000 (cdr name-mag))))
110 (define (ez-ball c l b)
111 (embedded-ps (list 'ez-ball c l b)))
113 (define (header-to-file fn key val)
114 (set! key (symbol->string key))
115 (if (not (equal? "-" fn))
116 (set! fn (string-append fn "." key))
119 (format "writing header field `~a' to `~a'..."
121 (if (equal? "-" fn) "<stdout>" fn)
123 (current-error-port))
126 (display val (open-file fn "w"))
128 (display "\n" (current-error-port))
133 (define (embedded-ps expr)
135 ((os (open-output-string)))
136 (ps-output-expression expr os)
137 (string-append "\\embeddedps{" (get-output-string os) "}")
141 (string-append "% " s "\n"))
145 ; uncomment for some stats about lily memory
146 ; (display (gc-stats))
147 (string-append "\n\\EndLilyPondOutput"
151 (define (experimental-on)
154 (define (repeat-slash w a t)
155 (embedded-ps (list 'repeat-slash w a t)))
157 (define (font-switch i)
161 (define (font-def i s)
163 "\\font" (font-switch i) "=" s "\n"))
167 "\\special{\\string! "
169 ;; URG: ly-gulp-file: now we can't use scm output without Lily
171 ;; fixed in 1.3.4 for powerpc -- broken on Windows
172 (regexp-substitute/global #f "\n"
173 (ly-gulp-file "music-drawing-routines.ps") 'pre " %\n" 'post)
174 (ly-gulp-file "music-drawing-routines.ps"))
175 (if (defined? 'ps-testing) "/testing true def%\n" "")
177 "\\input lilyponddefs \\outputscale=\\lilypondpaperoutputscale pt\\turnOnPostScript"))
179 ;; Note: this string must match the string in ly2dvi.py!!!
180 (define (header creator generate)
182 "% Generated automatically by: " creator generate "\n"))
184 (define (invoke-char s i)
186 "\n\\" s "{" (inexact->string i 10) "}" ))
188 (define (invoke-dim1 s d)
190 "\n\\" s "{" (number->dim d) "}"))
195 ;; need to do something to make this really safe.
197 (define (output-tex-string s)
198 (if security-paranoia
200 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
201 (begin (display "warning: not paranoid") (newline) s))
204 (define (lily-def key val)
207 ;; fixed in 1.3.4 for powerpc -- broken on Windows
208 (regexp-substitute/global
209 #f "_" (output-tex-string key) 'pre "X" 'post)
210 (output-tex-string key)))
211 (tex-val (output-tex-string val)))
212 (if (equal? (sans-surrounding-whitespace tex-val) "")
213 (string-append "\\let\\" tex-key "\\undefined\n")
214 (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
216 (define (number->dim x)
218 ;;ugh ly-* in backend needs compatibility func for standalone output
219 (ly-number->string x) " \\outputscale "))
221 (define (placebox x y s)
224 (number->dim y) "}{" (number->dim x) "}{" s "}%\n"))
226 (define (bezier-sandwich l thick)
227 (embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
229 (define (start-line ht)
230 (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
233 "}\\vss}\\interscoreline\n")
234 (define (stop-last-line)
237 (define (filledbox breapth width depth height)
238 (if (defined? 'ps-testing)
240 (string-append (numbers->string (list breapth width depth height))
243 "\\kern" (number->dim (- breapth))
244 "\\vrule width " (number->dim (+ breapth width))
245 "depth " (number->dim depth)
246 "height " (number->dim height) " ")))
249 (string-append "\\hbox{" (output-tex-string s) "}"))
251 (define (tuplet ht gapx dx dy thick dir)
252 (embedded-ps (list 'tuplet ht gapx dx dy thick dir)))
254 (define (volta h w thick vert_start vert_end)
255 (embedded-ps (list 'volta h w thick vert_start vert_end)))
256 (define (between-system-string string)
259 (define (define-origin file line col)
260 (if (procedure? point-and-click)
261 (string-append "\\special{src\\string:"
262 (point-and-click line col file)
267 ; no-origin not yet supported by Xdvi
268 (define (no-origin) "")
270 (define (tex-output-expression expr port)
271 (display (eval expr this-module) port )