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>
11 ;; TODO: port this to the new module framework.
13 (define-module (scm pdftex))
15 (use-modules (scm pdf)
20 (define font-name-alist '())
22 (define this-module (current-module))
27 (define (select-font name-mag-pair)
30 (c (assoc name-mag-pair font-name-alist))
36 (display (object-type (car name-mag-pair)))
37 (display (object-type (caaar font-name-alist)))
39 (ly-warn (string-append
40 "Programming error: No such font known "
41 (car name-mag-pair) " "
42 (ly-number->string (cdr name-mag-pair))
44 "") ; issue no command
45 (string-append "\\" (cddr c)))
50 (define (beam width slope thick)
51 (embedded-pdf (list 'beam width slope thick)))
53 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
54 (embedded-pdf (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
56 (define (dashed-slur thick dash l)
57 (embedded-pdf (list 'dashed-slur thick dash l)))
60 (string-append "\\char" (inexact->string i 10) " "))
62 (define (dashed-line thick on off dx dy)
63 (embedded-pdf (list 'dashed-line thick on off dx dy)))
65 (define (font-load-command name-mag command)
67 "\\font\\" command "="
70 (ly-number->string (inexact->exact (* 1000 (cdr name-mag))))
73 (define (ez-ball c l b)
74 (embedded-pdf (list 'ez-ball c l b)))
76 (define (header-to-file fn key val)
77 (set! key (symbol->string key))
78 (if (not (equal? "-" fn))
79 (set! fn (string-append fn "." key))
82 (format "writing header field `~a' to `~a'..."
84 (if (equal? "-" fn) "<stdout>" fn)
89 (display val (open-file fn "w"))
91 (display "\n" (current-error-port))
95 (if (or (equal? (minor-version) "4.1")
96 (equal? (minor-version) "4")
97 (equal? (minor-version) "3.4"))
98 (define (embedded-pdf expr)
100 (with-output-to-string
101 (lambda () (pdf-output-expression expr (current-output-port))))))
102 (string-append "\\embeddedpdf{" ps-string "}")))
103 (define (embedded-pdf expr)
105 ((os (open-output-string)))
106 (pdf-output-expression expr os)
107 (string-append "\\embeddedpdf{" (get-output-string os) "}"))))
111 (simple-format #f "% ~a\n" s))
115 ; uncomment for some stats about lily memory
116 ; (display (gc-stats))
117 (string-append "\n\\EndLilyPondOutput"
121 (define (experimental-on)
124 (define (repeat-slash w a t)
125 (embedded-pdf (list 'repeat-slash w a t)))
126 (define (fontify name-mag-pair exp)
127 (string-append (select-font name-mag-pair)
131 (define (tex-encoded-fontswitch name-mag)
132 (let* ((iname-mag (car name-mag))
133 (ename-mag (cdr name-mag)))
136 (string-append "magfont"
137 (string-encode-integer
138 (hashq (car ename-mag) 1000000))
140 (string-encode-integer
141 (inexact->exact (* 1000 (cdr ename-mag)))))))))
142 (define (define-fonts internal-external-name-mag-pairs)
143 (set! font-name-alist (map tex-encoded-fontswitch
144 internal-external-name-mag-pairs))
147 (font-load-command (car x) (cdr x)))
148 (map cdr font-name-alist))))
151 (define (font-switch i)
155 (define (font-def i s)
157 "\\font" (font-switch i) "=" s "\n"))
161 "\\def\\lilyoutputscalefactor{"
162 (number->string (cond
163 ((equal? (ly-unit) "mm") (/ 72.0 25.4))
164 ((equal? (ly-unit) "pt") (/ 72.0 72.27))
165 (else (error "unknown unit" (ly-unit)))
168 "\\input lilyponddefs \\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit"
170 "\\pdfcompresslevel=0"))
172 ;; Note: this string must match the string in ly2dvi.py!!!
173 (define (header creator generate)
175 "% Generated automatically by: " creator generate "\n"))
177 (define (invoke-char s i)
179 "\n\\" s "{" (inexact->string i 10) "}" ))
182 ;; need to do something to make this really safe.
184 (define (output-tex-string s)
185 (if security-paranoia
186 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
189 (define (lily-def key val)
191 (regexp-substitute/global
192 #f "_" (output-tex-string key) 'pre "X" 'post)
195 (tex-val (output-tex-string val)))
196 (if (equal? (sans-surrounding-whitespace tex-val) "")
197 (string-append "\\let\\" tex-key "\\undefined\n")
198 (string-append "\\def\\" tex-key "{" tex-val "}\n")))
200 (define (number->dim x)
202 ;;ugh ly-* in backend needs compatibility func for standalone output
203 (ly-number->string x) " \\outputscale "))
205 (define (placebox x y s)
208 (number->dim y) "}{" (number->dim x) "}{" s "}%\n"))
210 (define (bezier-bow l thick)
211 (embedded-pdf (list 'bezier-bow `(quote ,l) thick)))
213 (define (bezier-sandwich l thick)
214 (embedded-pdf (list 'bezier-sandwich `(quote ,l) thick)))
216 (define (start-system ht)
217 (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
219 (define (stop-system)
220 "}\\vss}\\interscoreline\n")
221 (define (stop-last-system)
223 (define (filledbox breapth width depth height)
225 "\\kern" (number->dim (- breapth))
226 "\\vrule width " (number->dim (+ breapth width))
227 "depth " (number->dim depth)
228 "height " (number->dim height) " "))
230 (define (roundfilledbox x y width height blotdiam)
231 (embedded-pdf (list 'roundfilledbox x y width height blotdiam)))
234 (string-append "\\hbox{" (output-tex-string s) "}"))
236 (define (draw-line thick fx fy tx ty)
237 (embedded-pdf (list 'draw-line thick fx fy tx ty)))
239 (define (define-origin file line col)
240 (if (procedure? point-and-click)
241 (string-append "\\special{src:\\string:"
242 (point-and-click line col file)
247 ; no-origin not supported in PDFTeX
248 (define (no-origin) "")
252 (define my-eval-in-module eval)
254 (if (or (equal? (minor-version) "4.1")
255 (equal? (minor-version) "4")
256 (equal? (minor-version) "3.4"))
257 (set! my-eval-in-module eval-in-module))
259 (define-public (pdftex-output-expression expr port)
260 (display (my-eval-in-module expr this-module) port) )