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)))
77 (if (or (equal? (minor-version) "4.1")
78 (equal? (minor-version) "4")
79 (equal? (minor-version) "3.4"))
80 (define (embedded-pdf expr)
82 (with-output-to-string
83 (lambda () (pdf-output-expression expr (current-output-port))))))
84 (string-append "\\embeddedpdf{" ps-string "}")))
85 (define (embedded-pdf expr)
87 ((os (open-output-string)))
88 (pdf-output-expression expr os)
89 (string-append "\\embeddedpdf{" (get-output-string os) "}"))))
93 (simple-format #f "% ~a\n" s))
97 ; uncomment for some stats about lily memory
98 ; (display (gc-stats))
99 (string-append "\n\\EndLilyPondOutput"
103 (define (experimental-on)
106 (define (repeat-slash w a t)
107 (embedded-pdf (list 'repeat-slash w a t)))
108 (define (fontify name-mag-pair exp)
109 (string-append (select-font name-mag-pair)
113 (define (tex-encoded-fontswitch name-mag)
114 (let* ((iname-mag (car name-mag))
115 (ename-mag (cdr name-mag)))
118 (string-append "magfont"
119 (string-encode-integer
120 (hashq (car ename-mag) 1000000))
122 (string-encode-integer
123 (inexact->exact (* 1000 (cdr ename-mag)))))))))
124 (define (define-fonts internal-external-name-mag-pairs)
125 (set! font-name-alist (map tex-encoded-fontswitch
126 internal-external-name-mag-pairs))
129 (font-load-command (car x) (cdr x)))
130 (map cdr font-name-alist))))
133 (define (font-switch i)
137 (define (font-def i s)
139 "\\font" (font-switch i) "=" s "\n"))
143 "\\input lilyponddefs\\newdimen\\outputscale \\outputscale=\\lilypondpaperoutputscale pt"
145 "\\pdfcompresslevel=0"))
147 ;; Note: this string must match the string in ly2dvi.py!!!
148 (define (header creator generate)
150 "% Generated automatically by: " creator generate "\n"))
152 (define (invoke-char s i)
154 "\n\\" s "{" (inexact->string i 10) "}" ))
157 ;; need to do something to make this really safe.
159 (define (output-tex-string s)
160 (if security-paranoia
162 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
163 (begin (display "warning: not paranoid") (newline) s))
166 (define (lily-def key val)
169 (regexp-substitute/global
170 #f "_" (output-tex-string key) 'pre "X" 'post)
171 (output-tex-string key)))
172 (tex-val (output-tex-string val)))
173 (if (equal? (sans-surrounding-whitespace tex-val) "")
174 (string-append "\\let\\" tex-key "\\undefined\n")
175 (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
177 (define (number->dim x)
179 ;;ugh ly-* in backend needs compatibility func for standalone output
180 (ly-number->string x) " \\outputscale "))
182 (define (placebox x y s)
185 (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
187 (define (bezier-bow l thick)
188 (embedded-pdf (list 'bezier-bow `(quote ,l) thick)))
190 (define (bezier-sandwich l thick)
191 (embedded-pdf (list 'bezier-sandwich `(quote ,l) thick)))
193 (define (start-system ht)
194 (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
196 (define (stop-system)
197 "}\\vss}\\interscoreline\n")
198 (define (stop-last-system)
200 (define (filledbox breapth width depth height)
202 "\\kern" (number->dim (- breapth))
203 "\\vrule width " (number->dim (+ breapth width))
204 "depth " (number->dim depth)
205 "height " (number->dim height) " "))
207 (define (roundfilledbox x y width height blotdiam)
208 (embedded-pdf (list 'roundfilledbox x y width height blotdiam)))
211 (string-append "\\hbox{" (output-tex-string s) "}"))
214 (define (define-origin file line col)
215 (if (procedure? point-and-click)
216 (string-append "\\special{src:\\string:"
217 (point-and-click line col file)
222 ; no-origin not supported in PDFTeX
223 (define (no-origin) "")
227 (define my-eval-in-module eval)
229 (if (or (equal? (minor-version) "4.1")
230 (equal? (minor-version) "4")
231 (equal? (minor-version) "3.4"))
232 (set! my-eval-in-module eval-in-module))
234 (define-public (pdftex-output-expression expr port)
235 (display (my-eval-in-module expr this-module) port) )