;;;; (c) 2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
(define-module (scm framework-tex)
- #:export (output-framework-tex
- output-classic-framework-tex
-))
+ #:export (output-framework-tex
+ output-classic-framework-tex))
(use-modules (ice-9 regex)
(ice-9 string-fun)
;; \lyitem{089.5557}{-15.3109}{\hbox{\magfontUGQLomTVo{}bla$\backslash${$\backslash$}}}%
;; --jcn
(define-public (sanitize-tex-string s)
- (if (ly:get-option 'safe)
- (regexp-substitute/global #f "\\\\"
- (regexp-substitute/global #f "([{}])" "bla{}" 'pre "\\" 1 'post )
- 'pre "$\\backslash$" 'post)
-
+ (if (ly:get-option 'safe)
+ (regexp-substitute/global
+ #f "\\\\"
+ (regexp-substitute/global #f "([{}])" "bla{}" 'pre "\\" 1 'post )
+ 'pre "$\\backslash$" 'post)
s))
(define (symbol->tex-key sym)
(define (font-load-command paper font)
(let* ((coding-alist (ly:font-encoding-alist font))
(font-encoding (assoc-get 'output-name coding-alist)))
-
(string-append
"\\font\\lilypond" (tex-font-command font) "="
(ly:font-filename font)
" \\lilypondfontencoding{T1}"
" ")
"\\lilypond" (tex-font-command font)
- "}%\n"
- )))
-
+ "}%\n")))
(define (define-fonts paper)
(string-append
- ;; UGH. FIXME.
+ ;; UGH. FIXME.
"\\def\\lilypondpaperunit{mm}%\n"
(tex-number-def "lilypondpaper" 'outputscale
(number->string (exact->inexact
(newline (current-error-port))
"")
-(define (output-scopes scopes fields basename)
+(define (output-scopes scopes fields basename)
(define (output-scope scope)
(apply
string-append
(module-map
(lambda (sym var)
- (let ((val (if (variable-bound? var) (variable-ref var) ""))
- )
-
+ (let ((val (if (variable-bound? var) (variable-ref var) "")))
(if (and (memq sym fields) (string? val))
(header-to-file basename sym val))
""))
(ly:output-def-lookup paper 'papersizename)
"paper"))
(landscape? (eq? #t (ly:output-def-lookup paper 'landscape))))
-
(string-append
"% Generated by LilyPond "
(lilypond-version) "\n"
(ly:number->string (* scale (ly:output-def-lookup paper 'linewidth))))
"\\def\\lilyponddocumentclassoptions{"
texpaper
- (if landscape? ",landscape" "")
- "}%\n"
+ (if landscape? ",landscape" "")
+ "}%\n"
(tex-string-def
"lilypondpaper" 'interscoreline
(ly:number->string
(define (dump-page putter page last? with-extents?)
(ly:outputter-dump-string
putter
- (format "\\vbox to ~a\\outputscale{%\n\\leavevmode\n\\lybox{0}{0}{0}{0}{%\n"
+ (format "\\lybox{~a}{~a}{%\n"
+ (if with-extents?
+ (interval-start (ly:stencil-extent page X))
+ 0.0)
(if with-extents?
(- (interval-start (ly:stencil-extent page Y)))
- 0.0
- )))
+ 0.0)))
(ly:outputter-dump-stencil putter page)
(ly:outputter-dump-string
putter
(if last?
- "}\\vss\n}\n\\vfill\n"
- "}\\vss\n}\n\\vfill\\lilypondpagebreak\n")))
+ "}%\n\\vfill\n"
+ "}%\n\\vfill\n\\lilypondpagebreak\n")))
(define-public (output-framework outputter book scopes fields basename )
(let* ((paper (ly:paper-book-paper book))
(pages (ly:paper-book-pages book))
(last-page (car (last-pair pages)))
(with-extents
- (eq? #t (ly:output-def-lookup paper 'dump-extents)))
- )
+ (eq? #t (ly:output-def-lookup paper 'dump-extents))))
(for-each
(lambda (x)
(ly:outputter-dump-string outputter x))
(header paper (length pages) #f)
(define-fonts paper)
(header-end)))
- (ly:outputter-dump-string outputter "\\lilypondnopagebreak")
+ (ly:outputter-dump-string outputter "\\lilypondnopagebreak\n")
(for-each
- (lambda (page) (dump-page outputter page (eq? last-page page) with-extents))
+ (lambda (page)
+ (dump-page outputter page (eq? last-page page) with-extents))
pages)
(ly:outputter-dump-string outputter "\\lilypondend\n")))
(define (dump-line putter line last?)
(ly:outputter-dump-string
putter
- (string-append "\\leavevmode\n\\lybox{0}{0}{0}{"
- (ly:number->string (interval-length (ly:paper-system-extent line Y)))
+ (string-append "\\lybox{"
+ (ly:number->string
+ (interval-length (ly:paper-system-extent line X)))
+ "}{"
+ (ly:number->string
+ (interval-length (ly:paper-system-extent line Y)))
"}{%\n"))
(ly:outputter-dump-stencil putter (ly:paper-system-stencil line))
(lambda (line) (dump-line outputter line (eq? line last-line))) lines)
(ly:outputter-dump-string outputter "\\lilypondend\n")))
-
(define-public (output-preview-framework
outputter book scopes fields basename )
(let* ((paper (ly:paper-book-paper book))
(dump-line outputter (car lines) #t)
(ly:outputter-dump-string outputter "\\lilypondend\n")))
-
(define-public (convert-to-pdf book name)
(let* ((defs (ly:paper-book-paper book))
(papersizename (ly:output-def-lookup defs 'papersizename)))
-
(postscript->pdf (if (string? papersizename) papersizename "a4")
- (string-append (basename name ".tex") ".ps"))))
+ (string-append
+ (basename name ".tex")
+ ".ps"))))
(define-public (convert-to-png book name)
(let* ((defs (ly:paper-book-paper book))
(resolution (ly:output-def-lookup defs 'pngresolution)))
-
(postscript->png
(if (number? resolution) resolution 90)
(string-append (basename name ".tex") ".ps"))))
(papersizename (ly:output-def-lookup paper 'papersizename))
(landscape? (eq? #t (ly:output-def-lookup paper 'landscape)))
(cmd (string-append "dvips "
-
(if preview?
" -E "
(string-append " -t " papersizename))
-
- (if landscape? " -t landscape " " ")
+ (if landscape?
+ " -t landscape "
+ " ")
" -u+ec-mftrace.map -u+lilypond.map -Ppdf "
(basename name ".tex"))))
-
(display (format #f (_ "Invoking ~S") cmd) (current-error-port))
(newline (current-error-port))
(system cmd)))
(define-public (convert-to-dvi book name)
- (let* ((curr-extra-mem (string->number
- (regexp-substitute/global
- #f " *%.*\n?"
- (ly:kpathsea-expand-variable "$extra_mem_top")
- 'pre "" 'post)))
- (cmd (string-append "latex \\\\nonstopmode \\\\input " name)))
-
+ (let* ((curr-extra-mem
+ (string->number
+ (regexp-substitute/global
+ #f " *%.*\n?"
+ (ly:kpathsea-expand-variable "$extra_mem_top")
+ 'pre "" 'post)))
+ (cmd (string-append "latex \\\\nonstopmode \\\\input " name)))
(setenv "extra_mem_top" (number->string (max curr-extra-mem 1024000)))
(newline (current-error-port))
(display (format #f (_ "Invoking ~S") cmd) (current-error-port))
;; fixme: set in environment?
(if (ly:get-option 'safe)
(set! cmd (string-append "openout_any=p " cmd)))
-
+
(system cmd)))
(define-public (convert-to-tex book name)
#t)
-
\special{header=music-drawing-routines.ps}
\gdef\lilypondspecial{}}
-
-
-
-%% Put the argument into a box which has zero height and depth (the
-%% \vss forces the latter -- TeXbook, page 80).
-%%
-\gdef\topalign#1{
- \vbox to 0pt{
- \hbox{#1}
- \vss}}
-
-%% Put the argument into a box which has zero width.
-%%
-\gdef\leftalign#1{
- \hbox to 0pt{
- #1
- \hss}}
-
%% The most used macro in LilyPond output. Put #3 into a zero-width box
%% which is moved to the right by #1 (scaled by \outputscale) and moved
-%% up by #2 (also scaled by \outputscale). Note that negative values for
-%% #2 change the depth of the box defined by \leftalign, not the height.
+%% up by #2 (also scaled by \outputscale).
%%
\gdef\lyitem#1#2#3{
- \raise#2\outputscale \leftalign{
- \kern#1\outputscale
- #3}}
-
-%% All LilyPond music data is enclosed in this macro (as fifth argument).
-%% The data is first put into a box with zero height and depth which is
-%% then moved to the right by #1 and moved down by #2. After this, it is
-%% put into a zero-width box, giving it a height #4 (and depth zero).
-%% Finally, the box is raised so that its true height is exactly the
-%% distance from one baseline to the next.
+ \raise #2\outputscale \hbox to 0pt {
+ \kern #1\outputscale
+ #3
+ \hss}}
+
+%% All LilyPond music data is enclosed in this macro (as third argument).
+%% The data (which consists of boxes with zero width) gets an artificial
+%% width of #1 and a height of #2. The resulting box is then centered
+%% vertically along the x-height of the current font.
%%
-%% Parameters #1 to #4 are scaled by \outputscale.
+%% Parameters #1 and #2 are scaled by \outputscale.
%%
-\gdef\lybox#1#2#3#4#5{
- \lytempdim\baselineskip
- \advance\lytempdim -#4\outputscale
- \raise\lytempdim
- \vbox to #4\outputscale{
- \leftalign{
- \kern #1\outputscale
- \lower #2\outputscale \topalign{
- #5}}
- \vss}}
+\gdef\lybox#1#2#3{
+ \lytempdim #2\outputscale
+ \lytempdim -0.5\lytempdim
+ \advance\lytempdim 1ex
+ \leavevmode
+ \raise \lytempdim \hbox to #1\outputscale {
+ %% Convert depth of #3 into height only.
+ \vbox to #2\outputscale {\hbox{#3}\vss}
+ \hss}}
%% Produce a black bar (width #2, depth #3, height #4) with a vertical
%% offset #1. Everything is scaled by \outputscale.