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 "% Generated by " creator "\n"
74 "% at " time-stamp "\n"
76 (tex-string-def "lilypond" 'classic "1")
78 ;; FIXME: duplicated in every backend
79 "\\def\\lilypondtagline{Engraved by LilyPond (version "
80 (lilypond-version)")}\n"
83 ;; this is -of course- severely broken, (--hwn)
84 (tex-string-def "lilypondpaper" 'linewidth
85 (ly:number->string (/ 18 0.175))) ; 18 cm.
86 (tex-string-def "lilypondpaper" 'interscoreline
87 (ly:number->string 0.0))
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")))
120 (define (dump-line putter line last?)
121 (ly:outputter-dump-string
123 (string-append "\\leavevmode\n\\lybox{0}{0}{0}{"
124 (ly:number->string (ly:paper-line-height line))
127 (ly:outputter-dump-stencil putter (ly:paper-line-stencil line))
128 (ly:outputter-dump-string
131 "}\\interscoreline\n"
135 (define-public (output-framework-tex outputter book scopes fields basename)
137 ((bookpaper (ly:paper-book-book-paper book))
138 (pages (ly:paper-book-pages book))
142 (ly:outputter-dump-string outputter x))
151 (define-fonts bookpaper)
156 (dump-page outputter page))
158 (ly:outputter-dump-string outputter "\\lilypondend\n")
161 (define-public (output-classic-framework-tex outputter book scopes fields basename)
163 ((bookpaper (ly:paper-book-book-paper book))
164 (lines (ly:paper-book-lines book))
165 (last-line (car (last-pair lines))))
168 (ly:outputter-dump-string outputter x))
170 (header "creator" ;FIXME
176 (output-scopes scopes fields basename)
177 (define-fonts bookpaper)
182 (dump-line outputter line (eq? line last-line)))
184 (ly:outputter-dump-string outputter "\\lilypondend\n")