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)
67 (string-append "\\" (tex-font-command font)
68 "\\char" (ly:inexact->string i 10) " "))
78 (define (dot x y radius)
79 (embedded-ps (list 'dot x y radius)))
82 (define (embedded-ps string)
83 (embedded-ps (list 'embedded-ps string)))
85 (define (white-dot x y radius)
86 (embedded-ps (list 'white-dot x y radius)))
88 (define (beam width slope thick blot)
89 (embedded-ps (list 'beam width slope thick blot)))
91 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
92 (embedded-ps (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
94 (define (dashed-slur thick dash l)
95 (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
97 (define (named-glyph font name)
98 (let* ((info (ly:otf-font-glyph-info font name))
99 (subfont (assoc-get 'subfont info))
100 (subidx (assoc-get 'subfont-index info)))
102 ;;(stderr "INFO: ~S\n" info)
103 ;;(stderr "FONT: ~S\n" font)
104 (if (and subfont subidx)
105 (string-append "\\" (tex-font-command-raw
107 (ly:font-magnification font))
108 "\\char" (number->string subidx))
111 (ly:warn "Can't find ~a in ~a" name font)
115 (define (dashed-line thick on off dx dy)
116 (embedded-ps (list 'dashed-line thick on off dx dy)))
118 (define (zigzag-line centre? zzw zzh thick dx dy)
119 (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
121 (define (ez-ball c l b)
122 (embedded-ps (list 'ez-ball c l b)))
124 (define (embedded-ps expr)
126 (with-output-to-string
127 (lambda () (ps-output-expression expr (current-output-port))))))
128 (string-append "\\embeddedps{" ps-string "}")))
130 (define (repeat-slash w a t)
131 (embedded-ps (list 'repeat-slash w a t)))
133 (define (number->dim x)
135 ;;ugh ly:* in backend needs compatibility func for standalone output
136 (ly:number->string x) " \\outputscale "))
138 (define (placebox x y s)
140 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
142 (define (bezier-sandwich l thick)
143 (embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
145 ;; WTF is this in every backend?
146 (define (horizontal-line x1 x2 th)
147 (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
149 (define (filledbox breapth width depth height)
150 (if (and #f (defined? 'ps-testing))
152 (string-append (ly:numbers->string (list breapth width depth height))
154 (string-append "\\lyvrule{"
155 (ly:number->string (- breapth)) "}{"
156 (ly:number->string (+ breapth width)) "}{"
157 (ly:number->string depth) "}{"
158 (ly:number->string height) "}")))
160 (define (round-filled-box x y width height blotdiam)
161 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
163 (define (text font s)
165 ((mapping #f) ;; (assoc-get 'char-mapping (ly:font-encoding-alist font))))
168 ;; TODO: we'd better do this for PS only
169 ;; LaTeX gets in the way, and we need to remap
170 ;; nonprintable chars.
172 (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
175 (string-append "\\hbox{\\" (tex-font-command font)
176 (if (string? input-enc-name)
177 (string-append "\\inputencoding{" input-enc-name "}")
180 (if (vector? mapping)
181 (reencode-string mapping s)
185 (define (white-text scale s)
186 (embedded-ps (list 'white-text scale s)))
188 (define (polygon points blotdiameter)
189 (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
191 (define (draw-line thick fx fy tx ty)
192 (embedded-ps (list 'draw-line thick fx fy tx ty)))
194 ;; no-origin not yet supported by Xdvi
195 (define (no-origin) "")
197 (define (grob-cause grob)
198 (if (procedure? point-and-click)
199 (let* ((cause (ly:grob-property grob 'cause))
200 (music-origin (if (ly:music? cause)
201 (ly:music-property cause 'origin)))
202 (location (if (ly:input-location? music-origin)
203 (ly:input-location music-origin))))
206 (string-append "\\special{src:"
207 (apply point-and-click location) "}")