X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Ftex.scm;h=b5b7d27a9c81f20060e5b7b7eddf62e8368baff0;hb=9019dd53357a12a3edce5e3d0dab529802584e04;hp=0cf48cd80d714e5bf048ab29693a6fe9f51b8858;hpb=42c9f0b04886b8a8318cb23d7fe72a90abb41afe;p=lilypond.git diff --git a/scm/tex.scm b/scm/tex.scm index 0cf48cd80d..b5b7d27a9c 100644 --- a/scm/tex.scm +++ b/scm/tex.scm @@ -1,256 +1,294 @@ + ;;; tex.scm -- implement Scheme output routines for TeX ;;; ;;; source file of the GNU LilyPond music typesetter ;;; -;;; (c) 1998--2000 Jan Nieuwenhuizen +;;; (c) 1998--2001 Jan Nieuwenhuizen ;;; Han-Wen Nienhuys -(define (tex-scm action-name) - (define (unknown) - "%\n\\unknown%\n") - - - (define (select-font name-mag-pair) - (let* - ( - (c (assoc name-mag-pair font-name-alist)) - ) - - (if (eq? c #f) - (begin - (display "FAILED\n") - (display (object-type (car name-mag-pair))) - (display (object-type (caaar font-name-alist))) - - (ly-warn (string-append - "Programming error: No such font known " - (car name-mag-pair) " " - (number->string (cdr name-mag-pair)) - )) - "") ; issue no command - (string-append "\\" (cddr c))) - - - )) - - (define (beam width slope thick) - (embedded-ps ((ps-scm 'beam) width slope thick))) - - (define (bracket arch_angle arch_width arch_height height arch_thick thick) - (embedded-ps ((ps-scm 'bracket) arch_angle arch_width arch_height height arch_thick thick))) - - (define (dashed-slur thick dash l) - (embedded-ps ((ps-scm 'dashed-slur) thick dash l))) - - (define (crescendo thick w h cont) - (embedded-ps ((ps-scm 'crescendo) thick w h cont))) - - (define (char i) - (string-append "\\char" (inexact->string i 10) " ")) - - (define (dashed-line thick on off dx dy) - (embedded-ps ((ps-scm 'dashed-line) thick on off dx dy))) - - (define (decrescendo thick w h cont) - (embedded-ps ((ps-scm 'decrescendo) thick w h cont))) - - (define (font-load-command name-mag command) - (string-append - "\\font\\" command "=" - (car name-mag) - " scaled " - (number->string (inexact->exact (* 1000 (cdr name-mag)))) - "\n")) - - (define (embedded-ps s) - (string-append "\\embeddedps{" s "}")) - - (define (comment s) - (string-append "% " s)) - - (define (end-output) +(define-module (scm tex) ) +(debug-enable 'backtrace) +(use-modules (scm ps) + (ice-9 regex) + (ice-9 string-fun) + (ice-9 format) + (guile) + (lily) + ) + +(define this-module (current-module)) + +;;;;;;;; +;;;;;;;; DOCUMENT ME! +;;;;;;;; + +(define font-name-alist '()) + +(define (tex-encoded-fontswitch name-mag) + (let* ((iname-mag (car name-mag)) + (ename-mag (cdr name-mag))) + (cons iname-mag + (cons ename-mag + (string-append "magfont" + (string-encode-integer + (hashq (car ename-mag) 1000000)) + "m" + (string-encode-integer + (inexact->exact (* 1000 (cdr ename-mag))))))))) + +(define (define-fonts internal-external-name-mag-pairs) + (set! font-name-alist (map tex-encoded-fontswitch + internal-external-name-mag-pairs)) + (apply string-append + (map (lambda (x) + (font-load-command (car x) (cdr x))) + (map cdr font-name-alist)))) + + + +;; urg, how can exp be #unspecified? -- in sketch output +;; +;; set! returns # --hwn +(define (fontify name-mag-pair exp) + (string-append (select-font name-mag-pair) + exp)) + + +(define (unknown) + "%\n\\unknown\n") + +(define (select-font name-mag-pair) + (let* + ( + (c (assoc name-mag-pair font-name-alist)) + ) + + (if (eq? c #f) (begin -; uncomment for some stats about lily memory -; (display (gc-stats)) - (string-append "\n\\EndLilyPondOutput" - ; Put GC stats here. + (display "FAILED\n") + (display (object-type (car name-mag-pair))) + (display (object-type (caaar font-name-alist))) + + (ly-warn (string-append + "Programming error: No such font known " + (car name-mag-pair) " " + (ly-number->string (cdr name-mag-pair)) + )) + "") ; issue no command + (string-append "\\" (cddr c))) + + + )) + +(define (beam width slope thick) + (embedded-ps (list 'beam width slope thick))) + +(define (bracket arch_angle arch_width arch_height height arch_thick thick) + (embedded-ps (list 'bracket arch_angle arch_width arch_height height arch_thick thick))) + +(define (dashed-slur thick dash l) + (embedded-ps (list 'dashed-slur thick dash `(quote ,l)))) + +(define (char i) + (string-append "\\char" (inexact->string i 10) " ")) + +(define (dashed-line thick on off dx dy) + (embedded-ps (list 'dashed-line thick on off dx dy))) + +(define (font-load-command name-mag command) + (string-append + "\\font\\" command "=" + (car name-mag) + " scaled " + (ly-number->string (inexact->exact (* 1000 (cdr name-mag)))) + "\n")) + +(define (ez-ball c l b) + (embedded-ps (list 'ez-ball c l b))) + +(define (header-to-file fn key val) + (set! key (symbol->string key)) + (if (not (equal? "-" fn)) + (set! fn (string-append fn "." key)) + ) + (display + (format "writing header field `~a' to `~a'..." + key + (if (equal? "-" fn) "" fn) + ) + (current-error-port)) + (if (equal? fn "-") + (display val) + (display val (open-file fn "w")) + ) + (display "\n" (current-error-port)) + "" + ) + +(if (or (equal? (minor-version) "4.1") + (equal? (minor-version) "4") + (equal? (minor-version) "3.4")) + (define (embedded-ps expr) + (let ((ps-string + (with-output-to-string + (lambda () (ps-output-expression expr (current-output-port)))))) + (string-append "\\embeddedps{" ps-string "}"))) + (define (embedded-ps expr) + (let + ((os (open-output-string))) + (ps-output-expression expr os) + (string-append "\\embeddedps{" (get-output-string os) "}")))) + +(define (comment s) + (string-append "% " s "\n")) + +(define (end-output) + (begin + ; uncomment for some stats about lily memory + ; (display (gc-stats)) + (string-append "%\n\\endgroup\\EndLilyPondOutput\n" + ; Put GC stats here. ))) - - (define (experimental-on) - "") - - (define (font-switch i) - (string-append - "\\" (font i) "\n")) - - (define (font-def i s) - (string-append - "\\font" (font-switch i) "=" s "\n")) - - (define (header-end) - (string-append - "\\special{! " - - ;; URG: ly-gulp-file: now we can't use scm output without Lily - (if use-regex - ;; fixed in 1.3.4 for powerpc -- broken on Windows - (regexp-substitute/global #f "\n" - (ly-gulp-file "lily.ps") 'pre " %\n" 'post) - (ly-gulp-file "lily.ps")) - "}" - "\\input lilyponddefs\\newdimen\\outputscale \\outputscale=\\lilypondpaperoutputscale pt\\turnOnPostScript")) - - (define (header creator generate) - (string-append - "%created by: " creator generate "\n")) - - (define (invoke-char s i) - (string-append - "\n\\" s "{" (inexact->string i 10) "}" )) - - (define (invoke-dim1 s d) - (string-append - "\n\\" s "{" (number->dim d) "}")) - (define (pt->sp x) - (* 65536 x)) - - ;; - ;; need to do something to make this really safe. - ;; - (define (output-tex-string s) - (if security-paranoia - (if use-regex - (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post) - (begin (display "warning: not paranoid") (newline) s)) - s)) - - (define (lily-def key val) - (string-append - "\\def\\" - (if use-regex - ;; fixed in 1.3.4 for powerpc -- broken on Windows - (regexp-substitute/global #f "_" - (output-tex-string key) 'pre "X" 'post) - (output-tex-string key)) - "{" (output-tex-string val) "}\n")) - - (define (number->dim x) - (string-append - ;;ugh ly-* in backend needs compatibility func for standalone output - (ly-number->string x) " \\outputscale ")) - - (define (placebox x y s) - (string-append - "\\placebox{" - (number->dim y) "}{" (number->dim x) "}{" s "}\n")) - - (define (bezier-sandwich l thick) - (embedded-ps ((ps-scm 'bezier-sandwich) l thick))) - - (define (start-line ht) - (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n")) - - (define (stop-line) - "}\\vss}\\interscoreline\n") - (define (stop-last-line) - "}\\vss}") - (define (filledbox breapth width depth height) - (string-append - "\\kern" (number->dim (- breapth)) - "\\vrule width " (number->dim (+ breapth width)) - "depth " (number->dim depth) - "height " (number->dim height) " ")) - - (define (text s) - (string-append "\\hbox{" (output-tex-string s) "}")) - - (define (tuplet ht gapx dx dy thick dir) - (embedded-ps ((ps-scm 'tuplet) ht gapx dx dy thick dir))) - - (define (volta h w thick vert_start vert_end) - (embedded-ps ((ps-scm 'volta) h w thick vert_start vert_end))) - - (define (define-origin file line col) - ; use this for column positions - (if point-and-click - (string-append "\\special{src:" (number->string line) ":" - (number->string col) " " file "}" - ;; arg, the clueless take over the mailing list... -; "\\special{-****-These-warnings-are-harmless-***}" -; "\\special{-****-PLEASE-read-http://appel.lilypond.org/wiki/index.php3?PostProcessing-****}" - ) - "") - - ; line numbers only: - ;(string-append "\\special{src:" (number->string line) " " file "}") -) - - ; no-origin not yet supported by Xdvi - (define (no-origin) "") - - ;; TeX - ;; The procedures listed below form the public interface of TeX-scm. - ;; (should merge the 2 lists) - (cond ((eq? action-name 'all-definitions) - `(begin - (define font-load-command ,font-load-command) - (define beam ,beam) - (define bezier-sandwich ,bezier-sandwich) - (define bracket ,bracket) - (define char ,char) - (define crescendo ,crescendo) - (define dashed-line ,dashed-line) - (define dashed-slur ,dashed-slur) - (define decrescendo ,decrescendo) - (define end-output ,end-output) - (define experimental-on ,experimental-on) - (define filledbox ,filledbox) - (define font-def ,font-def) - (define font-switch ,font-switch) - (define header-end ,header-end) - (define lily-def ,lily-def) - (define header ,header) - (define invoke-char ,invoke-char) - (define invoke-dim1 ,invoke-dim1) - (define placebox ,placebox) - (define select-font ,select-font) - (define start-line ,start-line) - (define stop-line ,stop-line) - (define stop-last-line ,stop-last-line) - (define text ,text) - (define tuplet ,tuplet) - (define volta ,volta) - (define define-origin ,define-origin) - (define no-origin ,no-origin) - )) - - ((eq? action-name 'beam) beam) - ((eq? action-name 'tuplet) tuplet) - ((eq? action-name 'bracket) bracket) - ((eq? action-name 'crescendo) crescendo) - ((eq? action-name 'dashed-line) dashed-line) - ((eq? action-name 'dashed-slur) dashed-slur) - ((eq? action-name 'decrescendo) decrescendo) - ((eq? action-name 'end-output) end-output) - ((eq? action-name 'experimental-on) experimental-on) - ((eq? action-name 'font-def) font-def) - ((eq? action-name 'font-switch) font-switch) - ((eq? action-name 'header-end) header-end) - ((eq? action-name 'lily-def) lily-def) - ((eq? action-name 'header) header) - ((eq? action-name 'invoke-char) invoke-char) - ((eq? action-name 'invoke-dim1) invoke-dim1) - ((eq? action-name 'placebox) placebox) - ((eq? action-name 'bezier-sandwich) bezier-sandwich) - ((eq? action-name 'start-line) start-line) - ((eq? action-name 'stem) stem) - ((eq? action-name 'stop-line) stop-line) - ((eq? action-name 'stop-last-line) stop-last-line) - ((eq? action-name 'volta) volta) - (else (error "unknown tag -- PS-TEX " action-name)) - ) + +(define (experimental-on) + "") + +(define (repeat-slash w a t) + (embedded-ps (list 'repeat-slash w a t))) + +(define (font-switch i) + (string-append + "\\" (font i) "\n")) + +(define (font-def i s) + (string-append + "\\font" (font-switch i) "=" s "\n")) + +(define (header-end) + (string-append + "\\def\\scaletounit{ " + (number->string (cond + ((equal? (ly-unit) "mm") (/ 72.0 25.4)) + ((equal? (ly-unit) "pt") (/ 72.0 72.27)) + (else (error "unknown unit" (ly-unit))) + )) + " mul }%\n" + "\\special{\\string! " + + ;; URG: ly-gulp-file: now we can't use scm output without Lily + (regexp-substitute/global #f "\n" + (ly-gulp-file "music-drawing-routines.ps") 'pre " %\n" 'post) + "}" + "\\input lilyponddefs\n" + "\\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit\n" + "\\turnOnPostScript\\begingroup\\parindent0pt\n")) + +;; Note: this string must match the string in ly2dvi.py!!! +(define (header creator generate) + (string-append + "% Generated automatically by: " creator generate "\n")) + +(define (invoke-char s i) + (string-append + "\n\\" s "{" (inexact->string i 10) "}" )) + +;; +;; need to do something to make this really safe. +;; +(define-public (output-tex-string s) + (if security-paranoia + (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post) + s)) + +(define (lily-def key val) + (let ((tex-key + (regexp-substitute/global + #f "_" (output-tex-string key) 'pre "X" 'post)) + + (tex-val (output-tex-string val))) + (if (equal? (sans-surrounding-whitespace tex-val) "") + (string-append "\\let\\" tex-key "\\undefined\n") + (string-append "\\def\\" tex-key "{" tex-val "}%\n")))) + +(define (number->dim x) + (string-append + ;;ugh ly-* in backend needs compatibility func for standalone output + (ly-number->string x) " \\outputscale ")) + +(define (placebox x y s) + (string-append + "\\placebox{" + (number->dim y) "}{" (number->dim x) "}{" s "}%\n")) + +(define (bezier-bow l thick) + (embedded-ps (list 'bezier-bow `(quote ,l) thick))) + +(define (bezier-sandwich l thick) + (embedded-ps (list 'bezier-sandwich `(quote ,l) thick))) + +(define (start-system wd ht) + (string-append "\\leavevmode\n" + "\\scoreshift = " (number->dim (* ht 0.5)) "\n" + "\\ifundefined{lilypondscoreshift}%\n" + "\\else\n" + " \\advance\\scoreshift by -\\lilypondscoreshift\n" + "\\fi\n" + "\\hbox to " (number->dim wd) "{%\n" + "\\lower\\scoreshift\n" + "\\vbox to " (number->dim ht) "{\\hbox{%\n")) + +(define (stop-system) + "}\\vss}\\hss}\\interscoreline\n") +(define (stop-last-system) + "}\\vss}\\hss}") + +(define (filledbox breapth width depth height) + (if (and #f (defined? 'ps-testing)) + (embedded-ps + (string-append (numbers->string (list breapth width depth height)) + " draw_box" )) + (string-append + "\\kern" (number->dim (- breapth)) + "\\vrule width " (number->dim (+ breapth width)) + "depth " (number->dim depth) + "height " (number->dim height) " "))) + +(define (roundfilledbox x y width height blotdiam) + (embedded-ps (list 'roundfilledbox x y width height blotdiam))) + +(define (text s) + (string-append "\\hbox{" (output-tex-string s) "}")) + +(define (tuplet ht gapx dx dy thick dir) + (embedded-ps (list 'tuplet ht gapx dx dy thick dir))) + +(define (draw-line thick fx fy tx ty) + (embedded-ps (list 'draw-line thick fx fy tx ty))) + +(define (between-system-string string) + string + ) +(define (define-origin file line col) + (if (procedure? point-and-click) + (string-append "\\special{src:" ;;; \\string ? + (point-and-click line col file) + "}" ) + "") ) -(define (scm-tex-output) - (ly-eval (tex-scm 'all-definitions))) + ; no-origin not yet supported by Xdvi +(define (no-origin) "") + +(define my-eval-in-module eval) + +(if (or (equal? (minor-version) "4.1") + (equal? (minor-version) "4") + (equal? (minor-version) "3.4")) + (set! my-eval-in-module eval-in-module)) + +(define-public (tex-output-expression expr port) + (display (my-eval-in-module expr this-module) port ) + ) + +