1 ;;;; tex.scm -- implement Scheme output routines for TeX
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 ;; (debug-enable 'backtrace)
11 ;; The public interface is tight.
12 ;; It has to be, because user-code is evalled with this module.
14 ;; ***It should also be clean, well defined, documented and reviewed***
16 ;; To be reasonably safe, you probably do not want to use the TeX
17 ;; backend anyway, but rather the PostScript backend. You may want
18 ;; to run gs in a uml sandbox too.
21 (define-module (scm output-tex)
24 ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
53 (use-modules (ice-9 regex)
75 (define (dot x y radius)
76 (embedded-ps (list 'dot x y radius)))
79 (define (embedded-ps string)
80 (embedded-ps (list 'embedded-ps string)))
82 (define (white-dot x y radius)
83 (embedded-ps (list 'white-dot x y radius)))
85 (define (beam width slope thick blot)
86 (embedded-ps (list 'beam width slope thick blot)))
88 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
89 (embedded-ps (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
91 (define (dashed-slur thick dash l)
92 (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
95 (string-append "\\" (tex-font-command font)
96 "\\char" (ly:inexact->string i 10) " "))
98 (define (dashed-line thick on off dx dy)
99 (embedded-ps (list 'dashed-line thick on off dx dy)))
101 (define (zigzag-line centre? zzw zzh thick dx dy)
102 (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
104 (define (symmetric-x-triangle t w h)
105 (embedded-ps (list 'symmetric-x-triangle t w h)))
108 (define (ez-ball c l b)
109 (embedded-ps (list 'ez-ball c l b)))
113 (define (embedded-ps expr)
115 (with-output-to-string
116 (lambda () (ps-output-expression expr (current-output-port))))))
117 (string-append "\\embeddedps{" ps-string "}")))
120 (define (repeat-slash w a t)
121 (embedded-ps (list 'repeat-slash w a t)))
125 (define (number->dim x)
127 ;;ugh ly:* in backend needs compatibility func for standalone output
128 (ly:number->string x) " \\outputscale "))
130 (define (placebox x y s)
132 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
134 (define (bezier-sandwich l thick)
135 (embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
137 ;; WTF is this in every backend?
138 (define (horizontal-line x1 x2 th)
139 (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
141 (define (filledbox breapth width depth height)
142 (if (and #f (defined? 'ps-testing))
144 (string-append (ly:numbers->string (list breapth width depth height))
146 (string-append "\\lyvrule{"
147 (ly:number->string (- breapth)) "}{"
148 (ly:number->string (+ breapth width)) "}{"
149 (ly:number->string depth) "}{"
150 (ly:number->string height) "}")))
152 (define (round-filled-box x y width height blotdiam)
153 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
155 (define (text font s)
157 ((mapping #f) ;; (assoc-get 'char-mapping (ly:font-encoding-alist font))))
160 ;; TODO: we'd better do this for PS only
161 ;; LaTeX gets in the way, and we need to remap
162 ;; nonprintable chars.
164 (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
167 (string-append "\\hbox{\\" (tex-font-command font)
168 (if (string? input-enc-name)
169 (string-append "\\inputencoding{" input-enc-name "}")
172 (if (vector? mapping)
173 (reencode-string mapping s)
177 (define (white-text scale s)
178 (embedded-ps (list 'white-text scale s)))
180 (define (tuplet ht gapx dx dy thick dir)
181 (embedded-ps (list 'tuplet ht gapx dx dy thick dir)))
183 (define (polygon points blotdiameter)
184 (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
186 (define (draw-line thick fx fy tx ty)
187 (embedded-ps (list 'draw-line thick fx fy tx ty)))
189 ;; no-origin not yet supported by Xdvi
190 (define (no-origin) "")
192 (define (grob-cause grob)
193 (if (procedure? point-and-click)
194 (let* ((cause (ly:grob-property grob 'cause))
195 (music-origin (if (ly:music? cause)
196 (ly:music-property cause 'origin)))
197 (location (if (ly:input-location? music-origin)
198 (ly:input-location music-origin))))
201 (string-append "\\special{src:"
202 (apply point-and-click location) "}")