1 ;;;; tex.scm -- implement Scheme output routines for TeX
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@xs4all.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
44 (use-modules (ice-9 regex)
60 (string-append "\\" (tex-font-command font)
61 "\\char" (ly:inexact->string i 10) " "))
66 (define (url-link url x y)
72 (define (circle radius thick)
73 (embedded-ps (list 'circle radius thick)))
75 (define (dot x y radius)
76 (embedded-ps (list 'dot x y radius)))
78 (define (embedded-ps string)
79 (embedded-ps (list 'embedded-ps string)))
81 (define (dashed-slur thick on off lst)
82 (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
84 (define (named-glyph font name)
85 (let* ((info (ly:otf-font-glyph-info font name))
86 (subfont (assoc-get 'subfont info))
87 (subidx (assoc-get 'subfont-index info)))
89 ;;(stderr "INFO: ~S\n" info)
90 ;;(stderr "FONT: ~S\n" font)
91 (if (and subfont subidx)
92 (string-append "\\" (tex-font-command-raw
94 (ly:font-magnification font))
95 "\\char" (number->string subidx))
98 (ly:warning (_ "cannot find ~a in ~a" name font))
101 (define (dashed-line thick on off dx dy phase)
102 (embedded-ps (list 'dashed-line thick on off dx dy phase)))
104 (define (zigzag-line centre? zzw zzh thick dx dy)
105 (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
107 (define (embedded-ps expr)
109 (with-output-to-string
110 (lambda () (ps-output-expression expr (current-output-port))))))
111 (string-append "\\embeddedps{" ps-string "}")))
113 (define (repeat-slash w a t)
114 (embedded-ps (list 'repeat-slash w a t)))
116 (define (number->dim x)
118 ;;ugh ly:* in backend needs compatibility func for standalone output
119 (ly:number->string x) " \\output-scale "))
121 (define (placebox x y s)
123 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
125 (define (bezier-sandwich lst thick)
126 (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
129 (define (round-filled-box x y width height blotdiam)
130 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
132 (define (text font s)
134 "\\hbox{\\~a{}~a}" (tex-font-command font)
135 (sanitize-tex-string s)))
137 (define (setcolor r g b)
138 (string-append "\\color[rgb]{"
139 (number->string r) ", "
140 (number->string g) ", "
141 (number->string b) "}"))
144 ;; The PostScript backend saves the current color
145 ;; during setcolor and restores it during resetcolor.
146 ;; We don't do that here.
148 (string-append "\\color[rgb]{0,0,0}\n"))
150 (define (polygon points blot-diameter fill)
151 (embedded-ps (list 'polygon `(quote ,points) blot-diameter fill)))
153 (define (draw-line thick fx fy tx ty)
154 (embedded-ps (list 'draw-line thick fx fy tx ty)))
156 ;; no-origin not yet supported by Xdvi
157 (define (no-origin) "")
160 (define-public (line-location file line col)
161 "Print an input location, without column number ."
162 (string-append (number->string line) " " file))
164 (define-public point-and-click #f)
166 (define (grob-cause offset grob)
167 (define (line-column-location file line col)
168 "Print an input location, including column number ."
169 (string-append (number->string line) ":"
170 (number->string col) " " file))
172 (if (procedure? point-and-click)
173 (let* ((cause (ly:grob-property grob 'cause))
174 (music-origin (if (ly:stream-event? cause)
175 (ly:event-property cause 'origin)))
176 (location (if (ly:input-location? music-origin)
177 (ly:input-file-line-column music-origin))))
180 (string-append "\\special{src:"
181 (line-column-location location) "}")