1 ;;;; tex.scm -- implement Scheme output routines for TeX
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 ;; The public interface is tight.
10 ;; It has to be, because user-code is evalled with this module.
12 ;; ***It should also be clean, well defined, documented and reviewed***
14 ;; To be reasonably safe, you probably do not want to use the TeX
15 ;; backend anyway, but rather the PostScript backend. You may want
16 ;; to run gs in a uml sandbox too.
19 (define-module (scm output-tex)
22 ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
46 (use-modules (ice-9 regex)
62 (string-append "\\" (tex-font-command font)
63 "\\char" (ly:inexact->string i 10) " "))
68 (define (url-link url x y)
74 (define (circle radius thick)
75 (embedded-ps (list 'circle radius thick)))
77 (define (dot x y radius)
78 (embedded-ps (list 'dot x y radius)))
80 (define (embedded-ps string)
81 (embedded-ps (list 'embedded-ps string)))
83 (define (beam width slope thick blot)
84 (embedded-ps (list 'beam width slope thick blot)))
86 (define (dashed-slur thick on off lst)
87 (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
89 (define (named-glyph font name)
90 (let* ((info (ly:otf-font-glyph-info font name))
91 (subfont (assoc-get 'subfont info))
92 (subidx (assoc-get 'subfont-index info)))
94 ;;(stderr "INFO: ~S\n" info)
95 ;;(stderr "FONT: ~S\n" font)
96 (if (and subfont subidx)
97 (string-append "\\" (tex-font-command-raw
99 (ly:font-magnification font))
100 "\\char" (number->string subidx))
103 (ly:warning (_ "can't find ~a in ~a" name font))
106 (define (dashed-line thick on off dx dy)
107 (embedded-ps (list 'dashed-line thick on off dx dy)))
109 (define (zigzag-line centre? zzw zzh thick dx dy)
110 (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
112 (define (embedded-ps expr)
114 (with-output-to-string
115 (lambda () (ps-output-expression expr (current-output-port))))))
116 (string-append "\\embeddedps{" ps-string "}")))
118 (define (repeat-slash w a t)
119 (embedded-ps (list 'repeat-slash w a t)))
121 (define (number->dim x)
123 ;;ugh ly:* in backend needs compatibility func for standalone output
124 (ly:number->string x) " \\outputscale "))
126 (define (placebox x y s)
128 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
130 (define (bezier-sandwich lst thick)
131 (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
133 (define (filledbox breapth width depth height)
134 (if (and #f (defined? 'ps-testing))
136 (string-append (ly:numbers->string (list breapth width depth height))
138 (string-append "\\lyvrule{"
139 (ly:number->string (- breapth)) "}{"
140 (ly:number->string (+ breapth width)) "}{"
141 (ly:number->string depth) "}{"
142 (ly:number->string height) "}")))
144 (define (round-filled-box x y width height blotdiam)
145 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
147 (define (text font s)
149 "\\hbox{\\~a{}~a}" (tex-font-command font)
150 (sanitize-tex-string s)))
152 (define (setcolor r g b)
153 (string-append "\\color[rgb]{"
154 (number->string r) ", "
155 (number->string g) ", "
156 (number->string b) "}"))
159 ;; The PostScript backend saves the current color
160 ;; during setcolor and restores it during resetcolor.
161 ;; We don't do that here.
163 (string-append "\\color[rgb]{0,0,0}\n"))
165 (define (polygon points blotdiameter fill)
166 (embedded-ps (list 'polygon `(quote ,points) blotdiameter fill)))
168 (define (draw-line thick fx fy tx ty)
169 (embedded-ps (list 'draw-line thick fx fy tx ty)))
171 ;; no-origin not yet supported by Xdvi
172 (define (no-origin) "")
177 (define-public (line-location file line col)
178 "Print an input location, without column number ."
179 (string-append (number->string line) " " file))
181 (define-public point-and-click #f)
183 (define (grob-cause offset grob)
184 (define (line-column-location file line col)
185 "Print an input location, including column number ."
186 (string-append (number->string line) ":"
187 (number->string col) " " file))
189 (if (procedure? point-and-click)
190 (let* ((cause (ly:grob-property grob 'cause))
191 (music-origin (if (ly:music? cause)
192 (ly:music-property cause 'origin)))
193 (location (if (ly:input-location? music-origin)
194 (ly:input-file-line-column music-origin))))
197 (string-append "\\special{src:"
198 (line-column-location location) "}")