3 (define-module (scm framework-tex))
5 (use-modules (ice-9 regex)
14 (define (define-fonts bookpaper)
16 "\\def\\lilypondpaperunit{mm}" ;; UGH. FIXME.
17 (tex-number-def "lilypondpaper" 'outputscale
18 (number->string (exact->inexact
19 (ly:bookpaper-outputscale bookpaper))))
20 (tex-string-def "lilypondpapersize" 'papersize
21 (eval 'papersize (ly:output-def-scope bookpaper)))
24 (map (lambda (x) (font-load-command bookpaper x))
25 (ly:bookpaper-fonts bookpaper)
28 (define-public (header-to-file fn key val)
29 (set! key (symbol->string key))
30 (if (not (equal? "-" fn))
31 (set! fn (string-append fn "." key))
34 (format "Writing header field `~a' to `~a'..."
36 (if (equal? "-" fn) "<stdout>" fn)
41 (display val (open-file fn "w"))
43 (display "\n" (current-error-port))
47 (define (output-scopes scopes fields basename)
48 (define (output-scope scope)
53 (let ((val (if (variable-bound? var) (variable-ref var) ""))
56 (if (and (memq sym fields) (string? val))
57 (header-to-file basename sym val))
62 (map output-scope scopes)))
65 (define (tex-string-def prefix key str)
66 (if (equal? "" (sans-surrounding-whitespace (sanitize-tex-string str)))
67 (string-append "\\let\\" prefix (symbol->tex-key key) "\\undefined%\n")
68 (string-append "\\def\\" prefix (symbol->tex-key key)
69 "{" (sanitize-tex-string str) "}%\n")))
71 (define (header creator time-stamp bookpaper page-count classic?)
73 ((scale (ly:output-def-lookup bookpaper 'outputscale)))
76 "% Generated by " creator "\n"
77 "% at " time-stamp "\n"
79 (tex-string-def "lilypond" 'classic "1")
82 (tex-string-def "lilypondpaper" 'linewidth
83 (ly:number->string (* scale
84 (ly:output-def-lookup bookpaper 'linewidth))))
86 (tex-string-def "lilypondpaper" 'interscoreline
89 (ly:output-def-lookup bookpaper 'interscoreline))))
94 "\\def\\scaletounit{ "
96 ((equal? (ly:unit) "mm") (/ 72.0 25.4))
97 ((equal? (ly:unit) "pt") (/ 72.0 72.27))
98 (else (error "unknown unit" (ly:unit)))
101 "\\ifx\\lilypondstart\\undefined\n"
102 " \\input lilyponddefs\n"
104 "\\outputscale = \\lilypondpaperoutputscale\\lilypondpaperunit\n"
106 "\\lilypondspecial\n"
107 "\\lilypondpostscript\n"))
110 (define (dump-page putter page)
111 (ly:outputter-dump-string
113 "\n\\vbox to 0pt{%\n\\leavevmode\n\\lybox{0}{0}{0}{0}{%\n")
114 (ly:outputter-dump-stencil putter (ly:page-stencil page))
115 (ly:outputter-dump-string
117 (if (ly:page-last? page)
118 "}\\vss\n}\n\\vfill\n"
119 "}\\vss\n}\n\\vfill\\lilypondpagebreak\n")))
122 (define (dump-line putter line last?)
123 (ly:outputter-dump-string
125 (string-append "\\leavevmode\n\\lybox{0}{0}{0}{"
126 (ly:number->string (ly:paper-line-extent line Y))
129 (ly:outputter-dump-stencil putter (ly:paper-line-stencil line))
130 (ly:outputter-dump-string
134 "}\\interscoreline\n"
137 (define-public (output-framework-tex outputter book scopes fields basename)
139 ((bookpaper (ly:paper-book-book-paper book))
140 (pages (ly:paper-book-pages book))
144 (ly:outputter-dump-string outputter x))
153 (define-fonts bookpaper)
158 (dump-page outputter page))
160 (ly:outputter-dump-string outputter "\\lilypondend\n")
163 (define-public (output-classic-framework-tex outputter book scopes fields basename)
165 ((bookpaper (ly:paper-book-book-paper book))
166 (lines (ly:paper-book-lines book))
167 (last-line (car (last-pair lines))))
170 (ly:outputter-dump-string outputter x))
172 (header "creator" ;FIXME
177 "\\def\\lilypondclassic{1}%\n"
178 (output-scopes scopes fields basename)
179 (define-fonts bookpaper)
184 (dump-line outputter line (eq? line last-line)))
186 (ly:outputter-dump-string outputter "\\lilypondend\n")