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 (output-scopes scopes fields basename)
29 (define (output-scope scope)
34 (let (;;(val (variable-ref var))
35 (val (if (variable-bound? var) (variable-ref var) '""))
36 (tex-key (symbol->string sym)))
38 (if (and (memq sym fields) (string? val))
39 (header-to-file basename sym val))
43 (tex-string-def "lilypond" sym val))
46 (tex-number-def "lilypond" sym
49 (number->string (exact->inexact val)))))
55 (map output-scope scopes)))
56 (define (tex-string-def prefix key str)
57 (if (equal? "" (sans-surrounding-whitespace (output-tex-string str)))
58 (string-append "\\let\\" prefix (symbol->tex-key key) "\\undefined%\n")
59 (string-append "\\def\\" prefix (symbol->tex-key key)
60 "{" (output-tex-string str) "}%\n")))
62 (define (header creator time-stamp bookpaper page-count classic?)
64 "% Generated by " creator "\n"
65 "% at " time-stamp "\n"
67 (tex-string-def "lilypond" 'classic "1")
69 ;; FIXME: duplicated in every backend
70 "\\def\\lilypondtagline{Engraved by LilyPond (version "
71 (lilypond-version)")}\n"
74 ;; this is -of course- severely broken, (--hwn)
75 (tex-string-def "lilypondpaper" 'linewidth
76 (ly:number->string (/ 18 0.175))) ; 18 cm.
77 (tex-string-def "lilypondpaper" 'interscoreline
78 (ly:number->string 0.0))
83 "\\def\\scaletounit{ "
85 ((equal? (ly:unit) "mm") (/ 72.0 25.4))
86 ((equal? (ly:unit) "pt") (/ 72.0 72.27))
87 (else (error "unknown unit" (ly:unit)))
90 "\\ifx\\lilypondstart\\undefined\n"
91 " \\input lilyponddefs\n"
93 "\\outputscale = \\lilypondpaperoutputscale\\lilypondpaperunit\n"
96 "\\lilypondpostscript\n"))
99 (define (dump-page putter page)
100 (ly:outputter-dump-string
102 "\n\\vbox to 0pt{%\n\\leavevmode\n\\lybox{0}{0}{0}{0}{%\n")
103 (ly:outputter-dump-stencil putter (ly:page-stencil page))
104 (ly:outputter-dump-string
106 (if (ly:page-last? page)
107 "}\\vss\n}\n\\vfill\n"
108 "}\\vss\n}\n\\vfill\\lilypondpagebreak\n")))
111 (define (dump-line putter line last?)
112 (ly:outputter-dump-string
114 (string-append "\\leavevmode\n\\lybox{0}{0}{0}{"
115 (ly:number->string (ly:paper-line-height line))
118 (ly:outputter-dump-stencil putter (ly:paper-line-stencil line))
119 (ly:outputter-dump-string
122 "}\\interscoreline\n"
126 ;; todo: only pass BOOK, FIELDS arguments
127 (define-public (output-framework-tex outputter book scopes fields basename)
129 ((bookpaper (ly:paper-book-book-paper book))
130 (pages (ly:paper-book-pages book))
134 (ly:outputter-dump-string outputter x))
143 (output-scopes scopes fields basename)
144 (define-fonts bookpaper)
149 (dump-page outputter page))
151 (ly:outputter-dump-string outputter "\\lilypondend\n")
154 (define-public (output-classic-framework-tex outputter book scopes fields basename)
156 ((bookpaper (ly:paper-book-book-paper book))
157 (lines (ly:paper-book-lines book))
158 (last-line (car (last-pair lines))))
161 (ly:outputter-dump-string outputter x))
169 (output-scopes scopes fields basename)
170 (define-fonts bookpaper)
175 (dump-line outputter line (eq? line last-line)))
177 (ly:outputter-dump-string outputter "\\lilypondend\n")