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)
21 (define this-module (current-module))
26 (define (select-font name-mag-pair)
29 (c (assoc name-mag-pair font-name-alist))
35 (display (object-type (car name-mag-pair)))
36 (display (object-type (caaar font-name-alist)))
38 (ly-warn (string-append
39 "Programming error: No such font known "
40 (car name-mag-pair) " "
41 (ly-number->string (cdr name-mag-pair))
43 "") ; issue no command
44 (string-append "\\" (cddr c)))
49 (define (beam width slope thick)
50 (embedded-pdf (list 'beam width slope thick)))
52 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
53 (embedded-pdf (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
55 (define (dashed-slur thick dash l)
56 (embedded-pdf (list 'dashed-slur thick dash l)))
59 (string-append "\\char" (inexact->string i 10) " "))
61 (define (dashed-line thick on off dx dy)
62 (embedded-pdf (list 'dashed-line thick on off dx dy)))
64 (define (font-load-command name-mag command)
66 "\\font\\" command "="
69 (ly-number->string (inexact->exact (* 1000 (cdr name-mag))))
72 (define (ez-ball c l b)
73 (embedded-pdf (list 'ez-ball c l b)))
75 (define (header-to-file fn key val)
76 (set! key (symbol->string key))
77 (if (not (equal? "-" fn))
78 (set! fn (string-append fn "." key))
81 (format "writing header field `~a' to `~a'..."
83 (if (equal? "-" fn) "<stdout>" fn)
88 (display val (open-file fn "w"))
90 (display "\n" (current-error-port))
94 (if (or (equal? (minor-version) "4.1")
95 (equal? (minor-version) "4")
96 (equal? (minor-version) "3.4"))
97 (define (embedded-pdf expr)
99 (with-output-to-string
100 (lambda () (pdf-output-expression expr (current-output-port))))))
101 (string-append "\\embeddedpdf{" ps-string "}")))
102 (define (embedded-pdf expr)
104 ((os (open-output-string)))
105 (pdf-output-expression expr os)
106 (string-append "\\embeddedpdf{" (get-output-string os) "}"))))
110 (simple-format #f "% ~a\n" s))
114 ; uncomment for some stats about lily memory
115 ; (display (gc-stats))
116 (string-append "\n\\EndLilyPondOutput"
120 (define (experimental-on)
123 (define (repeat-slash w a t)
124 (embedded-pdf (list 'repeat-slash w a t)))
125 (define (fontify name-mag-pair exp)
126 (string-append (select-font name-mag-pair)
130 (define (tex-encoded-fontswitch name-mag)
131 (let* ((iname-mag (car name-mag))
132 (ename-mag (cdr name-mag)))
135 (string-append "magfont"
136 (string-encode-integer
137 (hashq (car ename-mag) 1000000))
139 (string-encode-integer
140 (inexact->exact (* 1000 (cdr ename-mag)))))))))
141 (define (define-fonts internal-external-name-mag-pairs)
142 (set! font-name-alist (map tex-encoded-fontswitch
143 internal-external-name-mag-pairs))
146 (font-load-command (car x) (cdr x)))
147 (map cdr font-name-alist))))
150 (define (font-switch i)
154 (define (font-def i s)
156 "\\font" (font-switch i) "=" s "\n"))
160 "\\def\\lilyoutputscalefactor{"
161 (number->string (cond
162 ((equal? (ly-unit) "mm") (/ 72.0 25.4))
163 ((equal? (ly-unit) "pt") (/ 72.0 72.27))
164 (else (error "unknown unit" (ly-unit)))
167 "\\input lilyponddefs \\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit"
169 "\\pdfcompresslevel=0"))
171 ;; Note: this string must match the string in ly2dvi.py!!!
172 (define (header creator generate)
174 "% Generated automatically by: " creator generate "\n"))
176 (define (invoke-char s i)
178 "\n\\" s "{" (inexact->string i 10) "}" ))
181 ;; need to do something to make this really safe.
183 (define (output-tex-string s)
184 (if security-paranoia
186 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
187 (begin (display "warning: not paranoid") (newline) s))
190 (define (lily-def key val)
193 (regexp-substitute/global
194 #f "_" (output-tex-string key) 'pre "X" 'post)
195 (output-tex-string key)))
196 (tex-val (output-tex-string val)))
197 (if (equal? (sans-surrounding-whitespace tex-val) "")
198 (string-append "\\let\\" tex-key "\\undefined\n")
199 (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
201 (define (number->dim x)
203 ;;ugh ly-* in backend needs compatibility func for standalone output
204 (ly-number->string x) " \\outputscale "))
206 (define (placebox x y s)
209 (number->dim y) "}{" (number->dim x) "}{" s "}%\n"))
211 (define (bezier-bow l thick)
212 (embedded-pdf (list 'bezier-bow `(quote ,l) thick)))
214 (define (bezier-sandwich l thick)
215 (embedded-pdf (list 'bezier-sandwich `(quote ,l) thick)))
217 (define (start-system ht)
218 (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
220 (define (stop-system)
221 "}\\vss}\\interscoreline\n")
222 (define (stop-last-system)
224 (define (filledbox breapth width depth height)
226 "\\kern" (number->dim (- breapth))
227 "\\vrule width " (number->dim (+ breapth width))
228 "depth " (number->dim depth)
229 "height " (number->dim height) " "))
231 (define (roundfilledbox x y width height blotdiam)
232 (embedded-pdf (list 'roundfilledbox x y width height blotdiam)))
235 (string-append "\\hbox{" (output-tex-string s) "}"))
237 (define (draw-line thick fx fy tx ty)
238 (embedded-pdf (list 'draw-line thick fx fy tx ty)))
240 (define (define-origin file line col)
241 (if (procedure? point-and-click)
242 (string-append "\\special{src:\\string:"
243 (point-and-click line col file)
248 ; no-origin not supported in PDFTeX
249 (define (no-origin) "")
253 (define my-eval-in-module eval)
255 (if (or (equal? (minor-version) "4.1")
256 (equal? (minor-version) "4")
257 (equal? (minor-version) "3.4"))
258 (set! my-eval-in-module eval-in-module))
260 (define-public (pdftex-output-expression expr port)
261 (display (my-eval-in-module expr this-module) port) )