1 ;;; pdftex.scm -- implement Scheme output routines for PDFTeX
3 ;;; source file of the GNU LilyPond music typesetter
4 ;;; modified from the existing tex.scm
6 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 ;;; Stephen Peters <portnoy@portnoy.org>
10 (define (pdftex-scm action-name)
15 (define (select-font name-mag-pair)
18 (c (assoc name-mag-pair font-name-alist))
24 (display (object-type (car name-mag-pair)))
25 (display (object-type (caaar font-name-alist)))
27 (ly-warn (string-append
28 "Programming error: No such font known "
29 (car name-mag-pair) " "
30 (ly-number->string (cdr name-mag-pair))
32 "") ; issue no command
33 (string-append "\\" (cddr c)))
38 (define (beam width slope thick)
39 (embedded-pdf ((pdf-scm 'beam) width slope thick)))
41 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
42 (embedded-pdf ((pdf-scm 'bracket) arch_angle arch_width arch_height height arch_thick thick)))
44 (define (dashed-slur thick dash l)
45 (embedded-pdf ((pdf-scm 'dashed-slur) thick dash l)))
47 (define (hairpin thick w sh eh)
48 (embedded-pdf ((pdf-scm 'hairpin) thick w sh eh)))
51 (string-append "\\char" (inexact->string i 10) " "))
53 (define (dashed-line thick on off dx dy)
54 (embedded-pdf ((pdf-scm 'dashed-line) thick on off dx dy)))
56 (define (font-load-command name-mag command)
58 "\\font\\" command "="
61 (ly-number->string (inexact->exact (* 1000 (cdr name-mag))))
64 (define (ez-ball c l b)
65 (embedded-pdf ((pdf-scm 'ez-ball) c l b)))
67 (define (embedded-pdf s)
68 (string-append "\\embeddedpdf{ " s "}"))
71 (string-append "% " s))
75 ; uncomment for some stats about lily memory
76 ; (display (gc-stats))
77 (string-append "\n\\EndLilyPondOutput"
81 (define (experimental-on)
84 (define (repeat-slash w a t)
85 (embedded-pdf ((pdf-scm 'repeat-slash) w a t)))
87 (define (font-switch i)
91 (define (font-def i s)
93 "\\font" (font-switch i) "=" s "\n"))
97 "\\input lilyponddefs\\newdimen\\outputscale \\outputscale=\\lilypondpaperoutputscale pt"
99 "\\pdfcompresslevel=0"))
101 ;; Note: this string must match the string in ly2dvi.py!!!
102 (define (header creator generate)
104 "% Generated automatically by: " creator generate "\n"))
106 (define (invoke-char s i)
108 "\n\\" s "{" (inexact->string i 10) "}" ))
110 (define (invoke-dim1 s d)
112 "\n\\" s "{" (number->dim d) "}"))
117 ;; need to do something to make this really safe.
119 (define (output-tex-string s)
120 (if security-paranoia
122 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
123 (begin (display "warning: not paranoid") (newline) s))
126 (define (lily-def key val)
129 (regexp-substitute/global
130 #f "_" (output-tex-string key) 'pre "X" 'post)
131 (output-tex-string key)))
132 (tex-val (output-tex-string val)))
133 (if (equal? (sans-surrounding-whitespace tex-val) "")
134 (string-append "\\let\\" tex-key "\\undefined\n")
135 (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
137 (define (number->dim x)
139 ;;ugh ly-* in backend needs compatibility func for standalone output
140 (ly-number->string x) " \\outputscale "))
142 (define (placebox x y s)
145 (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
147 (define (bezier-sandwich l thick)
148 (embedded-pdf ((pdf-scm 'bezier-sandwich) l thick)))
150 (define (start-line ht)
151 (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
154 "}\\vss}\\interscoreline\n")
155 (define (stop-last-line)
157 (define (filledbox breapth width depth height)
159 "\\kern" (number->dim (- breapth))
160 "\\vrule width " (number->dim (+ breapth width))
161 "depth " (number->dim depth)
162 "height " (number->dim height) " "))
165 (string-append "\\hbox{" (output-tex-string s) "}"))
167 (define (tuplet ht gapx dx dy thick dir)
168 (embedded-pdf ((pdf-scm 'tuplet) ht gapx dx dy thick dir)))
170 (define (volta h w thick vert_start vert_end)
171 (embedded-pdf ((pdf-scm 'volta) h w thick vert_start vert_end)))
173 (define (define-origin file line col)
174 (if (procedure? point-and-click)
175 (string-append "\\special{src:\\string:"
176 (point-and-click line col file)
181 ; no-origin not supported in PDFTeX
182 (define (no-origin) "")
184 ;; The procedures listed below form the public interface of
185 ;; PDFTeX-scm. (should merge the 2 lists)
186 (cond ((eq? action-name 'all-definitions)
188 (define font-load-command ,font-load-command)
190 (define bezier-sandwich ,bezier-sandwich)
191 (define bracket ,bracket)
193 (define dashed-line ,dashed-line)
194 (define dashed-slur ,dashed-slur)
195 (define hairpin ,hairpin)
196 (define end-output ,end-output)
197 (define experimental-on ,experimental-on)
198 (define filledbox ,filledbox)
199 (define font-def ,font-def)
200 (define font-switch ,font-switch)
201 (define header-end ,header-end)
202 (define lily-def ,lily-def)
203 (define ez-ball ,ez-ball)
204 (define header ,header)
205 (define invoke-char ,invoke-char)
206 (define invoke-dim1 ,invoke-dim1)
207 (define placebox ,placebox)
208 (define select-font ,select-font)
209 (define start-line ,start-line)
210 (define stop-line ,stop-line)
211 (define stop-last-line ,stop-last-line)
213 (define tuplet ,tuplet)
214 (define volta ,volta)
215 (define define-origin ,define-origin)
216 (define no-origin ,no-origin)
217 (define repeat-slash ,repeat-slash)
220 ((eq? action-name 'beam) beam)
221 ((eq? action-name 'tuplet) tuplet)
222 ((eq? action-name 'bracket) bracket)
223 ((eq? action-name 'hairpin) hairpin)
224 ((eq? action-name 'dashed-line) dashed-line)
225 ((eq? action-name 'dashed-slur) dashed-slur)
226 ((eq? action-name 'end-output) end-output)
227 ((eq? action-name 'experimental-on) experimental-on)
228 ((eq? action-name 'font-def) font-def)
229 ((eq? action-name 'font-switch) font-switch)
230 ((eq? action-name 'header-end) header-end)
231 ((eq? action-name 'lily-def) lily-def)
232 ((eq? action-name 'header) header)
233 ((eq? action-name 'invoke-char) invoke-char)
234 ((eq? action-name 'invoke-dim1) invoke-dim1)
235 ((eq? action-name 'placebox) placebox)
236 ((eq? action-name 'bezier-sandwich) bezier-sandwich)
237 ((eq? action-name 'start-line) start-line)
238 ((eq? action-name 'stem) stem)
239 ((eq? action-name 'stop-line) stop-line)
240 ((eq? action-name 'stop-last-line) stop-last-line)
241 ((eq? action-name 'volta) volta)
242 ((eq? action-name 'repeat-slash) repeat-slash)
243 (else (error "unknown tag -- PDFTEX " action-name))
247 (define (scm-pdftex-output)
248 (primitive-eval (pdftex-scm 'all-definitions)))