1 (define-module (scm framework-tex))
3 (use-modules (ice-9 regex)
12 (define (define-fonts bookpaper)
14 "\\def\\lilypondpaperunit{mm}" ;; UGH. FIXME.
15 (tex-number-def "lilypondpaper" 'outputscale
16 (number->string (exact->inexact
17 (ly:bookpaper-outputscale bookpaper))))
18 (tex-string-def "lilypondpapersize" 'papersize
19 (eval 'papersize (ly:output-def-scope bookpaper)))
22 (map (lambda (x) (font-load-command bookpaper x))
23 (ly:bookpaper-fonts bookpaper)
26 (define-public (header-to-file fn key val)
27 (set! key (symbol->string key))
28 (if (not (equal? "-" fn))
29 (set! fn (string-append fn "." key))
32 (format "Writing header field `~a' to `~a'..."
34 (if (equal? "-" fn) "<stdout>" fn)
39 (display val (open-file fn "w"))
41 (display "\n" (current-error-port))
45 (define (output-scopes scopes fields basename)
46 (define (output-scope scope)
51 (let ((val (if (variable-bound? var) (variable-ref var) ""))
54 (if (and (memq sym fields) (string? val))
55 (header-to-file basename sym val))
60 (map output-scope scopes)))
63 (define (tex-string-def prefix key str)
64 (if (equal? "" (sans-surrounding-whitespace (sanitize-tex-string str)))
65 (string-append "\\let\\" prefix (symbol->tex-key key) "\\undefined%\n")
66 (string-append "\\def\\" prefix (symbol->tex-key key)
67 "{" (sanitize-tex-string str) "}%\n")))
69 (define (header creator time-stamp bookpaper page-count classic?)
71 ((scale (ly:output-def-lookup bookpaper 'outputscale)))
74 "% Generated by " creator "\n"
75 "% at " time-stamp "\n"
77 (tex-string-def "lilypond" 'classic "1")
80 (tex-string-def "lilypondpaper" 'linewidth
81 (ly:number->string (* scale
82 (ly:output-def-lookup bookpaper 'linewidth))))
84 (tex-string-def "lilypondpaper" 'interscoreline
87 (ly:output-def-lookup bookpaper 'interscoreline))))
92 "\\def\\scaletounit{ "
94 ((equal? (ly:unit) "mm") (/ 72.0 25.4))
95 ((equal? (ly:unit) "pt") (/ 72.0 72.27))
96 (else (error "unknown unit" (ly:unit)))
99 "\\ifx\\lilypondstart\\undefined\n"
100 " \\input lilyponddefs\n"
102 "\\outputscale = \\lilypondpaperoutputscale\\lilypondpaperunit\n"
104 "\\lilypondspecial\n"
105 "\\lilypondpostscript\n"))
108 (define (dump-page putter page)
109 (ly:outputter-dump-string
111 "\n\\vbox to 0pt{%\n\\leavevmode\n\\lybox{0}{0}{0}{0}{%\n")
112 (ly:outputter-dump-stencil putter (ly:page-stencil page))
113 (ly:outputter-dump-string
115 (if (ly:page-last? page)
116 "}\\vss\n}\n\\vfill\n"
117 "}\\vss\n}\n\\vfill\\lilypondpagebreak\n")))
121 (define-public (output-framework-tex outputter book scopes fields basename)
123 ((bookpaper (ly:paper-book-book-paper book))
124 (pages (ly:paper-book-pages book))
128 (ly:outputter-dump-string outputter x))
137 (define-fonts bookpaper)
142 (dump-page outputter page))
144 (ly:outputter-dump-string outputter "\\lilypondend\n")
147 (define (dump-line putter line last?)
148 (ly:outputter-dump-string
150 (string-append "\\leavevmode\n\\lybox{0}{0}{0}{"
151 (ly:number->string (ly:paper-line-extent line Y))
154 (ly:outputter-dump-stencil putter (ly:paper-line-stencil line))
155 (ly:outputter-dump-string
159 "}\\interscoreline\n"
162 (define-public (output-classic-framework-tex outputter book scopes fields basename)
164 ((bookpaper (ly:paper-book-book-paper book))
165 (lines (ly:paper-book-lines book))
166 (last-line (car (last-pair lines))))
169 (ly:outputter-dump-string outputter x))
171 (header "creator" ;FIXME
176 "\\def\\lilypondclassic{1}%\n"
177 (output-scopes scopes fields basename)
178 (define-fonts bookpaper)
183 (dump-line outputter line (eq? line last-line)))
185 (ly:outputter-dump-string outputter "\\lilypondend\n")