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
51 (use-modules (ice-9 regex)
73 (define (dot x y radius)
74 (embedded-ps (list 'dot x y radius)))
77 (define (embedded-ps string)
78 (embedded-ps (list 'embedded-ps string)))
80 (define (white-dot x y radius)
81 (embedded-ps (list 'white-dot x y radius)))
83 (define (beam width slope thick blot)
84 (embedded-ps (list 'beam width slope thick blot)))
86 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
87 (embedded-ps (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
89 (define (dashed-slur thick dash l)
90 (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
93 (define (named-glyph font name)
94 (string-append "\\" (tex-font-command font)
97 ; (digits->letters (ly:font-name font))
98 (regexp-substitute/global
100 (digits->letters name)
104 (define (dashed-line thick on off dx dy)
105 (embedded-ps (list 'dashed-line thick on off dx dy)))
107 (define (zigzag-line centre? zzw zzh thick dx dy)
108 (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
110 (define (ez-ball c l b)
111 (embedded-ps (list 'ez-ball c l b)))
115 (define (embedded-ps expr)
117 (with-output-to-string
118 (lambda () (ps-output-expression expr (current-output-port))))))
119 (string-append "\\embeddedps{" ps-string "}")))
122 (define (repeat-slash w a t)
123 (embedded-ps (list 'repeat-slash w a t)))
127 (define (number->dim x)
129 ;;ugh ly:* in backend needs compatibility func for standalone output
130 (ly:number->string x) " \\outputscale "))
132 (define (placebox x y s)
134 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
136 (define (bezier-sandwich l thick)
137 (embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
139 ;; WTF is this in every backend?
140 (define (horizontal-line x1 x2 th)
141 (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
143 (define (filledbox breapth width depth height)
144 (if (and #f (defined? 'ps-testing))
146 (string-append (ly:numbers->string (list breapth width depth height))
148 (string-append "\\lyvrule{"
149 (ly:number->string (- breapth)) "}{"
150 (ly:number->string (+ breapth width)) "}{"
151 (ly:number->string depth) "}{"
152 (ly:number->string height) "}")))
154 (define (round-filled-box x y width height blotdiam)
155 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
157 (define (text font s)
159 ((mapping #f) ;; (assoc-get 'char-mapping (ly:font-encoding-alist font))))
162 ;; TODO: we'd better do this for PS only
163 ;; LaTeX gets in the way, and we need to remap
164 ;; nonprintable chars.
166 (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
169 (string-append "\\hbox{\\" (tex-font-command font)
170 (if (string? input-enc-name)
171 (string-append "\\inputencoding{" input-enc-name "}")
174 (if (vector? mapping)
175 (reencode-string mapping s)
179 (define (white-text scale s)
180 (embedded-ps (list 'white-text scale s)))
182 (define (polygon points blotdiameter)
183 (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
185 (define (draw-line thick fx fy tx ty)
186 (embedded-ps (list 'draw-line thick fx fy tx ty)))
188 ;; no-origin not yet supported by Xdvi
189 (define (no-origin) "")
191 (define (grob-cause grob)
192 (if (procedure? point-and-click)
193 (let* ((cause (ly:grob-property grob 'cause))
194 (music-origin (if (ly:music? cause)
195 (ly:music-property cause 'origin)))
196 (location (if (ly:input-location? music-origin)
197 (ly:input-location music-origin))))
200 (string-append "\\special{src:"
201 (apply point-and-click location) "}")